Java Code Examples for io.grpc.internal.ServerStream#close()
The following examples show how to use
io.grpc.internal.ServerStream#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
/** * Helper that simply does an RPC. It can be used similar to a sleep for negative testing: to give * time for actions _not_ to happen. Since it is based on doing an actual RPC with actual * callbacks, it generally provides plenty of time for Runnables to execute. But it is also faster * on faster machines and more reliable on slower machines. */ private void doPingPong(MockServerListener serverListener) throws Exception { ManagedClientTransport client = newClientTransport(server); ManagedClientTransport.Listener listener = mock(ManagedClientTransport.Listener.class); startTransport(client, listener); ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener; serverStream.close(Status.OK, new Metadata()); assertNotNull(clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertNotNull(serverStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); client.shutdown(Status.UNAVAILABLE); }
Example 2
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void zeroMessageStream() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); serverTransport = serverTransportListener.transport; ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener; clientStream.halfClose(); assertTrue(serverStreamListener.awaitHalfClosed(TIMEOUT_MS, TimeUnit.MILLISECONDS)); serverStream.writeHeaders(new Metadata()); assertNotNull(clientStreamListener.headers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Status status = Status.OK.withDescription("Nice talking to you"); serverStream.close(status, new Metadata()); assertCodeEquals(Status.OK, serverStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Status clientStreamStatus = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertEquals(status.getCode(), clientStreamStatus.getCode()); assertEquals(status.getDescription(), clientStreamStatus.getDescription()); assertTrue(clientStreamTracer1.getOutboundHeaders()); assertTrue(clientStreamTracer1.getInboundHeaders()); assertSame(clientStreamStatus, clientStreamTracer1.getStatus()); assertSame(status, serverStreamTracer1.getStatus()); }
Example 3
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void earlyServerClose_withServerHeaders() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); serverTransport = serverTransportListener.transport; ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener; serverStream.writeHeaders(new Metadata()); assertNotNull(clientStreamListener.headers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Status strippedStatus = Status.OK.withDescription("Hello. Goodbye."); Status status = strippedStatus.withCause(new Exception()); serverStream.close(status, new Metadata()); assertCodeEquals(Status.OK, serverStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Status clientStreamStatus = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertEquals(status.getCode(), clientStreamStatus.getCode()); assertEquals("Hello. Goodbye.", clientStreamStatus.getDescription()); assertNull(clientStreamStatus.getCause()); assertTrue(clientStreamTracer1.getOutboundHeaders()); assertTrue(clientStreamTracer1.getInboundHeaders()); assertSame(clientStreamStatus, clientStreamTracer1.getStatus()); assertSame(status, serverStreamTracer1.getStatus()); }
Example 4
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void earlyServerClose_serverFailure() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); serverTransport = serverTransportListener.transport; ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener; Status strippedStatus = Status.INTERNAL.withDescription("I'm not listening"); Status status = strippedStatus.withCause(new Exception()); serverStream.close(status, new Metadata()); assertCodeEquals(Status.OK, serverStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Status clientStreamStatus = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertEquals(status.getCode(), clientStreamStatus.getCode()); assertEquals(status.getDescription(), clientStreamStatus.getDescription()); assertNull(clientStreamStatus.getCause()); assertTrue(clientStreamTracer1.getOutboundHeaders()); assertSame(clientStreamStatus, clientStreamTracer1.getStatus()); assertSame(status, serverStreamTracer1.getStatus()); }
Example 5
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void transportTracer_server_streamEnded_ok() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; if (!haveTransportTracer()) { return; } TransportStats serverBefore = getTransportStats(serverTransportListener.transport); assertEquals(0, serverBefore.streamsSucceeded); assertEquals(0, serverBefore.streamsFailed); TransportStats clientBefore = getTransportStats(client); assertEquals(0, clientBefore.streamsSucceeded); assertEquals(0, clientBefore.streamsFailed); clientStream.halfClose(); serverStream.close(Status.OK, new Metadata()); // do not validate stats until close() has been called on client assertNotNull(clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); TransportStats serverAfter = getTransportStats(serverTransportListener.transport); assertEquals(1, serverAfter.streamsSucceeded); assertEquals(0, serverAfter.streamsFailed); TransportStats clientAfter = getTransportStats(client); assertEquals(1, clientAfter.streamsSucceeded); assertEquals(0, clientAfter.streamsFailed); }
Example 6
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void transportTracer_server_streamEnded_nonOk() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; if (!haveTransportTracer()) { return; } TransportStats serverBefore = getTransportStats(serverTransportListener.transport); assertEquals(0, serverBefore.streamsFailed); assertEquals(0, serverBefore.streamsSucceeded); TransportStats clientBefore = getTransportStats(client); assertEquals(0, clientBefore.streamsFailed); assertEquals(0, clientBefore.streamsSucceeded); serverStream.close(Status.UNKNOWN, new Metadata()); // do not validate stats until close() has been called on client assertNotNull(clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); TransportStats serverAfter = getTransportStats(serverTransportListener.transport); assertEquals(1, serverAfter.streamsFailed); assertEquals(0, serverAfter.streamsSucceeded); TransportStats clientAfter = getTransportStats(client); assertEquals(1, clientAfter.streamsFailed); assertEquals(0, clientAfter.streamsSucceeded); client.shutdown(Status.UNAVAILABLE); }
Example 7
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void transportTracer_server_receive_msg() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener; if (!haveTransportTracer()) { return; } TransportStats serverBefore = getTransportStats(serverTransportListener.transport); assertEquals(0, serverBefore.messagesReceived); assertEquals(0, serverBefore.lastMessageReceivedTimeNanos); TransportStats clientBefore = getTransportStats(client); assertEquals(0, clientBefore.messagesSent); assertEquals(0, clientBefore.lastMessageSentTimeNanos); serverStream.request(1); clientStream.writeMessage(methodDescriptor.streamRequest("request")); clientStream.flush(); clientStream.halfClose(); verifyMessageCountAndClose(serverStreamListener.messageQueue, 1); TransportStats serverAfter = getTransportStats(serverTransportListener.transport); assertEquals(1, serverAfter.messagesReceived); assertEquals(fakeCurrentTimeNanos(), serverAfter.lastMessageReceivedTimeNanos); TransportStats clientAfter = getTransportStats(client); assertEquals(1, clientAfter.messagesSent); assertEquals(fakeCurrentTimeNanos(), clientAfter.lastMessageSentTimeNanos); serverStream.close(Status.OK, new Metadata()); }
Example 8
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void transportTracer_server_send_msg() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; if (!haveTransportTracer()) { return; } TransportStats serverBefore = getTransportStats(serverTransportListener.transport); assertEquals(0, serverBefore.messagesSent); assertEquals(0, serverBefore.lastMessageSentTimeNanos); TransportStats clientBefore = getTransportStats(client); assertEquals(0, clientBefore.messagesReceived); assertEquals(0, clientBefore.lastMessageReceivedTimeNanos); clientStream.request(1); serverStream.writeHeaders(new Metadata()); serverStream.writeMessage(methodDescriptor.streamResponse("response")); serverStream.flush(); verifyMessageCountAndClose(clientStreamListener.messageQueue, 1); TransportStats serverAfter = getTransportStats(serverTransportListener.transport); assertEquals(1, serverAfter.messagesSent); assertEquals(fakeCurrentTimeNanos(), serverAfter.lastMessageSentTimeNanos); TransportStats clientAfter = getTransportStats(client); assertEquals(1, clientAfter.messagesReceived); assertEquals(fakeCurrentTimeNanos(), clientAfter.lastMessageReceivedTimeNanos); serverStream.close(Status.OK, new Metadata()); }
Example 9
Source File: AbstractTransportTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Test public void earlyServerClose_noServerHeaders() throws Exception { server.start(serverListener); client = newClientTransport(server); startTransport(client, mockClientTransportListener); MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); serverTransport = serverTransportListener.transport; ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions); ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase(); clientStream.start(clientStreamListener); StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS); ServerStream serverStream = serverStreamCreation.stream; ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener; Status strippedStatus = Status.OK.withDescription("Hellogoodbye"); Status status = strippedStatus.withCause(new Exception()); Metadata trailers = new Metadata(); trailers.put(asciiKey, "trailers"); trailers.put(asciiKey, "dupvalue"); trailers.put(asciiKey, "dupvalue"); trailers.put(binaryKey, "äbinarytrailers"); serverStream.close(status, trailers); assertCodeEquals(Status.OK, serverStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Status clientStreamStatus = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); Metadata clientStreamTrailers = clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); assertEquals(status.getCode(), clientStreamStatus.getCode()); assertEquals("Hellogoodbye", clientStreamStatus.getDescription()); // Cause should not be transmitted to the client. assertNull(clientStreamStatus.getCause()); assertEquals( Lists.newArrayList(trailers.getAll(asciiKey)), Lists.newArrayList(clientStreamTrailers.getAll(asciiKey))); assertEquals( Lists.newArrayList(trailers.getAll(binaryKey)), Lists.newArrayList(clientStreamTrailers.getAll(binaryKey))); assertTrue(clientStreamTracer1.getOutboundHeaders()); assertSame(clientStreamStatus, clientStreamTracer1.getStatus()); assertSame(status, serverStreamTracer1.getStatus()); }