To avoid problems like this, I use a dependency injection system which is initialized in the prepare method of the bolts. In my case, I use macwire (in scala), but you should be able to use spring, guice or any other di system to achieve the same.
Cheers, John On Tue, Oct 21, 2014 at 10:10 AM, Stephen Armstrong < [email protected]> wrote: > Hello all, > > I've got a few topologies running, and have unit tests for each bolt/spout > in isolation that mock out the edges of the tests (Tuples and > OutputCollectors), but I want to have a full integration test. I setup > local mode using the following function: > > public void runTopology(StormTopology topology, Config config, int > seconds) { > long end = System.currentTimeMillis() + (seconds * 1000); > LocalCluster cluster = new LocalCluster(); > cluster.submitTopology("Test topology", config, topology); > try { > while (System.currentTimeMillis() < end) { > Thread.sleep(10); > } > LOG.info("Finished run, exiting"); > } catch (InterruptedException e) { > fail("Interrupted", e); > } > cluster.killTopology("Test topology"); > try { > Thread.sleep(1000); > } catch (InterruptedException e) { > fail("Interrupted", e); > } > cluster.shutdown(); > } > > The problem arises from using EasyMock for dependencies injected into the > Bolts/Spouts, since this system serializes them. Is there a way to turn off > the serialization of the bolts for local mode, or does anyone have any > other advice? > > One obvious but really ugly hack is to store the EasyMock objects in > static variables, and have serializable proxy objects that simply pull the > mock from the static variable, but that sounds pretty hideous so I'd like > to avoid it. > > Thanks > Steve >
