Remove client-streaming and bi-di streaming methods from blocking client interface.

The current signatures are not more useful than the async counterparts,
we'd rather not have them until more sepcific requirement comes up.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=80402647
This commit is contained in:
zhangkun 2014-11-20 11:45:33 -08:00 committed by Eric Anderson
parent 0d8477c85c
commit b186b377e8
3 changed files with 36 additions and 16 deletions

View File

@ -13,10 +13,9 @@ import com.google.protos.net.stubby.examples.Math.DivReply;
import com.google.protos.net.stubby.examples.Math.FibArgs;
import com.google.protos.net.stubby.examples.Math.Num;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@ -144,26 +143,41 @@ public class MathClient {
}
/**
* This example shows how to make a blocking client streaming call.
*
* <p> The asynchronous usage is similar to {@link #divMany}.
* This example shows how to make a client streaming call.
*/
public void blockingSum() {
logger.info("*** Blocking Sum");
public void sum() throws Exception {
final CountDownLatch completed = new CountDownLatch(1);
logger.info("*** Sum");
int count = 5;
Set<Num> numSet = new HashSet<Num>();
StreamObserver<Num> responseObserver = new StreamObserver<Num>() {
@Override
public void onValue(Num value) {
logger.info("Sum=" + value);
}
@Override
public void onError(Throwable t) {
logger.log(Level.SEVERE, "Error receiving response", t);
}
@Override
public void onCompleted() {
completed.countDown();
}
};
StreamObserver<Num> requestObserver = asyncStub.sum(responseObserver);
StringBuilder numMsg = new StringBuilder();
for (int i = 0; i < count; i++) {
int value = rand.nextInt();
numSet.add(Num.newBuilder().setNum(value).build());
requestObserver.onValue(Num.newBuilder().setNum(value).build());
numMsg.append(value);
if (i != count - 1) {
numMsg.append(" + ");
}
}
logger.info(numMsg.toString());
Num reply = blockingStub.sum(numSet.iterator());
logger.info("Result: " + numMsg.toString() + " = " + reply.getNum());
requestObserver.onCompleted();
completed.await();
}
/**
@ -196,7 +210,7 @@ public class MathClient {
client.blockingDiv(73, 0);
client.asyncDiv(1986, 12);
client.divMany();
client.blockingSum();
client.sum();
client.blockingFib();
} finally {
client.shutdown();

View File

@ -189,7 +189,14 @@ public abstract class AbstractTransportTest {
.setAggregatedPayloadSize(74922)
.build();
assertEquals(goldenResponse, blockingStub.streamingInputCall(requests.iterator()));
StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create();
StreamObserver<StreamingInputCallRequest> requestObserver =
asyncStub.streamingInputCall(responseObserver);
for (StreamingInputCallRequest request : requests) {
requestObserver.onValue(request);
}
requestObserver.onCompleted();
assertEquals(goldenResponse, responseObserver.firstValue().get());
}
@Test(timeout=5000)
@ -303,7 +310,7 @@ public abstract class AbstractTransportTest {
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestStream =
blockingStub.fullDuplexCall(recorder);
asyncStub.fullDuplexCall(recorder);
final int numRequests = 10;
for (int ix = numRequests; ix > 0; --ix) {
@ -465,8 +472,7 @@ public abstract class AbstractTransportTest {
@org.junit.Test
public void exchangeContextStreamingCall() throws Exception {
Assume.assumeTrue(AbstractStream.GRPC_V2_PROTOCOL);
TestServiceGrpc.TestServiceBlockingStub stub =
TestServiceGrpc.newBlockingStub(channel);
TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
// Capture the context exchange
Metadata.Headers fixedHeaders = new Metadata.Headers();

Binary file not shown.