Search in sources :

Example 6 with RoboBuilder

use of com.robo4j.RoboBuilder in project robo4j by Robo4J.

the class RoboHttpDynamicTests method pingExternalSystem.

/**
 * testing ping external system
 *
 * @throws Exception
 *             exception
 */
@Disabled("intent to run manual")
@Test
void pingExternalSystem() throws Exception {
    RoboBuilder pingSystemBuilder = getHttpClientRobotBuilder("127.0.0.1", 8080);
    pingSystemBuilder.add(StringConsumer.class, StringConsumer.NAME);
    RoboContext pingSystemContext = pingSystemBuilder.build();
    pingSystemContext.start();
    System.out.println("PingSystem state after start:");
    System.out.println(SystemUtil.printStateReport(pingSystemContext));
    RoboReference<HttpDecoratedRequest> httpClient = pingSystemContext.getReference(ID_CLIENT_UNIT);
    Thread.sleep(1000);
    for (int i = 0; i < 1; i++) {
        HttpRequestDenominator denominator = new HttpRequestDenominator(HttpMethod.GET, "/noparams", HttpVersion.HTTP_1_1);
        HttpDecoratedRequest request = new HttpDecoratedRequest(denominator);
        request.addCallback(StringConsumer.NAME);
        httpClient.sendMessage(request);
    }
    Thread.sleep(1000);
    pingSystemContext.stop();
    System.out.println("PingSystem state after stop:");
    System.out.println(SystemUtil.printStateReport(pingSystemContext));
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) HttpRequestDenominator(com.robo4j.socket.http.message.HttpRequestDenominator) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with RoboBuilder

use of com.robo4j.RoboBuilder 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 RoboBuilder

use of com.robo4j.RoboBuilder 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 RoboBuilder

use of com.robo4j.RoboBuilder 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 RoboBuilder

use of com.robo4j.RoboBuilder 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

RoboBuilder (com.robo4j.RoboBuilder)45 RoboContext (com.robo4j.RoboContext)33 InputStream (java.io.InputStream)20 Configuration (com.robo4j.configuration.Configuration)18 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)17 Test (org.junit.jupiter.api.Test)13 FileInputStream (java.io.FileInputStream)5 HttpPathConfigJsonBuilder (com.robo4j.socket.http.util.HttpPathConfigJsonBuilder)4 RoboBuilderException (com.robo4j.RoboBuilderException)3 IOException (java.io.IOException)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StringConsumer (com.robo4j.StringConsumer)2 BiColor (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor)2 DataEvent3f (com.robo4j.hw.rpi.imu.bno.DataEvent3f)2 CameraMessage (com.robo4j.socket.http.codec.CameraMessage)2 BnoRequest (com.robo4j.units.rpi.imu.BnoRequest)2 FileNotFoundException (java.io.FileNotFoundException)2 Path (java.nio.file.Path)2 Scanner (java.util.Scanner)2