use of examples.MyEvent in project kontraktor by RuedigerMoeller.
the class RxJava method remotingRxToRxWebSocketSampleEvent.
@Test
public void remotingRxToRxWebSocketSampleEvent() throws InterruptedException {
Observable<Integer> range = Observable.range(0, NUM_MSG / 4);
Publisher<MyEvent> pub = RxReactiveStreams.toPublisher(range.map(i -> new MyEvent(i, Math.random(), "Hello" + i)));
KxReactiveStreams.get().asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(7778).urlPath("/ws/rx"));
RateMeasure rm = new RateMeasure("events");
KxPublisher<MyEvent> remoteStream = KxReactiveStreams.get().connect(MyEvent.class, new WebSocketConnectable().url("ws://localhost:7778/ws/rx"));
CountDownLatch cnt = new CountDownLatch(NUM_MSG / 4);
RxReactiveStreams.toObservable(remoteStream).forEach(i -> {
rm.count();
cnt.countDown();
});
cnt.await(50, TimeUnit.SECONDS);
Assert.assertTrue(cnt.getCount() == 0);
}
Aggregations