use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class RoboHttpPingPongTest method runPongServer.
public void runPongServer() throws Exception {
RoboContext system = configurePongSystem(0);
system.start();
System.out.println("systemPong: State after start:");
System.out.println(SystemUtil.printStateReport(system));
System.out.println("Press <Enter>...");
System.in.read();
system.shutdown();
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class HttpServerUnitTests method httpServerUnitNoCodecsPackageTest.
@Test
void httpServerUnitNoCodecsPackageTest() throws Exception {
Throwable exception = assertThrows(RoboBuilderException.class, () -> {
RoboBuilder builder = new RoboBuilder();
Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).build();
builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
RoboContext system = builder.build();
system.start();
System.out.println("system: State after start:");
System.out.println(SystemUtil.printStateReport(system));
RoboReference<HttpServerUnit> systemReference = system.getReference(ID_HTTP_SERVER);
system.shutdown();
System.out.println("system: State after shutdown:");
System.out.println(SystemUtil.printStateReport(system));
assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
});
assertEquals("Error initializing RoboUnit", exception.getMessage());
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class RemoteContextTests method messageToDiscoveredContextAndReferenceToDiscoveredContextTest.
@Test
@SuppressWarnings("unchecked")
void messageToDiscoveredContextAndReferenceToDiscoveredContextTest() throws Exception {
RoboContext receiverSystem = buildRemoteReceiverContext(ACK_CONSUMER);
receiverSystem.start();
RoboReference<TestMessageType> ackConsumer = receiverSystem.getReference(ACK_CONSUMER);
// Note that all this cludging about with local lookup service
// implementations etc would normally not be needed.
// This is just to isolate this test from other tests.
final LocalLookupServiceImpl localLookup = new LocalLookupServiceImpl();
final LookupService service = LookupServiceTests.getLookupService(localLookup);
LookupServiceProvider.setDefaultLookupService(service);
service.start();
// context has been discovered
RoboContextDescriptor contextDescriptor = getRoboContextDescriptor(service, CONTEXT_ID_REMOTE_RECEIVER);
assertTrue(service.getDiscoveredContexts().size() > 0);
assertNotNull(contextDescriptor);
// build the producer system
RoboContext producerEmitterSystem = buildEmitterContext(TestMessageType.class, ACK_CONSUMER, REMOTE_UNIT_EMITTER);
producerEmitterSystem.start();
localLookup.addContext(producerEmitterSystem);
RoboReference<String> remoteTestMessageProducer = producerEmitterSystem.getReference(REMOTE_UNIT_EMITTER);
remoteTestMessageProducer.sendMessage(RemoteTestMessageProducer.ATTR_SEND_MESSAGE);
CountDownLatch ackConsumerCountDownLatch = ackConsumer.getAttribute(AckingStringConsumer.DESCRIPTOR_ACK_LATCH).get();
ackConsumerCountDownLatch.await();
List<TestMessageType> receivedMessages = (List<TestMessageType>) ackConsumer.getAttribute(AckingStringConsumer.DESCRIPTOR_MESSAGES).get();
assertTrue(receivedMessages.size() > 0);
CountDownLatch producerCountDownLatch = remoteTestMessageProducer.getAttribute(RemoteTestMessageProducer.DESCRIPTOR_COUNT_DOWN_LATCH).get();
producerCountDownLatch.await();
CountDownLatch producerAckLatch = remoteTestMessageProducer.getAttribute(RemoteTestMessageProducer.DESCRIPTOR_ACK_LATCH).get();
producerAckLatch.await();
Integer producerAcknowledge = remoteTestMessageProducer.getAttribute(RemoteTestMessageProducer.DESCRIPTOR_TOTAL_ACK).get();
assertTrue(producerAcknowledge > 0);
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class RemoteContextTests method messageIncludingReferenceToDiscoveredContextTest.
@Test
void messageIncludingReferenceToDiscoveredContextTest() throws RoboBuilderException, IOException, ConfigurationException {
RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testRemoteMessageReceiverAckSystem.xml"));
AckingStringConsumer consumer = new AckingStringConsumer(builder.getContext(), ACK_CONSUMER);
builder.add(consumer);
RoboContext receiverCtx = builder.build();
receiverCtx.start();
final LocalLookupServiceImpl localLookup = new LocalLookupServiceImpl();
final LookupService service = LookupServiceTests.getLookupService(localLookup);
LookupServiceProvider.setDefaultLookupService(service);
service.start();
for (int i = 0; i < NUMBER_ITERATIONS && (service.getDescriptor("9") == null); i++) {
SystemUtil.sleep(200);
}
assertTrue(service.getDiscoveredContexts().size() > 0);
RoboContextDescriptor descriptor = service.getDescriptor("9");
assertNotNull(descriptor);
builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testMessageEmitterSystem_8.xml"));
RemoteTestMessageProducer remoteTestMessageProducer = new RemoteTestMessageProducer(builder.getContext(), REMOTE_UNIT_EMITTER);
remoteTestMessageProducer.initialize(getEmitterConfiguration("9", ACK_CONSUMER));
builder.add(remoteTestMessageProducer);
RoboContext emitterContext = builder.build();
localLookup.addContext(emitterContext);
emitterContext.start();
remoteTestMessageProducer.sendMessage("sendMessage");
for (int i = 0; i < NUMBER_ITERATIONS && consumer.getReceivedMessages().size() == 0; i++) {
SystemUtil.sleep(200);
}
assertTrue(consumer.getReceivedMessages().size() > 0);
System.out.println("Got messages: " + consumer.getReceivedMessages());
assertTrue(remoteTestMessageProducer.getAckCount() > 0);
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class RemoteContextTests method messageToDiscoveredContextTest.
@Test
void messageToDiscoveredContextTest() throws RoboBuilderException, IOException, ConfigurationException {
RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testRemoteMessageReceiverSystem.xml"));
StringConsumer consumer = new StringConsumer(builder.getContext(), ACK_CONSUMER);
builder.add(consumer);
RoboContext receiverCtx = builder.build();
receiverCtx.start();
// Note that all this cludging about with local lookup service
// implementations etc would normally not be needed.
// This is just to isolate this test from other tests.
final LocalLookupServiceImpl localLookup = new LocalLookupServiceImpl();
final LookupService service = LookupServiceTests.getLookupService(localLookup);
LookupServiceProvider.setDefaultLookupService(service);
service.start();
for (int i = 0; i < NUMBER_ITERATIONS && (service.getDescriptor("7") == null); i++) {
SystemUtil.sleep(200);
}
assertTrue(service.getDiscoveredContexts().size() > 0);
RoboContextDescriptor descriptor = service.getDescriptor("7");
assertNotNull(descriptor);
builder = new RoboBuilder(RemoteContextTests.class.getClassLoader().getResourceAsStream("testMessageEmitterSystem_10.xml"));
RemoteStringProducer remoteStringProducer = new RemoteStringProducer(builder.getContext(), REMOTE_UNIT_EMITTER);
remoteStringProducer.initialize(getEmitterConfiguration("7", ACK_CONSUMER));
builder.add(remoteStringProducer);
RoboContext emitterContext = builder.build();
localLookup.addContext(emitterContext);
emitterContext.start();
remoteStringProducer.sendMessage("sendRandomMessage");
for (int i = 0; i < NUMBER_ITERATIONS && consumer.getReceivedMessages().size() == 0; i++) {
SystemUtil.sleep(200);
}
assertTrue(consumer.getReceivedMessages().size() > 0);
System.out.println("Got messages: " + consumer.getReceivedMessages());
emitterContext.shutdown();
receiverCtx.shutdown();
}
Aggregations