use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.
the class TcpTransportTest method transportMultipleConnectionsFailedClient.
/**
* This test checks the various behaviors of a tcp transport when the
* client is disrupted at the 5th byte. Multiple senders are started from
* multiple threads and ONLY ONE fails at the 5th byte. All senders should
* be able to continue on when that happens and so the message counts should
* increase.
*/
@Test
public void transportMultipleConnectionsFailedClient() throws Throwable {
runAllCombinations(new Checker() {
@Override
public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
SenderFactory factory = null;
TcpReceiver adaptor = null;
BasicStatsCollector statsCollector = new BasicStatsCollector();
try {
//===========================================
// setup the sender and receiver
adaptor = new TcpReceiver(null, getFailFast());
adaptor.setStatsCollector(statsCollector);
// distruptible sender factory
factory = makeSenderFactory(true, statsCollector, batchOutgoingMessagesDelayMillis);
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
//===========================================
// start the adaptor
adaptor.start();
// get the destination
Destination destination = adaptor.getDestination();
//===========================================
// Start up sender threads and save the off
ArrayList<Thread> threadsToJoinOn = new ArrayList<Thread>();
SenderRunnable[] senders = new SenderRunnable[numThreads];
for (int i = 0; i < numThreads; i++) threadsToJoinOn.add(i, new Thread(senders[i] = new SenderRunnable(destination, i, factory), "Test Sender for " + i));
for (Thread thread : threadsToJoinOn) thread.start();
//===========================================
//===========================================
// check that one sender has failed since this is disruptable.
assertTrue(TestUtils.poll(baseTimeoutMillis, statsCollector, new TestUtils.Condition<BasicStatsCollector>() {
@Override
public boolean conditionMet(BasicStatsCollector o) throws Throwable {
return o.getMessagesNotSentCount() > 0;
}
}));
//===========================================
//===========================================
// check that ONLY one failed (the others didn't) when we're not batching. Otherwise
// more may fail.
Thread.sleep(10);
if (// if we're batching then we only expect a failure but we don't know how many
batchOutgoingMessagesDelayMillis >= 0)
assertTrue(statsCollector.getMessagesNotSentCount() > 0);
else
assertEquals(1, statsCollector.getMessagesNotSentCount());
//===========================================
// all of the counts should increase.
long[] curCounts = new long[numThreads];
int i = 0;
for (SenderRunnable sender : senders) curCounts[i++] = sender.sentMessageCount.get();
// ==========================================
// go until they are all higher. The Senders should still be running
// and sending successfully (only one failed once) so all counts should
// be increasing.
boolean allHigher = false;
for (long endTime = System.currentTimeMillis() + numThreads * (baseTimeoutMillis); endTime > System.currentTimeMillis() && !allHigher; ) {
allHigher = true;
Thread.sleep(1);
i = 0;
for (SenderRunnable sender : senders) if (curCounts[i++] >= sender.sentMessageCount.get())
allHigher = false;
}
assertTrue(allHigher);
// Stop the senders.
for (SenderRunnable sender : senders) sender.keepGoing.set(false);
// wait until all threads are stopped
for (Thread t : threadsToJoinOn) t.join(5000);
// make sure everything actually stopped.
for (SenderRunnable sender : senders) assertTrue(sender.isStopped.get());
// ==========================================
} finally {
if (factory != null)
factory.stop();
if (adaptor != null)
adaptor.stop();
}
}
@Override
public String toString() {
return "transportMultipleConnectionsFailedClient";
}
});
}
use of com.nokia.dempsy.messagetransport.Destination 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();
}
Aggregations