use of com.nokia.dempsy.Dempsy.Application.Cluster.Node in project Dempsy by Dempsy.
the class TestDempsy method runMpKeyStoreTest.
public void runMpKeyStoreTest(final String methodName, final boolean disruptSession) throws Throwable {
Checker checker = new Checker() {
@Override
public void check(ApplicationContext context) throws Throwable {
// start things and verify that the init method was called
Dempsy dempsy = (Dempsy) context.getBean("dempsy");
TestMp mp = (TestMp) getMp(dempsy, "test-app", "test-cluster1");
// verify we haven't called it again, not that there's really
// a way to given the code
assertEquals(1, mp.startCalls.get());
// wait for clone calls to reach at least 2
assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {
@Override
public boolean conditionMet(TestMp mp) {
return mp.cloneCalls.get() == 2;
}
}));
final TestAdaptor adaptor = (TestAdaptor) context.getBean("adaptor");
// if the session has been disrupted then this may take some time to work again.
// wait until it works again.
assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {
@Override
public boolean conditionMet(TestMp mp) throws Throwable {
// this causes the container to clone the Mp
adaptor.pushMessage(new TestMessage("output"));
// wait for it to be received.
Thread.sleep(100);
// this will not go past 3 as long as the same TestMessage is sent.
return mp.cloneCalls.get() == 3;
}
}));
// this WONT causes the container to clone the Mp because test1 was already pre-instantiated.
adaptor.pushMessage(new TestMessage("test1"));
// give it a little time.
Thread.sleep(100);
// wait for it to be received.
assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {
@Override
public boolean conditionMet(TestMp mp) {
return mp.cloneCalls.get() == 3;
}
}));
List<Node> nodes = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes();
Assert.assertNotNull(nodes);
Assert.assertTrue(nodes.size() > 0);
Node node = nodes.get(0);
Assert.assertNotNull(node);
double duration = ((MetricGetters) node.getStatsCollector()).getPreInstantiationDuration();
Assert.assertTrue(duration > 0.0);
}
public String toString() {
return methodName;
}
@Override
public void setup() {
KeySourceImpl.disruptSession = disruptSession;
}
};
runAllCombinations("SinglestageWithKeyStoreApplicationActx.xml", checker);
runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
use of com.nokia.dempsy.Dempsy.Application.Cluster.Node in project Dempsy by Dempsy.
the class TestDempsy method testOverlappingKeyStoreCalls.
@Test
public void testOverlappingKeyStoreCalls() throws Throwable {
Checker checker = new Checker() {
@Override
public void check(ApplicationContext context) throws Throwable {
// wait until the KeySourceImpl has been created
assertTrue(poll(baseTimeoutMillis, null, new Condition<Object>() {
@Override
public boolean conditionMet(Object mp) {
return KeySourceImpl.lastCreated != null;
}
}));
final KeySourceImpl.KSIterable firstCreated = KeySourceImpl.lastCreated;
// start things and verify that the init method was called
Dempsy dempsy = (Dempsy) context.getBean("dempsy");
TestMp mp = (TestMp) getMp(dempsy, "test-app", "test-cluster1");
Dempsy.Application.Cluster c = dempsy.getCluster(new ClusterId("test-app", "test-cluster1"));
assertNotNull(c);
Dempsy.Application.Cluster.Node node = c.getNodes().get(0);
assertNotNull(node);
MpContainer container = node.getMpContainer();
// let it go and wait until there's a few keys.
firstCreated.m_pause.countDown();
// as the KeySource iterates, this will increase
assertTrue(poll(baseTimeoutMillis, mp, new Condition<TestMp>() {
@Override
public boolean conditionMet(TestMp mp) {
return mp.cloneCalls.get() > 10000;
}
}));
// prepare the next countdown latch
// just let the 2nd one go
KeySourceImpl.pause = new CountDownLatch(0);
// I want the next one to stop at 2
KeySourceImpl.infinite = false;
// Now force another call while the first is running
container.keyspaceResponsibilityChanged(node.strategyInbound, false, true);
// wait until the second one is created
assertTrue(poll(baseTimeoutMillis, null, new Condition<Object>() {
@Override
public boolean conditionMet(Object mp) {
return KeySourceImpl.lastCreated != null && firstCreated != KeySourceImpl.lastCreated;
}
}));
// now the first one should be done and therefore no longer incrementing.
String lastKeyOfFirstCreated = firstCreated.lastKey;
// and the second one should be done also and stopped at 2.
final KeySourceImpl.KSIterable secondCreated = KeySourceImpl.lastCreated;
assertTrue(firstCreated != secondCreated);
assertTrue(poll(baseTimeoutMillis, null, new Condition<Object>() {
@Override
public boolean conditionMet(Object mp) {
return "test2".equals(secondCreated.lastKey);
}
}));
Thread.sleep(50);
// make sure the first one isn't still moving on
assertEquals(lastKeyOfFirstCreated, firstCreated.lastKey);
assertEquals("test2", secondCreated.lastKey);
// prepare for the next run
KeySourceImpl.pause = new CountDownLatch(1);
KeySourceImpl.infinite = true;
KeySourceImpl.lastCreated = null;
}
public String toString() {
return "testOverlappingKeyStoreCalls";
}
public void setup() {
KeySourceImpl.pause = new CountDownLatch(1);
KeySourceImpl.infinite = true;
KeySourceImpl.lastCreated = null;
}
};
runAllCombinations("SinglestageWithKeyStoreApplicationActx.xml", checker);
runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
use of com.nokia.dempsy.Dempsy.Application.Cluster.Node in project Dempsy by Dempsy.
the class TestDempsy method getMp.
private static Object getMp(Dempsy dempsy, String appName, String clusterName) {
Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId(appName, clusterName));
// currently there is one node per cluster.
Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0);
return node.clusterDefinition.getMessageProcessorPrototype();
}
use of com.nokia.dempsy.Dempsy.Application.Cluster.Node in project Dempsy by Dempsy.
the class TestDempsy method getAdaptor.
private static Adaptor getAdaptor(Dempsy dempsy, String appName, String clusterName) {
Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId(appName, clusterName));
// currently there is one node per cluster.
Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0);
return node.clusterDefinition.getAdaptor();
}
Aggregations