new MessageRouter(map, sinks, jsonMapper),
config,
jsonMapper
);
ThriftServer server = new ThriftServer(config, msgProcessor);
server.start();
SuroClient client = createSuroClient(server.getPort());
Thread t = createClientThread(jsonMapper, client, TOPIC_NAME);
// checking the traffic goes
for (int i = 0; i < 10; ++i) {
if (client.getSentMessageCount() > 0) {
break;
}
Thread.sleep(1000);
}
assertTrue(client.getSentMessageCount() > 0);
// shutting down the traffic
hasEnoughSpace = false;
int count = 0;
while (count < 3) {
if (msgProcessor.getStatus() == ServiceStatus.WARNING) {
++count;
}
}
assertEquals(count, 3);
client.shutdown();
run.set(false);
t.join();
// resuming the traffic
hasEnoughSpace = true;
run.set(true);
SuroClient newClient = createSuroClient(server.getPort());
t = createClientThread(jsonMapper, newClient, TOPIC_NAME);
for (int i = 0; i < 10; ++i) {
if (client.getSentMessageCount() > 0) {
break;
}
Thread.sleep(1000);
}
assertTrue(client.getSentMessageCount() > 0);
run.set(false);
t.join();
client.shutdown();
server.shutdown();
sink.close();
assertEquals(sink.getNumOfPendingMessages(), 0);
}