Search in sources :

Example 6 with Configuration

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());
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) Test(org.junit.jupiter.api.Test)

Example 7 with Configuration

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;
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 8 with Configuration

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;
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder)

Example 9 with Configuration

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();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) HttpPathConfigJsonBuilder(com.robo4j.socket.http.util.HttpPathConfigJsonBuilder) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 10 with Configuration

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();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder)

Aggregations

Configuration (com.robo4j.configuration.Configuration)23 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)22 RoboBuilder (com.robo4j.RoboBuilder)18 RoboContext (com.robo4j.RoboContext)10 Test (org.junit.jupiter.api.Test)8 HttpPathConfigJsonBuilder (com.robo4j.socket.http.util.HttpPathConfigJsonBuilder)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 StringConsumer (com.robo4j.StringConsumer)1 LegoPlatformMessage (com.robo4j.units.lego.platform.LegoPlatformMessage)1 InputStream (java.io.InputStream)1 Disabled (org.junit.jupiter.api.Disabled)1