// verify we haven't called it again, not that there's really
// a way to given the code
assertEquals(1, mp.startCalls.get());
// make sure that there are no Mps
MetricGetters statsCollector = (MetricGetters)dempsy.getCluster(new ClusterId("test-app","test-cluster1")).getNodes().get(0).getStatsCollector();
Thread.sleep(10);
assertEquals(0,statsCollector.getMessageProcessorsCreated());
mp.failActivation.set("test1");
TestAdaptor adaptor = (TestAdaptor)context.getBean("adaptor");
adaptor.pushMessage(new TestMessage("test1")); // this causes the container to clone the Mp
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.cloneCalls.get()==1; } }));
Thread.sleep(100);
assertEquals(0,statsCollector.getMessageProcessorsCreated());
mp.failActivation.set(null);
KeySourceImpl.pause.countDown();
// instead of the latch we are going to poll for the correct result
// wait for it to be received.
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.cloneCalls.get()==3; } }));
assertTrue(poll(baseTimeoutMillis,statsCollector,new Condition<MetricGetters>() { @Override public boolean conditionMet(MetricGetters mg) { return mg.getMessageProcessorsCreated()==2; } }));
adaptor.pushMessage(new TestMessage("test1"));
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.handleCalls.get()==1; } }));
adaptor.pushMessage(new TestMessage("test2"));
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.handleCalls.get()==2; } }));
adaptor.pushMessage(new TestMessage("test1"));
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.handleCalls.get()==3; } }));
adaptor.pushMessage(new TestMessage("test2"));
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.handleCalls.get()==4; } }));
adaptor.pushMessage(new TestMessage("test1"));
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.handleCalls.get()==5; } }));
adaptor.pushMessage(new TestMessage("test2"));
// instead of the latch we are going to poll for the correct result
// wait for it to be received.
assertTrue(poll(baseTimeoutMillis,mp,new Condition<TestMp>() { @Override public boolean conditionMet(TestMp mp) { return mp.handleCalls.get()==6; } }));
Thread.sleep(100);
assertEquals(6,mp.handleCalls.get());
assertEquals(3,mp.cloneCalls.get());
assertEquals(2,statsCollector.getMessageProcessorsCreated());
// prepare for the next run
KeySourceImpl.pause = new CountDownLatch(1);
}