use of com.robo4j.socket.http.codec.CameraMessage in project robo4j by Robo4J.
the class JsonCodecsTests method cameraCodecJsonCycleTest.
@Test
void cameraCodecJsonCycleTest() {
final byte[] imageBytes = StreamUtils.inputStreamToByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("snapshot.png"));
String encodeString = new String(Base64.getEncoder().encode(imageBytes));
CameraMessage cameraMessage = new CameraMessage();
cameraMessage.setImage(encodeString);
cameraMessage.setType("jpg");
cameraMessage.setValue("22");
long start = System.nanoTime();
String cameraJson0 = cameraMessageCodec.encode(cameraMessage);
TimeUtils.printTimeDiffNano("cameraJson0", start);
start = System.nanoTime();
cameraMessageCodec.decode(cameraJson0);
TimeUtils.printTimeDiffNano("decodeCameraMessage0", start);
start = System.nanoTime();
String cameraJson = cameraMessageCodec.encode(cameraMessage);
TimeUtils.printTimeDiffNano("decodeFromJson", start);
System.out.println("cameraJson: " + cameraJson);
start = System.nanoTime();
CameraMessage codecCameraMessage = cameraMessageCodec.decode(cameraJson);
TimeUtils.printTimeDiffNano("decodeFromJson", start);
assertEquals(cameraMessage, codecCameraMessage);
}
use of com.robo4j.socket.http.codec.CameraMessage in project robo4j by Robo4J.
the class CameraDecoratedImageProducerConsumerTests method decoratorProducerConsumerTest.
@Test
void decoratorProducerConsumerTest() throws Exception {
RoboBuilder builderProducer = new RoboBuilder(Thread.currentThread().getContextClassLoader().getResourceAsStream("robo4jSystemProducer.xml"));
InputStream clientConfigInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("robo_camera_producer_decorated_test.xml");
builderProducer.add(clientConfigInputStream);
RoboContext producerSystem = builderProducer.build();
RoboBuilder builderConsumer = new RoboBuilder(Thread.currentThread().getContextClassLoader().getResourceAsStream("robo4jSystemConsumer.xml"));
InputStream serverConfigInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("robo_camera_consumer_decorated_test.xml");
builderConsumer.add(serverConfigInputStream);
RoboContext consumerSystem = builderConsumer.build();
long startTime = System.currentTimeMillis();
consumerSystem.start();
producerSystem.start();
RoboReference<Boolean> imageProducer = producerSystem.getReference("imageController");
RoboReference<CameraMessage> imageConsumer = consumerSystem.getReference("imageProcessor");
CountDownLatch startLatchConsumer = imageConsumer.getAttribute(CameraImageConsumerTestUnit.DESCRIPTOR_START_LATCH).get();
startLatchConsumer.await(5, TimeUnit.MINUTES);
CountDownLatch imagesLatchProducer = imageProducer.getAttribute(CameraImageProducerDesTestUnit.DESCRIPTOR_GENERATED_IMAGES_LATCH).get();
imagesLatchProducer.await(5, TimeUnit.MINUTES);
Integer totalImagesProducer = imageProducer.getAttribute(CameraImageProducerDesTestUnit.DESCRIPTOR_TOTAL_IMAGES).get();
CountDownLatch imagesLatchConsumer = imageConsumer.getAttribute(CameraImageConsumerTestUnit.DESCRIPTOR_IMAGES_LATCH).get();
imagesLatchConsumer.await(5, TimeUnit.MINUTES);
Integer totalImagesConsumer = imageConsumer.getAttribute(CameraImageConsumerTestUnit.DESCRIPTOR_RECEIVED_IMAGES).get();
RoboHttpUtils.printMeasuredTime(getClass(), "duration", startTime);
assertEquals(totalImagesProducer, totalImagesConsumer);
producerSystem.shutdown();
consumerSystem.shutdown();
System.out.println("Press <Enter> to quit!");
}
use of com.robo4j.socket.http.codec.CameraMessage in project robo4j by Robo4J.
the class CameraImageProducerConsumerTests method cameraImageProdConTest.
@Test
void cameraImageProdConTest() throws Exception {
RoboBuilder builderProducer = new RoboBuilder(Thread.currentThread().getContextClassLoader().getResourceAsStream("robo4jSystemProducer.xml"));
InputStream clientConfigInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("robo_camera_producer_test.xml");
builderProducer.add(clientConfigInputStream);
RoboContext producerSystem = builderProducer.build();
RoboBuilder builderConsumer = new RoboBuilder(Thread.currentThread().getContextClassLoader().getResourceAsStream("robo4jSystemConsumer.xml"));
InputStream serverConfigInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("robo_camera_consumer_test.xml");
builderConsumer.add(serverConfigInputStream);
RoboContext consumerSystem = builderConsumer.build();
long startTime = System.currentTimeMillis();
consumerSystem.start();
producerSystem.start();
RoboReference<CameraMessage> imageConsumer = consumerSystem.getReference("imageProcessor");
RoboReference<Boolean> imageProducer = producerSystem.getReference("imageController");
CountDownLatch startConsumerLatch = imageConsumer.getAttribute(CameraImageConsumerTestUnit.DESCRIPTOR_START_LATCH).get();
startConsumerLatch.await(5, TimeUnit.MINUTES);
Integer totalImagesProducer = imageProducer.getAttribute(CameraImageProducerDesTestUnit.DESCRIPTOR_TOTAL_IMAGES).get();
CountDownLatch imageProducerLatch = imageProducer.getAttribute(CameraImageProducerDesTestUnit.DESCRIPTOR_GENERATED_IMAGES_LATCH).get();
CountDownLatch imageConsumerLatch = imageConsumer.getAttribute(CameraImageConsumerTestUnit.DESCRIPTOR_IMAGES_LATCH).get();
System.out.println("LATCH");
imageProducerLatch.await(5, TimeUnit.MINUTES);
System.out.println("ONE");
imageConsumerLatch.await(5, TimeUnit.MINUTES);
System.out.println("TWO");
Integer receivedImagesConsumer = imageConsumer.getAttribute(CameraImageConsumerTestUnit.DESCRIPTOR_RECEIVED_IMAGES).get();
assertEquals(totalImagesProducer, receivedImagesConsumer);
RoboHttpUtils.printMeasuredTime(getClass(), "duration", startTime);
System.out.println("receivedImagesConsumer: " + receivedImagesConsumer);
producerSystem.shutdown();
consumerSystem.shutdown();
System.out.println("Press <Enter> to quit!");
}
Aggregations