use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.
the class TcpTransportTest method testReceiverStart.
@Test
public void testReceiverStart() throws Exception {
final AtomicBoolean resolverCalled = new AtomicBoolean(false);
try (ServiceTracker tr = new ServiceTracker()) {
final AbstractTcpReceiver<?, ?> r = tr.track(receiver.get()).resolver(a -> {
resolverCalled.set(true);
return a;
}).numHandlers(2).useLocalHost(true);
final Infrastructure infra = tr.track(new TestInfrastructure(new DefaultThreadingModel(TcpTransportTest.class.getSimpleName() + ".testReceiverStart")));
final TcpAddress addr = r.getAddress(infra);
LOGGER.debug(addr.toString());
r.start(null, infra);
assertTrue(resolverCalled.get());
}
}
use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.
the class TcpTransportTest method testLargeMessage.
@Test
public void testLargeMessage() throws Exception {
final String huge = TestWordCount.readBible();
try (final ServiceTracker tr = new ServiceTracker()) {
final AbstractTcpReceiver<?, ?> r = tr.track(receiver.get()).numHandlers(2).useLocalHost(true).maxMessageSize(1024 * 1024 * 1024);
final ThreadingModel tm = tr.track(new DefaultThreadingModel(TcpTransportTest.class.getSimpleName() + ".testLargeMessage"));
final Infrastructure infra = tr.track(new TestInfrastructure(tm));
final TcpAddress addr = r.getAddress(infra);
LOGGER.debug(addr.toString());
final AtomicReference<RoutedMessage> rm = new AtomicReference<>(null);
r.start((Listener<RoutedMessage>) msg -> {
rm.set(msg);
return true;
}, infra);
try (final SenderFactory sf = senderFactory.get()) {
sf.start(new TestInfrastructure(null, null));
final Sender sender = sf.getSender(addr);
sender.send(new RoutedMessage(new int[] { 0 }, "Hello", huge));
assertTrue(poll(o -> rm.get() != null));
assertEquals(huge, rm.get().message);
}
}
}
use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.
the class BlockingQueueTest method testBlockingQueue.
/*
* Test basic functionality for the BlockingQueue implementation of Message Transport. Verify that messages sent to the Sender arrive at the receiver via
* handleMessage.
*/
@Test
public void testBlockingQueue() throws Exception {
final AtomicReference<String> message = new AtomicReference<String>(null);
final ArrayBlockingQueue<Object> input = new ArrayBlockingQueue<>(16);
try (final Receiver r = new BlockingQueueReceiver(input);
final TestInfrastructure infra = new TestInfrastructure(new DefaultThreadingModel("BQTest-testBlockingQueue-"));
final TransportManager tranMan = chain(new TransportManager(), c -> c.start(infra));
SenderFactory sf = tranMan.getAssociatedInstance(transportTypeId)) {
final Sender sender = sf.getSender(r.getAddress(infra));
r.start((final String msg) -> {
message.set(new String(msg));
return true;
}, infra);
sender.send("Hello");
assertTrue(poll(o -> "Hello".equals(message.get())));
}
}
use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.
the class TestInstanceManager method setupContainer.
@SuppressWarnings("resource")
public LockingContainer setupContainer(final MessageProcessorLifecycle<?> prototype) throws ContainerException {
dispatcher = new DummyDispatcher();
statsCollector = new BasicClusterStatsCollector();
nodeStats = new BasicNodeStatsCollector();
container = (LockingContainer) new LockingContainer().setMessageProcessor(prototype).setClusterId(new ClusterId("test", "test"));
container.setDispatcher(dispatcher);
container.setInbound(new DummyInbound());
tm = new DefaultThreadingModel(TestInstanceManager.class.getName());
tm.start(TestInstanceManager.class.getName());
container.start(new TestInfrastructure(tm) {
@Override
public BasicClusterStatsCollector getClusterStatsCollector(final ClusterId clusterId) {
return statsCollector;
}
@Override
public NodeStatsCollector getNodeStatsCollector() {
return nodeStats;
}
});
return container;
}
use of net.dempsy.util.TestInfrastructure in project Dempsy by Dempsy.
the class TestOutputSchedulers method testRelativeSchedule.
/**
* Test relative schedule.
*
* @throws Exception the exception
*/
@Test
public void testRelativeSchedule() throws Exception {
try (final RelativeOutputSchedule relativeOutputSchedule = new RelativeOutputSchedule(1, TimeUnit.SECONDS)) {
relativeOutputSchedule.setOutputInvoker(container);
relativeOutputSchedule.start(new TestInfrastructure(null));
assertTrue(poll(outputInvoked, oi -> oi.get()));
}
}
Aggregations