You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by hi...@apache.org on 2017/06/26 16:26:48 UTC
[01/13] geode git commit: GEODE-2995: incorporating even more review
feedback
Repository: geode
Updated Branches:
refs/heads/develop 49123c475 -> e1c6c3a97
GEODE-2995: incorporating even more review feedback
Addressing feedback from Udo and Hitesh
Refactored test locations to match new src layout
Signed-off-by: Galen O'Sullivan <go...@pivotal.io>
Signed-off-by: Brian Rowe <br...@pivotal.io>
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a3c66e1a
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a3c66e1a
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a3c66e1a
Branch: refs/heads/develop
Commit: a3c66e1afc88700bd7839f56d54a0f6d44f00432
Parents: 0de1d97
Author: Brian Rowe <br...@pivotal.io>
Authored: Wed Jun 21 11:53:54 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
geode-protobuf/build.gradle | 6 +-
.../protobuf/EncodingTypeTranslator.java | 47 +++----
.../operations/GetRequestOperationHandler.java | 19 +--
.../geode/client/protocol/IntegrationTest.java | 124 -------------------
.../geode/client/protocol/MessageUtil.java | 41 ------
.../geode/client/protocol/OpsHandler.java | 21 ----
.../geode/protocol/IntegrationJUnitTest.java | 124 +++++++++++++++++++
.../org/apache/geode/protocol/MessageUtil.java | 41 ++++++
.../org/apache/geode/protocol/OpsHandler.java | 21 ++++
.../GetRequestOperationHandlerTest.java | 95 --------------
...eToSerializationTypeTranslatorJUnitTest.java | 73 +++++++++++
.../protobuf/ProtobufOpsProcessorJUnitTest.java | 62 ++++++++++
.../protobuf/ProtobufOpsProcessorTest.java | 62 ----------
.../GetRequestOperationHandlerJUnitTest.java | 96 ++++++++++++++
.../ProtobufProtocolSerializerJUnitTest.java | 2 +-
.../ProtobufSerializationServiceImplTest.java | 58 ---------
.../ProtobufSerializationServiceJUnitTest.java | 111 +++++++++++++++++
.../codec/BinaryFormatJUnitTest.java | 64 ++++++++++
.../codec/StringCodecJUnitTest.java | 64 ----------
...eToSerializationTypeTranslatorJUnitTest.java | 73 -----------
gradle/dependency-versions.properties | 3 +
21 files changed, 637 insertions(+), 570 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/build.gradle
----------------------------------------------------------------------
diff --git a/geode-protobuf/build.gradle b/geode-protobuf/build.gradle
index f069267..a63000e 100644
--- a/geode-protobuf/build.gradle
+++ b/geode-protobuf/build.gradle
@@ -23,7 +23,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
+ classpath 'com.google.protobuf:protobuf-gradle-plugin:' + project.'protobuf-gradle-plugin.version'
}
}
@@ -36,13 +36,13 @@ dependencies {
testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version'
testCompile 'org.powermock:powermock-api-mockito:' + project.'powermock.version'
- compile 'com.google.protobuf:protobuf-java:3.3.1'
+ compile 'com.google.protobuf:protobuf-java:' + project.'protobuf-java.version'
}
protobuf {
protoc {
// The artifact spec for the Protobuf Compiler
- artifact = 'com.google.protobuf:protoc:3.0.0'
+ artifact = 'com.google.protobuf:protoc:' + project.'protoc.version'
}
generatedFilesBaseDir = "$buildDir/generated-src/proto"
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java
index 650ac81..edb7c7e 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java
@@ -20,10 +20,28 @@ import org.apache.geode.protocol.protobuf.BasicTypes;
import org.apache.geode.serialization.SerializationType;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import java.util.HashMap;
+
/**
* This class maps protobuf specific encoding types and the corresponding serialization types.
*/
public abstract class EncodingTypeTranslator {
+ static final HashMap<Class, BasicTypes.EncodingType> typeToEncodingMap = intializeTypeMap();
+
+ private static HashMap<Class, BasicTypes.EncodingType> intializeTypeMap() {
+ HashMap<Class, BasicTypes.EncodingType> result = new HashMap<>();
+ result.put(Integer.class, BasicTypes.EncodingType.INT);
+ result.put(Byte.class, BasicTypes.EncodingType.BYTE);
+ result.put(Long.class, BasicTypes.EncodingType.LONG);
+ result.put(Float.class, BasicTypes.EncodingType.FLOAT);
+ result.put(Short.class, BasicTypes.EncodingType.SHORT);
+ result.put(byte[].class, BasicTypes.EncodingType.BINARY);
+ result.put(Double.class, BasicTypes.EncodingType.DOUBLE);
+ result.put(String.class, BasicTypes.EncodingType.STRING);
+ result.put(Boolean.class, BasicTypes.EncodingType.BOOLEAN);
+ return result;
+ }
+
public static SerializationType getSerializationTypeForEncodingType(
BasicTypes.EncodingType encodingType) throws UnsupportedEncodingTypeException {
switch (encodingType) {
@@ -55,32 +73,19 @@ public abstract class EncodingTypeTranslator {
public static BasicTypes.EncodingType getEncodingTypeForObject(Object resultValue)
throws UnsupportedEncodingTypeException {
- if (resultValue instanceof Integer) {
- return BasicTypes.EncodingType.INT;
- } else if (resultValue instanceof Byte) {
- return BasicTypes.EncodingType.BYTE;
- } else if (resultValue instanceof PdxInstance) {
+ if (resultValue instanceof PdxInstance) {
String pdxClassName = ((PdxInstance) resultValue).getClassName();
if (pdxClassName.equals(JSONFormatter.JSON_CLASSNAME)) {
return BasicTypes.EncodingType.JSON;
}
- } else if (resultValue instanceof Long) {
- return BasicTypes.EncodingType.LONG;
- } else if (resultValue instanceof Float) {
- return BasicTypes.EncodingType.FLOAT;
- } else if (resultValue instanceof Short) {
- return BasicTypes.EncodingType.SHORT;
- } else if (resultValue instanceof byte[]) {
- return BasicTypes.EncodingType.BINARY;
- } else if (resultValue instanceof Double) {
- return BasicTypes.EncodingType.DOUBLE;
- } else if (resultValue instanceof String) {
- return BasicTypes.EncodingType.STRING;
- } else if (resultValue instanceof Boolean) {
- return BasicTypes.EncodingType.BOOLEAN;
}
- throw new UnsupportedEncodingTypeException(
- "We cannot translate: " + resultValue.getClass() + " into a specific Protobuf Encoding");
+ BasicTypes.EncodingType encodingType = typeToEncodingMap.get(resultValue.getClass());
+ if (encodingType == null) {
+ throw new UnsupportedEncodingTypeException(
+ "We cannot translate: " + resultValue.getClass() + " into a specific Protobuf Encoding");
+ } else {
+ return encodingType;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
index 37d1d32..d9c1475 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
@@ -23,6 +23,7 @@ import org.apache.geode.protocol.protobuf.ClientProtocol;
import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.serialization.SerializationService;
import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.TypeEncodingException;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
@@ -31,8 +32,7 @@ public class GetRequestOperationHandler
@Override
public RegionAPI.GetResponse process(SerializationService serializationService,
- RegionAPI.GetRequest request, Cache cache)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ RegionAPI.GetRequest request, Cache cache) throws TypeEncodingException {
String regionName = request.getRegionName();
BasicTypes.EncodedValue key = request.getKey();
BasicTypes.EncodingType encodingType = key.getEncodingType();
@@ -42,6 +42,16 @@ public class GetRequestOperationHandler
Region region = cache.getRegion(regionName);
Object resultValue = region.get(decodedValue);
+ return buildGetResponse(serializationService, resultValue);
+ }
+
+ @Override
+ public int getOperationCode() {
+ return ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
+ }
+
+ private RegionAPI.GetResponse buildGetResponse(SerializationService serializationService,
+ Object resultValue) throws TypeEncodingException {
BasicTypes.EncodingType resultEncodingType =
EncodingTypeTranslator.getEncodingTypeForObject(resultValue);
byte[] resultEncodedValue = serializationService.encode(resultEncodingType, resultValue);
@@ -50,9 +60,4 @@ public class GetRequestOperationHandler
.setResult(ProtobufUtilities.getEncodedValue(resultEncodingType, resultEncodedValue))
.build();
}
-
- @Override
- public int getOperationCode() {
- return ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
- }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
deleted file mode 100644
index 63cde31..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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 com.google.protobuf.ByteString;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.Region;
-import org.apache.geode.protocol.protobuf.ProtobufStreamProcessor;
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.apache.geode.protocol.protobuf.RegionAPI;
-import org.apache.geode.serialization.codec.StringCodec;
-import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.SerializationCodecRegistry;
-import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-@Category(UnitTest.class)
-public class IntegrationTest {
-
- public static final String TEST_KEY = "my key";
- public static final String TEST_VALUE = "my value";
- public static final String TEST_REGION = "test region";
- private StringCodec stringCodec;
- private Cache cacheStub;
- private Region regionStub;
-
- @Before
- public void setup() throws CodecAlreadyRegisteredForTypeException,
- UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
- stringCodec = (StringCodec) serializationCodecRegistry.getCodecForType(
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
- regionStub = getRegionStub();
- cacheStub = getCacheStub(regionStub);
- }
-
- @Test
- public void testGetRequestProcessed() throws Exception {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-
- ProtobufStreamProcessor streamProcessor = new ProtobufStreamProcessor();
- streamProcessor.processOneMessage(getInputStream(getRequest(stringCodec)), outputStream,
- cacheStub);
-
- RegionAPI.GetResponse getResponse = getGetResponse(outputStream);
-
- Assert.assertNotNull(getResponse);
- Assert.assertEquals(BasicTypes.EncodingType.STRING, getResponse.getResult().getEncodingType());
- String actualValue = stringCodec.decode(getResponse.getResult().getValue().toByteArray());
- Assert.assertEquals(TEST_VALUE, actualValue);
- verify(regionStub, times(1)).get(TEST_KEY);
- verify(regionStub, times(1)).get(anyString());
- }
-
- private Region getRegionStub() {
- regionStub = mock(Region.class);
- when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
- return regionStub;
- }
-
- private Cache getCacheStub(Region region) {
- Cache cacheStub = mock(Cache.class);
- when(cacheStub.getRegion(TEST_REGION)).thenReturn(region);
- return cacheStub;
- }
-
- private RegionAPI.GetResponse getGetResponse(ByteArrayOutputStream outputStream)
- throws IOException {
- ByteArrayInputStream helperInputStream = new ByteArrayInputStream(outputStream.toByteArray());
- ClientProtocol.Message responseMessage =
- ClientProtocol.Message.parseDelimitedFrom(helperInputStream);
- ClientProtocol.Response response = responseMessage.getResponse();
- return response.getGetResponse();
- }
-
- private ByteArrayInputStream getInputStream(ClientProtocol.Message request) throws IOException {
- ByteArrayOutputStream helperOutputStream = new ByteArrayOutputStream();
- request.writeDelimitedTo(helperOutputStream);
- return new ByteArrayInputStream(helperOutputStream.toByteArray());
- }
-
- private ClientProtocol.Message getRequest(StringCodec stringCodec) {
- RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
- getRequestBuilder.setRegionName(TEST_REGION)
- .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
- .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
- ClientProtocol.Request request =
- ClientProtocol.Request.newBuilder().setGetRequest(getRequestBuilder).build();
- ClientProtocol.Message requestMessage = ClientProtocol.Message.newBuilder()
- .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setRequest(request).build();
-
- return requestMessage;
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/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
deleted file mode 100644
index c830b01..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java
deleted file mode 100644
index 793dace..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.serialization.registry.SerializationCodecRegistry;
-
-public interface OpsHandler<Req, Resp> {
- Resp process(SerializationCodecRegistry serializationCodecRegistry, Req request);
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/IntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/IntegrationJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/IntegrationJUnitTest.java
new file mode 100644
index 0000000..42cc7b3
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/IntegrationJUnitTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.protocol;
+
+import com.google.protobuf.ByteString;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.protocol.protobuf.ProtobufStreamProcessor;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.codec.StringCodec;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+@Category(UnitTest.class)
+public class IntegrationJUnitTest {
+
+ public static final String TEST_KEY = "my key";
+ public static final String TEST_VALUE = "my value";
+ public static final String TEST_REGION = "test region";
+ private StringCodec stringCodec;
+ private Cache cacheStub;
+ private Region regionStub;
+
+ @Before
+ public void setup() throws CodecAlreadyRegisteredForTypeException,
+ UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+ stringCodec = (StringCodec) serializationCodecRegistry.getCodecForType(
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
+ regionStub = getRegionStub();
+ cacheStub = getCacheStub(regionStub);
+ }
+
+ @Test
+ public void testGetRequestProcessed() throws Exception {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ ProtobufStreamProcessor streamProcessor = new ProtobufStreamProcessor();
+ streamProcessor.processOneMessage(getInputStream(getRequest(stringCodec)), outputStream,
+ cacheStub);
+
+ RegionAPI.GetResponse getResponse = getGetResponse(outputStream);
+
+ Assert.assertNotNull(getResponse);
+ Assert.assertEquals(BasicTypes.EncodingType.STRING, getResponse.getResult().getEncodingType());
+ String actualValue = stringCodec.decode(getResponse.getResult().getValue().toByteArray());
+ Assert.assertEquals(TEST_VALUE, actualValue);
+ verify(regionStub, times(1)).get(TEST_KEY);
+ verify(regionStub, times(1)).get(anyString());
+ }
+
+ private Region getRegionStub() {
+ regionStub = mock(Region.class);
+ when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
+ return regionStub;
+ }
+
+ private Cache getCacheStub(Region region) {
+ Cache cacheStub = mock(Cache.class);
+ when(cacheStub.getRegion(TEST_REGION)).thenReturn(region);
+ return cacheStub;
+ }
+
+ private RegionAPI.GetResponse getGetResponse(ByteArrayOutputStream outputStream)
+ throws IOException {
+ ByteArrayInputStream helperInputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ ClientProtocol.Message responseMessage =
+ ClientProtocol.Message.parseDelimitedFrom(helperInputStream);
+ ClientProtocol.Response response = responseMessage.getResponse();
+ return response.getGetResponse();
+ }
+
+ private ByteArrayInputStream getInputStream(ClientProtocol.Message request) throws IOException {
+ ByteArrayOutputStream helperOutputStream = new ByteArrayOutputStream();
+ request.writeDelimitedTo(helperOutputStream);
+ return new ByteArrayInputStream(helperOutputStream.toByteArray());
+ }
+
+ private ClientProtocol.Message getRequest(StringCodec stringCodec) {
+ RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
+ getRequestBuilder.setRegionName(TEST_REGION)
+ .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
+ .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
+ ClientProtocol.Request request =
+ ClientProtocol.Request.newBuilder().setGetRequest(getRequestBuilder).build();
+ ClientProtocol.Message requestMessage = ClientProtocol.Message.newBuilder()
+ .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setRequest(request).build();
+
+ return requestMessage;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
new file mode 100644
index 0000000..f0b0b41
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
@@ -0,0 +1,41 @@
+/*
+ * 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.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/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/OpsHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/OpsHandler.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/OpsHandler.java
new file mode 100644
index 0000000..2b4aa21
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/OpsHandler.java
@@ -0,0 +1,21 @@
+/*
+ * 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.protocol;
+
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+
+public interface OpsHandler<Req, Resp> {
+ Resp process(SerializationCodecRegistry serializationCodecRegistry, Req request);
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
deleted file mode 100644
index cb98eb7..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.protocol.operations.protobuf;
-
-import com.google.protobuf.ByteString;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.Region;
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.RegionAPI;
-import org.apache.geode.protocol.protobuf.operations.GetRequestOperationHandler;
-import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.codec.StringCodec;
-import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.SerializationCodecRegistry;
-import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.nio.charset.Charset;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@Category(UnitTest.class)
-public class GetRequestOperationHandlerTest {
- public static final String TEST_KEY = "my key";
- public static final String TEST_VALUE = "my value";
- public static final String TEST_REGION = "test region";
- public Cache cacheStub;
- public SerializationService serializationServiceStub;
-
- @Before
- public void setUp() throws Exception {
- serializationServiceStub = mock(SerializationService.class);
- when(serializationServiceStub.decode(BasicTypes.EncodingType.STRING,
- TEST_KEY.getBytes(Charset.forName("UTF-8")))).thenReturn(TEST_KEY);
- when(serializationServiceStub.encode(BasicTypes.EncodingType.STRING, TEST_VALUE))
- .thenReturn(TEST_VALUE.getBytes(Charset.forName("UTF-8")));
-
- Region regionStub = mock(Region.class);
- when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
-
- cacheStub = mock(Cache.class);
- when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub);
- }
-
- @Test
- public void processReturnsTheEncodedValueFromTheRegion() throws UnsupportedEncodingTypeException,
- CodecNotRegisteredForTypeException, CodecAlreadyRegisteredForTypeException {
- GetRequestOperationHandler operationHandler = new GetRequestOperationHandler();
-
- RegionAPI.GetResponse response =
- operationHandler.process(serializationServiceStub, makeGetRequest(), cacheStub);
-
- Assert.assertEquals(BasicTypes.EncodingType.STRING, response.getResult().getEncodingType());
- String actualValue = getStringCodec().decode(response.getResult().getValue().toByteArray());
- Assert.assertEquals(TEST_VALUE, actualValue);
- }
-
- private RegionAPI.GetRequest makeGetRequest() throws CodecNotRegisteredForTypeException,
- UnsupportedEncodingTypeException, CodecAlreadyRegisteredForTypeException {
- StringCodec stringCodec = getStringCodec();
- RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
- getRequestBuilder.setRegionName(TEST_REGION)
- .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
- .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
-
- return getRequestBuilder.build();
- }
-
- private StringCodec getStringCodec() throws CodecAlreadyRegisteredForTypeException,
- CodecNotRegisteredForTypeException, UnsupportedEncodingTypeException {
- SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
- return (StringCodec) serializationCodecRegistry.getCodecForType(
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
new file mode 100644
index 0000000..8e6f66a
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.protocol.protobuf;
+
+import static org.junit.Assert.assertSame;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class EncodingTypeToSerializationTypeTranslatorJUnitTest {
+
+ @Test
+ public void testTranslateEncodingTypes() throws UnsupportedEncodingTypeException {
+ assertSame(SerializationType.INT,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INT));
+ assertSame(SerializationType.LONG,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.LONG));
+ assertSame(SerializationType.SHORT,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.SHORT));
+ assertSame(SerializationType.BYTE,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BYTE));
+ assertSame(SerializationType.BOOLEAN, EncodingTypeTranslator
+ .getSerializationTypeForEncodingType(BasicTypes.EncodingType.BOOLEAN));
+ assertSame(SerializationType.BINARY,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BINARY));
+ assertSame(SerializationType.FLOAT,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.FLOAT));
+ assertSame(SerializationType.DOUBLE,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.DOUBLE));
+ assertSame(SerializationType.STRING,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
+ assertSame(SerializationType.JSON,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.JSON));
+ }
+
+ @Test(expected = UnsupportedEncodingTypeException.class)
+ public void testTranslateInvalidEncoding_throwsException()
+ throws UnsupportedEncodingTypeException {
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INVALID);
+ }
+
+ @Test
+ public void testAllEncodingTypeTranslations() {
+ for (BasicTypes.EncodingType encodingType : BasicTypes.EncodingType.values()) {
+ if (!(encodingType.equals(BasicTypes.EncodingType.UNRECOGNIZED)
+ || encodingType.equals(BasicTypes.EncodingType.INVALID))) {
+ try {
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingType);
+ } catch (UnsupportedEncodingTypeException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
new file mode 100644
index 0000000..fc980ae
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.protocol.protobuf;
+
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.TypeEncodingException;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class ProtobufOpsProcessorJUnitTest {
+ @Test
+ public void testOpsProcessor() throws TypeEncodingException,
+ OperationHandlerNotRegisteredException, InvalidProtocolMessageException {
+ OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class);
+ OperationHandler operationHandlerStub = mock(OperationHandler.class);
+ SerializationService serializationServiceStub = mock(SerializationService.class);
+ Cache dummyCache = mock(Cache.class);
+ int operationID = ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
+
+ ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder()
+ .setGetRequest(RegionAPI.GetRequest.newBuilder()).build();
+
+ RegionAPI.GetResponse expectedResponse = RegionAPI.GetResponse.newBuilder().build();
+
+ when(opsHandlerRegistryStub.getOperationHandlerForOperationId(operationID))
+ .thenReturn(operationHandlerStub);
+ when(operationHandlerStub.process(serializationServiceStub,
+ ProtobufOpsProcessor.getRequestForOperationTypeID(messageRequest), dummyCache))
+ .thenReturn(expectedResponse);
+
+ ProtobufOpsProcessor processor =
+ new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
+ ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
+ Assert.assertEquals(expectedResponse, response.getGetResponse());
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
deleted file mode 100644
index ac3d68f..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.protocol.protobuf;
-
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
-import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
-import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.exception.TypeEncodingException;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(UnitTest.class)
-public class ProtobufOpsProcessorTest {
- @Test
- public void testOpsProcessor() throws TypeEncodingException,
- OperationHandlerNotRegisteredException, InvalidProtocolMessageException {
- OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class);
- OperationHandler operationHandlerStub = mock(OperationHandler.class);
- SerializationService serializationServiceStub = mock(SerializationService.class);
- Cache dummyCache = mock(Cache.class);
- int operationID = ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
-
- ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder()
- .setGetRequest(RegionAPI.GetRequest.newBuilder()).build();
-
- RegionAPI.GetResponse expectedResponse = RegionAPI.GetResponse.newBuilder().build();
-
- when(opsHandlerRegistryStub.getOperationHandlerForOperationId(operationID))
- .thenReturn(operationHandlerStub);
- when(operationHandlerStub.process(serializationServiceStub,
- ProtobufOpsProcessor.getRequestForOperationTypeID(messageRequest), dummyCache))
- .thenReturn(expectedResponse);
-
- ProtobufOpsProcessor processor =
- new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
- ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
- Assert.assertEquals(expectedResponse, response.getGetResponse());
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
new file mode 100644
index 0000000..daa5870
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.protocol.protobuf.operations;
+
+import com.google.protobuf.ByteString;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.protocol.protobuf.operations.GetRequestOperationHandler;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.codec.StringCodec;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.TypeEncodingException;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.nio.charset.Charset;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@Category(UnitTest.class)
+public class GetRequestOperationHandlerJUnitTest {
+ public static final String TEST_KEY = "my key";
+ public static final String TEST_VALUE = "my value";
+ public static final String TEST_REGION = "test region";
+ public Cache cacheStub;
+ public SerializationService serializationServiceStub;
+
+ @Before
+ public void setUp() throws Exception {
+ serializationServiceStub = mock(SerializationService.class);
+ when(serializationServiceStub.decode(BasicTypes.EncodingType.STRING,
+ TEST_KEY.getBytes(Charset.forName("UTF-8")))).thenReturn(TEST_KEY);
+ when(serializationServiceStub.encode(BasicTypes.EncodingType.STRING, TEST_VALUE))
+ .thenReturn(TEST_VALUE.getBytes(Charset.forName("UTF-8")));
+
+ Region regionStub = mock(Region.class);
+ when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
+
+ cacheStub = mock(Cache.class);
+ when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub);
+ }
+
+ @Test
+ public void processReturnsTheEncodedValueFromTheRegion()
+ throws TypeEncodingException, CodecAlreadyRegisteredForTypeException {
+ GetRequestOperationHandler operationHandler = new GetRequestOperationHandler();
+
+ RegionAPI.GetResponse response =
+ operationHandler.process(serializationServiceStub, makeGetRequest(), cacheStub);
+
+ Assert.assertEquals(BasicTypes.EncodingType.STRING, response.getResult().getEncodingType());
+ String actualValue = getStringCodec().decode(response.getResult().getValue().toByteArray());
+ Assert.assertEquals(TEST_VALUE, actualValue);
+ }
+
+ private RegionAPI.GetRequest makeGetRequest() throws CodecNotRegisteredForTypeException,
+ UnsupportedEncodingTypeException, CodecAlreadyRegisteredForTypeException {
+ StringCodec stringCodec = getStringCodec();
+ RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
+ getRequestBuilder.setRegionName(TEST_REGION)
+ .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
+ .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
+
+ return getRequestBuilder.build();
+ }
+
+ private StringCodec getStringCodec() throws CodecAlreadyRegisteredForTypeException,
+ CodecNotRegisteredForTypeException, UnsupportedEncodingTypeException {
+ SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+ return (StringCodec) serializationCodecRegistry.getCodecForType(
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
index e1f7b5b..5a94dae 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
@@ -14,7 +14,7 @@
*/
package org.apache.geode.protocol.serializer;
-import org.apache.geode.client.protocol.MessageUtil;
+import org.apache.geode.protocol.MessageUtil;
import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
import org.apache.geode.protocol.protobuf.ClientProtocol;
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
deleted file mode 100644
index ef841c3..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.serialization;
-
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.ProtobufSerializationService;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(UnitTest.class)
-public class ProtobufSerializationServiceImplTest {
-
- public static final String PAYLOAD = "my value";
-
- @Test
- public void valuesPreservedByEncodingThenDecoding() throws CodecAlreadyRegisteredForTypeException,
- UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- ProtobufSerializationService protobufSerializationService = new ProtobufSerializationService();
-
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.STRING, "testString");
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.FLOAT, (float) 34.23);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.DOUBLE, 34.23);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.INT, 45);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.SHORT, (short) 45);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BYTE, (byte) 45);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.LONG, (long) 45);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BOOLEAN, false);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BOOLEAN, true);
- testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BINARY,
- "testString".getBytes());
- // TODO: Test JSON conversion
- }
-
- private void testEncodeDecode(ProtobufSerializationService service,
- BasicTypes.EncodingType encodingType, Object data)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- byte[] encodedValue = service.encode(encodingType, data);
- Object decodedValue = service.decode(encodingType, encodedValue);
- Assert.assertEquals(data, decodedValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceJUnitTest.java
new file mode 100644
index 0000000..122c8bc
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceJUnitTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.serialization;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ProtobufSerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class ProtobufSerializationServiceJUnitTest {
+
+ public static final String PAYLOAD = "my value";
+ private ProtobufSerializationService protobufSerializationService;
+
+ @Before
+ public void setup() throws CodecAlreadyRegisteredForTypeException {
+ protobufSerializationService = new ProtobufSerializationService();
+ }
+
+ @Test
+ public void stringValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.STRING, "testString");
+ }
+
+ @Test
+ public void floatValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.FLOAT, (float) 34.23);
+ }
+
+ @Test
+ public void doubleValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.DOUBLE, 34.23);
+ }
+
+ @Test
+ public void intValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.INT, 45);
+ }
+
+ @Test
+ public void shortValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.SHORT, (short) 45);
+ }
+
+ @Test
+ public void byteValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BYTE, (byte) 45);
+ }
+
+ @Test
+ public void longValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.LONG, (long) 45);
+ }
+
+ @Test
+ public void booleanValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BOOLEAN, false);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BOOLEAN, true);
+ }
+
+ @Test
+ public void binaryValuesPreservedByEncodingThenDecoding()
+ throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException {
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BINARY,
+ "testString".getBytes());
+ }
+
+ private void testEncodeDecode(ProtobufSerializationService service,
+ BasicTypes.EncodingType encodingType, Object data)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ byte[] encodedValue = service.encode(encodingType, data);
+ Object decodedValue = service.decode(encodingType, encodedValue);
+ Assert.assertEquals(data, decodedValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/BinaryFormatJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/BinaryFormatJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/BinaryFormatJUnitTest.java
new file mode 100644
index 0000000..dd72a19
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/BinaryFormatJUnitTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.serialization.codec;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.nio.charset.Charset;
+
+@Category(UnitTest.class)
+public class BinaryFormatJUnitTest {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
+ private static final Charset UTF16 = Charset.forName("UTF-16");
+ private String testString = "Test String";
+
+ private StringCodec stringCodec;
+
+ @Before
+ public void startup() {
+ stringCodec = new StringCodec();
+ }
+
+ @Test
+ public void testStringsUseUTF8Encoding() {
+ assertArrayEquals(testString.getBytes(UTF8), stringCodec.encode(testString));
+ }
+
+ @Test
+ public void testStringDontUseUTF16Encoding() {
+ byte[] expectedEncodedString = stringCodec.encode(testString);
+ byte[] incorrectEncodedString = testString.getBytes(UTF16);
+ assertNotEquals(expectedEncodedString.length, incorrectEncodedString.length);
+ }
+
+ @Test
+ public void testImproperlyEncodedStringDecodingFails() {
+ byte[] encodedString = testString.getBytes(UTF16);
+ assertNotEquals(testString, stringCodec.decode(encodedString));
+ }
+
+ @Test
+ public void testProperlyEncodedStringDecoding() {
+ byte[] encodedString = testString.getBytes(UTF8);
+ assertEquals(testString, stringCodec.decode(encodedString));
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java
deleted file mode 100644
index 8cd6029..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.serialization.codec;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.nio.charset.Charset;
-
-@Category(UnitTest.class)
-public class StringCodecJUnitTest {
- private static final Charset UTF8 = Charset.forName("UTF-8");
- private static final Charset UTF16 = Charset.forName("UTF-16");
- private String testString = "Test String";
-
- private StringCodec stringCodec;
-
- @Before
- public void startup() {
- stringCodec = new StringCodec();
- }
-
- @Test
- public void testStringEncoding() {
- assertArrayEquals(testString.getBytes(UTF8), stringCodec.encode(testString));
- }
-
- @Test
- public void testStringIncompatibleEncoding() {
- byte[] expectedEncodedString = stringCodec.encode(testString);
- byte[] incorrectEncodedString = testString.getBytes(UTF16);
- assertNotEquals(expectedEncodedString.length, incorrectEncodedString.length);
- }
-
- @Test
- public void testStringDecodingWithIncorrectEncodedString() {
- byte[] encodedString = testString.getBytes(UTF16);
- assertNotEquals(testString, stringCodec.decode(encodedString));
- }
-
- @Test
- public void testStringDecoding() {
- byte[] encodedString = testString.getBytes(UTF8);
- assertEquals(testString, stringCodec.decode(encodedString));
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
deleted file mode 100644
index 963cb85..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.serialization.protobuf.translation;
-
-import static org.junit.Assert.assertSame;
-
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
-import org.apache.geode.serialization.SerializationType;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(UnitTest.class)
-public class EncodingTypeToSerializationTypeTranslatorJUnitTest {
-
- @Test
- public void testTranslateEncodingTypes() throws UnsupportedEncodingTypeException {
- assertSame(SerializationType.INT,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INT));
- assertSame(SerializationType.LONG,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.LONG));
- assertSame(SerializationType.SHORT,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.SHORT));
- assertSame(SerializationType.BYTE,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BYTE));
- assertSame(SerializationType.BOOLEAN, EncodingTypeTranslator
- .getSerializationTypeForEncodingType(BasicTypes.EncodingType.BOOLEAN));
- assertSame(SerializationType.BINARY,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BINARY));
- assertSame(SerializationType.FLOAT,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.FLOAT));
- assertSame(SerializationType.DOUBLE,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.DOUBLE));
- assertSame(SerializationType.STRING,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
- assertSame(SerializationType.JSON,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.JSON));
- }
-
- @Test(expected = UnsupportedEncodingTypeException.class)
- public void testTranslateInvalidEncoding_throwsException()
- throws UnsupportedEncodingTypeException {
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INVALID);
- }
-
- @Test
- public void testAllEncodingTypeTranslations() {
- for (BasicTypes.EncodingType encodingType : BasicTypes.EncodingType.values()) {
- if (!(encodingType.equals(BasicTypes.EncodingType.UNRECOGNIZED)
- || encodingType.equals(BasicTypes.EncodingType.INVALID))) {
- try {
- EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingType);
- } catch (UnsupportedEncodingTypeException e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/a3c66e1a/gradle/dependency-versions.properties
----------------------------------------------------------------------
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index 183dafc..6a730a4 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -77,6 +77,9 @@ netty-all.version = 4.1.8.Final
open-json.version = 1.8
phantomjsdriver.version=1.3.0
powermock.version = 1.7.0RC4
+protobuf-gradle-plugin.version = 0.8.1
+protobuf-java.version = 3.3.1
+protoc.version = 3.0.0
selenium.version=3.0.1
shiro.version=1.3.2
slf4j-api.version = 1.7.23
[05/13] geode git commit: GEODE-3075: Initial refactor adding
NewProtocolServerConnection
Posted by hi...@apache.org.
GEODE-3075: Initial refactor adding NewProtocolServerConnection
subclassing `ServerConnection`.
The new code is broken but it won't be called under normal operation,
since it's gated on a system property, "geode.feature-protobuf-protocol"
Further refactoring and feature work to come.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/dfdde4af
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/dfdde4af
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/dfdde4af
Branch: refs/heads/develop
Commit: dfdde4af352566d60f18b0db156fc5b7f48ebd8b
Parents: 49123c4
Author: Galen OSullivan <go...@pivotal.io>
Authored: Mon Jun 12 09:33:35 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
.../geode/internal/cache/tier/Acceptor.java | 4 +
.../cache/tier/sockets/AcceptorImpl.java | 10 +--
.../cache/tier/sockets/ClientHealthMonitor.java | 7 +-
.../sockets/ClientProtocolMessageHandler.java | 29 +++++++
.../tier/sockets/LegacyServerConnection.java | 88 ++++++++++++++++++++
.../sockets/NewProtocolServerConnection.java | 86 +++++++++++++++++++
.../cache/tier/sockets/ServerConnection.java | 75 +++++++----------
.../tier/sockets/ServerConnectionFactory.java | 50 +++++++++++
.../sockets/ServerConnectionFactoryTest.java | 77 +++++++++++++++++
.../tier/sockets/ServerConnectionTest.java | 7 +-
10 files changed, 375 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
index 9a3241b..a95195a 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
@@ -71,6 +71,10 @@ public abstract class Acceptor {
*/
public static final byte CLIENT_TO_SERVER_FOR_QUEUE = (byte) 107;
+ /**
+ * For the new client-server protocol, which ignores the usual handshake mechanism.
+ */
+ public static final byte CLIENT_TO_SERVER_NEW_PROTOCOL = (byte) 110;
/**
* The GFE version of the server.
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
index 2a8818c..24efc93 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
@@ -1422,8 +1422,8 @@ public class AcceptorImpl extends Acceptor implements Runnable {
s.setTcpNoDelay(this.tcpNoDelay);
if (communicationMode == CLIENT_TO_SERVER || communicationMode == GATEWAY_TO_GATEWAY
- || communicationMode == MONITOR_TO_SERVER
- || communicationMode == CLIENT_TO_SERVER_FOR_QUEUE) {
+ || communicationMode == MONITOR_TO_SERVER || communicationMode == CLIENT_TO_SERVER_FOR_QUEUE
+ || communicationMode == CLIENT_TO_SERVER_NEW_PROTOCOL) {
String communicationModeStr = "";
switch (communicationMode) {
case CLIENT_TO_SERVER:
@@ -1466,9 +1466,9 @@ public class AcceptorImpl extends Acceptor implements Runnable {
return;
}
}
- ServerConnection serverConn = new ServerConnection(s, this.cache, this.crHelper, this.stats,
- AcceptorImpl.handShakeTimeout, this.socketBufferSize, communicationModeStr,
- communicationMode, this, this.securityService);
+ ServerConnection serverConn = ServerConnectionFactory.makeServerConnection(s, this.cache,
+ this.crHelper, this.stats, AcceptorImpl.handShakeTimeout, this.socketBufferSize,
+ communicationModeStr, communicationMode, this, this.securityService);
synchronized (this.allSCsLock) {
this.allSCs.add(serverConn);
ServerConnection snap[] = this.allSCList; // avoid volatile read
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientHealthMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientHealthMonitor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientHealthMonitor.java
index e0b5ab8..35cc33f 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientHealthMonitor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientHealthMonitor.java
@@ -478,12 +478,7 @@ public class ClientHealthMonitor {
Iterator connectionsIterator = connections.iterator();
while (connectionsIterator.hasNext()) {
ServerConnection sc = (ServerConnection) connectionsIterator.next();
- byte communicationMode = sc.getCommunicationMode();
- /* Check for all modes that could be used for Client-Server communication */
- if (communicationMode == Acceptor.CLIENT_TO_SERVER
- || communicationMode == Acceptor.PRIMARY_SERVER_TO_CLIENT
- || communicationMode == Acceptor.SECONDARY_SERVER_TO_CLIENT
- || communicationMode == Acceptor.CLIENT_TO_SERVER_FOR_QUEUE) {
+ if (sc.isClientServerConnection()) {
memberId = sc.getMembershipID(); // each ServerConnection has the same member id
cci.setMemberId(memberId);
cci.setNumberOfConnections(connections.size());
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
new file mode 100644
index 0000000..db42330
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
@@ -0,0 +1,29 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.internal.cache.InternalCache;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Stub, this will be hooked up to the new client protocol when it's implemented.
+ */
+public class ClientProtocolMessageHandler {
+ public void receiveMessage(InputStream inputStream, OutputStream outputStream,
+ InternalCache cache) {}
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/LegacyServerConnection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/LegacyServerConnection.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/LegacyServerConnection.java
new file mode 100644
index 0000000..2b46eb3
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/LegacyServerConnection.java
@@ -0,0 +1,88 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.internal.cache.tier.CachedRegionHelper;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.internal.logging.log4j.LocalizedMessage;
+import org.apache.geode.internal.security.SecurityService;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * Handles everything but the new client protocol.
+ *
+ * Legacy is therefore a bit of a misnomer; do you have a better name?
+ */
+public class LegacyServerConnection extends ServerConnection {
+ /**
+ * Set to false once handshake has been done
+ */
+ private boolean doHandshake = true;
+
+ /**
+ * Creates a new <code>ServerConnection</code> that processes messages received from an edge
+ * client over a given <code>Socket</code>.
+ *
+ * @param socket
+ * @param internalCache
+ * @param helper
+ * @param stats
+ * @param hsTimeout
+ * @param socketBufferSize
+ * @param communicationModeStr
+ * @param communicationMode
+ * @param acceptor
+ * @param securityService
+ */
+ public LegacyServerConnection(Socket socket, InternalCache internalCache,
+ CachedRegionHelper helper, CacheServerStats stats, int hsTimeout, int socketBufferSize,
+ String communicationModeStr, byte communicationMode, Acceptor acceptor,
+ SecurityService securityService) {
+ super(socket, internalCache, helper, stats, hsTimeout, socketBufferSize, communicationModeStr,
+ communicationMode, acceptor, securityService);
+ }
+
+ @Override
+ protected boolean doHandShake(byte epType, int qSize) {
+ try {
+ this.handshake.accept(theSocket.getOutputStream(), theSocket.getInputStream(), epType, qSize,
+ this.communicationMode, this.principal);
+ } catch (IOException ioe) {
+ if (!crHelper.isShutdown() && !isTerminated()) {
+ logger.warn(LocalizedMessage.create(
+ LocalizedStrings.ServerConnection_0_HANDSHAKE_ACCEPT_FAILED_ON_SOCKET_1_2,
+ new Object[] {this.name, this.theSocket, ioe}));
+ }
+ cleanup();
+ return false;
+ }
+ return true;
+ }
+
+ protected void doOneMessage() {
+ if (this.doHandshake) {
+ doHandshake();
+ this.doHandshake = false;
+ } else {
+ this.resetTransientData();
+ doNormalMsg();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
new file mode 100644
index 0000000..a78cd1c
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.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.internal.cache.tier.sockets;
+
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.internal.cache.tier.CachedRegionHelper;
+import org.apache.geode.internal.security.SecurityService;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+/**
+ * Holds the socket and protocol handler for the new client protocol. TODO: Currently unimplemented
+ * due the the protocol not being there.
+ */
+public class NewProtocolServerConnection extends ServerConnection {
+ // The new protocol lives in a separate module and gets loaded when this class is instantiated.
+ // TODO implement this.
+ private final ClientProtocolMessageHandler newClientProtocol;
+
+
+ /**
+ * Creates a new <code>NewProtocolServerConnection</code> that processes messages received from an
+ * edge client over a given <code>Socket</code>.
+ *
+ * @param s
+ * @param c
+ * @param helper
+ * @param stats
+ * @param hsTimeout
+ * @param socketBufferSize
+ * @param communicationModeStr
+ * @param communicationMode
+ * @param acceptor
+ */
+ public NewProtocolServerConnection(Socket s, InternalCache c, CachedRegionHelper helper,
+ CacheServerStats stats, int hsTimeout, int socketBufferSize, String communicationModeStr,
+ byte communicationMode, Acceptor acceptor, ClientProtocolMessageHandler newClientProtocol,
+ SecurityService securityService) {
+ super(s, c, helper, stats, hsTimeout, socketBufferSize, communicationModeStr, communicationMode,
+ acceptor, securityService);
+ assert (communicationMode == AcceptorImpl.CLIENT_TO_SERVER_NEW_PROTOCOL);
+ this.newClientProtocol = newClientProtocol;
+ }
+
+ @Override
+ protected void doOneMessage() {
+ try {
+ Socket socket = this.getSocket();
+ InputStream inputStream = socket.getInputStream();
+ OutputStream outputStream = socket.getOutputStream();
+ // TODO serialization types?
+ newClientProtocol.receiveMessage(inputStream, outputStream, this.getCache());
+ } catch (IOException e) {
+ // TODO?
+ }
+ return;
+ }
+
+ @Override
+ protected boolean doHandShake(byte epType, int qSize) {
+ // no handshake for new client protocol.
+ return true;
+ }
+
+ @Override
+ public boolean isClientServerConnection() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnection.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnection.java
index 947b836..ebc9dab 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnection.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnection.java
@@ -74,9 +74,9 @@ import org.apache.geode.security.GemFireSecurityException;
*
* @since GemFire 2.0.2
*/
-public class ServerConnection implements Runnable {
+public abstract class ServerConnection implements Runnable {
- private static final Logger logger = LogService.getLogger();
+ protected static final Logger logger = LogService.getLogger();
/**
* This is a buffer that we add to client readTimeout value before we cleanup the connection. This
@@ -138,12 +138,12 @@ public class ServerConnection implements Runnable {
}
}
- private Socket theSocket;
+ protected Socket theSocket;
// private InputStream in = null;
// private OutputStream out = null;
private ByteBuffer commBuffer;
- private final CachedRegionHelper crHelper;
- private String name = null;
+ protected final CachedRegionHelper crHelper;
+ protected String name = null;
// IMPORTANT: if new messages are added change setHandshake to initialize them
// to the correct Version for serializing to the client
@@ -168,7 +168,7 @@ public class ServerConnection implements Runnable {
/**
* Handshake reference uniquely identifying a client
*/
- private ClientHandShake handshake;
+ protected ClientHandShake handshake;
private int handShakeTimeout;
private final Object handShakeMonitor = new Object();
@@ -213,7 +213,7 @@ public class ServerConnection implements Runnable {
* The communication mode for this <code>ServerConnection</code>. Valid types include
* 'client-server', 'gateway-gateway' and 'monitor-server'.
*/
- private final byte communicationMode;
+ protected final byte communicationMode;
private final String communicationModeStr;
private long processingMessageStartTime = -1;
@@ -233,7 +233,7 @@ public class ServerConnection implements Runnable {
private Part securePart = null;
- private Principal principal;
+ protected Principal principal;
private MessageIdExtractor messageIdExtractor = new MessageIdExtractor();
@@ -592,19 +592,14 @@ public class ServerConnection implements Runnable {
}
}
- private boolean acceptHandShake(byte epType, int qSize) {
- try {
- this.handshake.accept(theSocket.getOutputStream(), theSocket.getInputStream(), epType, qSize,
- this.communicationMode, this.principal);
- } catch (IOException ioe) {
- if (!crHelper.isShutdown() && !isTerminated()) {
- logger.warn(LocalizedMessage.create(
- LocalizedStrings.ServerConnection_0_HANDSHAKE_ACCEPT_FAILED_ON_SOCKET_1_2,
- new Object[] {this.name, this.theSocket, ioe}));
- }
- cleanup();
- return false;
- }
+ protected boolean acceptHandShake(byte epType, int qSize) {
+ return doHandShake(epType, qSize) && handshakeAccepted();
+ }
+
+ protected abstract boolean doHandShake(byte epType, int qSize);
+
+
+ protected boolean handshakeAccepted() {
if (logger.isDebugEnabled()) {
logger.debug("{}: Accepted handshake", this.name);
}
@@ -670,6 +665,16 @@ public class ServerConnection implements Runnable {
}
}
+ /**
+ * @return whether this is a connection to a client, regardless of protocol.
+ */
+ public boolean isClientServerConnection() {
+ return communicationMode == Acceptor.CLIENT_TO_SERVER
+ || communicationMode == Acceptor.PRIMARY_SERVER_TO_CLIENT
+ || communicationMode == Acceptor.SECONDARY_SERVER_TO_CLIENT
+ || communicationMode == Acceptor.CLIENT_TO_SERVER_FOR_QUEUE;
+ }
+
static class Counter {
int cnt;
@@ -686,22 +691,12 @@ public class ServerConnection implements Runnable {
}
}
- // public void setUserAuthAttributes(ClientProxyMembershipID proxyId, AuthorizeRequest
- // authzRequest, AuthorizeRequestPP postAuthzRequest) {
- // UserAuthAttributes uaa = new UserAuthAttributes(authzRequest, postAuthzRequest);
- // }
-
- /**
- * Set to false once handshake has been done
- */
- private boolean doHandshake = true;
-
private boolean clientDisconnectedCleanly = false;
private Throwable clientDisconnectedException;
private int failureCount = 0;
private boolean processMessages = true;
- private void doHandshake() {
+ protected void doHandshake() {
// hitesh:to create new connection handshake
if (verifyClientConnection()) {
// Initialize the commands after the handshake so that the version
@@ -718,7 +713,7 @@ public class ServerConnection implements Runnable {
}
}
- private void doNormalMsg() {
+ protected void doNormalMsg() {
Message msg = null;
msg = BaseCommand.readRequest(this);
ThreadState threadState = null;
@@ -903,15 +898,7 @@ public class ServerConnection implements Runnable {
}
}
- private void doOneMessage() {
- if (this.doHandshake) {
- doHandshake();
- this.doHandshake = false;
- } else {
- this.resetTransientData();
- doNormalMsg();
- }
- }
+ protected abstract void doOneMessage();
private void initializeClientUserAuths() {
this.clientUserAuths = getClientUserAuths(this.proxyId);
@@ -1070,7 +1057,7 @@ public class ServerConnection implements Runnable {
/**
* MessageType of the messages (typically internal commands) which do not need to participate in
* security should be added in the following if block.
- *
+ *
* @return Part
* @see AbstractOp#processSecureBytes(Connection, Message)
* @see AbstractOp#needsUserId()
@@ -1495,7 +1482,7 @@ public class ServerConnection implements Runnable {
/**
* Just ensure that this class gets loaded.
- *
+ *
* @see SystemFailure#loadEmergencyClasses()
*/
public static void loadEmergencyClasses() {
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
new file mode 100644
index 0000000..4f2e304
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.internal.cache.tier.CachedRegionHelper;
+import org.apache.geode.internal.security.SecurityService;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * Creates instances of ServerConnection based on the connection mode provided.
+ */
+public class ServerConnectionFactory {
+ // TODO: implement ClientProtocolMessageHandler.
+ private static final ClientProtocolMessageHandler newClientProtocol =
+ new ClientProtocolMessageHandler();
+
+ public static ServerConnection makeServerConnection(Socket s, InternalCache c,
+ CachedRegionHelper helper, CacheServerStats stats, int hsTimeout, int socketBufferSize,
+ String communicationModeStr, byte communicationMode, Acceptor acceptor,
+ SecurityService securityService) throws IOException {
+ if (communicationMode == Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL) {
+ if (!Boolean.getBoolean("geode.feature-protobuf-protocol")) {
+ throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
+ } else {
+ return new NewProtocolServerConnection(s, c, helper, stats, hsTimeout, socketBufferSize,
+ communicationModeStr, communicationMode, acceptor, newClientProtocol, securityService);
+ }
+ } else {
+ return new LegacyServerConnection(s, c, helper, stats, hsTimeout, socketBufferSize,
+ communicationModeStr, communicationMode, acceptor, securityService);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
new file mode 100644
index 0000000..c314944
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.internal.cache.tier.CachedRegionHelper;
+import org.apache.geode.internal.security.SecurityService;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+public class ServerConnectionFactoryTest {
+ /**
+ * Safeguard that we won't create the new client protocol object unless the feature flag is enabled.
+ */
+ @Test(expected = IOException.class)
+ public void newClientProtocolThrows() throws Exception {
+ serverConnectionMockedExceptForCommunicationMode(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
+ }
+
+ @Test
+ public void newClientProtocolSucceedsWithSystemPropertySet() throws Exception {
+ System.setProperty("geode.feature-protobuf-protocol", "true");
+ ServerConnection serverConnection = serverConnectionMockedExceptForCommunicationMode(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
+ assertTrue(serverConnection instanceof NewProtocolServerConnection);
+ System.clearProperty("geode.feature-protobuf-protocol");
+ }
+
+ @Test
+ public void makeServerConnection() throws Exception {
+ byte[] communicationModes = new byte[]{
+ Acceptor.CLIENT_TO_SERVER,
+ Acceptor.PRIMARY_SERVER_TO_CLIENT,
+ Acceptor.SECONDARY_SERVER_TO_CLIENT,
+ Acceptor.GATEWAY_TO_GATEWAY,
+ Acceptor.MONITOR_TO_SERVER,
+ Acceptor.SUCCESSFUL_SERVER_TO_CLIENT,
+ Acceptor.UNSUCCESSFUL_SERVER_TO_CLIENT,
+ Acceptor.CLIENT_TO_SERVER_FOR_QUEUE,
+ };
+
+ for (byte communicationMode : communicationModes) {
+ ServerConnection serverConnection = serverConnectionMockedExceptForCommunicationMode(communicationMode);
+ assertTrue(serverConnection instanceof LegacyServerConnection);
+ }
+ }
+
+ private static ServerConnection serverConnectionMockedExceptForCommunicationMode(byte communicationMode) throws IOException {
+ Socket socketMock = mock(Socket.class);
+ when(socketMock.getInetAddress()).thenReturn(InetAddress.getByName("localhost"));
+
+ return ServerConnectionFactory.makeServerConnection(
+ socketMock, mock(InternalCache.class), mock(CachedRegionHelper.class),
+ mock(CacheServerStats.class), 0, 0, "",
+ communicationMode, mock(AcceptorImpl.class), mock(SecurityService.class));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode/blob/dfdde4af/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
index 794c610..d3ef21f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
@@ -39,6 +39,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
@@ -57,7 +58,7 @@ public class ServerConnectionTest {
private ServerConnection serverConnection;
@Before
- public void setUp() {
+ public void setUp() throws IOException {
AcceptorImpl acceptor = mock(AcceptorImpl.class);
InetAddress inetAddress = mock(InetAddress.class);
@@ -69,8 +70,8 @@ public class ServerConnectionTest {
InternalCache cache = mock(InternalCache.class);
SecurityService securityService = mock(SecurityService.class);
- serverConnection = new ServerConnection(socket, cache, null, null, 0, 0, null,
- Acceptor.PRIMARY_SERVER_TO_CLIENT, acceptor, securityService);
+ serverConnection = ServerConnectionFactory.makeServerConnection(socket, cache, null, null, 0, 0,
+ null, Acceptor.PRIMARY_SERVER_TO_CLIENT, acceptor, securityService);
MockitoAnnotations.initMocks(this);
}
[04/13] geode git commit: GEODE-2995: Implementing review feedback
Posted by hi...@apache.org.
GEODE-2995: Implementing review feedback
Numerous tweaks and fixes
Created protobuf package under org.apache.geode.protocol and moved several classes
Added javadoc comments
Signed-off-by: Galen O'Sullivan <go...@pivotal.io>
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/31f4de06
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/31f4de06
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/31f4de06
Branch: refs/heads/develop
Commit: 31f4de065bd32b5801017427a14cec142c5897fc
Parents: c71c28d
Author: Brian Rowe <br...@pivotal.io>
Authored: Tue Jun 20 15:49:11 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
geode-protobuf/build.gradle | 2 -
.../org/apache/geode/ProtobufUtilities.java | 34 --------
.../org/apache/geode/protocol/OpsProcessor.java | 53 ------------
.../InvalidProtocolMessageException.java | 3 +
.../handler/ProtobufStreamProcessor.java | 61 --------------
.../geode/protocol/handler/ProtocolHandler.java | 27 ------
.../protobuf/ProtobufProtocolHandler.java | 41 ---------
.../protocol/operations/OperationHandler.java | 10 +++
.../ProtobufRequestOperationParser.java | 33 --------
.../protobuf/GetRequestOperationHandler.java | 59 -------------
.../registry/OperationsHandlerRegistry.java | 3 +
...rationHandlerAlreadyRegisteredException.java | 3 +
.../OperationHandlerNotRegisteredException.java | 3 +
.../protobuf/EncodingTypeTranslator.java | 86 +++++++++++++++++++
.../protocol/protobuf/ProtobufOpsProcessor.java | 66 +++++++++++++++
.../protobuf/ProtobufSerializationService.java | 51 ++++++++++++
.../protobuf/ProtobufStreamProcessor.java | 60 +++++++++++++
.../protocol/protobuf/ProtobufUtilities.java | 34 ++++++++
.../operations/GetRequestOperationHandler.java | 58 +++++++++++++
.../serializer/ProtobufProtocolSerializer.java | 41 +++++++++
.../protocol/serializer/ProtocolSerializer.java | 31 +++++++
.../ProtobufSerializationService.java | 50 -----------
.../UnsupportedEncodingTypeException.java | 3 +
.../translation/EncodingTypeTranslator.java | 83 ------------------
.../UnsupportedEncodingTypeException.java | 21 -----
.../CodecAlreadyRegisteredForTypeException.java | 3 +
.../CodecNotRegisteredForTypeException.java | 3 +
...pache.geode.protocol.handler.ProtocolHandler | 1 -
...e.geode.protocol.operations.OperationHandler | 2 +-
...geode.protocol.serializer.ProtocolSerializer | 1 +
.../geode/client/protocol/IntegrationTest.java | 32 +++----
.../geode/client/protocol/OpsProcessorTest.java | 64 --------------
.../ProtobufProtocolHandlerJUnitTest.java | 88 --------------------
.../GetRequestOperationHandlerTest.java | 4 +-
.../protobuf/ProtobufOpsProcessorTest.java | 62 ++++++++++++++
.../ProtobufProtocolSerializerJUnitTest.java | 81 ++++++++++++++++++
.../ProtobufSerializationServiceImplTest.java | 5 +-
...eToSerializationTypeTranslatorJUnitTest.java | 1 +
.../registry/CodecRegistryJUnitTest.java | 16 ++--
39 files changed, 632 insertions(+), 647 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/build.gradle
----------------------------------------------------------------------
diff --git a/geode-protobuf/build.gradle b/geode-protobuf/build.gradle
index 2102f6a..f069267 100644
--- a/geode-protobuf/build.gradle
+++ b/geode-protobuf/build.gradle
@@ -44,13 +44,11 @@ protobuf {
// 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'
}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java b/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java
deleted file mode 100644
index c25fc14..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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;
-
-import com.google.protobuf.ByteString;
-
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-
-public abstract class ProtobufUtilities {
- public static BasicTypes.EncodedValue getEncodedValue(BasicTypes.EncodingType resultEncodingType,
- byte[] resultEncodedValue) {
- return BasicTypes.EncodedValue.newBuilder().setEncodingType(resultEncodingType)
- .setValue(ByteString.copyFrom(resultEncodedValue)).build();
- }
-
- public static ClientProtocol.Message wrapResponseWithDefaultHeader(
- ClientProtocol.Response response) {
- return ClientProtocol.Message.newBuilder()
- .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setResponse(response).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java
deleted file mode 100644
index 999fdf0..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.protocol;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.operations.ProtobufRequestOperationParser;
-import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.apache.geode.protocol.protobuf.RegionAPI;
-import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-
-public class OpsProcessor {
- private final OperationsHandlerRegistry opsHandlerRegistry;
- private final SerializationService serializationService;
-
- public OpsProcessor(OperationsHandlerRegistry opsHandlerRegistry,
- SerializationService serializationService) {
- this.opsHandlerRegistry = opsHandlerRegistry;
- this.serializationService = serializationService;
- }
-
- public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- OperationHandler opsHandler = null;
- try {
- opsHandler = opsHandlerRegistry
- .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber());
- } catch (OperationHandlerNotRegisteredException e) {
- e.printStackTrace();
- }
-
- Object responseMessage = opsHandler.process(serializationService,
- ProtobufRequestOperationParser.getRequestForOperationTypeID(request), cache);
- return ClientProtocol.Response.newBuilder()
- .setGetResponse((RegionAPI.GetResponse) responseMessage).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
index 8f73f57..dae03a1 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
@@ -14,6 +14,9 @@
*/
package org.apache.geode.protocol.exception;
+/**
+ * Indicates that a message didn't properly follow it's protocol specification.
+ */
public class InvalidProtocolMessageException extends Exception {
public InvalidProtocolMessageException(String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java
deleted file mode 100644
index e459f76..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.protocol.handler;
-
-import org.apache.geode.ProtobufUtilities;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.protocol.OpsProcessor;
-import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
-import org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler;
-import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.apache.geode.serialization.ProtobufSerializationService;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-public class ProtobufStreamProcessor {
- ProtobufProtocolHandler protobufProtocolHandler;
- OperationsHandlerRegistry registry;
- ProtobufSerializationService protobufSerializationService;
- OpsProcessor opsProcessor;
-
- public ProtobufStreamProcessor()
- throws OperationHandlerAlreadyRegisteredException, CodecAlreadyRegisteredForTypeException {
- protobufProtocolHandler = new ProtobufProtocolHandler();
- registry = new OperationsHandlerRegistry();
- protobufSerializationService = new ProtobufSerializationService();
- opsProcessor = new OpsProcessor(registry, protobufSerializationService);
- }
-
- public void processOneMessage(InputStream inputStream, OutputStream outputStream, Cache cache)
- throws InvalidProtocolMessageException, OperationHandlerNotRegisteredException,
- UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException, IOException {
- ClientProtocol.Message message = protobufProtocolHandler.deserialize(inputStream);
-
- ClientProtocol.Request request = message.getRequest();
- ClientProtocol.Response response = opsProcessor.process(request, cache);
-
- ClientProtocol.Message responseMessage =
- ProtobufUtilities.wrapResponseWithDefaultHeader(response);
- protobufProtocolHandler.serialize(responseMessage, outputStream);
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java
deleted file mode 100644
index 4947a0a..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.protocol.handler;
-
-import org.apache.geode.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 outputStream) throws IOException;
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
deleted file mode 100644
index f8c2abd..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.protocol.handler.protobuf;
-
-import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
-import org.apache.geode.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/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
index 020c27b..8eab146 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
@@ -15,13 +15,23 @@
package org.apache.geode.protocol.operations;
import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.protobuf.ProtobufOpsProcessor;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
import org.apache.geode.serialization.SerializationService;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+/**
+ * This interface is implemented by a object capable of handling request types 'Req' and returning an a response of type 'Resp'
+ *
+ * See {@link ProtobufOpsProcessor}
+ */
public interface OperationHandler<Req, Resp> {
Resp process(SerializationService serializationService, Req request, Cache cache)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+ /**
+ * @return the magic number used for registering the operation type with the {@link OperationsHandlerRegistry}.
+ */
int getOperationCode();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java
deleted file mode 100644
index 7fb0eab..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.protocol.operations;
-
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-
-public class ProtobufRequestOperationParser {
- public static Object getRequestForOperationTypeID(ClientProtocol.Request request) {
- switch (request.getRequestAPICase()) {
- case PUTREQUEST:
- return request.getPutRequest();
- case GETREQUEST:
- return request.getGetRequest();
- case PUTALLREQUEST:
- return request.getPutAllRequest();
- default:
- throw new RuntimeException(
- "Unknown request type: " + request.getRequestAPICase().getNumber());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java
deleted file mode 100644
index dafacc0..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.protocol.operations.protobuf;
-
-import org.apache.geode.ProtobufUtilities;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionService;
-import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.apache.geode.protocol.protobuf.RegionAPI;
-import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-
-public class GetRequestOperationHandler
- implements OperationHandler<RegionAPI.GetRequest, RegionAPI.GetResponse> {
-
- @Override
- public RegionAPI.GetResponse process(SerializationService serializationService,
- RegionAPI.GetRequest request, Cache cache)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- String regionName = request.getRegionName();
- BasicTypes.EncodedValue key = request.getKey();
- BasicTypes.EncodingType encodingType = key.getEncodingType();
- byte[] value = key.getValue().toByteArray();
- Object decodedValue = serializationService.decode(encodingType, value);
-
- Region region = cache.getRegion(regionName);
- Object resultValue = region.get(decodedValue);
-
- BasicTypes.EncodingType resultEncodingType =
- EncodingTypeTranslator.getEncodingTypeForObject(resultValue);
- byte[] resultEncodedValue = serializationService.encode(resultEncodingType, resultValue);
-
- return RegionAPI.GetResponse.newBuilder()
- .setResult(ProtobufUtilities.getEncodedValue(resultEncodingType, resultEncodedValue))
- .build();
- }
-
- @Override
- public int getOperationCode() {
- return ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
index 80e0459..8e3a331 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
@@ -21,6 +21,9 @@ import org.apache.geode.protocol.operations.registry.exception.OperationHandlerN
import java.util.HashMap;
import java.util.ServiceLoader;
+/**
+ * This class tracks which operation handlers are expected to handle which types of operations.
+ */
public class OperationsHandlerRegistry {
private HashMap<Integer, OperationHandler> registeredOperations = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
index 1f42c10..519698d 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
@@ -14,6 +14,9 @@
*/
package org.apache.geode.protocol.operations.registry.exception;
+/**
+ * Indicates that an operation handler is attempting to register for an already handled operation type.
+ */
public class OperationHandlerAlreadyRegisteredException extends Exception {
public OperationHandlerAlreadyRegisteredException(String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
index f83e1b3..6772e56 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
@@ -14,6 +14,9 @@
*/
package org.apache.geode.protocol.operations.registry.exception;
+/**
+ * Indicates that we're trying to handle an operation for which no operation handler has registered.
+ */
public class OperationHandlerNotRegisteredException extends Exception {
public OperationHandlerNotRegisteredException(String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.java
new file mode 100644
index 0000000..650ac81
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/EncodingTypeTranslator.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.protocol.protobuf;
+
+import org.apache.geode.pdx.JSONFormatter;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+
+/**
+ * This class maps protobuf specific encoding types and the corresponding serialization types.
+ */
+public abstract class EncodingTypeTranslator {
+ public static SerializationType getSerializationTypeForEncodingType(
+ BasicTypes.EncodingType encodingType) throws UnsupportedEncodingTypeException {
+ switch (encodingType) {
+ case INT:
+ return SerializationType.INT;
+ case BYTE:
+ return SerializationType.BYTE;
+ case JSON:
+ return SerializationType.JSON;
+ case LONG:
+ return SerializationType.LONG;
+ case FLOAT:
+ return SerializationType.FLOAT;
+ case SHORT:
+ return SerializationType.SHORT;
+ case BINARY:
+ return SerializationType.BINARY;
+ case DOUBLE:
+ return SerializationType.DOUBLE;
+ case STRING:
+ return SerializationType.STRING;
+ case BOOLEAN:
+ return SerializationType.BOOLEAN;
+ default:
+ throw new UnsupportedEncodingTypeException(
+ "No serialization type found for protobuf encoding type: " + encodingType);
+ }
+ }
+
+ public static BasicTypes.EncodingType getEncodingTypeForObject(Object resultValue)
+ throws UnsupportedEncodingTypeException {
+ if (resultValue instanceof Integer) {
+ return BasicTypes.EncodingType.INT;
+ } else if (resultValue instanceof Byte) {
+ return BasicTypes.EncodingType.BYTE;
+ } else if (resultValue instanceof PdxInstance) {
+ String pdxClassName = ((PdxInstance) resultValue).getClassName();
+ if (pdxClassName.equals(JSONFormatter.JSON_CLASSNAME)) {
+ return BasicTypes.EncodingType.JSON;
+ }
+ } else if (resultValue instanceof Long) {
+ return BasicTypes.EncodingType.LONG;
+ } else if (resultValue instanceof Float) {
+ return BasicTypes.EncodingType.FLOAT;
+ } else if (resultValue instanceof Short) {
+ return BasicTypes.EncodingType.SHORT;
+ } else if (resultValue instanceof byte[]) {
+ return BasicTypes.EncodingType.BINARY;
+ } else if (resultValue instanceof Double) {
+ return BasicTypes.EncodingType.DOUBLE;
+ } else if (resultValue instanceof String) {
+ return BasicTypes.EncodingType.STRING;
+ } else if (resultValue instanceof Boolean) {
+ return BasicTypes.EncodingType.BOOLEAN;
+ }
+
+ throw new UnsupportedEncodingTypeException(
+ "We cannot translate: " + resultValue.getClass() + " into a specific Protobuf Encoding");
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
new file mode 100644
index 0000000..c572d80
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.protocol.protobuf;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+/**
+ * This handles protobuf requests by determining the operation type of the request and dispatching it to the appropriate handler.
+ */
+public class ProtobufOpsProcessor {
+ private final OperationsHandlerRegistry opsHandlerRegistry;
+ private final SerializationService serializationService;
+
+ public ProtobufOpsProcessor(OperationsHandlerRegistry opsHandlerRegistry,
+ SerializationService serializationService) {
+ this.opsHandlerRegistry = opsHandlerRegistry;
+ this.serializationService = serializationService;
+ }
+
+ public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException,
+ OperationHandlerNotRegisteredException, InvalidProtocolMessageException {
+ OperationHandler opsHandler = opsHandlerRegistry
+ .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber());
+
+ Object responseMessage = opsHandler.process(serializationService,
+ getRequestForOperationTypeID(request), cache);
+ return ClientProtocol.Response.newBuilder()
+ .setGetResponse((RegionAPI.GetResponse) responseMessage).build();
+ }
+
+ // package visibility for testing
+ static Object getRequestForOperationTypeID(ClientProtocol.Request request)
+ throws InvalidProtocolMessageException {
+ switch (request.getRequestAPICase()) {
+ case PUTREQUEST:
+ return request.getPutRequest();
+ case GETREQUEST:
+ return request.getGetRequest();
+ case PUTALLREQUEST:
+ return request.getPutAllRequest();
+ default:
+ throw new InvalidProtocolMessageException(
+ "Unknown request type: " + request.getRequestAPICase().getNumber());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSerializationService.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSerializationService.java
new file mode 100644
index 0000000..fc76d5e
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSerializationService.java
@@ -0,0 +1,51 @@
+/*
+ * 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.protocol.protobuf;
+
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public class ProtobufSerializationService implements SerializationService<BasicTypes.EncodingType> {
+ private SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+
+ public ProtobufSerializationService() throws CodecAlreadyRegisteredForTypeException {}
+
+ @Override
+ public byte[] encode(BasicTypes.EncodingType encodingTypeValue, Object value)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
+ return codecForType.encode(value);
+ }
+
+ @Override
+ public Object decode(BasicTypes.EncodingType encodingTypeValue, byte[] value)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
+ return codecForType.decode(value);
+ }
+
+ private TypeCodec getTypeCodecForProtobufType(BasicTypes.EncodingType encodingTypeValue)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ SerializationType serializationTypeForEncodingType =
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingTypeValue);
+
+ return serializationCodecRegistry.getCodecForType(serializationTypeForEncodingType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
new file mode 100644
index 0000000..41a3c40
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
@@ -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.
+ */
+package org.apache.geode.protocol.protobuf;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * This object handles an incoming stream containing protobuf messages. It parses the protobuf messages, hands the requests to an appropriate handler, wraps the response in a protobuf message, and then pushes it to the output stream.
+ */
+public class ProtobufStreamProcessor {
+ ProtobufProtocolSerializer protobufProtocolSerializer;
+ OperationsHandlerRegistry registry;
+ ProtobufSerializationService protobufSerializationService;
+ ProtobufOpsProcessor protobufOpsProcessor;
+
+ public ProtobufStreamProcessor()
+ throws OperationHandlerAlreadyRegisteredException, CodecAlreadyRegisteredForTypeException {
+ protobufProtocolSerializer = new ProtobufProtocolSerializer();
+ registry = new OperationsHandlerRegistry();
+ protobufSerializationService = new ProtobufSerializationService();
+ protobufOpsProcessor = new ProtobufOpsProcessor(registry, protobufSerializationService);
+ }
+
+ public void processOneMessage(InputStream inputStream, OutputStream outputStream, Cache cache)
+ throws InvalidProtocolMessageException, OperationHandlerNotRegisteredException,
+ UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException, IOException {
+ ClientProtocol.Message message = protobufProtocolSerializer.deserialize(inputStream);
+
+ ClientProtocol.Request request = message.getRequest();
+ ClientProtocol.Response response = protobufOpsProcessor.process(request, cache);
+
+ ClientProtocol.Message responseMessage =
+ ProtobufUtilities.wrapResponseWithDefaultHeader(response);
+ protobufProtocolSerializer.serialize(responseMessage, outputStream);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufUtilities.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufUtilities.java
new file mode 100644
index 0000000..d763662
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufUtilities.java
@@ -0,0 +1,34 @@
+/*
+ * 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.protocol.protobuf;
+
+import com.google.protobuf.ByteString;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+
+public abstract class ProtobufUtilities {
+ public static BasicTypes.EncodedValue getEncodedValue(BasicTypes.EncodingType resultEncodingType,
+ byte[] resultEncodedValue) {
+ return BasicTypes.EncodedValue.newBuilder().setEncodingType(resultEncodingType)
+ .setValue(ByteString.copyFrom(resultEncodedValue)).build();
+ }
+
+ public static ClientProtocol.Message wrapResponseWithDefaultHeader(
+ ClientProtocol.Response response) {
+ return ClientProtocol.Message.newBuilder()
+ .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setResponse(response).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
new file mode 100644
index 0000000..37d1d32
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
@@ -0,0 +1,58 @@
+/*
+ * 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.protocol.protobuf.operations;
+
+import org.apache.geode.protocol.protobuf.ProtobufUtilities;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public class GetRequestOperationHandler
+ implements OperationHandler<RegionAPI.GetRequest, RegionAPI.GetResponse> {
+
+ @Override
+ public RegionAPI.GetResponse process(SerializationService serializationService,
+ RegionAPI.GetRequest request, Cache cache)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ String regionName = request.getRegionName();
+ BasicTypes.EncodedValue key = request.getKey();
+ BasicTypes.EncodingType encodingType = key.getEncodingType();
+ byte[] value = key.getValue().toByteArray();
+ Object decodedValue = serializationService.decode(encodingType, value);
+
+ Region region = cache.getRegion(regionName);
+ Object resultValue = region.get(decodedValue);
+
+ BasicTypes.EncodingType resultEncodingType =
+ EncodingTypeTranslator.getEncodingTypeForObject(resultValue);
+ byte[] resultEncodedValue = serializationService.encode(resultEncodingType, resultValue);
+
+ return RegionAPI.GetResponse.newBuilder()
+ .setResult(ProtobufUtilities.getEncodedValue(resultEncodingType, resultEncodedValue))
+ .build();
+ }
+
+ @Override
+ public int getOperationCode() {
+ return ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/serializer/ProtobufProtocolSerializer.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/serializer/ProtobufProtocolSerializer.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/serializer/ProtobufProtocolSerializer.java
new file mode 100644
index 0000000..683e42f
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/serializer/ProtobufProtocolSerializer.java
@@ -0,0 +1,41 @@
+/*
+ * 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.protocol.protobuf.serializer;
+
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.serializer.ProtocolSerializer;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ProtobufProtocolSerializer implements ProtocolSerializer<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/31f4de06/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
new file mode 100644
index 0000000..7191d87
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
@@ -0,0 +1,31 @@
+/*
+ * 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.protocol.serializer;
+
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * This interface is used to translate between binary data and protocol specific messages.
+ * @param <T> The message type of the protocol.
+ */
+public interface ProtocolSerializer<T> {
+ T deserialize(InputStream inputStream) throws InvalidProtocolMessageException;
+
+ void serialize(T inputMessage, OutputStream outputStream) throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java
deleted file mode 100644
index 9d78245..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.serialization;
-
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.SerializationCodecRegistry;
-import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-
-public class ProtobufSerializationService implements SerializationService<BasicTypes.EncodingType> {
- private SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
-
- public ProtobufSerializationService() throws CodecAlreadyRegisteredForTypeException {}
-
- @Override
- public byte[] encode(BasicTypes.EncodingType encodingTypeValue, Object value)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
- return codecForType.encode(value);
- }
-
- @Override
- public Object decode(BasicTypes.EncodingType encodingTypeValue, byte[] value)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
- return codecForType.decode(value);
- }
-
- private TypeCodec getTypeCodecForProtobufType(BasicTypes.EncodingType encodingTypeValue)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- SerializationType serializationTypeForEncodingType =
- EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingTypeValue);
-
- return serializationCodecRegistry.getCodecForType(serializationTypeForEncodingType);
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
index 9d75f56..6d2a032 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
@@ -14,6 +14,9 @@
*/
package org.apache.geode.serialization.exception;
+/**
+ * This indicates an encoding type that we don't know how to handle.
+ */
public class UnsupportedEncodingTypeException extends Exception {
public UnsupportedEncodingTypeException(String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java
deleted file mode 100644
index 667996d..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.serialization.protobuf.translation;
-
-import org.apache.geode.pdx.JSONFormatter;
-import org.apache.geode.pdx.PdxInstance;
-import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.serialization.SerializationType;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-
-public abstract class EncodingTypeTranslator {
- public static SerializationType getSerializationTypeForEncodingType(
- BasicTypes.EncodingType encodingType) throws UnsupportedEncodingTypeException {
- switch (encodingType) {
- case INT:
- return SerializationType.INT;
- case BYTE:
- return SerializationType.BYTE;
- case JSON:
- return SerializationType.JSON;
- case LONG:
- return SerializationType.LONG;
- case FLOAT:
- return SerializationType.FLOAT;
- case SHORT:
- return SerializationType.SHORT;
- case BINARY:
- return SerializationType.BINARY;
- case DOUBLE:
- return SerializationType.DOUBLE;
- case STRING:
- return SerializationType.STRING;
- case BOOLEAN:
- return SerializationType.BOOLEAN;
- default:
- throw new UnsupportedEncodingTypeException(
- "No serialization type found for protobuf encoding type: " + encodingType);
- }
- }
-
- public static BasicTypes.EncodingType getEncodingTypeForObject(Object resultValue)
- throws UnsupportedEncodingTypeException {
- if (resultValue instanceof Integer) {
- return BasicTypes.EncodingType.INT;
- } else if (resultValue instanceof Byte) {
- return BasicTypes.EncodingType.BYTE;
- } else if (resultValue instanceof PdxInstance) {
- String pdxClassName = ((PdxInstance) resultValue).getClassName();
- if (pdxClassName.equals(JSONFormatter.JSON_CLASSNAME)) {
- return BasicTypes.EncodingType.JSON;
- }
- } else if (resultValue instanceof Long) {
- return BasicTypes.EncodingType.LONG;
- } else if (resultValue instanceof Float) {
- return BasicTypes.EncodingType.FLOAT;
- } else if (resultValue instanceof Short) {
- return BasicTypes.EncodingType.SHORT;
- } else if (resultValue instanceof byte[]) {
- return BasicTypes.EncodingType.BINARY;
- } else if (resultValue instanceof Double) {
- return BasicTypes.EncodingType.DOUBLE;
- } else if (resultValue instanceof String) {
- return BasicTypes.EncodingType.STRING;
- } else if (resultValue instanceof Boolean) {
- return BasicTypes.EncodingType.BOOLEAN;
- }
-
- throw new UnsupportedEncodingTypeException(
- "We cannot translate: " + resultValue.getClass() + " into a specific Protobuf Encoding");
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java
deleted file mode 100644
index ad01eac..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.serialization.protobuf.translation.exception;
-
-public class UnsupportedEncodingTypeException extends Exception {
- public UnsupportedEncodingTypeException(String message) {
- super(message);
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
index 678d374..7e73ba9 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
@@ -14,6 +14,9 @@
*/
package org.apache.geode.serialization.registry.exception;
+/**
+ * This indicates that we're attempting to register a codec for a type which we already have a handler for.
+ */
public class CodecAlreadyRegisteredForTypeException extends Exception {
public CodecAlreadyRegisteredForTypeException(String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
index a1a6408..58cb691 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
@@ -14,6 +14,9 @@
*/
package org.apache.geode.serialization.registry.exception;
+/**
+ * This indicates we're attempting to handle a type for which we don't have a registered codec.
+ */
public class CodecNotRegisteredForTypeException extends Exception {
public CodecNotRegisteredForTypeException(String message) {
super(message);
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler
deleted file mode 100644
index 9af7c5d..0000000
--- a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
index fa7c3c6..b6ec564 100644
--- a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
+++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
@@ -1 +1 @@
-org.apache.geode.protocol.operations.protobuf.GetRequestOperationHandler
\ No newline at end of file
+org.apache.geode.protocol.protobuf.operations.GetRequestOperationHandler
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serializer.ProtocolSerializer
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serializer.ProtocolSerializer b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serializer.ProtocolSerializer
new file mode 100644
index 0000000..2a9af4e
--- /dev/null
+++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serializer.ProtocolSerializer
@@ -0,0 +1 @@
+org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
index e86e908..e32c711 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
@@ -18,15 +18,12 @@ import com.google.protobuf.ByteString;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
-import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
-import org.apache.geode.protocol.handler.ProtobufStreamProcessor;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.protocol.protobuf.ProtobufStreamProcessor;
import org.apache.geode.protocol.protobuf.BasicTypes;
import org.apache.geode.protocol.protobuf.ClientProtocol;
import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.serialization.codec.StringCodec;
-import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.SerializationCodecRegistry;
import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
@@ -37,7 +34,10 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
@@ -52,6 +52,7 @@ public class IntegrationTest {
public static final String TEST_REGION = "test region";
private StringCodec stringCodec;
private Cache cacheStub;
+ private Region regionStub;
@Before
public void setup() throws CodecAlreadyRegisteredForTypeException,
@@ -59,15 +60,13 @@ public class IntegrationTest {
SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
stringCodec = (StringCodec) serializationCodecRegistry.getCodecForType(
EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
- cacheStub = getCacheStub();
+ regionStub = getRegionStub();
+ cacheStub = getCacheStub(regionStub);
}
@Test
- public void testFullRequestToCache()
- throws OperationHandlerAlreadyRegisteredException, CodecAlreadyRegisteredForTypeException,
- UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException,
- OperationHandlerNotRegisteredException, IOException, InvalidProtocolMessageException {
-
+ public void testGetRequestProcessed()
+ throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ProtobufStreamProcessor streamProcessor = new ProtobufStreamProcessor();
@@ -80,14 +79,19 @@ public class IntegrationTest {
Assert.assertEquals(BasicTypes.EncodingType.STRING, getResponse.getResult().getEncodingType());
String actualValue = stringCodec.decode(getResponse.getResult().getValue().toByteArray());
Assert.assertEquals(TEST_VALUE, actualValue);
+ verify(regionStub, times(1)).get(TEST_KEY);
+ verify(regionStub, times(1)).get(anyString());
}
- private Cache getCacheStub() {
- Region regionStub = mock(Region.class);
+ private Region getRegionStub() {
+ regionStub = mock(Region.class);
when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
+ return regionStub;
+ }
+ private Cache getCacheStub(Region region) {
Cache cacheStub = mock(Cache.class);
- when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub);
+ when(cacheStub.getRegion(TEST_REGION)).thenReturn(region);
return cacheStub;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
deleted file mode 100644
index 1ec7a02..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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 static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.RegionService;
-import org.apache.geode.protocol.OpsProcessor;
-import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.operations.ProtobufRequestOperationParser;
-import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.apache.geode.protocol.protobuf.RegionAPI;
-import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category(UnitTest.class)
-public class OpsProcessorTest {
- @Test
- public void testOpsProcessor() throws CodecNotRegisteredForTypeException,
- OperationHandlerNotRegisteredException, UnsupportedEncodingTypeException {
- OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class);
- OperationHandler operationHandlerStub = mock(OperationHandler.class);
- SerializationService serializationServiceStub = mock(SerializationService.class);
- Cache dummyCache = mock(Cache.class);
- int operationID = ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
-
- ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder()
- .setGetRequest(RegionAPI.GetRequest.newBuilder()).build();
-
- RegionAPI.GetResponse expectedResponse = RegionAPI.GetResponse.newBuilder().build();
-
- when(opsHandlerRegistryStub.getOperationHandlerForOperationId(operationID))
- .thenReturn(operationHandlerStub);
- when(operationHandlerStub.process(serializationServiceStub,
- ProtobufRequestOperationParser.getRequestForOperationTypeID(messageRequest), dummyCache))
- .thenReturn(expectedResponse);
-
- OpsProcessor processor = new OpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
- ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
- Assert.assertEquals(expectedResponse, response.getGetResponse());
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java
deleted file mode 100644
index 21c3107..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.protocol.handler;
-
-import org.apache.geode.client.protocol.MessageUtil;
-import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
-import org.apache.geode.protocol.handler.ProtocolHandler;
-import org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.apache.geode.test.junit.categories.UnitTest;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ServiceLoader;
-
-@Category(UnitTest.class)
-public class ProtobufProtocolHandlerJUnitTest {
- private ProtocolHandler<ClientProtocol.Message> 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 = 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/31f4de06/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
index 359db7d..cb98eb7 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
@@ -18,12 +18,12 @@ import com.google.protobuf.ByteString;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionService;
import org.apache.geode.protocol.protobuf.BasicTypes;
import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.protocol.protobuf.operations.GetRequestOperationHandler;
import org.apache.geode.serialization.SerializationService;
import org.apache.geode.serialization.codec.StringCodec;
-import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.SerializationCodecRegistry;
import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
new file mode 100644
index 0000000..9298026
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.protocol.protobuf;
+
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class ProtobufOpsProcessorTest {
+ @Test
+ public void testOpsProcessor() throws CodecNotRegisteredForTypeException,
+ OperationHandlerNotRegisteredException, UnsupportedEncodingTypeException,
+ InvalidProtocolMessageException {
+ OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class);
+ OperationHandler operationHandlerStub = mock(OperationHandler.class);
+ SerializationService serializationServiceStub = mock(SerializationService.class);
+ Cache dummyCache = mock(Cache.class);
+ int operationID = ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
+
+ ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder()
+ .setGetRequest(RegionAPI.GetRequest.newBuilder()).build();
+
+ RegionAPI.GetResponse expectedResponse = RegionAPI.GetResponse.newBuilder().build();
+
+ when(opsHandlerRegistryStub.getOperationHandlerForOperationId(operationID))
+ .thenReturn(operationHandlerStub);
+ when(operationHandlerStub.process(serializationServiceStub,
+ ProtobufOpsProcessor.getRequestForOperationTypeID(messageRequest), dummyCache))
+ .thenReturn(expectedResponse);
+
+ ProtobufOpsProcessor
+ processor = new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
+ ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
+ Assert.assertEquals(expectedResponse, response.getGetResponse());
+ }
+}
[08/13] geode git commit: GEODE-2995: Handle stream of ProtoBuf
encoded messages
Posted by hi...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
new file mode 100644
index 0000000..fa7c3c6
--- /dev/null
+++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.operations.OperationHandler
@@ -0,0 +1 @@
+org.apache.geode.protocol.operations.protobuf.GetRequestOperationHandler
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.serialization.TypeCodec
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.serialization.TypeCodec b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.serialization.TypeCodec
new file mode 100644
index 0000000..1b7b333
--- /dev/null
+++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.serialization.TypeCodec
@@ -0,0 +1,10 @@
+org.apache.geode.serialization.codec.BinaryCodec
+org.apache.geode.serialization.codec.BooleanCodec
+org.apache.geode.serialization.codec.ByteCodec
+org.apache.geode.serialization.codec.DoubleCodec
+org.apache.geode.serialization.codec.FloatCodec
+org.apache.geode.serialization.codec.IntCodec
+org.apache.geode.serialization.codec.JSONCodec
+org.apache.geode.serialization.codec.LongCodec
+org.apache.geode.serialization.codec.ShortCodec
+org.apache.geode.serialization.codec.StringCodec
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
new file mode 100644
index 0000000..e86e908
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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 com.google.protobuf.ByteString;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.handler.ProtobufStreamProcessor;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.codec.StringCodec;
+import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+@Category(UnitTest.class)
+public class IntegrationTest {
+
+ public static final String TEST_KEY = "my key";
+ public static final String TEST_VALUE = "my value";
+ public static final String TEST_REGION = "test region";
+ private StringCodec stringCodec;
+ private Cache cacheStub;
+
+ @Before
+ public void setup() throws CodecAlreadyRegisteredForTypeException,
+ UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+ stringCodec = (StringCodec) serializationCodecRegistry.getCodecForType(
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
+ cacheStub = getCacheStub();
+ }
+
+ @Test
+ public void testFullRequestToCache()
+ throws OperationHandlerAlreadyRegisteredException, CodecAlreadyRegisteredForTypeException,
+ UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException,
+ OperationHandlerNotRegisteredException, IOException, InvalidProtocolMessageException {
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ ProtobufStreamProcessor streamProcessor = new ProtobufStreamProcessor();
+ streamProcessor.processOneMessage(getInputStream(getRequest(stringCodec)), outputStream,
+ cacheStub);
+
+ RegionAPI.GetResponse getResponse = getGetResponse(outputStream);
+
+ Assert.assertNotNull(getResponse);
+ Assert.assertEquals(BasicTypes.EncodingType.STRING, getResponse.getResult().getEncodingType());
+ String actualValue = stringCodec.decode(getResponse.getResult().getValue().toByteArray());
+ Assert.assertEquals(TEST_VALUE, actualValue);
+ }
+
+ private Cache getCacheStub() {
+ Region regionStub = mock(Region.class);
+ when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
+
+ Cache cacheStub = mock(Cache.class);
+ when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub);
+ return cacheStub;
+ }
+
+ private RegionAPI.GetResponse getGetResponse(ByteArrayOutputStream outputStream)
+ throws IOException {
+ ByteArrayInputStream helperInputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ ClientProtocol.Message responseMessage =
+ ClientProtocol.Message.parseDelimitedFrom(helperInputStream);
+ ClientProtocol.Response response = responseMessage.getResponse();
+ return response.getGetResponse();
+ }
+
+ private ByteArrayInputStream getInputStream(ClientProtocol.Message request) throws IOException {
+ ByteArrayOutputStream helperOutputStream = new ByteArrayOutputStream();
+ request.writeDelimitedTo(helperOutputStream);
+ return new ByteArrayInputStream(helperOutputStream.toByteArray());
+ }
+
+ private ClientProtocol.Message getRequest(StringCodec stringCodec) {
+ RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
+ getRequestBuilder.setRegionName(TEST_REGION)
+ .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
+ .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
+ ClientProtocol.Request request =
+ ClientProtocol.Request.newBuilder().setGetRequest(getRequestBuilder).build();
+ ClientProtocol.Message requestMessage = ClientProtocol.Message.newBuilder()
+ .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setRequest(request).build();
+
+ return requestMessage;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/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..c830b01
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/MessageUtil.java
@@ -0,0 +1,41 @@
+/*
+ * 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/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java
new file mode 100644
index 0000000..793dace
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandler.java
@@ -0,0 +1,21 @@
+/*
+ * 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.serialization.registry.SerializationCodecRegistry;
+
+public interface OpsHandler<Req, Resp> {
+ Resp process(SerializationCodecRegistry serializationCodecRegistry, Req request);
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
new file mode 100644
index 0000000..1ec7a02
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.RegionService;
+import org.apache.geode.protocol.OpsProcessor;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.ProtobufRequestOperationParser;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class OpsProcessorTest {
+ @Test
+ public void testOpsProcessor() throws CodecNotRegisteredForTypeException,
+ OperationHandlerNotRegisteredException, UnsupportedEncodingTypeException {
+ OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class);
+ OperationHandler operationHandlerStub = mock(OperationHandler.class);
+ SerializationService serializationServiceStub = mock(SerializationService.class);
+ Cache dummyCache = mock(Cache.class);
+ int operationID = ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
+
+ ClientProtocol.Request messageRequest = ClientProtocol.Request.newBuilder()
+ .setGetRequest(RegionAPI.GetRequest.newBuilder()).build();
+
+ RegionAPI.GetResponse expectedResponse = RegionAPI.GetResponse.newBuilder().build();
+
+ when(opsHandlerRegistryStub.getOperationHandlerForOperationId(operationID))
+ .thenReturn(operationHandlerStub);
+ when(operationHandlerStub.process(serializationServiceStub,
+ ProtobufRequestOperationParser.getRequestForOperationTypeID(messageRequest), dummyCache))
+ .thenReturn(expectedResponse);
+
+ OpsProcessor processor = new OpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
+ ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
+ Assert.assertEquals(expectedResponse, response.getGetResponse());
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java
new file mode 100644
index 0000000..21c3107
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerJUnitTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.protocol.handler;
+
+import org.apache.geode.client.protocol.MessageUtil;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.handler.ProtocolHandler;
+import org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ServiceLoader;
+
+@Category(UnitTest.class)
+public class ProtobufProtocolHandlerJUnitTest {
+ private ProtocolHandler<ClientProtocol.Message> 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 = 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/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
new file mode 100644
index 0000000..359db7d
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandlerTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.protocol.operations.protobuf;
+
+import com.google.protobuf.ByteString;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionService;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.codec.StringCodec;
+import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.nio.charset.Charset;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@Category(UnitTest.class)
+public class GetRequestOperationHandlerTest {
+ public static final String TEST_KEY = "my key";
+ public static final String TEST_VALUE = "my value";
+ public static final String TEST_REGION = "test region";
+ public Cache cacheStub;
+ public SerializationService serializationServiceStub;
+
+ @Before
+ public void setUp() throws Exception {
+ serializationServiceStub = mock(SerializationService.class);
+ when(serializationServiceStub.decode(BasicTypes.EncodingType.STRING,
+ TEST_KEY.getBytes(Charset.forName("UTF-8")))).thenReturn(TEST_KEY);
+ when(serializationServiceStub.encode(BasicTypes.EncodingType.STRING, TEST_VALUE))
+ .thenReturn(TEST_VALUE.getBytes(Charset.forName("UTF-8")));
+
+ Region regionStub = mock(Region.class);
+ when(regionStub.get(TEST_KEY)).thenReturn(TEST_VALUE);
+
+ cacheStub = mock(Cache.class);
+ when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub);
+ }
+
+ @Test
+ public void processReturnsTheEncodedValueFromTheRegion() throws UnsupportedEncodingTypeException,
+ CodecNotRegisteredForTypeException, CodecAlreadyRegisteredForTypeException {
+ GetRequestOperationHandler operationHandler = new GetRequestOperationHandler();
+
+ RegionAPI.GetResponse response =
+ operationHandler.process(serializationServiceStub, makeGetRequest(), cacheStub);
+
+ Assert.assertEquals(BasicTypes.EncodingType.STRING, response.getResult().getEncodingType());
+ String actualValue = getStringCodec().decode(response.getResult().getValue().toByteArray());
+ Assert.assertEquals(TEST_VALUE, actualValue);
+ }
+
+ private RegionAPI.GetRequest makeGetRequest() throws CodecNotRegisteredForTypeException,
+ UnsupportedEncodingTypeException, CodecAlreadyRegisteredForTypeException {
+ StringCodec stringCodec = getStringCodec();
+ RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
+ getRequestBuilder.setRegionName(TEST_REGION)
+ .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
+ .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
+
+ return getRequestBuilder.build();
+ }
+
+ private StringCodec getStringCodec() throws CodecAlreadyRegisteredForTypeException,
+ CodecNotRegisteredForTypeException, UnsupportedEncodingTypeException {
+ SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+ return (StringCodec) serializationCodecRegistry.getCodecForType(
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java
new file mode 100644
index 0000000..612e6a7
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistryJUnitTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.protocol.operations.registry;
+
+import static io.codearte.catchexception.shade.mockito.Mockito.mock;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class OperationsHandlerRegistryJUnitTest {
+ public static final int DUMMY_OPERATION_CODE = 999;
+ private OperationsHandlerRegistry operationsHandlerRegistry;
+
+ @Before
+ public void setup() throws OperationHandlerAlreadyRegisteredException {
+ operationsHandlerRegistry = new OperationsHandlerRegistry();
+ }
+
+ @Test
+ public void testAddOperationsHandlerForOperationType()
+ throws OperationHandlerAlreadyRegisteredException {
+ int initialHandlerCount = operationsHandlerRegistry.getRegisteredOperationHandlersCount();
+ operationsHandlerRegistry.registerOperationHandlerForOperationId(DUMMY_OPERATION_CODE,
+ mock(OperationHandler.class));
+ assertEquals(initialHandlerCount + 1,
+ operationsHandlerRegistry.getRegisteredOperationHandlersCount());
+ }
+
+ @Test
+ public void testAddingDuplicateOperationsHandlerForOperationType_ThrowsException()
+ throws OperationHandlerAlreadyRegisteredException, OperationHandlerNotRegisteredException {
+ OperationHandler expectedOperationHandler = mock(OperationHandler.class);
+ OperationHandler unexpectedOperationHandler = mock(OperationHandler.class);
+ operationsHandlerRegistry.registerOperationHandlerForOperationId(DUMMY_OPERATION_CODE,
+ expectedOperationHandler);
+ int initialHandlerCount = operationsHandlerRegistry.getRegisteredOperationHandlersCount();
+ boolean exceptionCaught = false;
+ try {
+ operationsHandlerRegistry.registerOperationHandlerForOperationId(DUMMY_OPERATION_CODE,
+ unexpectedOperationHandler);
+ } catch (OperationHandlerAlreadyRegisteredException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ assertEquals(initialHandlerCount,
+ operationsHandlerRegistry.getRegisteredOperationHandlersCount());
+ assertSame(expectedOperationHandler,
+ operationsHandlerRegistry.getOperationHandlerForOperationId(DUMMY_OPERATION_CODE));
+ }
+
+ @Test
+ public void testGetOperationsHandlerForOperationType()
+ throws OperationHandlerAlreadyRegisteredException, OperationHandlerNotRegisteredException {
+ OperationHandler expectedOperationHandler = mock(OperationHandler.class);
+
+ operationsHandlerRegistry.registerOperationHandlerForOperationId(DUMMY_OPERATION_CODE,
+ expectedOperationHandler);
+ OperationHandler operationHandler =
+ operationsHandlerRegistry.getOperationHandlerForOperationId(DUMMY_OPERATION_CODE);
+ assertSame(expectedOperationHandler, operationHandler);
+ }
+
+ @Test
+ public void testGetOperationsHandlerForMissingOperationType_ThrowsException() {
+ boolean exceptionCaught = false;
+ try {
+ operationsHandlerRegistry.getOperationHandlerForOperationId(DUMMY_OPERATION_CODE);
+ } catch (OperationHandlerNotRegisteredException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
new file mode 100644
index 0000000..a4c0a14
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.serialization;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class ProtobufSerializationServiceImplTest {
+
+ public static final String PAYLOAD = "my value";
+
+ @Test
+ public void valuesPreservedByEncodingThenDecoding() throws CodecAlreadyRegisteredForTypeException,
+ UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ ProtobufSerializationService protobufSerializationService = new ProtobufSerializationService();
+
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.STRING, "testString");
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.FLOAT, (float) 34.23);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.DOUBLE, 34.23);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.INT, 45);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.SHORT, (short) 45);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BYTE, (byte) 45);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.LONG, (long) 45);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BOOLEAN, false);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BOOLEAN, true);
+ testEncodeDecode(protobufSerializationService, BasicTypes.EncodingType.BINARY,
+ "testString".getBytes());
+ // TODO: Test JSON conversion
+ }
+
+ private void testEncodeDecode(ProtobufSerializationService service,
+ BasicTypes.EncodingType encodingType, Object data)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ byte[] encodedValue = service.encode(encodingType, data);
+ Object decdoedValue = service.decode(encodingType, encodedValue);
+ Assert.assertEquals(data, decdoedValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java
new file mode 100644
index 0000000..8cd6029
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/codec/StringCodecJUnitTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.serialization.codec;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.nio.charset.Charset;
+
+@Category(UnitTest.class)
+public class StringCodecJUnitTest {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
+ private static final Charset UTF16 = Charset.forName("UTF-16");
+ private String testString = "Test String";
+
+ private StringCodec stringCodec;
+
+ @Before
+ public void startup() {
+ stringCodec = new StringCodec();
+ }
+
+ @Test
+ public void testStringEncoding() {
+ assertArrayEquals(testString.getBytes(UTF8), stringCodec.encode(testString));
+ }
+
+ @Test
+ public void testStringIncompatibleEncoding() {
+ byte[] expectedEncodedString = stringCodec.encode(testString);
+ byte[] incorrectEncodedString = testString.getBytes(UTF16);
+ assertNotEquals(expectedEncodedString.length, incorrectEncodedString.length);
+ }
+
+ @Test
+ public void testStringDecodingWithIncorrectEncodedString() {
+ byte[] encodedString = testString.getBytes(UTF16);
+ assertNotEquals(testString, stringCodec.decode(encodedString));
+ }
+
+ @Test
+ public void testStringDecoding() {
+ byte[] encodedString = testString.getBytes(UTF8);
+ assertEquals(testString, stringCodec.decode(encodedString));
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
new file mode 100644
index 0000000..1af710c
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.serialization.protobuf.translation;
+
+import static org.junit.Assert.assertSame;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class EncodingTypeToSerializationTypeTranslatorJUnitTest {
+
+ @Test
+ public void testTranslateEncodingTypes() throws UnsupportedEncodingTypeException {
+ assertSame(SerializationType.INT,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INT));
+ assertSame(SerializationType.LONG,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.LONG));
+ assertSame(SerializationType.SHORT,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.SHORT));
+ assertSame(SerializationType.BYTE,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BYTE));
+ assertSame(SerializationType.BOOLEAN, EncodingTypeTranslator
+ .getSerializationTypeForEncodingType(BasicTypes.EncodingType.BOOLEAN));
+ assertSame(SerializationType.BINARY,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.BINARY));
+ assertSame(SerializationType.FLOAT,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.FLOAT));
+ assertSame(SerializationType.DOUBLE,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.DOUBLE));
+ assertSame(SerializationType.STRING,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.STRING));
+ assertSame(SerializationType.JSON,
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.JSON));
+ }
+
+ @Test(expected = UnsupportedEncodingTypeException.class)
+ public void testTranslateInvalidEncoding_throwsException()
+ throws UnsupportedEncodingTypeException {
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INVALID);
+ }
+
+ @Test
+ public void testAllEncodingTypeTranslations() {
+ for (BasicTypes.EncodingType encodingType : BasicTypes.EncodingType.values()) {
+ if (!(encodingType.equals(BasicTypes.EncodingType.UNRECOGNIZED)
+ || encodingType.equals(BasicTypes.EncodingType.INVALID))) {
+ try {
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingType);
+ } catch (UnsupportedEncodingTypeException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
new file mode 100644
index 0000000..2c37fb5
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.serialization.registry;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@Category(UnitTest.class)
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("*.UnitTest")
+@PrepareForTest({SerializationType.class})
+public class CodecRegistryJUnitTest {
+ private SerializationCodecRegistry codecRegistry;
+
+ @Before
+ public void startup() throws CodecAlreadyRegisteredForTypeException {
+ codecRegistry = new SerializationCodecRegistry();
+ }
+
+ @After
+ public void tearDown() {
+ codecRegistry.shutdown();
+ }
+
+ @Test
+ public void testRegisterCodec() throws CodecAlreadyRegisteredForTypeException {
+ Assert.assertEquals(10, codecRegistry.getRegisteredCodecCount());
+ SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+ codecRegistry.register(mockSerializationType, new DummyTypeCodec());
+ Assert.assertEquals(11, codecRegistry.getRegisteredCodecCount());
+ }
+
+ @Test
+ public void testRegisteringCodecForRegisteredType_throwsException()
+ throws CodecAlreadyRegisteredForTypeException {
+ SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+ codecRegistry.register(mockSerializationType, new DummyTypeCodec());
+
+ boolean caughtException = false;
+ try {
+ codecRegistry.register(mockSerializationType, new DummyTypeCodec());
+ } catch (CodecAlreadyRegisteredForTypeException e) {
+ caughtException = true;
+ }
+ Assert.assertTrue("This was supposed to have thrown a CodecAlreadyRegisteredException",
+ caughtException);
+ }
+
+ @Test
+ public void testGetRegisteredCodec()
+ throws CodecAlreadyRegisteredForTypeException, CodecNotRegisteredForTypeException {
+ TypeCodec expectedCodec = new DummyTypeCodec();
+ SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+ codecRegistry.register(mockSerializationType, expectedCodec);
+ TypeCodec codec = codecRegistry.getCodecForType(mockSerializationType);
+ Assert.assertSame(expectedCodec, codec);
+ }
+
+ @Test
+ public void testGetCodecForUnregisteredType_throwsException() {
+ boolean caughtException = false;
+ try {
+ SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+ codecRegistry.getCodecForType(mockSerializationType);
+ } catch (CodecNotRegisteredForTypeException e) {
+ caughtException = true;
+ }
+ Assert.assertTrue("This should have thrown a CodecNotRegisteredForTypeException",
+ caughtException);
+ }
+
+ class DummyTypeCodec implements TypeCodec {
+ @Override
+ public Object decode(byte[] incoming) {
+ return null;
+ }
+
+ @Override
+ public byte[] encode(Object incoming) {
+ return new byte[0];
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return PowerMockito.mock(SerializationType.class);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/gradle/rat.gradle
----------------------------------------------------------------------
diff --git a/gradle/rat.gradle b/gradle/rat.gradle
index 1bea584..a1582b9 100644
--- a/gradle/rat.gradle
+++ b/gradle/rat.gradle
@@ -113,11 +113,7 @@ rat {
'geode-core/src/test/resources/org/apache/geode/management/internal/configuration/domain/CacheElementJUnitTest.xml',
'geode-core/src/test/resources/org/apache/geode/management/internal/configuration/utils/*.xml',
- '**/META-INF/services/org.xml.sax.ext.EntityResolver2',
- '**/META-INF/services/org.apache.geode.internal.cache.CacheService',
- '**/META-INF/services/org.apache.geode.internal.cache.xmlcache.XmlParser',
- '**/META-INF/services/org.apache.geode.distributed.ServerLauncherCacheProvider',
- '**/META-INF/services/org.springframework.shell.core.CommandMarker',
+ '**/META-INF/**',
// --- Other Licenses ---
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/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)
}
+
+
[10/13] geode git commit: Add ServiceLoadingFailureException to
excludedClasses.txt so tests pass.
Posted by hi...@apache.org.
Add ServiceLoadingFailureException to excludedClasses.txt so tests pass.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/da64fc6f
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/da64fc6f
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/da64fc6f
Branch: refs/heads/develop
Commit: da64fc6fbccc6a148ac7bd488593881c90b092d8
Parents: db11ebc
Author: Brian Rowe <br...@pivotal.io>
Authored: Thu Jun 22 23:27:22 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:23 2017 -0700
----------------------------------------------------------------------
.../resources/org/apache/geode/codeAnalysis/excludedClasses.txt | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/da64fc6f/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
index 6a6e0c1..c2629f1 100644
--- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
+++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
@@ -7,6 +7,7 @@ org/apache/geode/distributed/LocatorLauncher$Command
org/apache/geode/distributed/ServerLauncher
org/apache/geode/distributed/ServerLauncher$Command
org/apache/geode/distributed/internal/DistributionManager
+org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException
org/apache/geode/internal/JarDeployer
org/apache/geode/internal/logging/GemFireLevel
org/apache/geode/internal/logging/LoggingThreadGroup
[12/13] geode git commit: GEODE-3075: fix an integration test.
Posted by hi...@apache.org.
GEODE-3075: fix an integration test.
I think the test fails because another test doesn't clean up system
properties when it's done.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/e62e8250
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/e62e8250
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/e62e8250
Branch: refs/heads/develop
Commit: e62e825090db50f77faaa3e222595ee1026d7a6c
Parents: a3c66e1
Author: Galen OSullivan <go...@pivotal.io>
Authored: Wed Jun 21 14:01:01 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:23 2017 -0700
----------------------------------------------------------------------
.../cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/e62e8250/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
index 82c4e54..9a1509f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
@@ -46,7 +46,9 @@ public class ServerConnectionFactoryIntegrationTest {
@Test
public void testNewProtocolHeaderLeadsToNewProtocolServerConnection() throws IOException {
System.setProperty("geode.feature-protobuf-protocol", "true");
+
CacheFactory cacheFactory = new CacheFactory();
+ cacheFactory.set("mcast-port","0"); //sometimes it isn't due to other tests.
Cache cache = cacheFactory.create();
CacheServer cacheServer = cache.addCacheServer();
[11/13] geode git commit: merge GEODE-2995,
GEODE-3775 into develop with integration test.
Posted by hi...@apache.org.
merge GEODE-2995, GEODE-3775 into develop with integration test.
Signed-off-by: Brian Rowe <br...@pivotal.io>
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/db11ebc1
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/db11ebc1
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/db11ebc1
Branch: refs/heads/develop
Commit: db11ebc1efdf2371bdf1566a7828dc08ea621e2c
Parents: e62e825
Author: Galen OSullivan <go...@pivotal.io>
Authored: Wed Jun 21 16:53:03 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:23 2017 -0700
----------------------------------------------------------------------
.../sockets/ClientProtocolMessageHandler.java | 18 +--
.../tier/sockets/ServerConnectionFactory.java | 39 +++++-
.../sockets/ServiceLoadingFailureException.java | 35 ++++++
.../ServerConnectionFactoryIntegrationTest.java | 67 ----------
.../sockets/ServerConnectionFactoryTest.java | 43 ++++++-
.../protobuf/ProtobufStreamProcessor.java | 15 ++-
...he.tier.sockets.ClientProtocolMessageHandler | 1 +
.../RoundTripCacheConnectionJUnitTest.java | 123 +++++++++++++++++++
8 files changed, 256 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
index 702609d..32e9e4b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
@@ -22,14 +22,14 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
- * Stub, this will be hooked up to the new client protocol when it's implemented.
+ * This is an interface that other modules can implement to hook into
+ * {@link GenericProtocolServerConnection} to handle messages sent to Geode.
+ *
+ * Currently, only one {@link ClientProtocolMessageHandler} at a time can be used in a Geode
+ * instance. It gets wired into {@link ServerConnectionFactory} to create all instances of
+ * {@link GenericProtocolServerConnection}.
*/
-public class ClientProtocolMessageHandler {
- /**
- * Bogus, but it lets us write an integration test so that nobody breaks our flow.
- */
- public void receiveMessage(InputStream inputStream, OutputStream outputStream,
- InternalCache cache) throws IOException {
- outputStream.write(inputStream.read());
- }
+public interface ClientProtocolMessageHandler {
+ void receiveMessage(InputStream inputStream, OutputStream outputStream, InternalCache cache)
+ throws IOException;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
index e4746a7..ad13b78 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
@@ -22,14 +22,46 @@ import org.apache.geode.internal.security.SecurityService;
import java.io.IOException;
import java.net.Socket;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+import javax.management.ServiceNotFoundException;
/**
* Creates instances of ServerConnection based on the connection mode provided.
*/
public class ServerConnectionFactory {
- // TODO: implement ClientProtocolMessageHandler.
- private static final ClientProtocolMessageHandler protobufProtocolHandler =
- new ClientProtocolMessageHandler();
+ private static ClientProtocolMessageHandler protobufProtocolHandler;
+ private static final Object protocolLoadLock = new Object();
+
+ private static ClientProtocolMessageHandler findClientProtocolMessageHandler() {
+ if (protobufProtocolHandler != null) {
+ return protobufProtocolHandler;
+ }
+
+ synchronized (protocolLoadLock) {
+ if (protobufProtocolHandler != null) {
+ return protobufProtocolHandler;
+ }
+
+ ServiceLoader<ClientProtocolMessageHandler> loader =
+ ServiceLoader.load(ClientProtocolMessageHandler.class);
+ Iterator<ClientProtocolMessageHandler> iterator = loader.iterator();
+
+ if (!iterator.hasNext()) {
+ throw new ServiceLoadingFailureException(
+ "ClientProtocolMessageHandler implementation not found in JVM");
+ }
+
+ ClientProtocolMessageHandler returnValue = iterator.next();
+
+ if (iterator.hasNext()) {
+ throw new ServiceLoadingFailureException(
+ "Multiple service implementations found for ClientProtocolMessageHandler");
+ }
+
+ return returnValue;
+ }
+ }
public static ServerConnection makeServerConnection(Socket s, InternalCache c,
CachedRegionHelper helper, CacheServerStats stats, int hsTimeout, int socketBufferSize,
@@ -39,6 +71,7 @@ public class ServerConnectionFactory {
if (!Boolean.getBoolean("geode.feature-protobuf-protocol")) {
throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
} else {
+ protobufProtocolHandler = findClientProtocolMessageHandler();
return new GenericProtocolServerConnection(s, c, helper, stats, hsTimeout, socketBufferSize,
communicationModeStr, communicationMode, acceptor, protobufProtocolHandler,
securityService);
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException.java
new file mode 100644
index 0000000..be39672
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.GemFireException;
+
+/**
+ * Indicates that an error has happened loading a necessary service.
+ */
+public class ServiceLoadingFailureException extends GemFireException {
+ public ServiceLoadingFailureException(String message) {
+ super(message);
+ }
+
+ public ServiceLoadingFailureException(Exception cause) {
+ super(cause);
+ }
+
+ public ServiceLoadingFailureException(String message, Exception cause) {
+ super(message, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
deleted file mode 100644
index 9a1509f..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.internal.cache.tier.sockets;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.cache.tier.Acceptor;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-import org.awaitility.Awaitility;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.contrib.java.lang.system.RestoreSystemProperties;
-import org.junit.experimental.categories.Category;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Test that switching on the header byte makes instances of
- * {@link GenericProtocolServerConnection}.
- */
-@Category(IntegrationTest.class)
-public class ServerConnectionFactoryIntegrationTest {
-
- @Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
-
- @Test
- public void testNewProtocolHeaderLeadsToNewProtocolServerConnection() throws IOException {
- System.setProperty("geode.feature-protobuf-protocol", "true");
-
- CacheFactory cacheFactory = new CacheFactory();
- cacheFactory.set("mcast-port","0"); //sometimes it isn't due to other tests.
- Cache cache = cacheFactory.create();
-
- CacheServer cacheServer = cache.addCacheServer();
- final int cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
- cacheServer.setPort(cacheServerPort);
- cacheServer.start();
-
- Socket socket = new Socket("localhost", cacheServerPort);
- Awaitility.await().atMost(5, TimeUnit.SECONDS).until(socket::isConnected);
- socket.getOutputStream().write(Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
- socket.getOutputStream().write(222);
- assertEquals(222, socket.getInputStream().read());
-
- cache.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
index 11b5289..4e994cd 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
@@ -31,6 +31,14 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+/**
+ * We don't test the path where the service providing protobufProtocolHandler is actually present,
+ * because it lives outside this module, and all the integration tests from that module will test
+ * the newclient protocol happy path.
+ *
+ * What we are concerned with is making sure that everything stays the same when the feature flag
+ * isn't set, and that we at least try to load the service when the feature flag is true.
+ */
@Category(UnitTest.class)
public class ServerConnectionFactoryTest {
/**
@@ -38,17 +46,22 @@ public class ServerConnectionFactoryTest {
* enabled.
*/
@Test(expected = IOException.class)
- public void newClientProtocolThrows() throws Exception {
- serverConnectionMockedExceptForCommunicationMode(Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
+ public void newClientProtocolFailsWithoutSystemPropertySet() throws Exception {
+ ServerConnection serverConnection =
+ serverConnectionMockedExceptForCommunicationMode(Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
+
}
- @Test
- public void newClientProtocolSucceedsWithSystemPropertySet() throws Exception {
+ /**
+ * @throws ServiceLoadingFailureException because the service is implemented in a different
+ * module, and when this unit test is run, that module won't be present.
+ */
+ @Test(expected = ServiceLoadingFailureException.class)
+ public void newClientProtocolFailsWithSystemPropertySet() throws Exception {
try {
System.setProperty("geode.feature-protobuf-protocol", "true");
ServerConnection serverConnection = serverConnectionMockedExceptForCommunicationMode(
Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
- assertTrue(serverConnection instanceof GenericProtocolServerConnection);
} finally {
System.clearProperty("geode.feature-protobuf-protocol");
}
@@ -69,6 +82,26 @@ public class ServerConnectionFactoryTest {
}
}
+ @Test
+ public void makeServerConnectionForOldProtocolWithFeatureFlagEnabled() throws IOException {
+ System.setProperty("geode.feature-protobuf-protocol", "true");
+ try {
+ byte[] communicationModes =
+ new byte[] {Acceptor.CLIENT_TO_SERVER, Acceptor.PRIMARY_SERVER_TO_CLIENT,
+ Acceptor.SECONDARY_SERVER_TO_CLIENT, Acceptor.GATEWAY_TO_GATEWAY,
+ Acceptor.MONITOR_TO_SERVER, Acceptor.SUCCESSFUL_SERVER_TO_CLIENT,
+ Acceptor.UNSUCCESSFUL_SERVER_TO_CLIENT, Acceptor.CLIENT_TO_SERVER_FOR_QUEUE,};
+
+ for (byte communicationMode : communicationModes) {
+ ServerConnection serverConnection =
+ serverConnectionMockedExceptForCommunicationMode(communicationMode);
+ assertTrue(serverConnection instanceof LegacyServerConnection);
+ }
+ } finally {
+ System.clearProperty("geode.feature-protobuf-protocol");
+ }
+ }
+
private static ServerConnection serverConnectionMockedExceptForCommunicationMode(
byte communicationMode) throws IOException {
Socket socketMock = mock(Socket.class);
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
index 1dcb61c..d7b5d4b 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
@@ -15,6 +15,8 @@
package org.apache.geode.protocol.protobuf;
import org.apache.geode.cache.Cache;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.tier.sockets.ClientProtocolMessageHandler;
import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
@@ -34,7 +36,7 @@ import java.io.OutputStream;
* messages, hands the requests to an appropriate handler, wraps the response in a protobuf message,
* and then pushes it to the output stream.
*/
-public class ProtobufStreamProcessor {
+public class ProtobufStreamProcessor implements ClientProtocolMessageHandler {
ProtobufProtocolSerializer protobufProtocolSerializer;
OperationsHandlerRegistry registry;
ProtobufSerializationService protobufSerializationService;
@@ -60,4 +62,15 @@ public class ProtobufStreamProcessor {
ProtobufUtilities.wrapResponseWithDefaultHeader(response);
protobufProtocolSerializer.serialize(responseMessage, outputStream);
}
+
+ @Override
+ public void receiveMessage(InputStream inputStream, OutputStream outputStream,
+ InternalCache cache) throws IOException {
+ try {
+ processOneMessage(inputStream, outputStream, cache);
+ } catch (InvalidProtocolMessageException | OperationHandlerNotRegisteredException
+ | TypeEncodingException e) {
+ throw new IOException(e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.internal.cache.tier.sockets.ClientProtocolMessageHandler
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.internal.cache.tier.sockets.ClientProtocolMessageHandler b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.internal.cache.tier.sockets.ClientProtocolMessageHandler
new file mode 100644
index 0000000..5a17eda
--- /dev/null
+++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.internal.cache.tier.sockets.ClientProtocolMessageHandler
@@ -0,0 +1 @@
+org.apache.geode.protocol.protobuf.ProtobufStreamProcessor
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode/blob/db11ebc1/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
new file mode 100644
index 0000000..b9faca3
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.protocol;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.protobuf.ByteString;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.internal.cache.tier.sockets.GenericProtocolServerConnection;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.ProtobufSerializationService;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
+import org.apache.geode.serialization.codec.StringCodec;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.awaitility.Awaitility;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Test that switching on the header byte makes instances of
+ * {@link GenericProtocolServerConnection}.
+ */
+@Category(IntegrationTest.class)
+public class RoundTripCacheConnectionJUnitTest {
+ public static final String TEST_KEY = "testKey";
+ public static final String TEST_VALUE = "testValue";
+ public static final String TEST_REGION = "testRegion";
+
+ private Cache cache;
+ private int cacheServerPort;
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Before
+ public void setup() throws IOException {
+ CacheFactory cacheFactory = new CacheFactory();
+ cacheFactory.set("mcast-port", "0"); // sometimes it isn't due to other tests.
+ cache = cacheFactory.create();
+
+ CacheServer cacheServer = cache.addCacheServer();
+ cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
+ cacheServer.setPort(cacheServerPort);
+ cacheServer.start();
+
+ RegionFactory<Object, Object> regionFactory = cache.createRegionFactory();
+ Region<Object, Object> testRegion = regionFactory.create(TEST_REGION);
+ testRegion.put(TEST_KEY, TEST_VALUE);
+ }
+
+ @After
+ public void cleanup() {
+ cache.close();
+ }
+
+ @Test
+ public void testNewProtocolHeaderLeadsToNewProtocolServerConnection() throws Exception {
+ System.setProperty("geode.feature-protobuf-protocol", "true");
+
+ Socket socket = new Socket("localhost", cacheServerPort);
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(socket::isConnected);
+ OutputStream outputStream = socket.getOutputStream();
+ outputStream.write(110);
+
+ ProtobufProtocolSerializer protobufProtocolSerializer = new ProtobufProtocolSerializer();
+ protobufProtocolSerializer.serialize(makeTestGetRequest(new StringCodec()), outputStream);
+
+ ClientProtocol.Message message =
+ protobufProtocolSerializer.deserialize(socket.getInputStream());
+ assertEquals(ClientProtocol.Message.MessageTypeCase.RESPONSE, message.getMessageTypeCase());
+ ClientProtocol.Response response = message.getResponse();
+ assertEquals(ClientProtocol.Response.ResponseAPICase.GETRESPONSE,
+ response.getResponseAPICase());
+ RegionAPI.GetResponse getResponse = response.getGetResponse();
+ BasicTypes.EncodedValue result = getResponse.getResult();
+ assertEquals(BasicTypes.EncodingType.STRING, result.getEncodingType());
+ assertEquals(TEST_VALUE, new ProtobufSerializationService().decode(result.getEncodingType(),
+ result.getValue().toByteArray()));
+ }
+
+ private ClientProtocol.Message makeTestGetRequest(StringCodec stringCodec) {
+ RegionAPI.GetRequest.Builder getRequestBuilder = RegionAPI.GetRequest.newBuilder();
+ getRequestBuilder.setRegionName(TEST_REGION)
+ .setKey(BasicTypes.EncodedValue.newBuilder().setEncodingType(BasicTypes.EncodingType.STRING)
+ .setValue(ByteString.copyFrom(stringCodec.encode(TEST_KEY))));
+ ClientProtocol.Request request =
+ ClientProtocol.Request.newBuilder().setGetRequest(getRequestBuilder).build();
+ ClientProtocol.Message requestMessage = ClientProtocol.Message.newBuilder()
+ .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setRequest(request).build();
+
+ return requestMessage;
+ }
+}
[09/13] geode git commit: GEODE-2995: Handle stream of ProtoBuf
encoded messages
Posted by hi...@apache.org.
GEODE-2995: Handle stream of ProtoBuf encoded messages
This for now exists in isolation, but will be hooked up with the code currently in review for GEODE-3075
Signed-off-by: Alexander Murmann <am...@pivotal.io>
Signed-off-by: Brian Rowe <br...@pivotal.io>
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/cdcc4d95
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/cdcc4d95
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/cdcc4d95
Branch: refs/heads/develop
Commit: cdcc4d95634ae6377c0198cadba92f52cd436be0
Parents: 4ace36a
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Mon Jun 12 15:12:18 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
geode-protobuf/build.gradle | 64 ++++++++++
.../org/apache/geode/ProtobufUtilities.java | 34 ++++++
.../org/apache/geode/protocol/OpsProcessor.java | 53 ++++++++
.../InvalidProtocolMessageException.java | 25 ++++
.../handler/ProtobufStreamProcessor.java | 61 ++++++++++
.../geode/protocol/handler/ProtocolHandler.java | 27 +++++
.../protobuf/ProtobufProtocolHandler.java | 41 +++++++
.../protocol/operations/OperationHandler.java | 27 +++++
.../ProtobufRequestOperationParser.java | 33 +++++
.../protobuf/GetRequestOperationHandler.java | 59 +++++++++
.../registry/OperationsHandlerRegistry.java | 57 +++++++++
...rationHandlerAlreadyRegisteredException.java | 21 ++++
.../OperationHandlerNotRegisteredException.java | 21 ++++
.../ProtobufSerializationService.java | 50 ++++++++
.../serialization/SerializationService.java | 27 +++++
.../geode/serialization/SerializationType.java | 36 ++++++
.../apache/geode/serialization/TypeCodec.java | 23 ++++
.../geode/serialization/codec/BinaryCodec.java | 35 ++++++
.../geode/serialization/codec/BooleanCodec.java | 37 ++++++
.../geode/serialization/codec/ByteCodec.java | 37 ++++++
.../geode/serialization/codec/DoubleCodec.java | 37 ++++++
.../geode/serialization/codec/FloatCodec.java | 37 ++++++
.../geode/serialization/codec/IntCodec.java | 38 ++++++
.../geode/serialization/codec/JSONCodec.java | 37 ++++++
.../geode/serialization/codec/LongCodec.java | 37 ++++++
.../geode/serialization/codec/ShortCodec.java | 37 ++++++
.../geode/serialization/codec/StringCodec.java | 39 ++++++
.../UnsupportedEncodingTypeException.java | 21 ++++
.../translation/EncodingTypeTranslator.java | 83 +++++++++++++
.../UnsupportedEncodingTypeException.java | 21 ++++
.../registry/SerializationCodecRegistry.java | 61 ++++++++++
.../CodecAlreadyRegisteredForTypeException.java | 21 ++++
.../CodecNotRegisteredForTypeException.java | 21 ++++
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 ++++++
...pache.geode.protocol.handler.ProtocolHandler | 1 +
...e.geode.protocol.operations.OperationHandler | 1 +
.../org.apache.geode.serialization.TypeCodec | 10 ++
.../geode/client/protocol/IntegrationTest.java | 121 +++++++++++++++++++
.../geode/client/protocol/MessageUtil.java | 41 +++++++
.../geode/client/protocol/OpsHandler.java | 21 ++++
.../geode/client/protocol/OpsProcessorTest.java | 64 ++++++++++
.../ProtobufProtocolHandlerJUnitTest.java | 88 ++++++++++++++
.../GetRequestOperationHandlerTest.java | 95 +++++++++++++++
.../OperationsHandlerRegistryJUnitTest.java | 94 ++++++++++++++
.../ProtobufSerializationServiceImplTest.java | 57 +++++++++
.../codec/StringCodecJUnitTest.java | 64 ++++++++++
...eToSerializationTypeTranslatorJUnitTest.java | 72 +++++++++++
.../registry/CodecRegistryJUnitTest.java | 113 +++++++++++++++++
gradle/rat.gradle | 6 +-
settings.gradle | 4 +-
53 files changed, 2394 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/build.gradle
----------------------------------------------------------------------
diff --git a/geode-protobuf/build.gradle b/geode-protobuf/build.gradle
new file mode 100644
index 0000000..2102f6a
--- /dev/null
+++ b/geode-protobuf/build.gradle
@@ -0,0 +1,64 @@
+/*
+ * 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)
+
+ testCompile 'org.powermock:powermock-core:' + project.'powermock.version'
+ testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version'
+ testCompile 'org.powermock:powermock-api-mockito:' + project.'powermock.version'
+
+ 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/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java b/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java
new file mode 100644
index 0000000..c25fc14
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/ProtobufUtilities.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import com.google.protobuf.ByteString;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+
+public abstract class ProtobufUtilities {
+ public static BasicTypes.EncodedValue getEncodedValue(BasicTypes.EncodingType resultEncodingType,
+ byte[] resultEncodedValue) {
+ return BasicTypes.EncodedValue.newBuilder().setEncodingType(resultEncodingType)
+ .setValue(ByteString.copyFrom(resultEncodedValue)).build();
+ }
+
+ public static ClientProtocol.Message wrapResponseWithDefaultHeader(
+ ClientProtocol.Response response) {
+ return ClientProtocol.Message.newBuilder()
+ .setMessageHeader(ClientProtocol.MessageHeader.newBuilder()).setResponse(response).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java
new file mode 100644
index 0000000..999fdf0
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/OpsProcessor.java
@@ -0,0 +1,53 @@
+/*
+ * 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.protocol;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.ProtobufRequestOperationParser;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public class OpsProcessor {
+ private final OperationsHandlerRegistry opsHandlerRegistry;
+ private final SerializationService serializationService;
+
+ public OpsProcessor(OperationsHandlerRegistry opsHandlerRegistry,
+ SerializationService serializationService) {
+ this.opsHandlerRegistry = opsHandlerRegistry;
+ this.serializationService = serializationService;
+ }
+
+ public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ OperationHandler opsHandler = null;
+ try {
+ opsHandler = opsHandlerRegistry
+ .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber());
+ } catch (OperationHandlerNotRegisteredException e) {
+ e.printStackTrace();
+ }
+
+ Object responseMessage = opsHandler.process(serializationService,
+ ProtobufRequestOperationParser.getRequestForOperationTypeID(request), cache);
+ return ClientProtocol.Response.newBuilder()
+ .setGetResponse((RegionAPI.GetResponse) responseMessage).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
new file mode 100644
index 0000000..8f73f57
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/exception/InvalidProtocolMessageException.java
@@ -0,0 +1,25 @@
+/*
+ * 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.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/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java
new file mode 100644
index 0000000..e459f76
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtobufStreamProcessor.java
@@ -0,0 +1,61 @@
+/*
+ * 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.protocol.handler;
+
+import org.apache.geode.ProtobufUtilities;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.OpsProcessor;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.serialization.ProtobufSerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ProtobufStreamProcessor {
+ ProtobufProtocolHandler protobufProtocolHandler;
+ OperationsHandlerRegistry registry;
+ ProtobufSerializationService protobufSerializationService;
+ OpsProcessor opsProcessor;
+
+ public ProtobufStreamProcessor()
+ throws OperationHandlerAlreadyRegisteredException, CodecAlreadyRegisteredForTypeException {
+ protobufProtocolHandler = new ProtobufProtocolHandler();
+ registry = new OperationsHandlerRegistry();
+ protobufSerializationService = new ProtobufSerializationService();
+ opsProcessor = new OpsProcessor(registry, protobufSerializationService);
+ }
+
+ public void processOneMessage(InputStream inputStream, OutputStream outputStream, Cache cache)
+ throws InvalidProtocolMessageException, OperationHandlerNotRegisteredException,
+ UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException, IOException {
+ ClientProtocol.Message message = protobufProtocolHandler.deserialize(inputStream);
+
+ ClientProtocol.Request request = message.getRequest();
+ ClientProtocol.Response response = opsProcessor.process(request, cache);
+
+ ClientProtocol.Message responseMessage =
+ ProtobufUtilities.wrapResponseWithDefaultHeader(response);
+ protobufProtocolHandler.serialize(responseMessage, outputStream);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.java
new file mode 100644
index 0000000..4947a0a
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/ProtocolHandler.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.protocol.handler;
+
+import org.apache.geode.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 outputStream) throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
new file mode 100644
index 0000000..f8c2abd
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
@@ -0,0 +1,41 @@
+/*
+ * 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.protocol.handler.protobuf;
+
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.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/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
new file mode 100644
index 0000000..020c27b
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.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.protocol.operations;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public interface OperationHandler<Req, Resp> {
+ Resp process(SerializationService serializationService, Req request, Cache cache)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+
+ int getOperationCode();
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java
new file mode 100644
index 0000000..7fb0eab
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/ProtobufRequestOperationParser.java
@@ -0,0 +1,33 @@
+/*
+ * 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.protocol.operations;
+
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+
+public class ProtobufRequestOperationParser {
+ public static Object getRequestForOperationTypeID(ClientProtocol.Request request) {
+ switch (request.getRequestAPICase()) {
+ case PUTREQUEST:
+ return request.getPutRequest();
+ case GETREQUEST:
+ return request.getGetRequest();
+ case PUTALLREQUEST:
+ return request.getPutAllRequest();
+ default:
+ throw new RuntimeException(
+ "Unknown request type: " + request.getRequestAPICase().getNumber());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java
new file mode 100644
index 0000000..dafacc0
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/protobuf/GetRequestOperationHandler.java
@@ -0,0 +1,59 @@
+/*
+ * 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.protocol.operations.protobuf;
+
+import org.apache.geode.ProtobufUtilities;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionService;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public class GetRequestOperationHandler
+ implements OperationHandler<RegionAPI.GetRequest, RegionAPI.GetResponse> {
+
+ @Override
+ public RegionAPI.GetResponse process(SerializationService serializationService,
+ RegionAPI.GetRequest request, Cache cache)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ String regionName = request.getRegionName();
+ BasicTypes.EncodedValue key = request.getKey();
+ BasicTypes.EncodingType encodingType = key.getEncodingType();
+ byte[] value = key.getValue().toByteArray();
+ Object decodedValue = serializationService.decode(encodingType, value);
+
+ Region region = cache.getRegion(regionName);
+ Object resultValue = region.get(decodedValue);
+
+ BasicTypes.EncodingType resultEncodingType =
+ EncodingTypeTranslator.getEncodingTypeForObject(resultValue);
+ byte[] resultEncodedValue = serializationService.encode(resultEncodingType, resultValue);
+
+ return RegionAPI.GetResponse.newBuilder()
+ .setResult(ProtobufUtilities.getEncodedValue(resultEncodingType, resultEncodedValue))
+ .build();
+ }
+
+ @Override
+ public int getOperationCode() {
+ return ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
new file mode 100644
index 0000000..80e0459
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/OperationsHandlerRegistry.java
@@ -0,0 +1,57 @@
+/*
+ * 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.protocol.operations.registry;
+
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
+import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+
+import java.util.HashMap;
+import java.util.ServiceLoader;
+
+public class OperationsHandlerRegistry {
+ private HashMap<Integer, OperationHandler> registeredOperations = new HashMap<>();
+
+ public OperationsHandlerRegistry() throws OperationHandlerAlreadyRegisteredException {
+ ServiceLoader<OperationHandler> operationHandlers = ServiceLoader.load(OperationHandler.class);
+ for (OperationHandler operationHandler : operationHandlers) {
+ registerOperationHandlerForOperationId(operationHandler.getOperationCode(), operationHandler);
+ }
+ }
+
+ public OperationHandler getOperationHandlerForOperationId(int operationCode)
+ throws OperationHandlerNotRegisteredException {
+ OperationHandler operationHandler = registeredOperations.get(operationCode);
+ if (operationHandler == null) {
+ throw new OperationHandlerNotRegisteredException(
+ "There is no operation handler registered for operation code: " + operationCode);
+ }
+ return operationHandler;
+ }
+
+ public synchronized void registerOperationHandlerForOperationId(int operationCode,
+ OperationHandler operationHandler) throws OperationHandlerAlreadyRegisteredException {
+ if (registeredOperations.containsKey(operationCode)) {
+ throw new OperationHandlerAlreadyRegisteredException(
+ "An operation handler for operationCode: " + operationCode
+ + " has already been registered!");
+ }
+ registeredOperations.put(operationCode, operationHandler);
+ }
+
+ public int getRegisteredOperationHandlersCount() {
+ return registeredOperations.size();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
new file mode 100644
index 0000000..1f42c10
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.protocol.operations.registry.exception;
+
+public class OperationHandlerAlreadyRegisteredException extends Exception {
+ public OperationHandlerAlreadyRegisteredException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
new file mode 100644
index 0000000..f83e1b3
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerNotRegisteredException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.protocol.operations.registry.exception;
+
+public class OperationHandlerNotRegisteredException extends Exception {
+ public OperationHandlerNotRegisteredException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java
new file mode 100644
index 0000000..9d78245
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/ProtobufSerializationService.java
@@ -0,0 +1,50 @@
+/*
+ * 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.serialization;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.serialization.protobuf.translation.EncodingTypeTranslator;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.SerializationCodecRegistry;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public class ProtobufSerializationService implements SerializationService<BasicTypes.EncodingType> {
+ private SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+
+ public ProtobufSerializationService() throws CodecAlreadyRegisteredForTypeException {}
+
+ @Override
+ public byte[] encode(BasicTypes.EncodingType encodingTypeValue, Object value)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
+ return codecForType.encode(value);
+ }
+
+ @Override
+ public Object decode(BasicTypes.EncodingType encodingTypeValue, byte[] value)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
+ return codecForType.decode(value);
+ }
+
+ private TypeCodec getTypeCodecForProtobufType(BasicTypes.EncodingType encodingTypeValue)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ SerializationType serializationTypeForEncodingType =
+ EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingTypeValue);
+
+ return serializationCodecRegistry.getCodecForType(serializationTypeForEncodingType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java
new file mode 100644
index 0000000..623a7bd
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.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.serialization;
+
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+public interface SerializationService<T> {
+
+ Object decode(T encodingTypeValue, byte[] value)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+
+ byte[] encode(T encodingTypeValue, Object value)
+ throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
new file mode 100644
index 0000000..4ea4422
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
@@ -0,0 +1,36 @@
+/*
+ * 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.serialization;
+
+import org.apache.geode.pdx.PdxInstance;
+
+public enum SerializationType {
+ STRING(String.class),
+ BINARY(byte[].class),
+ INT(int.class),
+ BYTE(byte.class),
+ SHORT(short.class),
+ LONG(long.class),
+ JSON(PdxInstance.class),
+ BOOLEAN(boolean.class),
+ FLOAT(float.class),
+ DOUBLE(double.class);
+
+ public final Class klass;
+
+ SerializationType(Class klass) {
+ this.klass = klass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
new file mode 100644
index 0000000..f2c7f90
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
@@ -0,0 +1,23 @@
+/*
+ * 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.serialization;
+
+public interface TypeCodec<T> {
+ T decode(byte[] incoming);
+
+ byte[] encode(T incoming);
+
+ SerializationType getSerializationType();
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BinaryCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BinaryCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BinaryCodec.java
new file mode 100644
index 0000000..c1bee43
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BinaryCodec.java
@@ -0,0 +1,35 @@
+/*
+ * 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.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+public class BinaryCodec implements TypeCodec<byte[]> {
+ @Override
+ public byte[] decode(byte[] incoming) {
+ return incoming;
+ }
+
+ @Override
+ public byte[] encode(byte[] incoming) {
+ return incoming;
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.BINARY;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BooleanCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BooleanCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BooleanCodec.java
new file mode 100644
index 0000000..e3e234d
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/BooleanCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+
+public class BooleanCodec implements TypeCodec<Boolean> {
+ @Override
+ public Boolean decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).get() == 1;
+ }
+
+ @Override
+ public byte[] encode(Boolean incoming) {
+ return ByteBuffer.allocate(Byte.BYTES).put(incoming ? (byte) 1 : (byte) 0).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.BOOLEAN;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ByteCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ByteCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ByteCodec.java
new file mode 100644
index 0000000..10db041
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ByteCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+
+public class ByteCodec implements TypeCodec<Byte> {
+ @Override
+ public Byte decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).get();
+ }
+
+ @Override
+ public byte[] encode(Byte incoming) {
+ return ByteBuffer.allocate(Byte.BYTES).put(incoming).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.BYTE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/DoubleCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/DoubleCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/DoubleCodec.java
new file mode 100644
index 0000000..0bcb852
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/DoubleCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+
+public class DoubleCodec implements TypeCodec<Double> {
+ @Override
+ public Double decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).getDouble();
+ }
+
+ @Override
+ public byte[] encode(Double incoming) {
+ return ByteBuffer.allocate(Double.BYTES).putDouble(incoming).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.DOUBLE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/FloatCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/FloatCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/FloatCodec.java
new file mode 100644
index 0000000..c41914b
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/FloatCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+
+public class FloatCodec implements TypeCodec<Float> {
+ @Override
+ public Float decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).getFloat();
+ }
+
+ @Override
+ public byte[] encode(Float incoming) {
+ return ByteBuffer.allocate(Float.BYTES).putFloat(incoming).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.FLOAT;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/IntCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/IntCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/IntCodec.java
new file mode 100644
index 0000000..6bd2b5c
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/IntCodec.java
@@ -0,0 +1,38 @@
+/*
+ * 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.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+public class IntCodec implements TypeCodec<Integer> {
+ @Override
+ public Integer decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).getInt();
+ }
+
+ @Override
+ public byte[] encode(Integer incoming) {
+ return ByteBuffer.allocate(Integer.BYTES).putInt(incoming).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.INT;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/JSONCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/JSONCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/JSONCodec.java
new file mode 100644
index 0000000..eb1ebc3
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/JSONCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.pdx.JSONFormatter;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+public class JSONCodec implements TypeCodec<PdxInstance> {
+ @Override
+ public PdxInstance decode(byte[] incoming) {
+ return JSONFormatter.fromJSON(incoming);
+ }
+
+ @Override
+ public byte[] encode(PdxInstance incoming) {
+ return JSONFormatter.toJSONByteArray(incoming);
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.JSON;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/LongCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/LongCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/LongCodec.java
new file mode 100644
index 0000000..9b064a7
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/LongCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+
+public class LongCodec implements TypeCodec<Long> {
+ @Override
+ public Long decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).getLong();
+ }
+
+ @Override
+ public byte[] encode(Long incoming) {
+ return ByteBuffer.allocate(Long.BYTES).putLong(incoming).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.LONG;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ShortCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ShortCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ShortCodec.java
new file mode 100644
index 0000000..8d7b1d4
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/ShortCodec.java
@@ -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.
+ */
+package org.apache.geode.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.ByteBuffer;
+
+public class ShortCodec implements TypeCodec<Short> {
+ @Override
+ public Short decode(byte[] incoming) {
+ return ByteBuffer.wrap(incoming).getShort();
+ }
+
+ @Override
+ public byte[] encode(Short incoming) {
+ return ByteBuffer.allocate(Short.BYTES).putShort(incoming).array();
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.SHORT;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/StringCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/StringCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/StringCodec.java
new file mode 100644
index 0000000..cc7904b
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/codec/StringCodec.java
@@ -0,0 +1,39 @@
+/*
+ * 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.serialization.codec;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+
+import java.nio.charset.Charset;
+
+public class StringCodec implements TypeCodec<String> {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
+
+ @Override
+ public String decode(byte[] incoming) {
+ return new String(incoming, UTF8);
+ }
+
+ @Override
+ public byte[] encode(String incoming) {
+ return incoming.getBytes(UTF8);
+ }
+
+ @Override
+ public SerializationType getSerializationType() {
+ return SerializationType.STRING;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
new file mode 100644
index 0000000..9d75f56
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.serialization.exception;
+
+public class UnsupportedEncodingTypeException extends Exception {
+ public UnsupportedEncodingTypeException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java
new file mode 100644
index 0000000..667996d
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeTranslator.java
@@ -0,0 +1,83 @@
+/*
+ * 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.serialization.protobuf.translation;
+
+import org.apache.geode.pdx.JSONFormatter;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
+
+public abstract class EncodingTypeTranslator {
+ public static SerializationType getSerializationTypeForEncodingType(
+ BasicTypes.EncodingType encodingType) throws UnsupportedEncodingTypeException {
+ switch (encodingType) {
+ case INT:
+ return SerializationType.INT;
+ case BYTE:
+ return SerializationType.BYTE;
+ case JSON:
+ return SerializationType.JSON;
+ case LONG:
+ return SerializationType.LONG;
+ case FLOAT:
+ return SerializationType.FLOAT;
+ case SHORT:
+ return SerializationType.SHORT;
+ case BINARY:
+ return SerializationType.BINARY;
+ case DOUBLE:
+ return SerializationType.DOUBLE;
+ case STRING:
+ return SerializationType.STRING;
+ case BOOLEAN:
+ return SerializationType.BOOLEAN;
+ default:
+ throw new UnsupportedEncodingTypeException(
+ "No serialization type found for protobuf encoding type: " + encodingType);
+ }
+ }
+
+ public static BasicTypes.EncodingType getEncodingTypeForObject(Object resultValue)
+ throws UnsupportedEncodingTypeException {
+ if (resultValue instanceof Integer) {
+ return BasicTypes.EncodingType.INT;
+ } else if (resultValue instanceof Byte) {
+ return BasicTypes.EncodingType.BYTE;
+ } else if (resultValue instanceof PdxInstance) {
+ String pdxClassName = ((PdxInstance) resultValue).getClassName();
+ if (pdxClassName.equals(JSONFormatter.JSON_CLASSNAME)) {
+ return BasicTypes.EncodingType.JSON;
+ }
+ } else if (resultValue instanceof Long) {
+ return BasicTypes.EncodingType.LONG;
+ } else if (resultValue instanceof Float) {
+ return BasicTypes.EncodingType.FLOAT;
+ } else if (resultValue instanceof Short) {
+ return BasicTypes.EncodingType.SHORT;
+ } else if (resultValue instanceof byte[]) {
+ return BasicTypes.EncodingType.BINARY;
+ } else if (resultValue instanceof Double) {
+ return BasicTypes.EncodingType.DOUBLE;
+ } else if (resultValue instanceof String) {
+ return BasicTypes.EncodingType.STRING;
+ } else if (resultValue instanceof Boolean) {
+ return BasicTypes.EncodingType.BOOLEAN;
+ }
+
+ throw new UnsupportedEncodingTypeException(
+ "We cannot translate: " + resultValue.getClass() + " into a specific Protobuf Encoding");
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java
new file mode 100644
index 0000000..ad01eac
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/protobuf/translation/exception/UnsupportedEncodingTypeException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.serialization.protobuf.translation.exception;
+
+public class UnsupportedEncodingTypeException extends Exception {
+ public UnsupportedEncodingTypeException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java
new file mode 100644
index 0000000..2c88306
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/SerializationCodecRegistry.java
@@ -0,0 +1,61 @@
+/*
+ * 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.serialization.registry;
+
+import org.apache.geode.serialization.SerializationType;
+import org.apache.geode.serialization.TypeCodec;
+import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
+import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+
+import java.util.HashMap;
+import java.util.ServiceLoader;
+
+public class SerializationCodecRegistry {
+ private HashMap<SerializationType, TypeCodec> codecRegistry = new HashMap<>();
+
+ public SerializationCodecRegistry() throws CodecAlreadyRegisteredForTypeException {
+ ServiceLoader<TypeCodec> typeCodecs = ServiceLoader.load(TypeCodec.class);
+ for (TypeCodec typeCodec : typeCodecs) {
+ register(typeCodec.getSerializationType(), typeCodec);
+ }
+ }
+
+ public synchronized void register(SerializationType serializationType, TypeCodec<?> typeCodec)
+ throws CodecAlreadyRegisteredForTypeException {
+ if (codecRegistry.containsKey(serializationType)) {
+ throw new CodecAlreadyRegisteredForTypeException(
+ "There is already a codec registered for type: " + serializationType);
+ }
+ codecRegistry.put(serializationType, typeCodec);
+ }
+
+ public int getRegisteredCodecCount() {
+ return codecRegistry.size();
+ }
+
+ public TypeCodec getCodecForType(SerializationType serializationType)
+ throws CodecNotRegisteredForTypeException {
+ TypeCodec typeCodec = codecRegistry.get(serializationType);
+ if (typeCodec == null) {
+ throw new CodecNotRegisteredForTypeException(
+ "There is no codec registered for type: " + serializationType);
+ }
+ return typeCodec;
+ }
+
+ public void shutdown() {
+ codecRegistry.clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
new file mode 100644
index 0000000..678d374
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.serialization.registry.exception;
+
+public class CodecAlreadyRegisteredForTypeException extends Exception {
+ public CodecAlreadyRegisteredForTypeException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
new file mode 100644
index 0000000..a1a6408
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.serialization.registry.exception;
+
+public class CodecNotRegisteredForTypeException extends Exception {
+ public CodecNotRegisteredForTypeException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/cdcc4d95/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/cdcc4d95/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..0c19295
--- /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 = 21;
+ DestroyRegionRequest destroyRegionRequest = 22;
+
+ PingRequest pingRequest = 41;
+ GetServersRequest getServersRequest = 42;
+ GetRegionsRequest getRegionsRequest = 43;
+ }
+}
+
+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 = 41;
+ GetServersResponse getServersResponse = 42;
+ GetRegionsResponse getRegionsResponse = 43;
+ }
+}
+
+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/cdcc4d95/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/cdcc4d95/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/cdcc4d95/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler
new file mode 100644
index 0000000..9af7c5d
--- /dev/null
+++ b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.handler.ProtocolHandler
@@ -0,0 +1 @@
+org.apache.geode.protocol.handler.protobuf.ProtobufProtocolHandler
\ No newline at end of file
[13/13] geode git commit: Move new exception to sanctioned
serializables.
Posted by hi...@apache.org.
Move new exception to sanctioned serializables.
Although we don't serialize it, exceptions sometimes get sent between
JVMs so it's best to be careful.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/e1c6c3a9
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/e1c6c3a9
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/e1c6c3a9
Branch: refs/heads/develop
Commit: e1c6c3a973413045c595fcf31a01c269e7df7e82
Parents: da64fc6
Author: Galen OSullivan <go...@pivotal.io>
Authored: Fri Jun 23 10:42:45 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:23 2017 -0700
----------------------------------------------------------------------
.../resources/org/apache/geode/codeAnalysis/excludedClasses.txt | 1 -
.../org/apache/geode/codeAnalysis/sanctionedSerializables.txt | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/e1c6c3a9/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
index c2629f1..6a6e0c1 100644
--- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
+++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/excludedClasses.txt
@@ -7,7 +7,6 @@ org/apache/geode/distributed/LocatorLauncher$Command
org/apache/geode/distributed/ServerLauncher
org/apache/geode/distributed/ServerLauncher$Command
org/apache/geode/distributed/internal/DistributionManager
-org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException
org/apache/geode/internal/JarDeployer
org/apache/geode/internal/logging/GemFireLevel
org/apache/geode/internal/logging/LoggingThreadGroup
http://git-wip-us.apache.org/repos/asf/geode/blob/e1c6c3a9/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
index 135f509..e5a111c 100755
--- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
+++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
@@ -340,6 +340,7 @@ org/apache/geode/internal/cache/tier/sockets/CacheClientNotifier$2,false,this$0:
org/apache/geode/internal/cache/tier/sockets/CacheClientProxy$MessageDispatcher$1,true,0,this$0:org/apache/geode/internal/cache/tier/sockets/CacheClientProxy$MessageDispatcher
org/apache/geode/internal/cache/tier/sockets/ClientTombstoneMessage$TOperation,false
org/apache/geode/internal/cache/tier/sockets/MessageTooLargeException,true,-8970585803331525833
+org/apache/geode/internal/cache/tier/sockets/ServiceLoadingFailureException,false
org/apache/geode/internal/cache/tier/sockets/UnregisterAllInterest,true,5026160621257178459
org/apache/geode/internal/cache/tx/TransactionalOperation$ServerRegionOperation,false
org/apache/geode/internal/cache/versions/ConcurrentCacheModificationException,true,2316928221010347462
[02/13] geode git commit: GEODE-2995: more review feedback and
spotlessApply
Posted by hi...@apache.org.
GEODE-2995: more review feedback and spotlessApply
Signed-off-by: Brian Rowe <br...@pivotal.io>
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/0de1d97e
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/0de1d97e
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/0de1d97e
Branch: refs/heads/develop
Commit: 0de1d97ea229ec43203437f58971c44fe37cef62
Parents: 31f4de0
Author: Galen O'Sullivan <go...@pivotal.io>
Authored: Tue Jun 20 16:58:51 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
.../protocol/operations/OperationHandler.java | 20 ++++++++++++------
...rationHandlerAlreadyRegisteredException.java | 3 ++-
.../protocol/protobuf/ProtobufOpsProcessor.java | 22 ++++++++++----------
.../protobuf/ProtobufStreamProcessor.java | 7 +++++--
.../protocol/serializer/ProtocolSerializer.java | 1 +
.../serialization/SerializationService.java | 7 ++++++-
.../geode/serialization/SerializationType.java | 3 +++
.../apache/geode/serialization/TypeCodec.java | 10 +++++++++
.../exception/TypeEncodingException.java | 21 +++++++++++++++++++
.../UnsupportedEncodingTypeException.java | 2 +-
.../CodecAlreadyRegisteredForTypeException.java | 3 ++-
.../CodecNotRegisteredForTypeException.java | 4 +++-
.../geode/client/protocol/IntegrationTest.java | 3 +--
.../protobuf/ProtobufOpsProcessorTest.java | 10 ++++-----
.../ProtobufProtocolSerializerJUnitTest.java | 2 +-
15 files changed, 86 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
index 8eab146..7683e3b 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
@@ -15,23 +15,31 @@
package org.apache.geode.protocol.operations;
import org.apache.geode.cache.Cache;
-import org.apache.geode.protocol.protobuf.ProtobufOpsProcessor;
import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
+import org.apache.geode.protocol.protobuf.ProtobufOpsProcessor;
import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.serialization.exception.TypeEncodingException;
/**
- * This interface is implemented by a object capable of handling request types 'Req' and returning an a response of type 'Resp'
+ * This interface is implemented by a object capable of handling request types 'Req' and returning
+ * an a response of type 'Resp'
*
* See {@link ProtobufOpsProcessor}
*/
public interface OperationHandler<Req, Resp> {
+ /**
+ * Decode the message, deserialize contained values using the serialization service, do the work
+ * indicated on the provided cache, and return a response.
+ *
+ * @throws TypeEncodingException if a problem occurs decoding an encoded value contained in the
+ * request.
+ */
Resp process(SerializationService serializationService, Req request, Cache cache)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+ throws TypeEncodingException;
/**
- * @return the magic number used for registering the operation type with the {@link OperationsHandlerRegistry}.
+ * @return the magic number used for registering the operation type with the
+ * {@link OperationsHandlerRegistry}.
*/
int getOperationCode();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
index 519698d..18475d8 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java
@@ -15,7 +15,8 @@
package org.apache.geode.protocol.operations.registry.exception;
/**
- * Indicates that an operation handler is attempting to register for an already handled operation type.
+ * Indicates that an operation handler is attempting to register for an already handled operation
+ * type.
*/
public class OperationHandlerAlreadyRegisteredException extends Exception {
public OperationHandlerAlreadyRegisteredException(String message) {
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
index c572d80..d426149 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
@@ -20,37 +20,37 @@ import org.apache.geode.protocol.operations.OperationHandler;
import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
import org.apache.geode.serialization.SerializationService;
-import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.serialization.exception.TypeEncodingException;
/**
- * This handles protobuf requests by determining the operation type of the request and dispatching it to the appropriate handler.
+ * This handles protobuf requests by determining the operation type of the request and dispatching
+ * it to the appropriate handler.
*/
public class ProtobufOpsProcessor {
private final OperationsHandlerRegistry opsHandlerRegistry;
private final SerializationService serializationService;
public ProtobufOpsProcessor(OperationsHandlerRegistry opsHandlerRegistry,
- SerializationService serializationService) {
+ SerializationService serializationService) {
this.opsHandlerRegistry = opsHandlerRegistry;
this.serializationService = serializationService;
}
public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException,
- OperationHandlerNotRegisteredException, InvalidProtocolMessageException {
+ throws TypeEncodingException, OperationHandlerNotRegisteredException,
+ InvalidProtocolMessageException {
OperationHandler opsHandler = opsHandlerRegistry
- .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber());
+ .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber());
- Object responseMessage = opsHandler.process(serializationService,
- getRequestForOperationTypeID(request), cache);
+ Object responseMessage =
+ opsHandler.process(serializationService, getRequestForOperationTypeID(request), cache);
return ClientProtocol.Response.newBuilder()
.setGetResponse((RegionAPI.GetResponse) responseMessage).build();
}
// package visibility for testing
static Object getRequestForOperationTypeID(ClientProtocol.Request request)
- throws InvalidProtocolMessageException {
+ throws InvalidProtocolMessageException {
switch (request.getRequestAPICase()) {
case PUTREQUEST:
return request.getPutRequest();
@@ -60,7 +60,7 @@ public class ProtobufOpsProcessor {
return request.getPutAllRequest();
default:
throw new InvalidProtocolMessageException(
- "Unknown request type: " + request.getRequestAPICase().getNumber());
+ "Unknown request type: " + request.getRequestAPICase().getNumber());
}
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
index 41a3c40..1dcb61c 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
@@ -20,6 +20,7 @@ import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException;
import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.serialization.exception.TypeEncodingException;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
@@ -29,7 +30,9 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
- * This object handles an incoming stream containing protobuf messages. It parses the protobuf messages, hands the requests to an appropriate handler, wraps the response in a protobuf message, and then pushes it to the output stream.
+ * This object handles an incoming stream containing protobuf messages. It parses the protobuf
+ * messages, hands the requests to an appropriate handler, wraps the response in a protobuf message,
+ * and then pushes it to the output stream.
*/
public class ProtobufStreamProcessor {
ProtobufProtocolSerializer protobufProtocolSerializer;
@@ -47,7 +50,7 @@ public class ProtobufStreamProcessor {
public void processOneMessage(InputStream inputStream, OutputStream outputStream, Cache cache)
throws InvalidProtocolMessageException, OperationHandlerNotRegisteredException,
- UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException, IOException {
+ TypeEncodingException, IOException {
ClientProtocol.Message message = protobufProtocolSerializer.deserialize(inputStream);
ClientProtocol.Request request = message.getRequest();
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
index 7191d87..46e491f 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java
@@ -22,6 +22,7 @@ import java.io.OutputStream;
/**
* This interface is used to translate between binary data and protocol specific messages.
+ *
* @param <T> The message type of the protocol.
*/
public interface ProtocolSerializer<T> {
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java
index 623a7bd..cdeb170 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java
@@ -17,8 +17,13 @@ package org.apache.geode.serialization;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
+/**
+ * This interface takes an protocol specific encodingTypeValue enum and converts between objects and
+ * bytes using the encodingTypeValue to decide what encoding type to use.
+ *
+ * @param <T> the enumeration of types known to a particular protocol
+ */
public interface SerializationService<T> {
-
Object decode(T encodingTypeValue, byte[] value)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
index 4ea4422..91466a1 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java
@@ -16,6 +16,9 @@ package org.apache.geode.serialization;
import org.apache.geode.pdx.PdxInstance;
+/**
+ * Enumerates the serialization types currently available to wire protocols.
+ */
public enum SerializationType {
STRING(String.class),
BINARY(byte[].class),
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
index f2c7f90..8506a53 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java
@@ -14,10 +14,20 @@
*/
package org.apache.geode.serialization;
+/**
+ * This interface converts a particular type to and from its binary representation.
+ *
+ * NOTE: it is expected that T will be one of the serialization types in @{@link SerializationType}.
+ *
+ * @param <T> the type this codec knows how to convert
+ */
public interface TypeCodec<T> {
T decode(byte[] incoming);
byte[] encode(T incoming);
+ /**
+ * @return the SerializationType corresponding to T
+ */
SerializationType getSerializationType();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java
new file mode 100644
index 0000000..f3145a7
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java
@@ -0,0 +1,21 @@
+/*
+ * 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.serialization.exception;
+
+public class TypeEncodingException extends Exception {
+ public TypeEncodingException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
index 6d2a032..c577e76 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java
@@ -17,7 +17,7 @@ package org.apache.geode.serialization.exception;
/**
* This indicates an encoding type that we don't know how to handle.
*/
-public class UnsupportedEncodingTypeException extends Exception {
+public class UnsupportedEncodingTypeException extends TypeEncodingException {
public UnsupportedEncodingTypeException(String message) {
super(message);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
index 7e73ba9..66ae850 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
@@ -15,7 +15,8 @@
package org.apache.geode.serialization.registry.exception;
/**
- * This indicates that we're attempting to register a codec for a type which we already have a handler for.
+ * This indicates that we're attempting to register a codec for a type which we already have a
+ * handler for.
*/
public class CodecAlreadyRegisteredForTypeException extends Exception {
public CodecAlreadyRegisteredForTypeException(String message) {
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
index 58cb691..5c923a5 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java
@@ -14,10 +14,12 @@
*/
package org.apache.geode.serialization.registry.exception;
+import org.apache.geode.serialization.exception.TypeEncodingException;
+
/**
* This indicates we're attempting to handle a type for which we don't have a registered codec.
*/
-public class CodecNotRegisteredForTypeException extends Exception {
+public class CodecNotRegisteredForTypeException extends TypeEncodingException {
public CodecNotRegisteredForTypeException(String message) {
super(message);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
index e32c711..63cde31 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java
@@ -65,8 +65,7 @@ public class IntegrationTest {
}
@Test
- public void testGetRequestProcessed()
- throws Exception {
+ public void testGetRequestProcessed() throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ProtobufStreamProcessor streamProcessor = new ProtobufStreamProcessor();
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
index 9298026..ac3d68f 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java
@@ -24,6 +24,7 @@ import org.apache.geode.protocol.operations.OperationHandler;
import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
import org.apache.geode.serialization.SerializationService;
+import org.apache.geode.serialization.exception.TypeEncodingException;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
import org.apache.geode.test.junit.categories.UnitTest;
@@ -34,9 +35,8 @@ import org.junit.experimental.categories.Category;
@Category(UnitTest.class)
public class ProtobufOpsProcessorTest {
@Test
- public void testOpsProcessor() throws CodecNotRegisteredForTypeException,
- OperationHandlerNotRegisteredException, UnsupportedEncodingTypeException,
- InvalidProtocolMessageException {
+ public void testOpsProcessor() throws TypeEncodingException,
+ OperationHandlerNotRegisteredException, InvalidProtocolMessageException {
OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class);
OperationHandler operationHandlerStub = mock(OperationHandler.class);
SerializationService serializationServiceStub = mock(SerializationService.class);
@@ -54,8 +54,8 @@ public class ProtobufOpsProcessorTest {
ProtobufOpsProcessor.getRequestForOperationTypeID(messageRequest), dummyCache))
.thenReturn(expectedResponse);
- ProtobufOpsProcessor
- processor = new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
+ ProtobufOpsProcessor processor =
+ new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
Assert.assertEquals(expectedResponse, response.getGetResponse());
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
index 95244d2..e1f7b5b 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
@@ -60,7 +60,7 @@ public class ProtobufProtocolSerializerJUnitTest {
@Test(expected = InvalidProtocolMessageException.class)
public void testDeserializeInvalidByteThrowsException()
- throws IOException, InvalidProtocolMessageException {
+ throws IOException, InvalidProtocolMessageException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byteArrayOutputStream.write("Some incorrect byte array".getBytes());
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
[03/13] geode git commit: GEODE-2995: Implementing review feedback
Posted by hi...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
new file mode 100644
index 0000000..95244d2
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.protocol.serializer;
+
+import org.apache.geode.client.protocol.MessageUtil;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ServiceLoader;
+
+@Category(UnitTest.class)
+public class ProtobufProtocolSerializerJUnitTest {
+ private ProtocolSerializer<ClientProtocol.Message> protocolSerializer;
+
+ @Before
+ public void startup() {
+ ServiceLoader<ProtocolSerializer> serviceLoader = ServiceLoader.load(ProtocolSerializer.class);
+ for (ProtocolSerializer protocolSerializer : serviceLoader) {
+ if (protocolSerializer instanceof ProtobufProtocolSerializer) {
+ this.protocolSerializer = protocolSerializer;
+ }
+ }
+ }
+
+ @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 = protocolSerializer.deserialize(inputStream);
+ Assert.assertEquals(expectedRequestMessage, actualMessage);
+ }
+
+ @Test(expected = InvalidProtocolMessageException.class)
+ public void testDeserializeInvalidByteThrowsException()
+ throws IOException, InvalidProtocolMessageException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ byteArrayOutputStream.write("Some incorrect byte array".getBytes());
+ InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+ protocolSerializer.deserialize(inputStream);
+ }
+
+ @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();
+ protocolSerializer.serialize(message, actualByteArrayOutputStream);
+ Assert.assertArrayEquals(expectedByteArray, actualByteArrayOutputStream.toByteArray());
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
index a4c0a14..ef841c3 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/ProtobufSerializationServiceImplTest.java
@@ -15,6 +15,7 @@
package org.apache.geode.serialization;
import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ProtobufSerializationService;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
@@ -51,7 +52,7 @@ public class ProtobufSerializationServiceImplTest {
BasicTypes.EncodingType encodingType, Object data)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
byte[] encodedValue = service.encode(encodingType, data);
- Object decdoedValue = service.decode(encodingType, encodedValue);
- Assert.assertEquals(data, decdoedValue);
+ Object decodedValue = service.decode(encodingType, encodedValue);
+ Assert.assertEquals(data, decodedValue);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
index 1af710c..963cb85 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/protobuf/translation/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
@@ -17,6 +17,7 @@ package org.apache.geode.serialization.protobuf.translation;
import static org.junit.Assert.assertSame;
import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
import org.apache.geode.serialization.SerializationType;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.test.junit.categories.UnitTest;
http://git-wip-us.apache.org/repos/asf/geode/blob/31f4de06/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
index 2c37fb5..1d038f5 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
@@ -81,17 +81,11 @@ public class CodecRegistryJUnitTest {
Assert.assertSame(expectedCodec, codec);
}
- @Test
- public void testGetCodecForUnregisteredType_throwsException() {
- boolean caughtException = false;
- try {
- SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
- codecRegistry.getCodecForType(mockSerializationType);
- } catch (CodecNotRegisteredForTypeException e) {
- caughtException = true;
- }
- Assert.assertTrue("This should have thrown a CodecNotRegisteredForTypeException",
- caughtException);
+ @Test(expected = CodecNotRegisteredForTypeException.class)
+ public void testGetCodecForUnregisteredType_throwsException()
+ throws CodecNotRegisteredForTypeException {
+ SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+ codecRegistry.getCodecForType(mockSerializationType);
}
class DummyTypeCodec implements TypeCodec {
[06/13] geode git commit: GEODE-3075: changes in response to feedback;
refactor some.
Posted by hi...@apache.org.
GEODE-3075: changes in response to feedback; refactor some.
`AcceptorImpl.handleNewClientConnection` has had refactoring and should
be a bit more understandable.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/c71c28df
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/c71c28df
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/c71c28df
Branch: refs/heads/develop
Commit: c71c28dff7fd6d20798fadcbd6a1a15f055ae52e
Parents: cdcc4d9
Author: Galen OSullivan <go...@pivotal.io>
Authored: Mon Jun 19 17:48:53 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
.../geode/internal/cache/tier/Acceptor.java | 2 +-
.../cache/tier/sockets/AcceptorImpl.java | 316 ++++++++++---------
.../GenericProtocolServerConnection.java | 85 +++++
.../sockets/NewProtocolServerConnection.java | 87 -----
.../tier/sockets/ServerConnectionFactory.java | 9 +-
.../ServerConnectionFactoryIntegrationTest.java | 45 ++-
.../sockets/ServerConnectionFactoryTest.java | 15 +-
7 files changed, 291 insertions(+), 268 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
index a95195a..e12a409 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/Acceptor.java
@@ -74,7 +74,7 @@ public abstract class Acceptor {
/**
* For the new client-server protocol, which ignores the usual handshake mechanism.
*/
- public static final byte CLIENT_TO_SERVER_NEW_PROTOCOL = (byte) 110;
+ public static final byte PROTOBUF_CLIENT_SERVER_PROTOCOL = (byte) 110;
/**
* The GFE version of the server.
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
index 24efc93..50f7006 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
@@ -94,7 +94,7 @@ import javax.net.ssl.SSLException;
/**
* Implements the acceptor thread on the bridge server. Accepts connections from the edge and starts
* up threads to process requests from these.
- *
+ *
* @since GemFire 2.0.2
*/
@SuppressWarnings("deprecation")
@@ -113,19 +113,29 @@ public class AcceptorImpl extends Acceptor implements Runnable {
*/
private final ThreadPoolExecutor hsPool;
- /** The port on which this acceptor listens for client connections */
+ /**
+ * The port on which this acceptor listens for client connections
+ */
private final int localPort;
- /** The server socket that handles requests for connections */
+ /**
+ * The server socket that handles requests for connections
+ */
private ServerSocket serverSock = null;
- /** The GemFire cache served up by this acceptor */
+ /**
+ * The GemFire cache served up by this acceptor
+ */
protected final InternalCache cache;
- /** Caches region information */
+ /**
+ * Caches region information
+ */
private final CachedRegionHelper crHelper;
- /** A lock to prevent close from occurring while creating a ServerConnection */
+ /**
+ * A lock to prevent close from occurring while creating a ServerConnection
+ */
private final Object syncLock = new Object();
/**
@@ -165,7 +175,9 @@ public class AcceptorImpl extends Acceptor implements Runnable {
*/
public static final int DEFAULT_HANDSHAKE_TIMEOUT_MS = 59000;
- /** Test value for handshake timeout */
+ /**
+ * Test value for handshake timeout
+ */
protected static final int handShakeTimeout =
Integer.getInteger(HANDSHAKE_TIMEOUT_PROPERTY_NAME, DEFAULT_HANDSHAKE_TIMEOUT_MS).intValue();
@@ -180,17 +192,25 @@ public class AcceptorImpl extends Acceptor implements Runnable {
*/
public static final int DEFAULT_ACCEPT_TIMEOUT_MS = 9900;
- /** Test value for accept timeout */
+ /**
+ * Test value for accept timeout
+ */
private final int acceptTimeout =
Integer.getInteger(ACCEPT_TIMEOUT_PROPERTY_NAME, DEFAULT_ACCEPT_TIMEOUT_MS).intValue();
- /** The mininum value of max-connections */
+ /**
+ * The mininum value of max-connections
+ */
public static final int MINIMUM_MAX_CONNECTIONS = 16;
- /** The buffer size for server-side sockets. */
+ /**
+ * The buffer size for server-side sockets.
+ */
private final int socketBufferSize;
- /** Notifies clients of updates */
+ /**
+ * Notifies clients of updates
+ */
private CacheClientNotifier clientNotifier;
/**
@@ -198,7 +218,9 @@ public class AcceptorImpl extends Acceptor implements Runnable {
*/
private static final int DEFAULT_BACKLOG = 1000;
- /** The system property name for setting the {@link ServerSocket}backlog */
+ /**
+ * The system property name for setting the {@link ServerSocket}backlog
+ */
public static final String BACKLOG_PROPERTY_NAME = "BridgeServer.backlog";
/**
@@ -206,13 +228,19 @@ public class AcceptorImpl extends Acceptor implements Runnable {
*/
public final AtomicInteger clientServerCnxCount = new AtomicInteger();
- /** Has this acceptor been shut down */
+ /**
+ * Has this acceptor been shut down
+ */
private volatile boolean shutdownStarted = false;
- /** The thread that runs the acceptor */
+ /**
+ * The thread that runs the acceptor
+ */
private Thread thread = null;
- /** The thread that runs the selector loop if any */
+ /**
+ * The thread that runs the selector loop if any
+ */
private Thread selectorThread = null;
/**
@@ -222,16 +250,16 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* List of ServerConnection.
- *
+ *
* Instances added when constructed; removed when terminated.
- *
+ *
* guarded.By {@link #allSCsLock}
*/
private final HashSet allSCs = new HashSet();
/**
* List of ServerConnections, for {@link #emergencyClose()}
- *
+ *
* guarded.By {@link #allSCsLock}
*/
private volatile ServerConnection allSCList[] = new ServerConnection[0];
@@ -239,7 +267,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* The ip address or host name this acceptor is to bind to; <code>null</code> or "" indicates it
* will listen on all local addresses.
- *
+ *
* @since GemFire 5.7
*/
private final String bindHostName;
@@ -249,10 +277,14 @@ public class AcceptorImpl extends Acceptor implements Runnable {
*/
private final ConnectionListener connectionListener;
- /** The client health monitor tracking connections for this acceptor */
+ /**
+ * The client health monitor tracking connections for this acceptor
+ */
private ClientHealthMonitor healthMonitor;
- /** bridge's setting of notifyBySubscription */
+ /**
+ * bridge's setting of notifyBySubscription
+ */
private final boolean notifyBySubscription;
/**
@@ -273,7 +305,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* Initializes this acceptor thread to listen for connections on the given port.
- *
+ *
* @param port The port on which this acceptor listens for connections. If <code>0</code>, a
* random port will be chosen.
* @param bindHostName The ip address or host name this acceptor listens on for connections. If
@@ -284,7 +316,6 @@ public class AcceptorImpl extends Acceptor implements Runnable {
* @param internalCache The GemFire cache whose contents is served to clients
* @param maxConnections the maximum number of connections allowed in the server pool
* @param maxThreads the maximum number of threads allowed in the server pool
- *
* @see SocketCreator#createServerSocket(int, int, InetAddress)
* @see ClientHealthMonitor
* @since GemFire 5.7
@@ -615,7 +646,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* This system property is only used if max-threads == 0. This is for 5.0.2 backwards
* compatibility.
- *
+ *
* @deprecated since 5.1 use cache-server max-threads instead
*/
@Deprecated
@@ -624,7 +655,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* This system property is only used if max-threads == 0. This is for 5.0.2 backwards
* compatibility.
- *
+ *
* @deprecated since 5.1 use cache-server max-threads instead
*/
@Deprecated
@@ -693,7 +724,9 @@ public class AcceptorImpl extends Acceptor implements Runnable {
wakeupSelector();
}
- /** wake up the selector thread */
+ /**
+ * wake up the selector thread
+ */
private void wakeupSelector() {
Selector s = getSelector();
if (s != null && s.isOpen()) {
@@ -760,7 +793,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* Ensure that the CachedRegionHelper and ServerConnection classes get loaded.
- *
+ *
* @see SystemFailure#loadEmergencyClasses()
*/
public static void loadEmergencyClasses() {
@@ -1146,7 +1179,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* The work loop of this acceptor
- *
+ *
* @see #accept
*/
public void run() {
@@ -1369,156 +1402,145 @@ public class AcceptorImpl extends Acceptor implements Runnable {
return this.clientServerCnxCount.get();
}
- protected void handleNewClientConnection(final Socket s) throws IOException {
+ protected void handleNewClientConnection(final Socket socket) throws IOException {
// Read the first byte. If this socket is being used for 'client to server'
// communication, create a ServerConnection. If this socket is being used
// for 'server to client' communication, send it to the CacheClientNotifier
// for processing.
byte communicationMode;
if (isSelector()) {
- ByteBuffer bb = ByteBuffer.allocateDirect(1);
- final SocketChannel sc = s.getChannel();
- sc.configureBlocking(false);
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1);
+ final SocketChannel socketChannel = socket.getChannel();
+ socketChannel.configureBlocking(false);
// try to read the byte first in non-blocking mode
- int res = sc.read(bb);
- sc.configureBlocking(true);
+ int res = socketChannel.read(byteBuffer);
+ socketChannel.configureBlocking(true);
if (res < 0) {
throw new EOFException();
} else if (res == 0) {
// now do a blocking read so setup a timer to close the socket if the
// the read takes too long
- SystemTimer.SystemTimerTask st = new SystemTimer.SystemTimerTask() {
+ SystemTimer.SystemTimerTask timerTask = new SystemTimer.SystemTimerTask() {
@Override
public void run2() {
logger.warn(LocalizedMessage.create(
LocalizedStrings.AcceptorImpl_CACHE_SERVER_TIMED_OUT_WAITING_FOR_HANDSHAKE_FROM__0,
- s.getRemoteSocketAddress()));
- closeSocket(s);
+ socket.getRemoteSocketAddress()));
+ closeSocket(socket);
}
};
- this.hsTimer.schedule(st, this.acceptTimeout);
- res = sc.read(bb);
- if ((!st.cancel()) || res <= 0) {
+ this.hsTimer.schedule(timerTask, this.acceptTimeout);
+ res = socketChannel.read(byteBuffer);
+ if ((!timerTask.cancel()) || res <= 0) {
throw new EOFException();
}
}
- communicationMode = bb.get(0);
- if (logger.isTraceEnabled()) {
- logger.trace("read communications mode(1) ", communicationMode);
- }
+ communicationMode = byteBuffer.get(0);
} else {
- s.setSoTimeout(this.acceptTimeout);
- this.socketCreator.configureServerSSLSocket(s);
- communicationMode = (byte) s.getInputStream().read();
- if (logger.isTraceEnabled()) {
- logger.trace("read communications mode(2) ", communicationMode);
- }
+ socket.setSoTimeout(this.acceptTimeout);
+ this.socketCreator.configureServerSSLSocket(socket);
+ communicationMode = (byte) socket.getInputStream().read();
if (communicationMode == -1) {
throw new EOFException();
}
- s.setSoTimeout(0);
+ socket.setSoTimeout(0);
}
- s.setTcpNoDelay(this.tcpNoDelay);
+ socket.setTcpNoDelay(this.tcpNoDelay);
- if (communicationMode == CLIENT_TO_SERVER || communicationMode == GATEWAY_TO_GATEWAY
- || communicationMode == MONITOR_TO_SERVER || communicationMode == CLIENT_TO_SERVER_FOR_QUEUE
- || communicationMode == CLIENT_TO_SERVER_NEW_PROTOCOL) {
- String communicationModeStr = "";
- switch (communicationMode) {
- case CLIENT_TO_SERVER:
- communicationModeStr = "client";
- break;
- case GATEWAY_TO_GATEWAY:
- communicationModeStr = "gateway";
- break;
- case MONITOR_TO_SERVER:
- communicationModeStr = "monitor";
- break;
- case CLIENT_TO_SERVER_FOR_QUEUE:
- communicationModeStr = "clientToServerForQueue";
- break;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Bridge server: Initializing {} communication socket: {}",
- communicationModeStr, s);
+ String communicationModeStr;
+ switch (communicationMode) {
+ default:
+ throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
+
+ case PRIMARY_SERVER_TO_CLIENT:
+ logger.debug(
+ ":Bridge server: Initializing primary server-to-client communication socket: {}",
+ socket);
+ AcceptorImpl.this.clientNotifier.registerClient(socket, true, this.acceptorId,
+ this.notifyBySubscription);
+ return;
+
+ case SECONDARY_SERVER_TO_CLIENT:
+ logger.debug(
+ ":Bridge server: Initializing secondary server-to-client communication socket: {}",
+ socket);
+ AcceptorImpl.this.clientNotifier.registerClient(socket, false, this.acceptorId,
+ this.notifyBySubscription);
+ return;
+
+ case CLIENT_TO_SERVER:
+ communicationModeStr = "client";
+ break;
+ case GATEWAY_TO_GATEWAY:
+ communicationModeStr = "gateway";
+ break;
+ case MONITOR_TO_SERVER:
+ communicationModeStr = "monitor";
+ break;
+ case CLIENT_TO_SERVER_FOR_QUEUE:
+ communicationModeStr = "clientToServerForQueue";
+ break;
+ case PROTOBUF_CLIENT_SERVER_PROTOCOL:
+ communicationModeStr = "Protobuf client";
+ break;
+ }
+
+ logger.debug("Bridge server: Initializing {} communication socket: {}", communicationModeStr,
+ socket);
+ if (communicationMode != CLIENT_TO_SERVER_FOR_QUEUE) {
+ int curCnt = this.getClientServerCnxCount();
+ if (curCnt >= this.maxConnections) {
+ logger.warn(LocalizedMessage.create(
+ LocalizedStrings.AcceptorImpl_REJECTED_CONNECTION_FROM_0_BECAUSE_CURRENT_CONNECTION_COUNT_OF_1_IS_GREATER_THAN_OR_EQUAL_TO_THE_CONFIGURED_MAX_OF_2,
+ new Object[] {socket.getInetAddress(), Integer.valueOf(curCnt),
+ Integer.valueOf(this.maxConnections)}));
+ try {
+ ServerHandShakeProcessor.refuse(socket.getOutputStream(),
+ LocalizedStrings.AcceptorImpl_EXCEEDED_MAX_CONNECTIONS_0
+ .toLocalizedString(Integer.valueOf(this.maxConnections)));
+ } catch (Exception ex) {
+ logger.debug("rejection message failed", ex);
+ }
+ closeSocket(socket);
+ return;
}
- if (communicationMode != CLIENT_TO_SERVER_FOR_QUEUE) {
- int curCnt = this.getClientServerCnxCount();
- if (curCnt >= this.maxConnections) {
- logger.warn(LocalizedMessage.create(
- LocalizedStrings.AcceptorImpl_REJECTED_CONNECTION_FROM_0_BECAUSE_CURRENT_CONNECTION_COUNT_OF_1_IS_GREATER_THAN_OR_EQUAL_TO_THE_CONFIGURED_MAX_OF_2,
- new Object[] {s.getInetAddress(), Integer.valueOf(curCnt),
- Integer.valueOf(this.maxConnections)}));
- // if (s != null) (cannot be null)
- {
- try {
- ServerHandShakeProcessor.refuse(s.getOutputStream(),
- LocalizedStrings.AcceptorImpl_EXCEEDED_MAX_CONNECTIONS_0
- .toLocalizedString(Integer.valueOf(this.maxConnections)));
- } catch (Exception ex) {
- if (logger.isDebugEnabled()) {
- logger.debug("rejection message failed", ex);
- }
- }
- closeSocket(s);
- }
+ }
+
+ ServerConnection serverConn = ServerConnectionFactory.makeServerConnection(socket, this.cache,
+ this.crHelper, this.stats, AcceptorImpl.handShakeTimeout, this.socketBufferSize,
+ communicationModeStr, communicationMode, this, this.securityService);
+
+ synchronized (this.allSCsLock) {
+ this.allSCs.add(serverConn);
+ ServerConnection snap[] = this.allSCList; // avoid volatile read
+ this.allSCList = (ServerConnection[]) ArrayUtils.insert(snap, snap.length, serverConn);
+ }
+ if (communicationMode != CLIENT_TO_SERVER_FOR_QUEUE) {
+ incClientServerCnxCount();
+ }
+ if (isSelector()) {
+ serverConn.registerWithSelector();
+ } else {
+ try {
+ pool.execute(serverConn);
+ } catch (RejectedExecutionException rejected) {
+ if (!isRunning()) {
return;
}
- }
- ServerConnection serverConn = ServerConnectionFactory.makeServerConnection(s, this.cache,
- this.crHelper, this.stats, AcceptorImpl.handShakeTimeout, this.socketBufferSize,
- communicationModeStr, communicationMode, this, this.securityService);
- synchronized (this.allSCsLock) {
- this.allSCs.add(serverConn);
- ServerConnection snap[] = this.allSCList; // avoid volatile read
- this.allSCList = (ServerConnection[]) ArrayUtils.insert(snap, snap.length, serverConn);
- }
- if (communicationMode != CLIENT_TO_SERVER_FOR_QUEUE) {
- incClientServerCnxCount();
- }
- if (isSelector()) {
- serverConn.registerWithSelector();
- } else {
+ logger.warn(LocalizedMessage.create(
+ LocalizedStrings.AcceptorImpl_REJECTED_CONNECTION_FROM_0_BECAUSE_REQUEST_REJECTED_BY_POOL,
+ new Object[] {serverConn}));
try {
- pool.execute(serverConn);
- } catch (RejectedExecutionException rejected) {
- if (!isRunning()) {
- return;
- }
- logger.warn(LocalizedMessage.create(
- LocalizedStrings.AcceptorImpl_REJECTED_CONNECTION_FROM_0_BECAUSE_REQUEST_REJECTED_BY_POOL,
- new Object[] {serverConn}));
- try {
- ServerHandShakeProcessor.refuse(s.getOutputStream(),
- LocalizedStrings.AcceptorImpl_EXCEEDED_MAX_CONNECTIONS_0
- .toLocalizedString(Integer.valueOf(this.maxConnections)));
+ ServerHandShakeProcessor.refuse(socket.getOutputStream(),
+ LocalizedStrings.AcceptorImpl_EXCEEDED_MAX_CONNECTIONS_0
+ .toLocalizedString(Integer.valueOf(this.maxConnections)));
- } catch (Exception ex) {
- if (logger.isDebugEnabled()) {
- logger.debug("rejection message failed", ex);
- }
- }
- serverConn.cleanup();
+ } catch (Exception ex) {
+ logger.debug("rejection message failed", ex);
}
+ serverConn.cleanup();
}
- } else if (communicationMode == PRIMARY_SERVER_TO_CLIENT) {
- if (logger.isDebugEnabled()) {
- logger.debug(
- ":Bridge server: Initializing primary server-to-client communication socket: {}", s);
- }
- // try {
- AcceptorImpl.this.clientNotifier.registerClient(s, true, this.acceptorId,
- this.notifyBySubscription);
- } else if (communicationMode == SECONDARY_SERVER_TO_CLIENT) {
- if (logger.isDebugEnabled()) {
- logger.debug(
- ":Bridge server: Initializing secondary server-to-client communication socket: {}", s);
- }
- AcceptorImpl.this.clientNotifier.registerClient(s, false, this.acceptorId,
- this.notifyBySubscription);
- } else {
- throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
}
}
@@ -1645,7 +1667,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
* then calculate it.
* @return the ip address or host name this acceptor will listen on. An "" if all local addresses
* will be listened to.
- *
+ *
* @since GemFire 5.7
*/
private static String calcBindHostName(Cache cache, String bindName) {
@@ -1682,7 +1704,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* Gets the address that this bridge server can be contacted on from external processes.
- *
+ *
* @since GemFire 5.7
*/
public String getExternalAddress() {
@@ -1716,7 +1738,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
/**
* This method finds a client notifier and returns it. It is used to propagate interest
* registrations to other servers
- *
+ *
* @return the instance that provides client notification
*/
public CacheClientNotifier getCacheClientNotifier() {
@@ -1773,7 +1795,7 @@ public class AcceptorImpl extends Acceptor implements Runnable {
* This method returns a thread safe structure which can be iterated over without worrying about
* ConcurrentModificationException. JMX MBeans/Commands need to iterate over this list to get
* client info.
- *
+ *
*/
public ServerConnection[] getAllServerConnectionList() {
return this.allSCList;
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/GenericProtocolServerConnection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/GenericProtocolServerConnection.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/GenericProtocolServerConnection.java
new file mode 100644
index 0000000..8edd83c
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/GenericProtocolServerConnection.java
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.internal.cache.tier.CachedRegionHelper;
+import org.apache.geode.internal.security.SecurityService;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+/**
+ * Holds the socket and protocol handler for the new client protocol. TODO: Currently unimplemented
+ * due the the protocol not being there.
+ */
+public class GenericProtocolServerConnection extends ServerConnection {
+ // The new protocol lives in a separate module and gets loaded when this class is instantiated.
+ // TODO implement this.
+ private final ClientProtocolMessageHandler messageHandler;
+
+ /**
+ * Creates a new <code>GenericProtocolServerConnection</code> that processes messages received
+ * from an edge client over a given <code>Socket</code>.
+ *
+ * @param s
+ * @param c
+ * @param helper
+ * @param stats
+ * @param hsTimeout
+ * @param socketBufferSize
+ * @param communicationModeStr
+ * @param communicationMode
+ * @param acceptor
+ */
+ public GenericProtocolServerConnection(Socket s, InternalCache c, CachedRegionHelper helper,
+ CacheServerStats stats, int hsTimeout, int socketBufferSize, String communicationModeStr,
+ byte communicationMode, Acceptor acceptor, ClientProtocolMessageHandler newClientProtocol,
+ SecurityService securityService) {
+ super(s, c, helper, stats, hsTimeout, socketBufferSize, communicationModeStr, communicationMode,
+ acceptor, securityService);
+ this.messageHandler = newClientProtocol;
+ }
+
+ @Override
+ protected void doOneMessage() {
+ try {
+ Socket socket = this.getSocket();
+ InputStream inputStream = socket.getInputStream();
+ OutputStream outputStream = socket.getOutputStream();
+
+ // TODO serialization types?
+ messageHandler.receiveMessage(inputStream, outputStream, this.getCache());
+ } catch (IOException e) {
+ // TODO?
+ }
+ return;
+ }
+
+ @Override
+ protected boolean doHandShake(byte epType, int qSize) {
+ // no handshake for new client protocol.
+ return true;
+ }
+
+ @Override
+ public boolean isClientServerConnection() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
deleted file mode 100644
index 83b23b1..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.internal.cache.tier.sockets;
-
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.cache.tier.Acceptor;
-import org.apache.geode.internal.cache.tier.CachedRegionHelper;
-import org.apache.geode.internal.security.SecurityService;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-
-/**
- * Holds the socket and protocol handler for the new client protocol. TODO: Currently unimplemented
- * due the the protocol not being there.
- */
-public class NewProtocolServerConnection extends ServerConnection {
- // The new protocol lives in a separate module and gets loaded when this class is instantiated.
- // TODO implement this.
- private final ClientProtocolMessageHandler newClientProtocol;
-
-
- /**
- * Creates a new <code>NewProtocolServerConnection</code> that processes messages received from an
- * edge client over a given <code>Socket</code>.
- *
- * @param s
- * @param c
- * @param helper
- * @param stats
- * @param hsTimeout
- * @param socketBufferSize
- * @param communicationModeStr
- * @param communicationMode
- * @param acceptor
- */
- public NewProtocolServerConnection(Socket s, InternalCache c, CachedRegionHelper helper,
- CacheServerStats stats, int hsTimeout, int socketBufferSize, String communicationModeStr,
- byte communicationMode, Acceptor acceptor, ClientProtocolMessageHandler newClientProtocol,
- SecurityService securityService) {
- super(s, c, helper, stats, hsTimeout, socketBufferSize, communicationModeStr, communicationMode,
- acceptor, securityService);
- assert (communicationMode == AcceptorImpl.CLIENT_TO_SERVER_NEW_PROTOCOL);
- this.newClientProtocol = newClientProtocol;
- }
-
- @Override
- protected void doOneMessage() {
- try {
- Socket socket = this.getSocket();
- InputStream inputStream = socket.getInputStream();
- OutputStream outputStream = socket.getOutputStream();
-
- // TODO serialization types?
- newClientProtocol.receiveMessage(inputStream, outputStream, this.getCache());
- } catch (IOException e) {
- // TODO?
- }
- return;
- }
-
- @Override
- protected boolean doHandShake(byte epType, int qSize) {
- // no handshake for new client protocol.
- return true;
- }
-
- @Override
- public boolean isClientServerConnection() {
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
index 4f2e304..e4746a7 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
@@ -28,19 +28,20 @@ import java.net.Socket;
*/
public class ServerConnectionFactory {
// TODO: implement ClientProtocolMessageHandler.
- private static final ClientProtocolMessageHandler newClientProtocol =
+ private static final ClientProtocolMessageHandler protobufProtocolHandler =
new ClientProtocolMessageHandler();
public static ServerConnection makeServerConnection(Socket s, InternalCache c,
CachedRegionHelper helper, CacheServerStats stats, int hsTimeout, int socketBufferSize,
String communicationModeStr, byte communicationMode, Acceptor acceptor,
SecurityService securityService) throws IOException {
- if (communicationMode == Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL) {
+ if (communicationMode == Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL) {
if (!Boolean.getBoolean("geode.feature-protobuf-protocol")) {
throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
} else {
- return new NewProtocolServerConnection(s, c, helper, stats, hsTimeout, socketBufferSize,
- communicationModeStr, communicationMode, acceptor, newClientProtocol, securityService);
+ return new GenericProtocolServerConnection(s, c, helper, stats, hsTimeout, socketBufferSize,
+ communicationModeStr, communicationMode, acceptor, protobufProtocolHandler,
+ securityService);
}
} else {
return new LegacyServerConnection(s, c, helper, stats, hsTimeout, socketBufferSize,
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
index 007d1d6..82c4e54 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
@@ -15,6 +15,8 @@
package org.apache.geode.internal.cache.tier.sockets;
+import static org.junit.Assert.assertEquals;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.server.CacheServer;
@@ -22,45 +24,42 @@ import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.tier.Acceptor;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.awaitility.Awaitility;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.experimental.categories.Category;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertEquals;
-
/**
- * Test that switching on the header byte makes instances of {@link NewProtocolServerConnection}.
+ * Test that switching on the header byte makes instances of
+ * {@link GenericProtocolServerConnection}.
*/
@Category(IntegrationTest.class)
public class ServerConnectionFactoryIntegrationTest {
- /**
- *
- * @throws IOException
- */
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
@Test
public void testNewProtocolHeaderLeadsToNewProtocolServerConnection() throws IOException {
System.setProperty("geode.feature-protobuf-protocol", "true");
- try {
- CacheFactory cacheFactory = new CacheFactory();
- Cache cache = cacheFactory.create();
+ CacheFactory cacheFactory = new CacheFactory();
+ Cache cache = cacheFactory.create();
- CacheServer cacheServer = cache.addCacheServer();
- final int cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
- cacheServer.setPort(cacheServerPort);
- cacheServer.start();
+ CacheServer cacheServer = cache.addCacheServer();
+ final int cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
+ cacheServer.setPort(cacheServerPort);
+ cacheServer.start();
- Socket socket = new Socket("localhost", cacheServerPort);
- Awaitility.await().atMost(5, TimeUnit.SECONDS).until(socket::isConnected);
- socket.getOutputStream().write(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
- socket.getOutputStream().write(222);
- assertEquals(222, socket.getInputStream().read());
+ Socket socket = new Socket("localhost", cacheServerPort);
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(socket::isConnected);
+ socket.getOutputStream().write(Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
+ socket.getOutputStream().write(222);
+ assertEquals(222, socket.getInputStream().read());
- cache.close();
- } finally {
- System.clearProperty("geode.feature-protobuf-protocol");
- }
+ cache.close();
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/c71c28df/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
index 8e241b2..11b5289 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
@@ -39,16 +39,19 @@ public class ServerConnectionFactoryTest {
*/
@Test(expected = IOException.class)
public void newClientProtocolThrows() throws Exception {
- serverConnectionMockedExceptForCommunicationMode(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
+ serverConnectionMockedExceptForCommunicationMode(Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
}
@Test
public void newClientProtocolSucceedsWithSystemPropertySet() throws Exception {
- System.setProperty("geode.feature-protobuf-protocol", "true");
- ServerConnection serverConnection =
- serverConnectionMockedExceptForCommunicationMode(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
- assertTrue(serverConnection instanceof NewProtocolServerConnection);
- System.clearProperty("geode.feature-protobuf-protocol");
+ try {
+ System.setProperty("geode.feature-protobuf-protocol", "true");
+ ServerConnection serverConnection = serverConnectionMockedExceptForCommunicationMode(
+ Acceptor.PROTOBUF_CLIENT_SERVER_PROTOCOL);
+ assertTrue(serverConnection instanceof GenericProtocolServerConnection);
+ } finally {
+ System.clearProperty("geode.feature-protobuf-protocol");
+ }
}
@Test
[07/13] geode git commit: GEODE-3075: Add an integration test for the
ServerConnectionFactory
Posted by hi...@apache.org.
GEODE-3075: Add an integration test for the ServerConnectionFactory
the current implementation is bogus, but does test that the flow works.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/4ace36af
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/4ace36af
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/4ace36af
Branch: refs/heads/develop
Commit: 4ace36af00a22e0995a2e0d07db75f5508524a25
Parents: dfdde4a
Author: Galen OSullivan <go...@pivotal.io>
Authored: Fri Jun 16 09:59:11 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Mon Jun 26 09:26:22 2017 -0700
----------------------------------------------------------------------
.../sockets/ClientProtocolMessageHandler.java | 8 ++-
.../sockets/NewProtocolServerConnection.java | 7 ++-
.../ServerConnectionFactoryIntegrationTest.java | 66 ++++++++++++++++++++
.../sockets/ServerConnectionFactoryTest.java | 44 ++++++-------
4 files changed, 100 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/4ace36af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
index db42330..702609d 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProtocolMessageHandler.java
@@ -17,6 +17,7 @@ package org.apache.geode.internal.cache.tier.sockets;
import org.apache.geode.internal.cache.InternalCache;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -24,6 +25,11 @@ import java.io.OutputStream;
* Stub, this will be hooked up to the new client protocol when it's implemented.
*/
public class ClientProtocolMessageHandler {
+ /**
+ * Bogus, but it lets us write an integration test so that nobody breaks our flow.
+ */
public void receiveMessage(InputStream inputStream, OutputStream outputStream,
- InternalCache cache) {}
+ InternalCache cache) throws IOException {
+ outputStream.write(inputStream.read());
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/4ace36af/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
index a78cd1c..83b23b1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/NewProtocolServerConnection.java
@@ -50,9 +50,9 @@ public class NewProtocolServerConnection extends ServerConnection {
* @param acceptor
*/
public NewProtocolServerConnection(Socket s, InternalCache c, CachedRegionHelper helper,
- CacheServerStats stats, int hsTimeout, int socketBufferSize, String communicationModeStr,
- byte communicationMode, Acceptor acceptor, ClientProtocolMessageHandler newClientProtocol,
- SecurityService securityService) {
+ CacheServerStats stats, int hsTimeout, int socketBufferSize, String communicationModeStr,
+ byte communicationMode, Acceptor acceptor, ClientProtocolMessageHandler newClientProtocol,
+ SecurityService securityService) {
super(s, c, helper, stats, hsTimeout, socketBufferSize, communicationModeStr, communicationMode,
acceptor, securityService);
assert (communicationMode == AcceptorImpl.CLIENT_TO_SERVER_NEW_PROTOCOL);
@@ -65,6 +65,7 @@ public class NewProtocolServerConnection extends ServerConnection {
Socket socket = this.getSocket();
InputStream inputStream = socket.getInputStream();
OutputStream outputStream = socket.getOutputStream();
+
// TODO serialization types?
newClientProtocol.receiveMessage(inputStream, outputStream, this.getCache());
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/geode/blob/4ace36af/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
new file mode 100644
index 0000000..007d1d6
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryIntegrationTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.internal.cache.tier.sockets;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.awaitility.Awaitility;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test that switching on the header byte makes instances of {@link NewProtocolServerConnection}.
+ */
+@Category(IntegrationTest.class)
+public class ServerConnectionFactoryIntegrationTest {
+ /**
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testNewProtocolHeaderLeadsToNewProtocolServerConnection() throws IOException {
+ System.setProperty("geode.feature-protobuf-protocol", "true");
+ try {
+ CacheFactory cacheFactory = new CacheFactory();
+ Cache cache = cacheFactory.create();
+
+ CacheServer cacheServer = cache.addCacheServer();
+ final int cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
+ cacheServer.setPort(cacheServerPort);
+ cacheServer.start();
+
+ Socket socket = new Socket("localhost", cacheServerPort);
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(socket::isConnected);
+ socket.getOutputStream().write(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
+ socket.getOutputStream().write(222);
+ assertEquals(222, socket.getInputStream().read());
+
+ cache.close();
+ } finally {
+ System.clearProperty("geode.feature-protobuf-protocol");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/4ace36af/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
index c314944..8e241b2 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactoryTest.java
@@ -19,18 +19,23 @@ import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.tier.Acceptor;
import org.apache.geode.internal.cache.tier.CachedRegionHelper;
import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.test.junit.categories.UnitTest;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+@Category(UnitTest.class)
public class ServerConnectionFactoryTest {
/**
- * Safeguard that we won't create the new client protocol object unless the feature flag is enabled.
+ * Safeguard that we won't create the new client protocol object unless the feature flag is
+ * enabled.
*/
@Test(expected = IOException.class)
public void newClientProtocolThrows() throws Exception {
@@ -40,38 +45,35 @@ public class ServerConnectionFactoryTest {
@Test
public void newClientProtocolSucceedsWithSystemPropertySet() throws Exception {
System.setProperty("geode.feature-protobuf-protocol", "true");
- ServerConnection serverConnection = serverConnectionMockedExceptForCommunicationMode(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
+ ServerConnection serverConnection =
+ serverConnectionMockedExceptForCommunicationMode(Acceptor.CLIENT_TO_SERVER_NEW_PROTOCOL);
assertTrue(serverConnection instanceof NewProtocolServerConnection);
System.clearProperty("geode.feature-protobuf-protocol");
}
@Test
public void makeServerConnection() throws Exception {
- byte[] communicationModes = new byte[]{
- Acceptor.CLIENT_TO_SERVER,
- Acceptor.PRIMARY_SERVER_TO_CLIENT,
- Acceptor.SECONDARY_SERVER_TO_CLIENT,
- Acceptor.GATEWAY_TO_GATEWAY,
- Acceptor.MONITOR_TO_SERVER,
- Acceptor.SUCCESSFUL_SERVER_TO_CLIENT,
- Acceptor.UNSUCCESSFUL_SERVER_TO_CLIENT,
- Acceptor.CLIENT_TO_SERVER_FOR_QUEUE,
- };
+ byte[] communicationModes =
+ new byte[] {Acceptor.CLIENT_TO_SERVER, Acceptor.PRIMARY_SERVER_TO_CLIENT,
+ Acceptor.SECONDARY_SERVER_TO_CLIENT, Acceptor.GATEWAY_TO_GATEWAY,
+ Acceptor.MONITOR_TO_SERVER, Acceptor.SUCCESSFUL_SERVER_TO_CLIENT,
+ Acceptor.UNSUCCESSFUL_SERVER_TO_CLIENT, Acceptor.CLIENT_TO_SERVER_FOR_QUEUE,};
for (byte communicationMode : communicationModes) {
- ServerConnection serverConnection = serverConnectionMockedExceptForCommunicationMode(communicationMode);
+ ServerConnection serverConnection =
+ serverConnectionMockedExceptForCommunicationMode(communicationMode);
assertTrue(serverConnection instanceof LegacyServerConnection);
}
}
- private static ServerConnection serverConnectionMockedExceptForCommunicationMode(byte communicationMode) throws IOException {
+ private static ServerConnection serverConnectionMockedExceptForCommunicationMode(
+ byte communicationMode) throws IOException {
Socket socketMock = mock(Socket.class);
when(socketMock.getInetAddress()).thenReturn(InetAddress.getByName("localhost"));
- return ServerConnectionFactory.makeServerConnection(
- socketMock, mock(InternalCache.class), mock(CachedRegionHelper.class),
- mock(CacheServerStats.class), 0, 0, "",
- communicationMode, mock(AcceptorImpl.class), mock(SecurityService.class));
+ return ServerConnectionFactory.makeServerConnection(socketMock, mock(InternalCache.class),
+ mock(CachedRegionHelper.class), mock(CacheServerStats.class), 0, 0, "", communicationMode,
+ mock(AcceptorImpl.class), mock(SecurityService.class));
}
-}
\ No newline at end of file
+}