use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class Router method registerOutbound.
@Override
public void registerOutbound(RoutingStrategy.Outbound outbound, Collection<Class<?>> classes) {
synchronized (outbound) {
unregisterOutbound(outbound);
ClusterId clusterId = outbound.getClusterId();
if (classes != null && classes.size() > 0) {
// find the appropriate ClusterDefinition
ClusterDefinition curClusterDef = applicationDefinition.getClusterDefinition(clusterId);
if (curClusterDef != null) {
// create a corresponding ClusterRouter
@SuppressWarnings("unchecked") ClusterRouter clusterRouter = new ClusterRouter((Serializer<Object>) curClusterDef.getSerializer(), outbound);
for (Class<?> clazz : classes) {
// potential
Set<ClusterRouter> cur = Collections.newSetFromMap(new ConcurrentHashMap<ClusterRouter, Boolean>());
Set<ClusterRouter> tmp = routerMap.putIfAbsent(clazz, cur);
if (tmp != null)
cur = tmp;
cur.add(clusterRouter);
}
} else {
logger.error("Couldn't find the ClusterDefinition for " + clusterId + " while registering the Outbound " + SafeString.objectDescription(outbound) + " given the ApplicationDefinition " + applicationDefinition);
}
}
}
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method testFailedMessageHandlingWithKeyStore.
@Test
public void testFailedMessageHandlingWithKeyStore() throws Throwable {
final AtomicBoolean currentActivateCheckedException = new AtomicBoolean(false);
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());
// 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");
// this causes the container to clone the Mp
adaptor.pushMessage(new TestMessage("test1"));
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);
}
public String toString() {
return "testFailedMessageHandlingWithKeyStore";
}
public void setup() {
KeySourceImpl.pause = new CountDownLatch(1);
TestMp.activateCheckedException = currentActivateCheckedException.get();
}
};
// make sure both exceptions are handled since the logic in the container
// actually varies depending on whether or not the exception is checked or not.
currentActivateCheckedException.set(true);
runAllCombinations("SinglestageWithKeyStoreApplicationActx.xml", checker);
currentActivateCheckedException.set(false);
runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
use of com.nokia.dempsy.config.ClusterId 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.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method testFailedClusterManagerDuringKeyStoreCalls.
@Test
public void testFailedClusterManagerDuringKeyStoreCalls() throws Throwable {
Checker checker = new Checker() {
@Override
public void check(ApplicationContext context) throws Throwable {
ClusterInfoSession session = null;
try {
// 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");
final ClusterId clusterId = new ClusterId("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());
// make sure that there are no Mps
MetricGetters statsCollector = (MetricGetters) dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes().get(0).getStatsCollector();
assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {
@Override
public boolean conditionMet(MetricGetters sc) {
return 100000 == sc.getMessageProcessorCount();
}
}));
// now there's 100000 mps in the container created from the KeySource. So we steal the
// shard and force if offline but continuously disrupt it while it tries to come
// back up.
// now push the cluster into backup node.
ClusterInfoSession originalSession = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")).getNodes().get(0).retouRteg().getClusterSession();
ClusterInfoSessionFactory factory = dempsy.getClusterSessionFactory();
String path = clusterId.asPath() + "/" + String.valueOf(0);
session = TestUtils.stealShard(originalSession, factory, path, baseTimeoutMillis);
DefaultRouterSlotInfo si = (DefaultRouterSlotInfo) session.getData(path, null);
// checks to see who actually has the slot.
assertTrue(si.getDestination() instanceof JunkDestination);
// we will keep disrupting the session but we should still end up with zero mps.
for (int i = 0; i < 100; i++) {
((DisruptibleSession) originalSession).disrupt();
Thread.sleep(1);
}
// now wait until we get to zero.
assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {
@Override
public boolean conditionMet(MetricGetters sc) {
return 0 == sc.getMessageProcessorCount();
}
}));
Thread.sleep(10);
assertEquals(0, statsCollector.getMessageProcessorCount());
// ok. Now we will close the session that's holding the shard and allow the container
// to re-establish control of that shard. During the KeyStore reinstantiation of the
// MPs we will be disrupting the session.
session.stop();
for (int i = 0; i < 100; i++) {
((DisruptibleSession) originalSession).disrupt();
Thread.sleep(1);
}
// Now we should get back to 100000 Mps.
poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {
@Override
public boolean conditionMet(MetricGetters sc) {
return 100000 == sc.getMessageProcessorCount();
}
});
assertEquals(100000, statsCollector.getMessageProcessorCount());
} finally {
if (session != null)
session.stop();
}
}
public String toString() {
return "testFailedClusterManagerDuringKeyStoreCalls";
}
public void setup() {
KeySourceImpl.maxcount = 100000;
System.setProperty("min_nodes_for_cluster", "1");
System.setProperty("total_slots_for_cluster", "1");
}
};
runAllCombinations("SinglestageWithKeyStoreAndExecutorApplicationActx.xml", checker);
}
use of com.nokia.dempsy.config.ClusterId 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();
}
Aggregations