use of com.robo4j.StringConsumer in project robo4j by Robo4J.
the class RemoteContextTests method buildReceiverSystemStringConsumer.
/*
* Builds a system ready to receive strings.
*/
private RoboContext buildReceiverSystemStringConsumer() throws RoboBuilderException, ConfigurationException {
RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testRemoteReceiver.xml"));
Configuration configuration = new ConfigurationBuilder().addInteger("totalNumberMessages", 1).build();
StringConsumer stringConsumer = new StringConsumer(builder.getContext(), UNIT_STRING_CONSUMER);
stringConsumer.initialize(configuration);
builder.add(stringConsumer);
RoboContext receiverSystem = builder.build();
receiverSystem.start();
return receiverSystem;
}
use of com.robo4j.StringConsumer 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