use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestMpContainer method testConfiguration.
//----------------------------------------------------------------------------
// Test Cases
//----------------------------------------------------------------------------
@Test
public void testConfiguration() throws Exception {
// this assertion is superfluous, since we deref container in setUp()
assertNotNull("did not create container", container);
assertEquals(new ClusterId("test", "test"), container.getClusterId());
TestProcessor prototype = context.getBean(TestProcessor.class);
assertEquals(1, prototype.startCalled.get());
assertNotNull(prototype.clusterId);
}
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 Router method initialize.
/**
* Prior to the {@link Router} being used it needs to be initialized.
*/
public void initialize() throws ClusterInfoException, DempsyException {
// applicationDefinition cannot be null because the constructor checks
// put all of the cluster definitions into a map for easy lookup
Map<ClusterId, ClusterDefinition> defs = new HashMap<ClusterId, ClusterDefinition>();
for (ClusterDefinition clusterDef : applicationDefinition.getClusterDefinitions()) defs.put(clusterDef.getClusterId(), clusterDef);
// now see about the one that we are.
ClusterDefinition currentClusterDef = null;
if (currentCluster != null) {
currentClusterDef = defs.get(currentCluster);
if (currentClusterDef == null)
throw new DempsyException("This Dempsy instance seems to be misconfigured. While this VM thinks it's an instance of " + currentCluster + " the application it's configured with doesn't contain this cluster definition. The application configuration consists of: " + applicationDefinition);
}
// get the set of explicit destinations if they exist
Set<ClusterId> explicitClusterDestinations = (currentClusterDef != null && currentClusterDef.hasExplicitDestinations()) ? new HashSet<ClusterId>() : null;
if (explicitClusterDestinations != null)
explicitClusterDestinations.addAll(Arrays.asList(currentClusterDef.getDestinations()));
// then those are the only ones we want to consider
for (ClusterDefinition clusterDef : applicationDefinition.getClusterDefinitions()) {
if ((explicitClusterDestinations == null || explicitClusterDestinations.contains(clusterDef.getClusterId())) && !clusterDef.isRouteAdaptorType()) {
RoutingStrategy strategy = (RoutingStrategy) clusterDef.getRoutingStrategy();
ClusterId clusterId = clusterDef.getClusterId();
if (strategy == null)
throw new DempsyException("Could not retrieve the routing strategy for " + SafeString.valueOf(clusterId));
// This create will result in a callback on the Router as the Outbound.Coordinator with a
// registration event. The Outbound may (will) call back on the Router to retrieve the
// MpClusterSession and register itself with the appropriate cluster.
outbounds.add(strategy.createOutbound(this, mpClusterSession, clusterId));
}
}
//-------------------------------------------------------------------------------------
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestDempsy method testForkedFailure.
@Test
public void testForkedFailure() throws Throwable {
runAllCombinations("SimpleMultistageApplicationActx.xml", new Checker() {
@Override
public void check(ApplicationContext context) throws Throwable {
final AtomicBoolean stopIt = new AtomicBoolean(false);
final AtomicBoolean failed = new AtomicBoolean(false);
final AtomicBoolean stopped = new AtomicBoolean(false);
try {
// start things and verify that the init method was called
Dempsy dempsy = (Dempsy) context.getBean("dempsy");
final TestAdaptor adaptor = (TestAdaptor) getAdaptor(dempsy, "test-app", "test-cluster0");
assertNotNull(adaptor);
Thread adaptorThread = new Thread(new Runnable() {
@Override
public void run() {
try {
long i = 0;
while (!stopIt.get()) {
adaptor.pushMessage(new TestMessage("" + i));
i++;
Thread.sleep(10);
}
} catch (Throwable th) {
failed.set(true);
} finally {
stopped.set(true);
}
}
}, "testForkedFailure-Adaptor Thread ");
adaptorThread.start();
TestMp[] mps = new TestMp[3];
DisruptibleSession[] sessions = new DisruptibleSession[3];
for (int i = 0; i < mps.length; i++) {
String cluster = "test-cluster" + (i + 1);
mps[i] = (TestMp) getMp(dempsy, "test-app", cluster);
sessions[i] = (DisruptibleSession) (dempsy.getCluster(new ClusterId("test-app", cluster)).getNodes().get(0).retouRteg().getClusterSession());
assertEquals(1, mps[i].startCalls.get());
}
for (int i = 0; i < mps.length; i++) {
for (int j = 0; j < mps.length; j++) {
if (i != j)
assertTrue(mps[i] != mps[j]);
}
}
// now check to see that data is going to all 3.
for (int i = 0; i < mps.length; i++) {
assertTrue(poll(baseTimeoutMillis, mps[i], new Condition<TestMp>() {
public boolean conditionMet(TestMp o) {
return o.handleCalls.get() > 0;
}
}));
}
int curPos = 0;
for (int j = 0; j < 3; j++) {
// now kill a cluster or 2 (or 3)
for (int k = 0; k <= j; k++) sessions[curPos++ % sessions.length].disrupt();
for (int i = 0; i < mps.length; i++) {
final long curCalls = mps[i].handleCalls.get();
assertTrue(poll(baseTimeoutMillis, mps[i], new Condition<TestMp>() {
public boolean conditionMet(TestMp o) {
return o.handleCalls.get() > curCalls;
}
}));
}
}
} finally {
stopIt.set(true);
assertFalse(failed.get());
assertTrue(poll(baseTimeoutMillis, stopped, new Condition<AtomicBoolean>() {
public boolean conditionMet(AtomicBoolean o) {
return o.get();
}
}));
}
}
public String toString() {
return "testForkedFailure";
}
});
}
Aggregations