use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestMpContainerLoadHandling method setUp.
@Before
public void setUp() throws Exception {
ClusterId cid = new ClusterId("TestMpContainerLoadHandling", "test" + sequence++);
dispatcher = new MockDispatcher();
StatsCollectorCoda sc = new StatsCollectorCoda(cid, new StatsCollectorFactoryCoda().getNamingStrategy());
stats = sc;
JavaSerializer<Object> serializer = new JavaSerializer<Object>();
container = new MpContainer(cid);
container.setDispatcher(dispatcher);
container.setStatCollector(sc);
container.setSerializer(serializer);
container.setPrototype(new TestMessageProcessor());
forceOutputException = false;
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestStatsCollectorCoda method testEnvPrefixFromSystemProperty.
@Test
public void testEnvPrefixFromSystemProperty() throws Throwable {
tearDown();
System.setProperty(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName, "Hello.");
setUp();
StatsCollectorFactoryCoda.MetricNamingStrategy strategy = statsCollectorFactory.getNamingStrategy();
ClusterId clusterId = new ClusterId("app", "cluster");
MetricName name = strategy.createName(clusterId, "metric");
assertEquals("metric", name.getName());
assertEquals("app-cluster", name.getGroup());
assertTrue(strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("Hello."));
// make sure setting the environment prefix doesn't effect the -D option
statsCollectorFactory.setEnvironmentPrefix("otherEnvPrefix");
assertTrue(strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("Hello."));
// make sure that without the system property the setEnvironmentPrefix value works
System.getProperties().remove(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName);
assertTrue(strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("otherEnvPrefix"));
// make sure that delting the environmentPrefix doesn't create an issue.
statsCollectorFactory.setEnvironmentPrefix(null);
strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("otherEnvPrefix");
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method testExpandingAndContractingKeySpace.
@Test
public void testExpandingAndContractingKeySpace() 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();
// This will wait until the keySpace is up to the maxcount which is set (in the setup, below) to 100000
assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {
@Override
public boolean conditionMet(MetricGetters sc) {
return 100000 == sc.getMessageProcessorCount();
}
}));
// 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();
session = TestUtils.stealShard(originalSession, factory, clusterId.asPath() + "/" + String.valueOf(0), baseTimeoutMillis);
// If we got here then the MpContainer is on standby and the number of Mps should
// drop 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());
// this should give control back over to the original session.
session.stop();
session = null;
// If we got here then the MpContainer is no longer on standby and the number of Mps should
// go back to the original amount.
assertTrue(poll(baseTimeoutMillis, statsCollector, new Condition<MetricGetters>() {
@Override
public boolean conditionMet(MetricGetters sc) {
return 100000 == sc.getMessageProcessorCount();
}
}));
Thread.sleep(10);
assertEquals(100000, statsCollector.getMessageProcessorCount());
} finally {
if (session != null)
session.stop();
}
}
public String toString() {
return "testExpandingAndContractingKeySpace";
}
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 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.config.ClusterId in project Dempsy by Dempsy.
the class TestUtils method getStatsCollector.
public static StatsCollector getStatsCollector(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.statsCollector;
}
Aggregations