use of org.nustaq.kontraktor.reactivestreams.EventSink in project kontraktor by RuedigerMoeller.
the class Java8Streams method remoteJava8EndlessStreams.
// just manual
@Test
// just manual
@org.junit.Ignore
public <T> void remoteJava8EndlessStreams() throws InterruptedException {
EventSink sink = new EventSink();
sink.serve(new TCPPublisher().port(8125));
runTimeClient("c1");
runTimeClient("c2");
runTimeClient("c3");
for (int i = 0; i < 1000; i++) {
while (!sink.offer(new Date())) {
Thread.sleep(1);
}
Thread.sleep(1000);
}
}
use of org.nustaq.kontraktor.reactivestreams.EventSink in project kontraktor by RuedigerMoeller.
the class Basics method testStopThreadsError.
@Test
public void testStopThreadsError() throws InterruptedException {
resetThreadCount();
EventSink<Integer> eventSink = new EventSink<Integer>();
AtomicInteger sum = new AtomicInteger(0);
AtomicInteger elems = new AtomicInteger(0);
RateMeasure ms = new RateMeasure("rate");
eventSink.syncMap(i -> i * i).map(i -> "" + i).syncMap(s -> s.substring(0, s.length() / 2)).map(s -> s.length()).subscribe((len, err) -> {
ms.count();
if (len != null) {
// complete signal
elems.incrementAndGet();
sum.addAndGet(len);
}
});
for (int i = 0; i < MASMSG_NUM; i++) {
while (!eventSink.offer(i)) {
Thread.yield();
}
}
eventSink.error(new RuntimeException("error"));
System.out.println("count:" + DispatcherThread.activeDispatchers.get());
int cnt = 0;
while (sum.get() != 94803201 && cnt < 10) {
Thread.sleep(1000);
cnt++;
}
System.out.println("count:" + DispatcherThread.activeDispatchers.get());
Thread.sleep(1000);
System.out.println("elems:" + elems.get());
Thread.sleep(5000);
Assert.assertTrue(elems.get() == MASMSG_NUM);
System.out.println("disp:" + DispatcherThread.activeDispatchers.get());
Assert.assertTrue(DispatcherThread.activeDispatchers.get() == 0);
}
use of org.nustaq.kontraktor.reactivestreams.EventSink in project kontraktor by RuedigerMoeller.
the class Basics method testStopThreads.
@Test
public void testStopThreads() throws InterruptedException {
resetThreadCount();
EventSink<Integer> eventSink = new EventSink<Integer>();
AtomicInteger sum = new AtomicInteger(0);
AtomicInteger cnt = new AtomicInteger(0);
RateMeasure ms = new RateMeasure("rate");
eventSink.syncMap(i -> i * i).map(i -> "" + i).syncMap(s -> s.substring(0, s.length() / 2)).map(s -> s.length()).subscribe((len, err) -> {
ms.count();
if (len != null) {
// complete signal
cnt.incrementAndGet();
sum.addAndGet(len);
}
});
for (int i = 0; i < MASMSG_NUM; i++) {
while (!eventSink.offer(i)) {
Thread.yield();
}
}
eventSink.complete();
int count = 0;
while (cnt.get() != MASMSG_NUM && count < 10) {
Thread.sleep(1000);
count++;
}
Thread.sleep(5000);
System.out.println("threads:" + DispatcherThread.activeDispatchers.get());
Assert.assertTrue(DispatcherThread.activeDispatchers.get() == 0);
}
use of org.nustaq.kontraktor.reactivestreams.EventSink in project kontraktor by RuedigerMoeller.
the class TCPNIOKStreamsTest method simpleTest.
@Test
@Ignore
public void simpleTest() {
AtomicLong counter = new AtomicLong(0);
AtomicLong received = new AtomicLong(0);
EventSink<String> stringSink = new EventSink<>();
stringSink.syncMap(in -> in.length()).subscribe((str, err) -> {
if (isErrorOrComplete(err)) {
System.out.println("complete");
} else if (isError(err)) {
System.out.println("ERROR");
} else {
received.incrementAndGet();
// simulate slow receiver
LockSupport.parkNanos(1000 * 1000);
}
});
long l = System.currentTimeMillis();
long prev = 0;
while (true) {
if (stringSink.offer("" + counter.get())) {
counter.incrementAndGet();
}
if (System.currentTimeMillis() - l > 1000) {
long rate = received.get() - prev;
prev = received.get();
System.out.println("sent:" + counter.get() + " received:" + received.get() + " diff:" + (counter.get() - received.get()));
System.out.println(" " + rate);
l = System.currentTimeMillis();
}
}
}
use of org.nustaq.kontraktor.reactivestreams.EventSink in project kontraktor by RuedigerMoeller.
the class Basics method testConnectionCloseOnCompleteWithSink.
@Test
public void testConnectionCloseOnCompleteWithSink() throws InterruptedException {
EventSink<Integer> sink = new EventSink<>();
sink.serve(new TCPPublisher().port(7850));
AtomicInteger cnt = new AtomicInteger(0);
KxReactiveStreams.get().connect(Integer.class, new TCPConnectable().host("localhost").port(7850)).subscribe((r, e) -> {
if (Actors.isResult(e)) {
cnt.incrementAndGet();
} else {
System.out.println("not result " + r + " " + e);
}
});
for (int i = 0; i < 100_000; i++) {
while (!sink.offer(i)) {
Thread.yield();
}
}
sink.complete();
System.out.println("received:" + cnt.get());
Thread.sleep(1000);
System.out.println("received:" + cnt.get());
Assert.assertTrue(cnt.get() == 100_000);
System.out.println("count:" + DispatcherThread.activeDispatchers.get());
}
Aggregations