use of com.dexels.navajo.document.stream.xml.XMLEvent in project navajo by Dexels.
the class TestRx method testBackpressure.
@Test
public void testBackpressure() {
final int DELAY = 1;
final int REQUESTCOUNT = 1;
final Thread me = Thread.currentThread();
final long started = System.currentTimeMillis();
AtomicLong count = new AtomicLong();
Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml.xml"), 1).lift(XML.parseFlowable(1)).flatMap(e -> e).subscribe(new Subscriber<XMLEvent>() {
Disposable timer;
@Override
public void onComplete() {
long complete = System.currentTimeMillis();
System.err.println("Total run took: " + (complete - started) + " for " + count.get() + " elements. Should be little more than: " + (DELAY * count.get() / REQUESTCOUNT));
timer.dispose();
me.interrupt();
}
@Override
public void onError(Throwable e) {
timer.dispose();
e.printStackTrace();
me.interrupt();
}
@Override
public void onSubscribe(Subscription s) {
s.request(1);
timer = Observable.interval(DELAY, TimeUnit.MILLISECONDS).subscribe(l -> s.request(REQUESTCOUNT));
}
@Override
public void onNext(XMLEvent x) {
count.incrementAndGet();
}
});
try {
Thread.sleep(500000);
} catch (InterruptedException e1) {
}
}
Aggregations