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;
}
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();
}
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();
}
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());
}
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();
}
Aggregations