use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class RoboUnitTests method testSystem.
@Test
void testSystem() throws Exception {
int totalMessages = 10;
RoboSystem system = new RoboSystem();
assertEquals(system.getState(), LifecycleState.UNINITIALIZED);
StringProducer producer = new StringProducer(system, "producer");
Configuration config = new ConfigurationBuilder().addString(StringProducer.PROP_TARGET, "consumer").addInteger(StringProducer.PROP_TOTAL_MESSAGES, totalMessages).build();
producer.initialize(config);
StringConsumer consumer = new StringConsumer(system, "consumer");
system.addUnits(producer, consumer);
system.start();
assertEquals(system.getState(), LifecycleState.STARTED);
assertTrue(system.getState() == LifecycleState.STARTING || system.getState() == LifecycleState.STARTED);
for (int i = 0; i < totalMessages; i++) {
producer.sendRandomMessage();
}
system.shutdown();
assertEquals(totalMessages, consumer.getReceivedMessages().size());
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class RoboHttpDynamicTests method getServerRoboSystem.
// Private Methods
private RoboContext getServerRoboSystem(int totalMessageNumber) throws Exception {
/* tested system configuration */
RoboBuilder builder = new RoboBuilder();
Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).addString("packages", "com.robo4j.socket.http.units.test.codec").addString(PROPERTY_UNIT_PATHS_CONFIG, HttpPathConfigJsonBuilder.Builder().addPath(ID_TARGET_UNIT, HttpMethod.POST).build()).build();
builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
config = new ConfigurationBuilder().addString(PROPERTY_TARGET, StringConsumer.NAME).build();
builder.add(HttpCommandTestController.class, config, ID_TARGET_UNIT);
config = new ConfigurationBuilder().addInteger(StringConsumer.PROP_TOTAL_NUMBER_MESSAGES, totalMessageNumber).build();
builder.add(StringConsumer.class, config, StringConsumer.NAME);
RoboContext result = builder.build();
assertNotNull(result.getUnits());
assertEquals(3, result.getUnits().size());
assertEquals(LifecycleState.INITIALIZED, result.getReference(ID_HTTP_SERVER).getState());
assertEquals(LifecycleState.INITIALIZED, result.getState());
result.start();
System.out.println(SystemUtil.printSocketEndPoint(result.getReference(ID_HTTP_SERVER), result.getReference(ID_TARGET_UNIT)));
return result;
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class RoboHttpDynamicTests method getHttpClientRobotBuilder.
private RoboBuilder getHttpClientRobotBuilder(String host, int port) throws Exception {
/* system which is testing main system */
RoboBuilder result = new RoboBuilder();
Configuration config = new ConfigurationBuilder().addString(PROPERTY_HOST, host).addInteger(PROPERTY_SOCKET_PORT, port).build();
result.add(HttpClientUnit.class, config, ID_CLIENT_UNIT);
return result;
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class RoboHttpUnitGetTestApp method systemWithHttpServerOnlyTest.
/**
* Run the system with only server unit
*
* @throws Exception
* exception
*/
public void systemWithHttpServerOnlyTest() throws Exception {
final String httpServerUnitName = "http_server";
final HttpPathConfigJsonBuilder pathBuilder = HttpPathConfigJsonBuilder.Builder().addPath(httpServerUnitName, HttpMethod.GET);
// @formatter:off
Configuration systemConfiguration = new ConfigurationBuilder().addInteger("poolSizeScheduler", 3).addInteger("poolSizeWorker", 2).addInteger("poolSizeBlocking", 2).build();
RoboBuilder builder = new RoboBuilder("roboSystem1", systemConfiguration);
// @formatter:on
// @formatter:off
Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, SERVER_PORT).addString("packages", "com.robo4j.socket.http.codec").addString(PROPERTY_UNIT_PATHS_CONFIG, pathBuilder.build()).build();
// @formatter:on
builder.add(HttpServerUnit.class, config, httpServerUnitName);
RoboContext system = builder.build();
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.configuration.Configuration in project robo4j by Robo4J.
the class RoboHttpUnitGetTestApp method attributeRequestSystem.
private RoboContext attributeRequestSystem() throws Exception {
RoboBuilder builder = new RoboBuilder();
Configuration config = new ConfigurationBuilder().addString(PROPERTY_HOST, HOST_SYSTEM).addInteger(PROPERTY_SOCKET_PORT, SERVER_PORT).build();
builder.add(HttpClientUnit.class, config, UNIT_ID_HTTP_CLIENT);
builder.add(StringConsumer.class, StringConsumer.NAME);
return builder.build();
}
Aggregations