Search in sources :

Example 11 with RoboContext

use of com.robo4j.RoboContext 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 12 with RoboContext

use of com.robo4j.RoboContext 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 13 with RoboContext

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

the class RoboHttpClientWithResponseTests method simpleRoboSystemGetRequestTest.

// private static final String ROBO_SYSTEM_DESC =
// "[{\"id\":\"stringConsumer\",\"state\":\"STARTED\"},{\"id\":\"httpServer\",\"state\":\"STARTED\"}]";
@Test
void simpleRoboSystemGetRequestTest() throws Exception {
    RoboContext producerSystem = RoboContextUtils.loadRoboContextByXml("robo_http_client_request_producer_text.xml");
    RoboContext consumerSystem = RoboContextUtils.loadRoboContextByXml("robo_http_client_request_consumer_text.xml");
    consumerSystem.start();
    producerSystem.start();
    System.out.println("consumer: State after start:");
    System.out.println(SystemUtil.printStateReport(consumerSystem));
    System.out.println("producer: State after start:");
    System.out.println(SystemUtil.printStateReport(producerSystem));
    RoboReference<Integer> decoratedProducer = producerSystem.getReference("decoratedProducer");
    CountDownLatch producerSetupLatch = decoratedProducer.getAttribute(SocketMessageDecoratedProducerUnit.DESCRIPTOR_SETUP_LATCH).get();
    decoratedProducer.sendMessage(MAX_NUMBER);
    producerSetupLatch.await(TIMEOUT, TIME_UNIT);
    CountDownLatch producerLatch = decoratedProducer.getAttribute(SocketMessageDecoratedProducerUnit.DESCRIPTOR_MESSAGES_LATCH).get();
    producerLatch.await(TIMEOUT, TIME_UNIT);
    final RoboReference<String> producerStringConsumer = producerSystem.getReference(StringConsumer.NAME);
    final CountDownLatch messagesLatchStringConsumer = producerStringConsumer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
    messagesLatchStringConsumer.await(TIMEOUT, TIME_UNIT);
    final Integer totalNumber = producerStringConsumer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
    assertEquals(MAX_NUMBER, totalNumber);
    producerSystem.shutdown();
    consumerSystem.shutdown();
}
Also used : RoboContext(com.robo4j.RoboContext) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 14 with RoboContext

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

the class HttpServerUnitTests method httpServerUnitNoPathTest.

@Test
void httpServerUnitNoPathTest() throws Exception {
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).addString(PROPERTY_CODEC_PACKAGES, PACKAGE_CODECS).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());
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) Test(org.junit.jupiter.api.Test)

Example 15 with RoboContext

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

the class TankExampleTests method legoTankExampleTest.

@Test
@Disabled("rethink and remove dependency")
void legoTankExampleTest() throws Exception {
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addString("target", ID_UNIT_CONTROLLER).addInteger("port", PORT).addString("packages", "com.robo4j.units.lego.example.codec").addString(RoboHttpUtils.PROPERTY_UNIT_PATHS_CONFIG, HttpPathConfigJsonBuilder.Builder().addPath(ID_UNIT_CONTROLLER, HttpMethod.GET).build()).build();
    builder.add(HttpServerUnit.class, config, ID_HTTP);
    builder.add(TankExampleController.class, new ConfigurationBuilder().addString("target", ID_PLATFORM).build(), ID_UNIT_CONTROLLER);
    /* platform is listening to the bus */
    config = new ConfigurationBuilder().addString("leftMotorPort", "B").addCharacter("leftMotorType", 'N').addString("rightMotorPort", "C").addCharacter("rightMotorType", 'N').build();
    builder.add(SimpleTankTestUnit.class, config, ID_PLATFORM);
    /* lcd is listening to the bus */
    builder.add(LcdTestUnit.class, ID_LCD);
    RoboContext context = builder.build();
    context.start();
    context.getReference(ID_LCD).sendMessage("Press <Enter> to quit!");
    System.in.read();
    context.shutdown();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

RoboContext (com.robo4j.RoboContext)50 RoboBuilder (com.robo4j.RoboBuilder)33 Test (org.junit.jupiter.api.Test)20 InputStream (java.io.InputStream)17 Configuration (com.robo4j.configuration.Configuration)10 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 FileInputStream (java.io.FileInputStream)5 RoboReference (com.robo4j.RoboReference)4 RoboBuilderException (com.robo4j.RoboBuilderException)3 ServerPathConfig (com.robo4j.socket.http.units.ServerPathConfig)3 List (java.util.List)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 HttpMethod (com.robo4j.socket.http.HttpMethod)2 CameraMessage (com.robo4j.socket.http.codec.CameraMessage)2 HttpPathMethodDTO (com.robo4j.socket.http.dto.HttpPathMethodDTO)2