use of com.robo4j.configuration.ConfigurationBuilder 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.configuration.ConfigurationBuilder in project robo4j by Robo4J.
the class MessageServerTest method testClientServerMessagePassing.
@Test
void testClientServerMessagePassing() throws Exception {
final List<String> messages = new ArrayList<>();
final CountDownLatch messageLatch = new CountDownLatch(3);
Configuration serverConfig = new ConfigurationBuilder().addString(PROPERTY_SERVER_NAME, "Server Name").addString(MessageServer.KEY_HOST_NAME, "localhost").build();
MessageServer server = new MessageServer((uuid, id, message) -> {
System.out.println("Got uuid: " + uuid + " id:" + id + " message:" + message);
messages.add(String.valueOf(message));
messageLatch.countDown();
}, serverConfig);
Thread t = new Thread(() -> {
try {
server.start();
} catch (IOException e) {
exception = e;
fail(e.getMessage());
}
}, "Server Listener");
t.setDaemon(true);
t.start();
for (int i = 0; i < 10; i++) {
if (server.getListeningPort() == 0) {
Thread.sleep(250);
} else {
break;
}
}
Configuration clientConfig = ConfigurationFactory.createEmptyConfiguration();
MessageClient client = new MessageClient(server.getListeningURI(), CONST_MYUUID, clientConfig);
if (exception != null) {
throw exception;
}
List<String> testMessage = getOrderedTestMessage("My First Little Message!", "My Second Little Message!", "My Third Little Message!");
client.connect();
for (String message : testMessage) {
client.sendMessage("test", message);
}
messageLatch.await(2, TimeUnit.SECONDS);
assertEquals(testMessage.size(), messages.size());
assertArrayEquals(testMessage.toArray(), messages.toArray());
}
Aggregations