Skip to content

Commit 42fcc50

Browse files
committed
Implement empty_stream integration test
The test was going to use a queue like ping_pong, but using a mock proved much simpler. Thus, I also updated ping_pong to use the simpler model, because it is useful for the two tests to be similar. InProcessTransportTest failed for empty_stream due to gRPC v2 issues, and so instead of ignoring emptyStream() I found the broken tests that were preventing swapping to gRPC v2 and ignored them instead. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=82733943
1 parent b09c26b commit 42fcc50

2 files changed

Lines changed: 25 additions & 45 deletions

File tree

integration-testing/src/main/java/com/google/net/stubby/testing/integration/AbstractTransportTest.java

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
import static com.google.net.stubby.testing.integration.Messages.PayloadType.COMPRESSABLE;
3535
import static com.google.net.stubby.testing.integration.Util.assertEquals;
3636
import static org.junit.Assert.assertEquals;
37-
import static org.junit.Assert.fail;
37+
import static org.mockito.Mockito.mock;
38+
import static org.mockito.Mockito.timeout;
39+
import static org.mockito.Mockito.verify;
40+
import static org.mockito.Mockito.verifyNoMoreInteractions;
3841

39-
import com.google.common.base.Throwables;
4042
import com.google.common.util.concurrent.ListenableFuture;
4143
import com.google.common.util.concurrent.SettableFuture;
4244
import com.google.common.util.concurrent.Uninterruptibles;
@@ -79,7 +81,6 @@
7981
import java.util.Random;
8082
import java.util.concurrent.Executors;
8183
import java.util.concurrent.ScheduledExecutorService;
82-
import java.util.concurrent.SynchronousQueue;
8384
import java.util.concurrent.TimeUnit;
8485
import java.util.concurrent.atomic.AtomicReference;
8586

@@ -279,52 +280,29 @@ public void pingPong() throws Exception {
279280
.setBody(ByteString.copyFrom(new byte[58979])))
280281
.build());
281282

282-
final SynchronousQueue<Object> queue = new SynchronousQueue<Object>();
283-
final Object sentinel = new Object();
284-
StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(
285-
new StreamObserver<StreamingOutputCallResponse>() {
286-
@Override
287-
public void onValue(StreamingOutputCallResponse response) {
288-
put(response);
289-
}
290-
291-
@Override
292-
public void onError(Throwable t) {
293-
put(t);
294-
}
295-
296-
@Override
297-
public void onCompleted() {
298-
put(sentinel);
299-
}
300-
301-
public void put(Object o) {
302-
try {
303-
queue.put(o);
304-
} catch (InterruptedException ex) {
305-
Thread.currentThread().interrupt();
306-
throw new AssertionError(ex);
307-
}
308-
}
309-
});
283+
@SuppressWarnings("unchecked")
284+
StreamObserver<StreamingOutputCallResponse> responseObserver = mock(StreamObserver.class);
285+
StreamObserver<StreamingOutputCallRequest> requestObserver
286+
= asyncStub.fullDuplexCall(responseObserver);
310287
for (int i = 0; i < requests.size(); i++) {
311288
requestObserver.onValue(requests.get(i));
312-
Object o = queue.take();
313-
if (o == sentinel) {
314-
fail("Premature onCompleted");
315-
} else if (o instanceof Throwable) {
316-
throw Throwables.propagate((Throwable) o);
317-
}
318-
try {
319-
assertEquals(goldenResponses.get(i), (StreamingOutputCallResponse) o);
320-
} catch (Exception e) {
321-
requestObserver.onError(e);
322-
while (queue.take() instanceof StreamingOutputCallResponse) {}
323-
throw e;
324-
}
289+
verify(responseObserver, timeout(1000)).onValue(goldenResponses.get(i));
290+
verifyNoMoreInteractions(responseObserver);
325291
}
326292
requestObserver.onCompleted();
327-
assertEquals(sentinel, queue.take());
293+
verify(responseObserver, timeout(1000)).onCompleted();
294+
verifyNoMoreInteractions(responseObserver);
295+
}
296+
297+
@Test
298+
public void emptyStream() throws Exception {
299+
@SuppressWarnings("unchecked")
300+
StreamObserver<StreamingOutputCallResponse> responseObserver = mock(StreamObserver.class);
301+
StreamObserver<StreamingOutputCallRequest> requestObserver
302+
= asyncStub.fullDuplexCall(responseObserver);
303+
requestObserver.onCompleted();
304+
verify(responseObserver, timeout(1000)).onCompleted();
305+
verifyNoMoreInteractions(responseObserver);
328306
}
329307

330308
@Test

integration-testing/src/main/java/com/google/net/stubby/testing/integration/TestServiceClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ private static void runTest(Tester tester, String testCase) throws Exception {
221221
tester.serverStreaming();
222222
} else if ("ping_pong".equals(testCase)) {
223223
tester.pingPong();
224+
} else if ("empty_stream".equals(testCase)) {
225+
tester.emptyStream();
224226
} else {
225227
throw new IllegalArgumentException("Unknown test case: " + testCase);
226228
}

0 commit comments

Comments
 (0)