You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2017/06/13 20:05:46 UTC
geode git commit: GEODE-2995: Handle some refactoring (package
renaming)
Repository: geode
Updated Branches:
refs/heads/feature/GEODE-2995 e3af5a42c -> 51fccbb0d
GEODE-2995: Handle some refactoring (package renaming)
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/51fccbb0
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/51fccbb0
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/51fccbb0
Branch: refs/heads/feature/GEODE-2995
Commit: 51fccbb0d20207287fa8d1d3f6c11dd300525b17
Parents: e3af5a4
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Tue Jun 13 13:05:42 2017 -0700
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Tue Jun 13 13:05:42 2017 -0700
----------------------------------------------------------------------
.../protobuf/ProtobufProtocolHandler.java | 43 ++++++++++
.../client/protocol/OpsHandlerRegistry.java | 24 ------
.../protocol/ProtobufProtocolHandlerTest.java | 86 -------------------
.../ProtobufRequestOperationParser.java | 31 +++++++
.../handler/ProtobufProtocolHandlerTest.java | 87 ++++++++++++++++++++
5 files changed, 161 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/51fccbb0/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..84fc50f
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/handler/protobuf/ProtobufProtocolHandler.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geode.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/51fccbb0/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandlerRegistry.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandlerRegistry.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandlerRegistry.java
deleted file mode 100644
index 3fdd1bc..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsHandlerRegistry.java
+++ /dev/null
@@ -1,24 +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;
-
-/**
- * Created by ukohlmeyer on 6/12/17.
- */
-public interface OpsHandlerRegistry<T> {
- public OpsHandler getOpsHandler(T operationCode);
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/51fccbb0/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java
deleted file mode 100644
index a0c9a62..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufProtocolHandlerTest.java
+++ /dev/null
@@ -1,86 +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.client.protocol.exception.InvalidProtocolMessageException;
-import org.apache.geode.client.protocol.handler.ProtocolHandler;
-import org.apache.geode.client.protocol.handler.protobuf.ProtobufProtocolHandler;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ServiceLoader;
-
-public class ProtobufProtocolHandlerTest {
- private ProtocolHandler protocolHandler;
-
- @Before
- public void startup() {
- ServiceLoader<ProtocolHandler> serviceLoader = ServiceLoader.load(ProtocolHandler.class);
- for (ProtocolHandler protocolHandler : serviceLoader) {
- if (protocolHandler instanceof ProtobufProtocolHandler) {
- this.protocolHandler = protocolHandler;
- }
- }
- }
-
- @Test
- public void testDeserializeByteArrayToMessage()
- throws IOException, InvalidProtocolMessageException {
- ClientProtocol.Message expectedRequestMessage = MessageUtil.createGetRequestMessage();
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
- expectedRequestMessage.writeDelimitedTo(byteArrayOutputStream);
- InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-
- ClientProtocol.Message actualMessage = (ClientProtocol.Message) protocolHandler.deserialize(inputStream);
- Assert.assertEquals(expectedRequestMessage, actualMessage);
- }
-
- @Test
- public void testDeserializeInvalidByteThrowsException() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- byteArrayOutputStream.write("Some incorrect byte array".getBytes());
- InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-
- boolean caughtException = false;
- try {
- protocolHandler.deserialize(inputStream);
- } catch (InvalidProtocolMessageException e) {
- caughtException = true;
- }
- Assert.assertTrue(caughtException);
- }
-
- @Test
- public void testSerializeMessageToByteArray() throws IOException {
- ClientProtocol.Message message = MessageUtil.createGetRequestMessage();
- ByteArrayOutputStream expectedByteArrayOutputStream = new ByteArrayOutputStream();
- message.writeDelimitedTo(expectedByteArrayOutputStream);
- byte[] expectedByteArray = expectedByteArrayOutputStream.toByteArray();
-
- ByteArrayOutputStream actualByteArrayOutputStream = new ByteArrayOutputStream();
- protocolHandler.serialize(message, actualByteArrayOutputStream);
- Assert.assertArrayEquals(expectedByteArray,actualByteArrayOutputStream.toByteArray());
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/51fccbb0/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.java
new file mode 100644
index 0000000..9f04fcb
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/ProtobufRequestOperationParser.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.client.protocol;
+
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+
+class ProtobufRequestOperationParser {
+ static Object getRequestForOperationTypeID(ClientProtocol.Request request) {
+ switch (request.getRequestAPICase()) {
+ case PUTREQUEST: return request.getPutRequest();
+ case GETREQUEST: return request.getGetRequest();
+ default:
+ throw new RuntimeException(
+ "Unknown request type: " + request.getRequestAPICase().getNumber());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/51fccbb0/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java
new file mode 100644
index 0000000..e8ffd87
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/handler/ProtobufProtocolHandlerTest.java
@@ -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.
+ */
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ServiceLoader;
+
+public class ProtobufProtocolHandlerTest {
+ private ProtocolHandler<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());
+ }
+}