use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class ParallelJoinTest method overflowSlowpathDelayError.
@Test
public void overflowSlowpathDelayError() {
@SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {
@Override
public void onNext(Integer t) {
super.onNext(t);
if (t == 1) {
subs[0].onNext(2);
subs[0].onNext(3);
}
}
};
new ParallelFlowable<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer>[] subscribers) {
subs[0] = subscribers[0];
subscribers[0].onSubscribe(new BooleanSubscription());
subscribers[0].onNext(1);
}
@Override
public int parallelism() {
return 1;
}
}.sequentialDelayError(1).subscribe(ts);
ts.request(1);
ts.assertFailure(MissingBackpressureException.class, 1, 2);
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class ParallelJoinTest method overflowSlowpath.
@Test
public void overflowSlowpath() {
@SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {
@Override
public void onNext(Integer t) {
super.onNext(t);
subs[0].onNext(2);
subs[0].onNext(3);
}
};
new ParallelFlowable<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer>[] subscribers) {
subs[0] = subscribers[0];
subscribers[0].onSubscribe(new BooleanSubscription());
subscribers[0].onNext(1);
}
@Override
public int parallelism() {
return 1;
}
}.sequential(1).subscribe(ts);
ts.assertFailure(MissingBackpressureException.class, 1);
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class ParallelJoinTest method onNextMissingBackpressureDelayErrorRace.
@Test
public void onNextMissingBackpressureDelayErrorRace() throws Throwable {
TestHelper.withErrorTracking(errors -> {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
AtomicReference<Subscriber<? super Integer>> ref2 = new AtomicReference<>();
Flowable<Integer> f1 = new Flowable<Integer>() {
@Override
public void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
ref1.set(s);
}
};
Flowable<Integer> f2 = new Flowable<Integer>() {
@Override
public void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
ref2.set(s);
}
};
ParallelFlowable.fromArray(f1, f2).sequentialDelayError(1).test(0);
TestHelper.race(() -> {
ref1.get().onNext(1);
ref1.get().onNext(2);
}, () -> {
ref2.get().onNext(3);
ref2.get().onNext(4);
});
errors.clear();
}
});
}
use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.
the class ParallelMapTest method conditionalCancelIgnored.
@Test
public void conditionalCancelIgnored() {
Flowable<Integer> f = new Flowable<Integer>() {
@Override
protected void subscribeActual(@NonNull Subscriber<@NonNull ? super @NonNull Integer> s) {
@SuppressWarnings("unchecked") ConditionalSubscriber<Integer> subscriber = (ConditionalSubscriber<Integer>) s;
subscriber.onSubscribe(new BooleanSubscription());
subscriber.tryOnNext(1);
subscriber.tryOnNext(2);
}
};
ParallelFlowable.fromArray(f).map(v -> {
throw new TestException();
}).filter(v -> true).sequential().test().assertFailure(TestException.class);
}
use of org.reactivestreams.Subscriber in project vertx-proton by vert-x3.
the class Receiver method main.
public static void main(String[] args) throws Exception {
try {
Vertx vertx = Vertx.vertx();
ProtonClient client = ProtonClient.create(vertx);
// Connect, then use the event loop thread to process the connection
client.connect("localhost", 5672, res -> {
Context ctx = Vertx.currentContext();
if (res.succeeded()) {
System.out.println("We're connected");
ProtonConnection connection = res.result();
connection.open();
Publisher<Message> consumerPublisher = ProtonStreams.createConsumer(connection, "queue");
Subscriber<Message> subscriber = new Subscriber<Message>() {
AtomicInteger receievedCount = new AtomicInteger();
Subscription subscription;
@Override
public void onSubscribe(Subscription s) {
subscription = s;
// Initial request for some messages
subscription.request(REQ_WINDOW);
}
@Override
public void onNext(Message env) {
int msgNum = receievedCount.incrementAndGet();
String content = (String) ((AmqpValue) env.getBody()).getValue();
System.out.println("Received message: " + content);
if (msgNum % REQ_WINDOW == 0 && msgNum < COUNT) {
// Request more messages
subscription.request(REQ_WINDOW);
} else if (msgNum == COUNT) {
// Done, clean up.
subscription.cancel();
closeConnection(vertx, connection);
}
}
@Override
public void onError(Throwable t) {
System.out.println("onError(): " + t);
closeConnection(vertx, connection);
}
@Override
public void onComplete() {
System.out.println("onComplete()");
closeConnection(vertx, connection);
}
private void closeConnection(Vertx vertx, ProtonConnection connection) {
ctx.runOnContext(x -> {
System.out.println("Subscriber finished, closing connection.");
connection.closeHandler(y -> {
System.out.println("Connection closed.");
connection.disconnect();
vertx.close();
}).close();
});
}
};
consumerPublisher.subscribe(subscriber);
} else {
System.out.println("Failed to connect, exiting: " + res.cause());
System.exit(1);
}
});
} catch (Exception exp) {
System.out.println("Caught exception, exiting.");
exp.printStackTrace(System.out);
System.exit(1);
}
}
Aggregations