This is an automated email from the ASF dual-hosted git repository.
mivanac 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 c4ab763dea GEODE-10336: set lastInstance to null (#7843)
c4ab763dea is described below
commit c4ab763dea39328ba276e8c527bf531050f20cde
Author: Mario Ivanac <[email protected]>
AuthorDate: Fri Sep 9 08:05:51 2022 +0200
GEODE-10336: set lastInstance to null (#7843)
* GEODE-10336: set lastInstance to null
* GEODE-10336: added test
---
.../apache/geode/internal/tcp/ConnectionTable.java | 6 ++++++
.../geode/internal/tcp/ConnectionTableTest.java | 21 ++++++++++++++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
b/geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
index f1d157d27f..0a4cf5f8dd 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/tcp/ConnectionTable.java
@@ -655,6 +655,7 @@ public class ConnectionTable {
map.clear();
}
socketCloser.close();
+ emergencyClose();
}
public void executeCommand(Runnable runnable) {
@@ -1025,6 +1026,11 @@ public class ConnectionTable {
return receivers.size();
}
+ static boolean checkLastInstanceIsNull() {
+ ConnectionTable ct = lastInstance.get();
+ return ct == null;
+ }
+
private class PendingConnection {
/**
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/tcp/ConnectionTableTest.java
b/geode-core/src/test/java/org/apache/geode/internal/tcp/ConnectionTableTest.java
index 06112f73c1..31c9c3f20e 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/tcp/ConnectionTableTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/tcp/ConnectionTableTest.java
@@ -14,7 +14,7 @@
*/
package org.apache.geode.internal.tcp;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -74,7 +74,10 @@ public class ConnectionTableTest {
when(connection.isSocketClosed()).thenReturn(true);
connectionTable.acceptConnection(socket, factory);
- assertEquals(0, connectionTable.getNumberOfReceivers());
+ assertThat(connectionTable.getNumberOfReceivers()).isEqualTo(0);
+
+ connectionTable.close();
+ assertThat(ConnectionTable.checkLastInstanceIsNull()).isTrue();
}
@Test
@@ -86,7 +89,10 @@ public class ConnectionTableTest {
when(connection.isReceiverStopped()).thenReturn(true);
connectionTable.acceptConnection(socket, factory);
- assertEquals(0, connectionTable.getNumberOfReceivers());
+ assertThat(connectionTable.getNumberOfReceivers()).isEqualTo(0);
+
+ connectionTable.close();
+ assertThat(ConnectionTable.checkLastInstanceIsNull()).isTrue();
}
@Test
@@ -95,7 +101,10 @@ public class ConnectionTableTest {
when(connection.isSocketClosed()).thenReturn(false);
connectionTable.acceptConnection(socket, factory);
- assertEquals(1, connectionTable.getNumberOfReceivers());
+ assertThat(connectionTable.getNumberOfReceivers()).isEqualTo(1);
+
+ connectionTable.close();
+ assertThat(ConnectionTable.checkLastInstanceIsNull()).isTrue();
}
@Test
@@ -106,11 +115,13 @@ public class ConnectionTableTest {
Map<DistributedMember, Connection> threadConnectionMap = new HashMap<>();
ConnectionTable.threadOrderedConnMap.set(threadConnectionMap);
ConnectionTable.releaseThreadsSockets();
- assertEquals(0, threadConnectionMap.size());
+ assertThat(threadConnectionMap.size()).isEqualTo(0);
} finally {
if (wantsResources != Boolean.FALSE) {
ConnectionTable.threadWantsSharedResources();
}
}
+ connectionTable.close();
+ assertThat(ConnectionTable.checkLastInstanceIsNull()).isTrue();
}
}