use of io.reactivex.Flowable in project cxf by apache.
the class JAXRSRxJava2FlowableTest method testFlowableErrorsResponseWithMapper.
@Test
public void testFlowableErrorsResponseWithMapper() throws Exception {
String address = "http://localhost:" + PORT + "/rx22/flowable/mapper/errors";
final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
obs.subscribe(subscriber);
subscriber.await(3, TimeUnit.SECONDS);
subscriber.assertValue(r -> r.getStatus() == 400).assertComplete();
}
use of io.reactivex.Flowable in project cxf by apache.
the class JAXRSRxJava2FlowableTest method testGetHelloWorldEmpty.
@Test
public void testGetHelloWorldEmpty() throws Exception {
String address = "http://localhost:" + PORT + "/rx2/flowable/empty";
final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
obs.subscribe(subscriber);
subscriber.await(3, TimeUnit.SECONDS);
subscriber.assertValue(r -> "[]".equals(r.readEntity(String.class))).assertComplete();
}
use of io.reactivex.Flowable in project cxf by apache.
the class JAXRSRxJava2FlowableTest method testGetHelloWorldAsyncObservable.
@Test
public void testGetHelloWorldAsyncObservable() throws Exception {
String address = "http://localhost:" + PORT + "/rx2/flowable/textAsync";
WebClient wc = WebClient.create(address, Collections.singletonList(new FlowableRxInvokerProvider()));
Flowable<String> obs = wc.accept("text/plain").rx(FlowableRxInvoker.class).get(String.class);
final TestSubscriber<String> subscriber = new TestSubscriber<>();
obs.map(s -> s + s).subscribe(subscriber);
subscriber.await(2, TimeUnit.SECONDS);
subscriber.assertResult("Hello, world!Hello, world!");
}
use of io.reactivex.Flowable in project vertx-proton by vert-x3.
the class ProtonSubscriberIntTest method testSubCancelledOnConnectionEnd.
@Test(timeout = 20000)
public void testSubCancelledOnConnectionEnd(TestContext context) throws Exception {
server.close();
final Async serverLinkOpenAsync = context.async();
final Async subCancelled = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
// Set the local terminus details [naively]
serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());
serverReceiver.open();
serverLinkOpenAsync.complete();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection, "myAddress");
// Create a Publisher that doesn't produce elements, but indicates when its subscription is cancelled.
Publisher<Tracker> producer = Flowable.<Tracker>never().doOnCancel(() -> {
LOG.trace("Cancelled!");
subCancelled.complete();
});
producer.subscribe(subscriber);
});
serverLinkOpenAsync.awaitSuccess();
context.assertFalse(subCancelled.isCompleted());
protonServer.close();
protonServer = null;
subCancelled.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of io.reactivex.Flowable in project vertx-proton by vert-x3.
the class ProtonSubscriberIntTest method testSubCancelledOnLinkClose.
@Test(timeout = 20000)
public void testSubCancelledOnLinkClose(TestContext context) throws Exception {
server.close();
final Async serverLinkOpenAsync = context.async();
final Async clientLinkCloseAsync = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
// Set the local terminus details [naively]
serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());
serverReceiver.open();
serverLinkOpenAsync.complete();
serverReceiver.close();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection, "myAddress");
// Create a Publisher that doesn't produce elements, but indicates when its subscription is cancelled.
Publisher<Tracker> producer = Flowable.<Tracker>never().doOnCancel(() -> {
LOG.trace("Cancelled!");
clientLinkCloseAsync.complete();
});
producer.subscribe(subscriber);
});
serverLinkOpenAsync.awaitSuccess();
clientLinkCloseAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
Aggregations