Repository: geode Updated Branches: refs/heads/feature/GEODE-2995 [created] 336b0e0a5
GEODE-2995: Adding ProtobufProtocolHandler Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/719c6919 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/719c6919 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/719c6919 Branch: refs/heads/feature/GEODE-2995 Commit: 719c6919cb29080a5ec8dc0b4e6397c22a83534e Parents: 122b07a Author: Udo Kohlmeyer <[email protected]> Authored: Mon Jun 12 15:12:18 2017 -0700 Committer: Udo Kohlmeyer <[email protected]> Committed: Mon Jun 12 15:12:18 2017 -0700 ---------------------------------------------------------------------- geode-protobuf/build.gradle | 60 +++++++++++ .../InvalidProtocolMessageException.java | 27 +++++ .../protocol/handler/ProtocolHandler.java | 28 +++++ .../protobuf/ProtobufProtocolHandler.java | 43 ++++++++ geode-protobuf/src/main/proto/basicTypes.proto | 60 +++++++++++ .../src/main/proto/clientProtocol.proto | 87 +++++++++++++++ geode-protobuf/src/main/proto/region_API.proto | 106 +++++++++++++++++++ geode-protobuf/src/main/proto/server_API.proto | 37 +++++++ ...eode.client.protocol.handler.ProtocolHandler | 1 + .../geode/client/protocol/MessageUtil.java | 43 ++++++++ .../protocol/ProtobufProtocolHandlerTest.java | 86 +++++++++++++++ settings.gradle | 4 +- 12 files changed, 581 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/build.gradle ---------------------------------------------------------------------- diff --git a/geode-protobuf/build.gradle b/geode-protobuf/build.gradle new file mode 100644 index 0000000..7a5cbfb --- /dev/null +++ b/geode-protobuf/build.gradle @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'com.google.protobuf' +apply plugin: 'idea' + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1' + } +} + +dependencies { + provided project(':geode-core') + testCompile project(':geode-junit') + testCompile files(project(':geode-core').sourceSets.test.output) + + compile 'com.google.protobuf:protobuf-java:3.3.1' +} + +protobuf { + protoc { + // The artifact spec for the Protobuf Compiler + artifact = 'com.google.protobuf:protoc:3.0.0' + } + // this allows our spotless rule to skip this directory (hopefully rat too) + generatedFilesBaseDir = "$buildDir/generated-src/proto" +} + +sourceSets { + main { + + java { + srcDir 'build/generated-src/proto/main/java' + } + } +} +// let IntelliJ know where the generated sources are. +idea { + module { + sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java") + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/java/org/apache/geode/client/protocol/exception/InvalidProtocolMessageException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/client/protocol/exception/InvalidProtocolMessageException.java b/geode-protobuf/src/main/java/org/apache/geode/client/protocol/exception/InvalidProtocolMessageException.java new file mode 100644 index 0000000..9f80205 --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/client/protocol/exception/InvalidProtocolMessageException.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geode.client.protocol.exception; + +public class InvalidProtocolMessageException extends Exception { + public InvalidProtocolMessageException(String message) { + super(message); + } + + public InvalidProtocolMessageException(String message, Throwable cause) { + super(message, cause); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/ProtocolHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/ProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/ProtocolHandler.java new file mode 100644 index 0000000..1faacec --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/ProtocolHandler.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geode.client.protocol.handler; + +import org.apache.geode.client.protocol.exception.InvalidProtocolMessageException; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public interface ProtocolHandler <T> { + T deserialize(InputStream inputStream) throws InvalidProtocolMessageException; + void serialize(T inputMessage, OutputStream byteArrayOutputStream) throws IOException; +} http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/protobuf/ProtobufProtocolHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/protobuf/ProtobufProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/protobuf/ProtobufProtocolHandler.java new file mode 100644 index 0000000..9b87b31 --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/client/protocol/handler/protobuf/ProtobufProtocolHandler.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geode.client.protocol.handler.protobuf; + +import org.apache.geode.client.protocol.exception.InvalidProtocolMessageException; +import org.apache.geode.client.protocol.handler.ProtocolHandler; +import org.apache.geode.protocol.protobuf.ClientProtocol; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class ProtobufProtocolHandler implements ProtocolHandler<ClientProtocol.Message> { + @Override + public ClientProtocol.Message deserialize(InputStream inputStream) + throws InvalidProtocolMessageException { + try { + return ClientProtocol.Message.parseDelimitedFrom(inputStream); + } catch (IOException e) { + throw new InvalidProtocolMessageException("Failed to parse Protobuf Message", e); + } + } + + @Override + public void serialize(ClientProtocol.Message inputMessage, OutputStream outputStream) + throws IOException { + inputMessage.writeDelimitedTo(outputStream); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/proto/basicTypes.proto ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/proto/basicTypes.proto b/geode-protobuf/src/main/proto/basicTypes.proto new file mode 100644 index 0000000..502e28e --- /dev/null +++ b/geode-protobuf/src/main/proto/basicTypes.proto @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +syntax = "proto3"; +package org.apache.geode.protocol.protobuf; + +import "google/protobuf/any.proto"; +import "google/protobuf/empty.proto"; + +message Entry { + EncodedValue key = 1; + EncodedValue value = 2; +} + +message EncodedValue { + EncodingType encodingType = 1; + bytes value = 2; +} + +enum EncodingType { + INVALID = 0; + INT = 1; + LONG = 2; + SHORT = 3; + BYTE = 4; + BOOLEAN = 5; + BINARY = 6; + FLOAT = 7; + DOUBLE = 8; + STRING = 9; + JSON = 10; +} + +message CallbackArguments { + oneof callbackArgs { + google.protobuf.Empty hasCallbackArgument = 1; + EncodedValue callbackValue = 2; + } +} + +message Region { + string name = 1; + // TODO: key, value types? +} + +message Server { + string url = 1; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/proto/clientProtocol.proto ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/proto/clientProtocol.proto b/geode-protobuf/src/main/proto/clientProtocol.proto new file mode 100644 index 0000000..9dc0efb --- /dev/null +++ b/geode-protobuf/src/main/proto/clientProtocol.proto @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +syntax = "proto3"; +package org.apache.geode.protocol.protobuf; + +import "google/protobuf/any.proto"; +import "region_API.proto"; +import "server_API.proto"; +import "basicTypes.proto"; + +message Message { + MessageHeader messageHeader = 1; + oneof messageType { + Request request = 2; + Response response = 3; + } +} + +message MessageHeader { + int32 correlationId = 1; + MetaData metadata = 2; +} + +message Request { + CallbackArguments callbackArg = 1; + oneof requestAPI { + PutRequest putRequest = 2; + GetRequest getRequest = 3; + PutAllRequest putAllRequest = 4; + GetAllRequest getAllRequest = 5; + RemoveRequest removeRequest = 6; + RemoveAllRequest removeAllRequest = 7; + ListKeysRequest listKeysRequest = 8; + + CreateRegionRequest createRegionRequest = 9; + DestroyRegionRequest destroyRegionRequest = 10; + + PingRequest pingRequest = 11; + GetServersRequest getServersRequest = 12; + GetRegionsRequest getRegionsRequest = 13; + } +} + +message Response { + ResponseHeader responseHeader = 1; + oneof responseAPI { + PutResponse putResponse = 2; + GetResponse getResponse = 3; + PutAllResponse putAllResponse = 4; + GetAllResponse getAllResponse = 5; + RemoveResponse removeResponse = 6; + RemoveAllResponse removeAllResponse = 7; + ListKeysResponse listKeysResponse = 8; + + CreateRegionResponse createRegionResponse = 20; + DestroyRegionResponse destroyRegionResponse = 21; + + PingResponse pingResponse = 31; + GetServersResponse getServersResponse = 32; + GetRegionsResponse getRegionsResponse = 33; + } +} + +message ResponseHeader { + oneof reponseType { + int32 responseTypeID = 1; + int32 errorCode = 2; + } +} + +message MetaData { + int32 numberOfMetadata = 1; + map<int32, google.protobuf.Any> metaDataEntries = 2; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/proto/region_API.proto ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/proto/region_API.proto b/geode-protobuf/src/main/proto/region_API.proto new file mode 100644 index 0000000..52291c4 --- /dev/null +++ b/geode-protobuf/src/main/proto/region_API.proto @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +syntax = "proto3"; +package org.apache.geode.protocol.protobuf; + +import "basicTypes.proto"; + +message PutRequest { + string regionName = 1; + Entry entry = 2; +} + +message PutResponse { + bool success = 1; +} + +message GetRequest { + string regionName = 1; + EncodedValue key = 2; +} + +message GetResponse { + EncodedValue result = 1; +} + +message PutAllRequest { + string regionName = 1; + repeated Entry entry = 2; +} + +message PutAllResponse { + repeated EncodedValue failedKeys = 1; +} + +message GetAllRequest { + string regionName = 1; + repeated EncodedValue key = 2; + EncodedValue callbackArg = 3; +} + +message GetAllResponse { + repeated Entry entries = 1; +} + +message ListKeysRequest { + string regionName = 1; +} + +message ListKeysResponse { + repeated EncodedValue key = 1; +} + +message RemoveRequest { + string regionName = 1; + EncodedValue key = 2; +} + +message RemoveResponse { + bool success = 1; +} + +message RemoveAllRequest { + string regionName = 1; + repeated EncodedValue key = 2; +} + +message RemoveAllResponse { + bool success = 1; +} + +message CreateRegionRequest { + string regionName = 1; +} + +message CreateRegionResponse { + bool success = 1; +} + +message DestroyRegionRequest { + string regionName = 1; +} + +message DestroyRegionResponse { + bool success = 1; +} + +message GetRegionsRequest { + +} + +message GetRegionsResponse { + repeated Region regions = 1; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/proto/server_API.proto ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/proto/server_API.proto b/geode-protobuf/src/main/proto/server_API.proto new file mode 100644 index 0000000..d957921 --- /dev/null +++ b/geode-protobuf/src/main/proto/server_API.proto @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +syntax = "proto3"; +package org.apache.geode.protocol.protobuf; + +import "basicTypes.proto"; + +// PingResponse sends the same number back. +message PingRequest { + int32 sequenceNumber = 1; +} + +message PingResponse { + int32 sequenceNumber = 1; +} + +message GetServersRequest { + +} + +message GetServersResponse { + int32 numberOfServers = 1; + repeated Server servers = 2; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.client.protocol.handler.ProtocolHandler ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.client.protocol.handler.ProtocolHandler b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.client.protocol.handler.ProtocolHandler new file mode 100644 index 0000000..60279ae --- /dev/null +++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.client.protocol.handler.ProtocolHandler @@ -0,0 +1 @@ +org.apache.geode.client.protocol.handler.protobuf.ProtobufProtocolHandler \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java new file mode 100644 index 0000000..ec07355 --- /dev/null +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geode.client.protocol; + +import org.apache.geode.protocol.protobuf.ClientProtocol; +import org.apache.geode.protocol.protobuf.RegionAPI; + +public class MessageUtil { + public static ClientProtocol.Message createGetRequestMessage(){ + ClientProtocol.Message.Builder messageBuilder = ClientProtocol.Message.newBuilder(); + messageBuilder.setMessageHeader(getMessageHeaderBuilder()); + ClientProtocol.Request.Builder requestBuilder = getRequestBuilder(); + requestBuilder.setGetRequest(getGetRequestBuilder()); + messageBuilder.setRequest(requestBuilder); + return messageBuilder.build(); + } + + private static ClientProtocol.Request.Builder getRequestBuilder() { + return ClientProtocol.Request.newBuilder(); + } + + private static RegionAPI.GetRequest.Builder getGetRequestBuilder() { + return RegionAPI.GetRequest.newBuilder(); + } + + private static ClientProtocol.MessageHeader.Builder getMessageHeaderBuilder() { + return ClientProtocol.MessageHeader.newBuilder(); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java new file mode 100644 index 0000000..a0c9a62 --- /dev/null +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geode.client.protocol; + +import org.apache.geode.client.protocol.exception.InvalidProtocolMessageException; +import org.apache.geode.client.protocol.handler.ProtocolHandler; +import org.apache.geode.client.protocol.handler.protobuf.ProtobufProtocolHandler; +import org.apache.geode.protocol.protobuf.ClientProtocol; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ServiceLoader; + +public class ProtobufProtocolHandlerTest { + private ProtocolHandler protocolHandler; + + @Before + public void startup() { + ServiceLoader<ProtocolHandler> serviceLoader = ServiceLoader.load(ProtocolHandler.class); + for (ProtocolHandler protocolHandler : serviceLoader) { + if (protocolHandler instanceof ProtobufProtocolHandler) { + this.protocolHandler = protocolHandler; + } + } + } + + @Test + public void testDeserializeByteArrayToMessage() + throws IOException, InvalidProtocolMessageException { + ClientProtocol.Message expectedRequestMessage = MessageUtil.createGetRequestMessage(); + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + + expectedRequestMessage.writeDelimitedTo(byteArrayOutputStream); + InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + + ClientProtocol.Message actualMessage = (ClientProtocol.Message) protocolHandler.deserialize(inputStream); + Assert.assertEquals(expectedRequestMessage, actualMessage); + } + + @Test + public void testDeserializeInvalidByteThrowsException() throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + byteArrayOutputStream.write("Some incorrect byte array".getBytes()); + InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + + boolean caughtException = false; + try { + protocolHandler.deserialize(inputStream); + } catch (InvalidProtocolMessageException e) { + caughtException = true; + } + Assert.assertTrue(caughtException); + } + + @Test + public void testSerializeMessageToByteArray() throws IOException { + ClientProtocol.Message message = MessageUtil.createGetRequestMessage(); + ByteArrayOutputStream expectedByteArrayOutputStream = new ByteArrayOutputStream(); + message.writeDelimitedTo(expectedByteArrayOutputStream); + byte[] expectedByteArray = expectedByteArrayOutputStream.toByteArray(); + + ByteArrayOutputStream actualByteArrayOutputStream = new ByteArrayOutputStream(); + protocolHandler.serialize(message, actualByteArrayOutputStream); + Assert.assertArrayEquals(expectedByteArray,actualByteArrayOutputStream.toByteArray()); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/719c6919/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index c0fdb6e..39697b7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -37,8 +37,10 @@ include 'extensions/geode-modules-tomcat8' include 'extensions/geode-modules-session-internal' include 'extensions/geode-modules-session' include 'extensions/geode-modules-assembly' - +include 'geode-protobuf' if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) { throw new GradleException('Running with unsupported Gradle Version. Use Gradle Wrapper or with Gradle version >= ' + minimumGradleVersion) } + +
