From 8a1c8340be7151ba38eca59597b4eda04ebdcc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Wed, 28 Mar 2012 17:14:22 +0200 Subject: Add functional test. --- build_protobufs.sh | 3 + .../com/orbekk/protobuf/SimpleProtobufClient.java | 54 +- .../com/orbekk/protobuf/SimpleProtobufServer.java | 44 +- src/main/java/com/orbekk/protobuf/Test.java | 1039 --------------- src/main/java/com/orbekk/protobuf/Test.proto | 15 - .../orbekk/protobuf/ProtobufFunctionalTest.java | 68 + src/test/java/com/orbekk/protobuf/Test.java | 1344 ++++++++++++++++++++ src/test/java/com/orbekk/protobuf/Test.proto | 20 + 8 files changed, 1486 insertions(+), 1101 deletions(-) delete mode 100644 src/main/java/com/orbekk/protobuf/Test.java delete mode 100644 src/main/java/com/orbekk/protobuf/Test.proto create mode 100644 src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java create mode 100644 src/test/java/com/orbekk/protobuf/Test.java create mode 100644 src/test/java/com/orbekk/protobuf/Test.proto diff --git a/build_protobufs.sh b/build_protobufs.sh index 59136c6..fd1e2d1 100755 --- a/build_protobufs.sh +++ b/build_protobufs.sh @@ -1,4 +1,7 @@ #!/bin/bash +find src/test/java -name '*.proto' -exec \ + protoc {} --java_out=src/test/java \; + find src/main/java -name '*.proto' -exec \ protoc {} --java_out=src/main/java \; diff --git a/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java b/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java index b17c0bc..7d0dc6a 100644 --- a/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java +++ b/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java @@ -9,31 +9,31 @@ public class SimpleProtobufClient { static final Logger logger = Logger.getLogger(SimpleProtobufClient.class.getName()); - public void run() { - RpcChannel channel = RpcChannel.create("localhost", 10000); - Test.TestService test = Test.TestService.newStub(channel); - Test.TestRequest request = Test.TestRequest.newBuilder() - .setId("Hello!") - .build(); - int count = 10; - final CountDownLatch stop = new CountDownLatch(count); - for (int i = 0; i < count; i++) { - logger.info("Sending request."); - test.run(null, request, new RpcCallback() { - @Override public void run(Test.TestResponse response) { - System.out.println("Response from server: " + response); - stop.countDown(); - } - }); - } - try { - stop.await(); - } catch (InterruptedException e) { - // Stop waiting. - } - } - - public static void main(String[] args) { - new SimpleProtobufClient().run(); - } +// public void run() { +// RpcChannel channel = RpcChannel.create("localhost", 10000); +// Test.TestService test = Test.TestService.newStub(channel); +// Test.TestRequest request = Test.TestRequest.newBuilder() +// .setId("Hello!") +// .build(); +// int count = 10; +// final CountDownLatch stop = new CountDownLatch(count); +// for (int i = 0; i < count; i++) { +// logger.info("Sending request."); +// test.run(null, request, new RpcCallback() { +// @Override public void run(Test.TestResponse response) { +// System.out.println("Response from server: " + response); +// stop.countDown(); +// } +// }); +// } +// try { +// stop.await(); +// } catch (InterruptedException e) { +// // Stop waiting. +// } +// } +// +// public static void main(String[] args) { +// new SimpleProtobufClient().run(); +// } } diff --git a/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java b/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java index a6dd7c4..690da81 100644 --- a/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java +++ b/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java @@ -39,6 +39,10 @@ public class SimpleProtobufServer extends Thread { public SimpleProtobufServer(ServerSocket serverSocket) { this.serverSocket = serverSocket; } + + public int getPort() { + return serverSocket.getLocalPort(); + } public synchronized void registerService(Service service) { String serviceName = service.getDescriptorForType().getFullName(); @@ -120,24 +124,24 @@ public class SimpleProtobufServer extends Thread { } } - public static void main(String[] args) { - SimpleProtobufServer server = SimpleProtobufServer.create(10000); - Test.TestService testService = new Test.TestService() { - @Override public void run(RpcController controller, - Test.TestRequest request, - RpcCallback done) { - System.out.println("Hello from TestService!"); - done.run(Test.TestResponse.newBuilder() - .setId("Hello from server.") - .build()); - } - }; - server.registerService(testService); - server.start(); - try { - server.join(); - } catch (InterruptedException e) { - System.out.println("Stopped."); - } - } +// public static void main(String[] args) { +// SimpleProtobufServer server = SimpleProtobufServer.create(10000); +// Test.TestService testService = new Test.TestService() { +// @Override public void run(RpcController controller, +// Test.TestRequest request, +// RpcCallback done) { +// System.out.println("Hello from TestService!"); +// done.run(Test.TestResponse.newBuilder() +// .setId("Hello from server.") +// .build()); +// } +// }; +// server.registerService(testService); +// server.start(); +// try { +// server.join(); +// } catch (InterruptedException e) { +// System.out.println("Stopped."); +// } +// } } diff --git a/src/main/java/com/orbekk/protobuf/Test.java b/src/main/java/com/orbekk/protobuf/Test.java deleted file mode 100644 index f1be1a9..0000000 --- a/src/main/java/com/orbekk/protobuf/Test.java +++ /dev/null @@ -1,1039 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: src/main/java/com/orbekk/protobuf/Test.proto - -package com.orbekk.protobuf; - -public final class Test { - private Test() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface TestRequestOrBuilder - extends com.google.protobuf.MessageOrBuilder { - - // optional string id = 1; - boolean hasId(); - String getId(); - } - public static final class TestRequest extends - com.google.protobuf.GeneratedMessage - implements TestRequestOrBuilder { - // Use TestRequest.newBuilder() to construct. - private TestRequest(Builder builder) { - super(builder); - } - private TestRequest(boolean noInit) {} - - private static final TestRequest defaultInstance; - public static TestRequest getDefaultInstance() { - return defaultInstance; - } - - public TestRequest getDefaultInstanceForType() { - return defaultInstance; - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestRequest_fieldAccessorTable; - } - - private int bitField0_; - // optional string id = 1; - public static final int ID_FIELD_NUMBER = 1; - private java.lang.Object id_; - public boolean hasId() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - public String getId() { - java.lang.Object ref = id_; - if (ref instanceof String) { - return (String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - String s = bs.toStringUtf8(); - if (com.google.protobuf.Internal.isValidUtf8(bs)) { - id_ = s; - } - return s; - } - } - private com.google.protobuf.ByteString getIdBytes() { - java.lang.Object ref = id_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((String) ref); - id_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private void initFields() { - id_ = ""; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, getIdBytes()); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getIdBytes()); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static com.orbekk.protobuf.Test.TestRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data, extensionRegistry) - .buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data, extensionRegistry) - .buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return newBuilder().mergeFrom(input).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return newBuilder().mergeFrom(input, extensionRegistry) - .buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - Builder builder = newBuilder(); - if (builder.mergeDelimitedFrom(input)) { - return builder.buildParsed(); - } else { - return null; - } - } - public static com.orbekk.protobuf.Test.TestRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - Builder builder = newBuilder(); - if (builder.mergeDelimitedFrom(input, extensionRegistry)) { - return builder.buildParsed(); - } else { - return null; - } - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return newBuilder().mergeFrom(input).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return newBuilder().mergeFrom(input, extensionRegistry) - .buildParsed(); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(com.orbekk.protobuf.Test.TestRequest prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements com.orbekk.protobuf.Test.TestRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestRequest_fieldAccessorTable; - } - - // Construct using com.orbekk.protobuf.Test.TestRequest.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder(BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - id_ = ""; - bitField0_ = (bitField0_ & ~0x00000001); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.orbekk.protobuf.Test.TestRequest.getDescriptor(); - } - - public com.orbekk.protobuf.Test.TestRequest getDefaultInstanceForType() { - return com.orbekk.protobuf.Test.TestRequest.getDefaultInstance(); - } - - public com.orbekk.protobuf.Test.TestRequest build() { - com.orbekk.protobuf.Test.TestRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - private com.orbekk.protobuf.Test.TestRequest buildParsed() - throws com.google.protobuf.InvalidProtocolBufferException { - com.orbekk.protobuf.Test.TestRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException( - result).asInvalidProtocolBufferException(); - } - return result; - } - - public com.orbekk.protobuf.Test.TestRequest buildPartial() { - com.orbekk.protobuf.Test.TestRequest result = new com.orbekk.protobuf.Test.TestRequest(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - result.id_ = id_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.orbekk.protobuf.Test.TestRequest) { - return mergeFrom((com.orbekk.protobuf.Test.TestRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.orbekk.protobuf.Test.TestRequest other) { - if (other == com.orbekk.protobuf.Test.TestRequest.getDefaultInstance()) return this; - if (other.hasId()) { - setId(other.getId()); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder( - this.getUnknownFields()); - while (true) { - int tag = input.readTag(); - switch (tag) { - case 0: - this.setUnknownFields(unknownFields.build()); - onChanged(); - return this; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - this.setUnknownFields(unknownFields.build()); - onChanged(); - return this; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - id_ = input.readBytes(); - break; - } - } - } - } - - private int bitField0_; - - // optional string id = 1; - private java.lang.Object id_ = ""; - public boolean hasId() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - public String getId() { - java.lang.Object ref = id_; - if (!(ref instanceof String)) { - String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); - id_ = s; - return s; - } else { - return (String) ref; - } - } - public Builder setId(String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; - id_ = value; - onChanged(); - return this; - } - public Builder clearId() { - bitField0_ = (bitField0_ & ~0x00000001); - id_ = getDefaultInstance().getId(); - onChanged(); - return this; - } - void setId(com.google.protobuf.ByteString value) { - bitField0_ |= 0x00000001; - id_ = value; - onChanged(); - } - - // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.TestRequest) - } - - static { - defaultInstance = new TestRequest(true); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.TestRequest) - } - - public interface TestResponseOrBuilder - extends com.google.protobuf.MessageOrBuilder { - - // optional string id = 1; - boolean hasId(); - String getId(); - } - public static final class TestResponse extends - com.google.protobuf.GeneratedMessage - implements TestResponseOrBuilder { - // Use TestResponse.newBuilder() to construct. - private TestResponse(Builder builder) { - super(builder); - } - private TestResponse(boolean noInit) {} - - private static final TestResponse defaultInstance; - public static TestResponse getDefaultInstance() { - return defaultInstance; - } - - public TestResponse getDefaultInstanceForType() { - return defaultInstance; - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestResponse_fieldAccessorTable; - } - - private int bitField0_; - // optional string id = 1; - public static final int ID_FIELD_NUMBER = 1; - private java.lang.Object id_; - public boolean hasId() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - public String getId() { - java.lang.Object ref = id_; - if (ref instanceof String) { - return (String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - String s = bs.toStringUtf8(); - if (com.google.protobuf.Internal.isValidUtf8(bs)) { - id_ = s; - } - return s; - } - } - private com.google.protobuf.ByteString getIdBytes() { - java.lang.Object ref = id_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8((String) ref); - id_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private void initFields() { - id_ = ""; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, getIdBytes()); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getIdBytes()); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static com.orbekk.protobuf.Test.TestResponse parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data, extensionRegistry) - .buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data, extensionRegistry) - .buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { - return newBuilder().mergeFrom(input).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return newBuilder().mergeFrom(input, extensionRegistry) - .buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - Builder builder = newBuilder(); - if (builder.mergeDelimitedFrom(input)) { - return builder.buildParsed(); - } else { - return null; - } - } - public static com.orbekk.protobuf.Test.TestResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - Builder builder = newBuilder(); - if (builder.mergeDelimitedFrom(input, extensionRegistry)) { - return builder.buildParsed(); - } else { - return null; - } - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return newBuilder().mergeFrom(input).buildParsed(); - } - public static com.orbekk.protobuf.Test.TestResponse parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return newBuilder().mergeFrom(input, extensionRegistry) - .buildParsed(); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(com.orbekk.protobuf.Test.TestResponse prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements com.orbekk.protobuf.Test.TestResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_TestResponse_fieldAccessorTable; - } - - // Construct using com.orbekk.protobuf.Test.TestResponse.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder(BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - id_ = ""; - bitField0_ = (bitField0_ & ~0x00000001); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.orbekk.protobuf.Test.TestResponse.getDescriptor(); - } - - public com.orbekk.protobuf.Test.TestResponse getDefaultInstanceForType() { - return com.orbekk.protobuf.Test.TestResponse.getDefaultInstance(); - } - - public com.orbekk.protobuf.Test.TestResponse build() { - com.orbekk.protobuf.Test.TestResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - private com.orbekk.protobuf.Test.TestResponse buildParsed() - throws com.google.protobuf.InvalidProtocolBufferException { - com.orbekk.protobuf.Test.TestResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException( - result).asInvalidProtocolBufferException(); - } - return result; - } - - public com.orbekk.protobuf.Test.TestResponse buildPartial() { - com.orbekk.protobuf.Test.TestResponse result = new com.orbekk.protobuf.Test.TestResponse(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - result.id_ = id_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.orbekk.protobuf.Test.TestResponse) { - return mergeFrom((com.orbekk.protobuf.Test.TestResponse)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.orbekk.protobuf.Test.TestResponse other) { - if (other == com.orbekk.protobuf.Test.TestResponse.getDefaultInstance()) return this; - if (other.hasId()) { - setId(other.getId()); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder( - this.getUnknownFields()); - while (true) { - int tag = input.readTag(); - switch (tag) { - case 0: - this.setUnknownFields(unknownFields.build()); - onChanged(); - return this; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - this.setUnknownFields(unknownFields.build()); - onChanged(); - return this; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - id_ = input.readBytes(); - break; - } - } - } - } - - private int bitField0_; - - // optional string id = 1; - private java.lang.Object id_ = ""; - public boolean hasId() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - public String getId() { - java.lang.Object ref = id_; - if (!(ref instanceof String)) { - String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); - id_ = s; - return s; - } else { - return (String) ref; - } - } - public Builder setId(String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; - id_ = value; - onChanged(); - return this; - } - public Builder clearId() { - bitField0_ = (bitField0_ & ~0x00000001); - id_ = getDefaultInstance().getId(); - onChanged(); - return this; - } - void setId(com.google.protobuf.ByteString value) { - bitField0_ |= 0x00000001; - id_ = value; - onChanged(); - } - - // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.TestResponse) - } - - static { - defaultInstance = new TestResponse(true); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.TestResponse) - } - - public static abstract class TestService - implements com.google.protobuf.Service { - protected TestService() {} - - public interface Interface { - public abstract void run( - com.google.protobuf.RpcController controller, - com.orbekk.protobuf.Test.TestRequest request, - com.google.protobuf.RpcCallback done); - - } - - public static com.google.protobuf.Service newReflectiveService( - final Interface impl) { - return new TestService() { - @java.lang.Override - public void run( - com.google.protobuf.RpcController controller, - com.orbekk.protobuf.Test.TestRequest request, - com.google.protobuf.RpcCallback done) { - impl.run(controller, request, done); - } - - }; - } - - public static com.google.protobuf.BlockingService - newReflectiveBlockingService(final BlockingInterface impl) { - return new com.google.protobuf.BlockingService() { - public final com.google.protobuf.Descriptors.ServiceDescriptor - getDescriptorForType() { - return getDescriptor(); - } - - public final com.google.protobuf.Message callBlockingMethod( - com.google.protobuf.Descriptors.MethodDescriptor method, - com.google.protobuf.RpcController controller, - com.google.protobuf.Message request) - throws com.google.protobuf.ServiceException { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.callBlockingMethod() given method descriptor for " + - "wrong service type."); - } - switch(method.getIndex()) { - case 0: - return impl.run(controller, (com.orbekk.protobuf.Test.TestRequest)request); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getRequestPrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getRequestPrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return com.orbekk.protobuf.Test.TestRequest.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getResponsePrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getResponsePrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return com.orbekk.protobuf.Test.TestResponse.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - }; - } - - public abstract void run( - com.google.protobuf.RpcController controller, - com.orbekk.protobuf.Test.TestRequest request, - com.google.protobuf.RpcCallback done); - - public static final - com.google.protobuf.Descriptors.ServiceDescriptor - getDescriptor() { - return com.orbekk.protobuf.Test.getDescriptor().getServices().get(0); - } - public final com.google.protobuf.Descriptors.ServiceDescriptor - getDescriptorForType() { - return getDescriptor(); - } - - public final void callMethod( - com.google.protobuf.Descriptors.MethodDescriptor method, - com.google.protobuf.RpcController controller, - com.google.protobuf.Message request, - com.google.protobuf.RpcCallback< - com.google.protobuf.Message> done) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.callMethod() given method descriptor for wrong " + - "service type."); - } - switch(method.getIndex()) { - case 0: - this.run(controller, (com.orbekk.protobuf.Test.TestRequest)request, - com.google.protobuf.RpcUtil.specializeCallback( - done)); - return; - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getRequestPrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getRequestPrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return com.orbekk.protobuf.Test.TestRequest.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getResponsePrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getResponsePrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return com.orbekk.protobuf.Test.TestResponse.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public static Stub newStub( - com.google.protobuf.RpcChannel channel) { - return new Stub(channel); - } - - public static final class Stub extends com.orbekk.protobuf.Test.TestService implements Interface { - private Stub(com.google.protobuf.RpcChannel channel) { - this.channel = channel; - } - - private final com.google.protobuf.RpcChannel channel; - - public com.google.protobuf.RpcChannel getChannel() { - return channel; - } - - public void run( - com.google.protobuf.RpcController controller, - com.orbekk.protobuf.Test.TestRequest request, - com.google.protobuf.RpcCallback done) { - channel.callMethod( - getDescriptor().getMethods().get(0), - controller, - request, - com.orbekk.protobuf.Test.TestResponse.getDefaultInstance(), - com.google.protobuf.RpcUtil.generalizeCallback( - done, - com.orbekk.protobuf.Test.TestResponse.class, - com.orbekk.protobuf.Test.TestResponse.getDefaultInstance())); - } - } - - public static BlockingInterface newBlockingStub( - com.google.protobuf.BlockingRpcChannel channel) { - return new BlockingStub(channel); - } - - public interface BlockingInterface { - public com.orbekk.protobuf.Test.TestResponse run( - com.google.protobuf.RpcController controller, - com.orbekk.protobuf.Test.TestRequest request) - throws com.google.protobuf.ServiceException; - } - - private static final class BlockingStub implements BlockingInterface { - private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) { - this.channel = channel; - } - - private final com.google.protobuf.BlockingRpcChannel channel; - - public com.orbekk.protobuf.Test.TestResponse run( - com.google.protobuf.RpcController controller, - com.orbekk.protobuf.Test.TestRequest request) - throws com.google.protobuf.ServiceException { - return (com.orbekk.protobuf.Test.TestResponse) channel.callBlockingMethod( - getDescriptor().getMethods().get(0), - controller, - request, - com.orbekk.protobuf.Test.TestResponse.getDefaultInstance()); - } - - } - } - - private static com.google.protobuf.Descriptors.Descriptor - internal_static_com_orbekk_protobuf_TestRequest_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_com_orbekk_protobuf_TestRequest_fieldAccessorTable; - private static com.google.protobuf.Descriptors.Descriptor - internal_static_com_orbekk_protobuf_TestResponse_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_com_orbekk_protobuf_TestResponse_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n,src/main/java/com/orbekk/protobuf/Test" + - ".proto\022\023com.orbekk.protobuf\"\031\n\013TestReque" + - "st\022\n\n\002id\030\001 \001(\t\"\032\n\014TestResponse\022\n\n\002id\030\001 \001" + - "(\t2Y\n\013TestService\022J\n\003Run\022 .com.orbekk.pr" + - "otobuf.TestRequest\032!.com.orbekk.protobuf" + - ".TestResponseB\003\210\001\001" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - internal_static_com_orbekk_protobuf_TestRequest_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_com_orbekk_protobuf_TestRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_com_orbekk_protobuf_TestRequest_descriptor, - new java.lang.String[] { "Id", }, - com.orbekk.protobuf.Test.TestRequest.class, - com.orbekk.protobuf.Test.TestRequest.Builder.class); - internal_static_com_orbekk_protobuf_TestResponse_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_com_orbekk_protobuf_TestResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_com_orbekk_protobuf_TestResponse_descriptor, - new java.lang.String[] { "Id", }, - com.orbekk.protobuf.Test.TestResponse.class, - com.orbekk.protobuf.Test.TestResponse.Builder.class); - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/src/main/java/com/orbekk/protobuf/Test.proto b/src/main/java/com/orbekk/protobuf/Test.proto deleted file mode 100644 index 3abb507..0000000 --- a/src/main/java/com/orbekk/protobuf/Test.proto +++ /dev/null @@ -1,15 +0,0 @@ -package com.orbekk.protobuf; - -option java_generic_services = true; - -message TestRequest { - optional string id = 1; -} - -message TestResponse { - optional string id = 1; -} - -service TestService { - rpc Run (TestRequest) returns (TestResponse); -} diff --git a/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java b/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java new file mode 100644 index 0000000..d60a016 --- /dev/null +++ b/src/test/java/com/orbekk/protobuf/ProtobufFunctionalTest.java @@ -0,0 +1,68 @@ +package com.orbekk.protobuf; + +import java.util.concurrent.CountDownLatch; + +import org.junit.Before; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.orbekk.protobuf.Test.Type1; +import com.orbekk.protobuf.Test.Type2; + +public class ProtobufFunctionalTest { + CountDownLatch returnC = new CountDownLatch(1); + SimpleProtobufServer server = SimpleProtobufServer.create(0); + int serverport = server.getPort(); + RpcChannel channel = RpcChannel.create("localhost", serverport); + TestService directService = new TestService(); + Test.Service service = Test.Service.newStub(channel); + + @Before public void setUp() { + server.registerService(directService); + } + + public class TestService extends Test.Service { + @Override + public void testA(RpcController controller, Type1 request, + RpcCallback done) { + Type2 response = Type2.newBuilder() + .setMessage("TestA") + .build(); + done.run(response); + } + + @Override + public void testB(RpcController controller, Type1 request, + RpcCallback done) { + controller.setFailed("error"); + } + + @Override + public void testC(RpcController controller, Type1 request, + RpcCallback done) { + try { + returnC.await(); + } catch (InterruptedException e) { + } + Type2 response = Type2.newBuilder() + .setResult(request.getA() + request.getB()) + .setMessage("TestC result") + .build(); + done.run(response); + } + } + + @org.junit.Test public void respondsNormally() { + Test.Type1 request = Test.Type1.newBuilder().build(); + int count = 10; + final CountDownLatch stop = new CountDownLatch(count); + service.testA(null, request, new RpcCallback() { + @Override public void run(Type2 result) { + assertThat(result.getMessage(), is("TestA")); + stop.countDown(); + } + }); + } +} diff --git a/src/test/java/com/orbekk/protobuf/Test.java b/src/test/java/com/orbekk/protobuf/Test.java new file mode 100644 index 0000000..3fe8efb --- /dev/null +++ b/src/test/java/com/orbekk/protobuf/Test.java @@ -0,0 +1,1344 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: src/test/java/com/orbekk/protobuf/Test.proto + +package com.orbekk.protobuf; + +public final class Test { + private Test() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface Type1OrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // optional int32 a = 1; + boolean hasA(); + int getA(); + + // optional int32 b = 2; + boolean hasB(); + int getB(); + + // optional string message = 3; + boolean hasMessage(); + String getMessage(); + } + public static final class Type1 extends + com.google.protobuf.GeneratedMessage + implements Type1OrBuilder { + // Use Type1.newBuilder() to construct. + private Type1(Builder builder) { + super(builder); + } + private Type1(boolean noInit) {} + + private static final Type1 defaultInstance; + public static Type1 getDefaultInstance() { + return defaultInstance; + } + + public Type1 getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type1_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type1_fieldAccessorTable; + } + + private int bitField0_; + // optional int32 a = 1; + public static final int A_FIELD_NUMBER = 1; + private int a_; + public boolean hasA() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public int getA() { + return a_; + } + + // optional int32 b = 2; + public static final int B_FIELD_NUMBER = 2; + private int b_; + public boolean hasB() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public int getB() { + return b_; + } + + // optional string message = 3; + public static final int MESSAGE_FIELD_NUMBER = 3; + private java.lang.Object message_; + public boolean hasMessage() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public String getMessage() { + java.lang.Object ref = message_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + message_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getMessageBytes() { + java.lang.Object ref = message_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + message_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + a_ = 0; + b_ = 0; + message_ = ""; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt32(1, a_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeInt32(2, b_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(3, getMessageBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, a_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(2, b_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, getMessageBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static com.orbekk.protobuf.Test.Type1 parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.orbekk.protobuf.Test.Type1 parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.orbekk.protobuf.Test.Type1 parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type1 parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(com.orbekk.protobuf.Test.Type1 prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements com.orbekk.protobuf.Test.Type1OrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type1_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type1_fieldAccessorTable; + } + + // Construct using com.orbekk.protobuf.Test.Type1.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + a_ = 0; + bitField0_ = (bitField0_ & ~0x00000001); + b_ = 0; + bitField0_ = (bitField0_ & ~0x00000002); + message_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.orbekk.protobuf.Test.Type1.getDescriptor(); + } + + public com.orbekk.protobuf.Test.Type1 getDefaultInstanceForType() { + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + } + + public com.orbekk.protobuf.Test.Type1 build() { + com.orbekk.protobuf.Test.Type1 result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private com.orbekk.protobuf.Test.Type1 buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + com.orbekk.protobuf.Test.Type1 result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public com.orbekk.protobuf.Test.Type1 buildPartial() { + com.orbekk.protobuf.Test.Type1 result = new com.orbekk.protobuf.Test.Type1(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.a_ = a_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.b_ = b_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.message_ = message_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.orbekk.protobuf.Test.Type1) { + return mergeFrom((com.orbekk.protobuf.Test.Type1)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.orbekk.protobuf.Test.Type1 other) { + if (other == com.orbekk.protobuf.Test.Type1.getDefaultInstance()) return this; + if (other.hasA()) { + setA(other.getA()); + } + if (other.hasB()) { + setB(other.getB()); + } + if (other.hasMessage()) { + setMessage(other.getMessage()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + a_ = input.readInt32(); + break; + } + case 16: { + bitField0_ |= 0x00000002; + b_ = input.readInt32(); + break; + } + case 26: { + bitField0_ |= 0x00000004; + message_ = input.readBytes(); + break; + } + } + } + } + + private int bitField0_; + + // optional int32 a = 1; + private int a_ ; + public boolean hasA() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public int getA() { + return a_; + } + public Builder setA(int value) { + bitField0_ |= 0x00000001; + a_ = value; + onChanged(); + return this; + } + public Builder clearA() { + bitField0_ = (bitField0_ & ~0x00000001); + a_ = 0; + onChanged(); + return this; + } + + // optional int32 b = 2; + private int b_ ; + public boolean hasB() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public int getB() { + return b_; + } + public Builder setB(int value) { + bitField0_ |= 0x00000002; + b_ = value; + onChanged(); + return this; + } + public Builder clearB() { + bitField0_ = (bitField0_ & ~0x00000002); + b_ = 0; + onChanged(); + return this; + } + + // optional string message = 3; + private java.lang.Object message_ = ""; + public boolean hasMessage() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public String getMessage() { + java.lang.Object ref = message_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + message_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setMessage(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + message_ = value; + onChanged(); + return this; + } + public Builder clearMessage() { + bitField0_ = (bitField0_ & ~0x00000004); + message_ = getDefaultInstance().getMessage(); + onChanged(); + return this; + } + void setMessage(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000004; + message_ = value; + onChanged(); + } + + // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.Type1) + } + + static { + defaultInstance = new Type1(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.Type1) + } + + public interface Type2OrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // optional int32 result = 1; + boolean hasResult(); + int getResult(); + + // optional string message = 2; + boolean hasMessage(); + String getMessage(); + } + public static final class Type2 extends + com.google.protobuf.GeneratedMessage + implements Type2OrBuilder { + // Use Type2.newBuilder() to construct. + private Type2(Builder builder) { + super(builder); + } + private Type2(boolean noInit) {} + + private static final Type2 defaultInstance; + public static Type2 getDefaultInstance() { + return defaultInstance; + } + + public Type2 getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type2_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type2_fieldAccessorTable; + } + + private int bitField0_; + // optional int32 result = 1; + public static final int RESULT_FIELD_NUMBER = 1; + private int result_; + public boolean hasResult() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public int getResult() { + return result_; + } + + // optional string message = 2; + public static final int MESSAGE_FIELD_NUMBER = 2; + private java.lang.Object message_; + public boolean hasMessage() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getMessage() { + java.lang.Object ref = message_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + message_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getMessageBytes() { + java.lang.Object ref = message_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + message_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + result_ = 0; + message_ = ""; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt32(1, result_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getMessageBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, result_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getMessageBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static com.orbekk.protobuf.Test.Type2 parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.orbekk.protobuf.Test.Type2 parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static com.orbekk.protobuf.Test.Type2 parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static com.orbekk.protobuf.Test.Type2 parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(com.orbekk.protobuf.Test.Type2 prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements com.orbekk.protobuf.Test.Type2OrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type2_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.orbekk.protobuf.Test.internal_static_com_orbekk_protobuf_Type2_fieldAccessorTable; + } + + // Construct using com.orbekk.protobuf.Test.Type2.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + result_ = 0; + bitField0_ = (bitField0_ & ~0x00000001); + message_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.orbekk.protobuf.Test.Type2.getDescriptor(); + } + + public com.orbekk.protobuf.Test.Type2 getDefaultInstanceForType() { + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + } + + public com.orbekk.protobuf.Test.Type2 build() { + com.orbekk.protobuf.Test.Type2 result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private com.orbekk.protobuf.Test.Type2 buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + com.orbekk.protobuf.Test.Type2 result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public com.orbekk.protobuf.Test.Type2 buildPartial() { + com.orbekk.protobuf.Test.Type2 result = new com.orbekk.protobuf.Test.Type2(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.result_ = result_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.message_ = message_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.orbekk.protobuf.Test.Type2) { + return mergeFrom((com.orbekk.protobuf.Test.Type2)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.orbekk.protobuf.Test.Type2 other) { + if (other == com.orbekk.protobuf.Test.Type2.getDefaultInstance()) return this; + if (other.hasResult()) { + setResult(other.getResult()); + } + if (other.hasMessage()) { + setMessage(other.getMessage()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + result_ = input.readInt32(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + message_ = input.readBytes(); + break; + } + } + } + } + + private int bitField0_; + + // optional int32 result = 1; + private int result_ ; + public boolean hasResult() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public int getResult() { + return result_; + } + public Builder setResult(int value) { + bitField0_ |= 0x00000001; + result_ = value; + onChanged(); + return this; + } + public Builder clearResult() { + bitField0_ = (bitField0_ & ~0x00000001); + result_ = 0; + onChanged(); + return this; + } + + // optional string message = 2; + private java.lang.Object message_ = ""; + public boolean hasMessage() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getMessage() { + java.lang.Object ref = message_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + message_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setMessage(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + message_ = value; + onChanged(); + return this; + } + public Builder clearMessage() { + bitField0_ = (bitField0_ & ~0x00000002); + message_ = getDefaultInstance().getMessage(); + onChanged(); + return this; + } + void setMessage(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000002; + message_ = value; + onChanged(); + } + + // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.Type2) + } + + static { + defaultInstance = new Type2(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.Type2) + } + + public static abstract class Service + implements com.google.protobuf.Service { + protected Service() {} + + public interface Interface { + public abstract void testA( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done); + + public abstract void testB( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done); + + public abstract void testC( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done); + + } + + public static com.google.protobuf.Service newReflectiveService( + final Interface impl) { + return new Service() { + @java.lang.Override + public void testA( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done) { + impl.testA(controller, request, done); + } + + @java.lang.Override + public void testB( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done) { + impl.testB(controller, request, done); + } + + @java.lang.Override + public void testC( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done) { + impl.testC(controller, request, done); + } + + }; + } + + public static com.google.protobuf.BlockingService + newReflectiveBlockingService(final BlockingInterface impl) { + return new com.google.protobuf.BlockingService() { + public final com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptorForType() { + return getDescriptor(); + } + + public final com.google.protobuf.Message callBlockingMethod( + com.google.protobuf.Descriptors.MethodDescriptor method, + com.google.protobuf.RpcController controller, + com.google.protobuf.Message request) + throws com.google.protobuf.ServiceException { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.callBlockingMethod() given method descriptor for " + + "wrong service type."); + } + switch(method.getIndex()) { + case 0: + return impl.testA(controller, (com.orbekk.protobuf.Test.Type1)request); + case 1: + return impl.testB(controller, (com.orbekk.protobuf.Test.Type1)request); + case 2: + return impl.testC(controller, (com.orbekk.protobuf.Test.Type1)request); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getRequestPrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getRequestPrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + case 1: + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + case 2: + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getResponsePrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getResponsePrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + case 1: + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + case 2: + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + }; + } + + public abstract void testA( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done); + + public abstract void testB( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done); + + public abstract void testC( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done); + + public static final + com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptor() { + return com.orbekk.protobuf.Test.getDescriptor().getServices().get(0); + } + public final com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptorForType() { + return getDescriptor(); + } + + public final void callMethod( + com.google.protobuf.Descriptors.MethodDescriptor method, + com.google.protobuf.RpcController controller, + com.google.protobuf.Message request, + com.google.protobuf.RpcCallback< + com.google.protobuf.Message> done) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.callMethod() given method descriptor for wrong " + + "service type."); + } + switch(method.getIndex()) { + case 0: + this.testA(controller, (com.orbekk.protobuf.Test.Type1)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; + case 1: + this.testB(controller, (com.orbekk.protobuf.Test.Type1)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; + case 2: + this.testC(controller, (com.orbekk.protobuf.Test.Type1)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getRequestPrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getRequestPrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + case 1: + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + case 2: + return com.orbekk.protobuf.Test.Type1.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getResponsePrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getResponsePrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + case 1: + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + case 2: + return com.orbekk.protobuf.Test.Type2.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public static Stub newStub( + com.google.protobuf.RpcChannel channel) { + return new Stub(channel); + } + + public static final class Stub extends com.orbekk.protobuf.Test.Service implements Interface { + private Stub(com.google.protobuf.RpcChannel channel) { + this.channel = channel; + } + + private final com.google.protobuf.RpcChannel channel; + + public com.google.protobuf.RpcChannel getChannel() { + return channel; + } + + public void testA( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(0), + controller, + request, + com.orbekk.protobuf.Test.Type2.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + com.orbekk.protobuf.Test.Type2.class, + com.orbekk.protobuf.Test.Type2.getDefaultInstance())); + } + + public void testB( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(1), + controller, + request, + com.orbekk.protobuf.Test.Type2.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + com.orbekk.protobuf.Test.Type2.class, + com.orbekk.protobuf.Test.Type2.getDefaultInstance())); + } + + public void testC( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(2), + controller, + request, + com.orbekk.protobuf.Test.Type2.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + com.orbekk.protobuf.Test.Type2.class, + com.orbekk.protobuf.Test.Type2.getDefaultInstance())); + } + } + + public static BlockingInterface newBlockingStub( + com.google.protobuf.BlockingRpcChannel channel) { + return new BlockingStub(channel); + } + + public interface BlockingInterface { + public com.orbekk.protobuf.Test.Type2 testA( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request) + throws com.google.protobuf.ServiceException; + + public com.orbekk.protobuf.Test.Type2 testB( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request) + throws com.google.protobuf.ServiceException; + + public com.orbekk.protobuf.Test.Type2 testC( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request) + throws com.google.protobuf.ServiceException; + } + + private static final class BlockingStub implements BlockingInterface { + private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) { + this.channel = channel; + } + + private final com.google.protobuf.BlockingRpcChannel channel; + + public com.orbekk.protobuf.Test.Type2 testA( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request) + throws com.google.protobuf.ServiceException { + return (com.orbekk.protobuf.Test.Type2) channel.callBlockingMethod( + getDescriptor().getMethods().get(0), + controller, + request, + com.orbekk.protobuf.Test.Type2.getDefaultInstance()); + } + + + public com.orbekk.protobuf.Test.Type2 testB( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request) + throws com.google.protobuf.ServiceException { + return (com.orbekk.protobuf.Test.Type2) channel.callBlockingMethod( + getDescriptor().getMethods().get(1), + controller, + request, + com.orbekk.protobuf.Test.Type2.getDefaultInstance()); + } + + + public com.orbekk.protobuf.Test.Type2 testC( + com.google.protobuf.RpcController controller, + com.orbekk.protobuf.Test.Type1 request) + throws com.google.protobuf.ServiceException { + return (com.orbekk.protobuf.Test.Type2) channel.callBlockingMethod( + getDescriptor().getMethods().get(2), + controller, + request, + com.orbekk.protobuf.Test.Type2.getDefaultInstance()); + } + + } + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_com_orbekk_protobuf_Type1_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_com_orbekk_protobuf_Type1_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_com_orbekk_protobuf_Type2_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_com_orbekk_protobuf_Type2_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n,src/test/java/com/orbekk/protobuf/Test" + + ".proto\022\023com.orbekk.protobuf\".\n\005Type1\022\t\n\001" + + "a\030\001 \001(\005\022\t\n\001b\030\002 \001(\005\022\017\n\007message\030\003 \001(\t\"(\n\005T" + + "ype2\022\016\n\006result\030\001 \001(\005\022\017\n\007message\030\002 \001(\t2\314\001" + + "\n\007Service\022?\n\005TestA\022\032.com.orbekk.protobuf" + + ".Type1\032\032.com.orbekk.protobuf.Type2\022?\n\005Te" + + "stB\022\032.com.orbekk.protobuf.Type1\032\032.com.or" + + "bekk.protobuf.Type2\022?\n\005TestC\022\032.com.orbek" + + "k.protobuf.Type1\032\032.com.orbekk.protobuf.T" + + "ype2B\003\210\001\001" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + internal_static_com_orbekk_protobuf_Type1_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_com_orbekk_protobuf_Type1_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_com_orbekk_protobuf_Type1_descriptor, + new java.lang.String[] { "A", "B", "Message", }, + com.orbekk.protobuf.Test.Type1.class, + com.orbekk.protobuf.Test.Type1.Builder.class); + internal_static_com_orbekk_protobuf_Type2_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_com_orbekk_protobuf_Type2_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_com_orbekk_protobuf_Type2_descriptor, + new java.lang.String[] { "Result", "Message", }, + com.orbekk.protobuf.Test.Type2.class, + com.orbekk.protobuf.Test.Type2.Builder.class); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/src/test/java/com/orbekk/protobuf/Test.proto b/src/test/java/com/orbekk/protobuf/Test.proto new file mode 100644 index 0000000..9bbe629 --- /dev/null +++ b/src/test/java/com/orbekk/protobuf/Test.proto @@ -0,0 +1,20 @@ +package com.orbekk.protobuf; + +option java_generic_services = true; + +message Type1 { + optional int32 a = 1; + optional int32 b = 2; + optional string message = 3; +} + +message Type2 { + optional int32 result = 1; + optional string message = 2; +} + +service Service { + rpc TestA (Type1) returns (Type2); + rpc TestB (Type1) returns (Type2); + rpc TestC (Type1) returns (Type2); +} -- cgit v1.2.3