geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject [32/46] geode git commit: GEODE-3075: Add an integration test for the ServerConnectionFactory
Date Tue, 27 Jun 2017 05:00:47 GMT
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/feature/GEM-1483
Commit: 4ace36af00a22e0995a2e0d07db75f5508524a25
Parents: dfdde4a
Author: Galen OSullivan <gosullivan@pivotal.io>
Authored: Fri Jun 16 09:59:11 2017 -0700
Committer: Hitesh Khamesra <hkhamesra@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
+}


Mime
View raw message