use of io.servicetalk.concurrent.api.Publisher in project servicetalk by apple.
the class NettyPipelinedConnectionTest method writeSubscribeThrowsLetsSubsequentRequestsThrough.
@Test
void writeSubscribeThrowsLetsSubsequentRequestsThrough() {
AtomicBoolean firstReadOperation = new AtomicBoolean();
TestPublisher<Integer> mockReadPublisher1 = new TestPublisher<>();
TestPublisher<Integer> mockReadPublisher2 = new TestPublisher<>();
@SuppressWarnings("unchecked") NettyConnection<Integer, Integer> mockConnection = mock(NettyConnection.class);
doAnswer((Answer<Publisher<Integer>>) invocation -> firstReadOperation.compareAndSet(false, true) ? mockReadPublisher1 : mockReadPublisher2).when(mockConnection).read();
doAnswer((Answer<Completable>) invocation -> new Completable() {
@Override
protected void handleSubscribe(final CompletableSource.Subscriber subscriber) {
throw DELIBERATE_EXCEPTION;
}
}).when(mockConnection).write(eq(writePublisher1), any(), any());
doAnswer((Answer<Completable>) invocation -> {
Publisher<Integer> writePub = invocation.getArgument(0);
return writePub.ignoreElements();
}).when(mockConnection).write(eq(writePublisher2), any(), any());
requester = new NettyPipelinedConnection<>(mockConnection, 2);
toSource(requester.write(writePublisher1)).subscribe(readSubscriber);
toSource(requester.write(writePublisher2)).subscribe(readSubscriber2);
Subscription readSubscription = readSubscriber.awaitSubscription();
readSubscription.request(1);
assertTrue(mockReadPublisher1.isSubscribed());
mockReadPublisher1.onError(newSecondException());
assertThat(readSubscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
assertFalse(writePublisher1.isSubscribed());
verifySecondRequestProcessed(mockReadPublisher2, mockConnection);
}
use of io.servicetalk.concurrent.api.Publisher in project servicetalk by apple.
the class NettyPipelinedConnectionTest method readThrowsClosesConnection.
@Test
void readThrowsClosesConnection() {
@SuppressWarnings("unchecked") NettyConnection<Integer, Integer> mockConnection = mock(NettyConnection.class);
doAnswer((Answer<Publisher<Integer>>) invocation -> {
throw DELIBERATE_EXCEPTION;
}).when(mockConnection).read();
doAnswer((Answer<Completable>) invocation -> {
Publisher<Integer> writePub = invocation.getArgument(0);
return writePub.ignoreElements();
}).when(mockConnection).write(any(), any(), any());
when(mockConnection.closeAsync()).thenReturn(completed());
requester = new NettyPipelinedConnection<>(mockConnection, 2);
toSource(requester.write(writePublisher1)).subscribe(readSubscriber);
Subscription readSubscription = readSubscriber.awaitSubscription();
readSubscription.request(1);
writePublisher1.onError(newSecondException());
assertThat(readSubscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
assertTrue(writePublisher1.isSubscribed());
verify(mockConnection).closeAsync();
}
use of io.servicetalk.concurrent.api.Publisher in project servicetalk by apple.
the class AfterErrorTest method testCallbackThrowsError.
@Override
@Test
void testCallbackThrowsError() {
DeliberateException srcEx = new DeliberateException();
doError(Publisher.<String>failed(srcEx), t -> {
throw DELIBERATE_EXCEPTION;
}).subscribe(subscriber);
assertThat(subscriber.awaitOnError(), sameInstance(srcEx));
}
use of io.servicetalk.concurrent.api.Publisher in project servicetalk by apple.
the class TestMulti method multiGenerated.
@Test
void multiGenerated() throws ExecutionException, InterruptedException {
TesterService service = new TesterService() {
@Override
public Publisher<TestReply> testBiDiStream(final GrpcServiceContext ctx, final Publisher<TestRequest> request) {
return Publisher.from(TestReply.newBuilder().build());
}
@Override
public Single<TestReply> testRequestStream(final GrpcServiceContext ctx, final Publisher<TestRequest> request) {
return Single.succeeded(TestReply.newBuilder().build());
}
@Override
public Publisher<TestReply> testResponseStream(final GrpcServiceContext ctx, final TestRequest request) {
return Publisher.from(TestReply.newBuilder().build());
}
@Override
public Single<TestReply> test(final GrpcServiceContext ctx, final TestRequest request) {
return Single.succeeded(TestReply.newBuilder().build());
}
};
Tester2Service service2 = new Tester2Service() {
@Override
public Publisher<Untils> testUntils(final GrpcServiceContext ctx, final Generic.Empty request) {
return Publisher.from(Untils.newBuilder().build());
}
@Override
public Single<SharedReply> testShared(final GrpcServiceContext ctx, final TestRequest request) {
return Single.succeeded(SharedReply.newBuilder().build());
}
};
service.closeAsync().toFuture().get();
service2.closeAsync().toFuture().get();
}
use of io.servicetalk.concurrent.api.Publisher in project servicetalk by apple.
the class TestSingle method singleGenerated.
@Test
void singleGenerated() throws ExecutionException, InterruptedException {
GreeterService service = new GreeterService() {
@Override
public Single<HelloReply> sayHelloFromMany(final GrpcServiceContext ctx, final Publisher<UserRequest> request) {
return Single.succeeded(HelloReply.newBuilder().build());
}
@Override
public Single<HelloReply> sayHello(final GrpcServiceContext ctx, final UserRequest request) {
return Single.succeeded(HelloReply.newBuilder().build());
}
@Override
public Publisher<HelloReply> sayHelloToFromMany(final GrpcServiceContext ctx, final Publisher<UserRequest> request) {
return Publisher.from(HelloReply.newBuilder().build());
}
@Override
public Publisher<HelloReply> sayHelloToMany(final GrpcServiceContext ctx, final UserRequest request) {
return Publisher.from(HelloReply.newBuilder().build());
}
};
FarewellerService service2 = new FarewellerService() {
@Override
public Publisher<Untils> getAllUntils(final GrpcServiceContext ctx, final Generic.Empty request) {
return Publisher.from(Untils.newBuilder().build());
}
@Override
public Single<SharedReply> sayGoodbye(final GrpcServiceContext ctx, final UserRequest request) {
return Single.succeeded(SharedReply.newBuilder().build());
}
};
service.closeAsync().toFuture().get();
service2.closeAsync().toFuture().get();
}
Aggregations