use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TcpTransportTest method testTransportInstantiation.
/**
* Just send a simple message and make sure it gets through.
*/
@Test
public void testTransportInstantiation() throws Throwable {
final AtomicBoolean batchedAtLeastOnce = new AtomicBoolean(false);
runAllCombinations(new Checker() {
@Override
public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination() {
});
SenderFactory factory = null;
TcpReceiver adaptor = null;
try {
boolean shouldBatch = batchOutgoingMessagesDelayMillis >= 0;
if (shouldBatch)
batchedAtLeastOnce.set(true);
TcpTransport transport = new TcpTransport();
transport.setFailFast(getFailFast());
// by default batching isn't disabled.
assertFalse(transport.isBatchingDisabled());
if (!shouldBatch)
transport.setDisableBatching(true);
if (!shouldBatch)
assertTrue(transport.isBatchingDisabled());
assertEquals(!shouldBatch, transport.isBatchingDisabled());
//===========================================
// setup the sender and receiver
adaptor = (TcpReceiver) transport.createInbound(null);
adaptor.setStatsCollector(statsCollector);
StringListener receiver = new StringListener();
adaptor.setListener(receiver);
factory = transport.createOutbound(null, statsCollector);
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
//===========================================
// start the adaptor
adaptor.start();
// get the destination
Destination destination = adaptor.getDestination();
// send a message
byte[] messageBytes = "Hello".getBytes();
Sender sender = factory.getSender(destination);
assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender) sender).getBatchOutgoingMessagesDelayMillis());
sender.send(messageBytes);
sender.send(messageBytes);
// wait for it to be received.
for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2; ) Thread.sleep(1);
assertEquals(2, receiver.numMessages.get());
// verify everything came over ok.
assertEquals(1, receiver.receivedStringMessages.size());
assertEquals("Hello", receiver.receivedStringMessages.iterator().next());
if (shouldBatch) {
// verify the histogram
Histogram histogram = ((TcpSender) sender).getBatchingHistogram();
assertEquals(calcMean(2), histogram.mean(), 0.0000001);
assertEquals(1, histogram.count());
}
} finally {
if (factory != null)
factory.stop();
if (adaptor != null)
adaptor.stop();
}
}
@Override
public String toString() {
return "testTransportInstantiation";
}
});
assertTrue(batchedAtLeastOnce.get());
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestRouterClusterManagement method testChangingClusterInfo.
@Test
public void testChangingClusterInfo() throws Throwable {
// check that the message didn't go through.
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("testDempsy/Dempsy.xml", "testDempsy/ClusterInfo-LocalActx.xml", "testDempsy/Serializer-KryoActx.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml");
Dempsy dempsy = (Dempsy) context.getBean("dempsy");
ClusterInfoSessionFactory factory = dempsy.getClusterSessionFactory();
ClusterInfoSession session = factory.createSession();
ClusterId curCluster = new ClusterId("test-app", "test-cluster1");
TestUtils.createClusterLevel(curCluster, session);
session.setData(curCluster.asPath(), new DecentralizedRoutingStrategy.DefaultRouterClusterInfo(20, 2));
session.stop();
dempsy.stop();
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestRouterClusterManagement method init.
@Before
public void init() throws Throwable {
onodes = System.setProperty("min_nodes_for_cluster", "1");
oslots = System.setProperty("total_slots_for_cluster", "20");
final ClusterId clusterId = new ClusterId("test", "test-slot");
Destination destination = new Destination() {
};
ApplicationDefinition app = new ApplicationDefinition(clusterId.getApplicationName());
DecentralizedRoutingStrategy strategy = new DecentralizedRoutingStrategy(1, 1);
app.setRoutingStrategy(strategy);
app.setSerializer(new JavaSerializer<Object>());
ClusterDefinition cd = new ClusterDefinition(clusterId.getMpClusterName());
cd.setMessageProcessorPrototype(new GoodTestMp());
app.add(cd);
app.initialize();
LocalClusterSessionFactory mpfactory = new LocalClusterSessionFactory();
ClusterInfoSession session = mpfactory.createSession();
TestUtils.createClusterLevel(clusterId, session);
// fake the inbound side setup
inbound = strategy.createInbound(session, clusterId, new Dempsy() {
public List<Class<?>> gm(ClusterDefinition clusterDef) {
return super.getAcceptedMessages(clusterDef);
}
}.gm(cd), destination, new RoutingStrategy.Inbound.KeyspaceResponsibilityChangeListener() {
@Override
public void keyspaceResponsibilityChanged(Inbound inbound, boolean less, boolean more) {
}
});
routerFactory = new Router(app);
routerFactory.setClusterSession(session);
routerFactory.setCurrentCluster(clusterId);
routerFactory.initialize();
}
use of com.nokia.dempsy.config.ClusterId in project Dempsy by Dempsy.
the class TestRouterClusterManagement method testGetRouterFound.
@Test
public void testGetRouterFound() {
Set<ClusterRouter> routers = routerFactory.getRouter(java.lang.Exception.class);
Assert.assertNotNull(routers);
Assert.assertEquals(false, routerFactory.missingMsgTypes.containsKey(java.lang.Exception.class));
Set<ClusterRouter> routers1 = routerFactory.getRouter(ClassNotFoundException.class);
Assert.assertEquals(routers, routers1);
Assert.assertEquals(new ClusterId("test", "test-slot"), routerFactory.getThisClusterId());
}
Aggregations