You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bo...@apache.org on 2018/01/24 23:17:42 UTC

[geode] branch develop updated: GEODE-4358: Added check for null updater

This is an automated email from the ASF dual-hosted git repository.

boglesby pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new ee9b51b  GEODE-4358: Added check for null updater
ee9b51b is described below

commit ee9b51b3d6693a21ad95d1e8d85b331aba81b917
Author: Barry Oglesby <bo...@users.noreply.github.com>
AuthorDate: Wed Jan 24 15:17:37 2018 -0800

    GEODE-4358: Added check for null updater
---
 .../cache/client/internal/QueueConnectionImpl.java |  4 +-
 .../cache/client/internal/QueueManagerImpl.java    |  6 ++-
 .../internal/QueueConnectionImplJUnitTest.java     | 47 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueConnectionImpl.java b/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueConnectionImpl.java
index 47e0503..c6f138d 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueConnectionImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueConnectionImpl.java
@@ -73,7 +73,9 @@ public class QueueConnectionImpl implements Connection {
     try {
       getConnection().close(keepAlive);
     } finally {
-      updater.close();
+      if (updater != null) {
+        updater.close();
+      }
     }
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java b/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
index 9431ade..b655de9 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
@@ -1030,8 +1030,10 @@ public class QueueManagerImpl implements QueueManager {
       try {
         connection.internalClose(pool.getKeepAlive());
       } catch (Exception e) {
-        logger.warn("Error destroying client to server connection to {}", connection.getEndpoint(),
-            e);
+        if (logger.isDebugEnabled()) {
+          logger.debug("Error destroying client to server connection to {}",
+              connection.getEndpoint(), e);
+        }
       }
     }
 
diff --git a/geode-core/src/test/java/org/apache/geode/cache/client/internal/QueueConnectionImplJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/client/internal/QueueConnectionImplJUnitTest.java
new file mode 100644
index 0000000..05e1b08
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/client/internal/QueueConnectionImplJUnitTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.cache.client.internal;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category({UnitTest.class, ClientServerTest.class})
+public class QueueConnectionImplJUnitTest {
+
+  @Test
+  public void testInternalDestroyFollowedByInternalClose() throws Exception {
+    // Mock ClientUpdater and Connection
+    ClientUpdater updater = mock(ClientUpdater.class);
+    Connection connection = mock(Connection.class);
+
+    // Create a QueueConnectionImpl on the mocks
+    QueueConnectionImpl qci = new QueueConnectionImpl(null, connection, updater, null);
+
+    // Invoke internalDestroy (which sets the updater to null)
+    qci.internalDestroy();
+
+    // Assert that invoking internalClose throws a ConnectionDestroyedException and not a
+    // NullPointerException
+    assertThatThrownBy(() -> qci.internalClose(false))
+        .isInstanceOf(ConnectionDestroyedException.class);
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
boglesby@apache.org.