You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by go...@apache.org on 2018/12/13 21:55:38 UTC
[geode] branch develop updated: Geode-5793: LocatorDUnitTest.
testNonSSLLocatorDiesWhenConnectingToSSLLocator (#2654)
This is an automated email from the ASF dual-hosted git repository.
gosullivan 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 0b87a36 Geode-5793: LocatorDUnitTest. testNonSSLLocatorDiesWhenConnectingToSSLLocator (#2654)
0b87a36 is described below
commit 0b87a36357c0a9b1343acc7b17d460cc8cd546f0
Author: mhansonp <mh...@pivotal.io>
AuthorDate: Thu Dec 13 13:55:29 2018 -0800
Geode-5793: LocatorDUnitTest. testNonSSLLocatorDiesWhenConnectingToSSLLocator (#2654)
* Refactoring
* Rethrow `LocatorCancelException` during `startLocator` rather than swallowing.
* address some timing issues
---
...tServerHostNameVerificationDistributedTest.java | 73 +-
.../apache/geode/distributed/LocatorDUnitTest.java | 1538 +++++++++-----------
.../distributed/LocatorUDPSecurityDUnitTest.java | 27 +-
.../TcpServerBackwardCompatDUnitTest.java | 189 +--
.../geode/internal/cache/GridAdvisorDUnitTest.java | 1340 ++++++-----------
.../geode/distributed/DistributedSystem.java | 2 +-
.../distributed/internal/InternalLocator.java | 14 +-
.../distributed/internal/tcpserver/TcpClient.java | 55 +-
.../distributed/internal/tcpserver/TcpServer.java | 4 +-
9 files changed, 1296 insertions(+), 1946 deletions(-)
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/cache/client/internal/ClientServerHostNameVerificationDistributedTest.java b/geode-core/src/distributedTest/java/org/apache/geode/cache/client/internal/ClientServerHostNameVerificationDistributedTest.java
index 2e48755..eda8d9c 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/cache/client/internal/ClientServerHostNameVerificationDistributedTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/cache/client/internal/ClientServerHostNameVerificationDistributedTest.java
@@ -40,19 +40,12 @@ import org.apache.geode.cache.ssl.TestSSLUtils.CertificateBuilder;
import org.apache.geode.distributed.internal.tcpserver.LocatorCancelException;
import org.apache.geode.internal.net.SocketCreatorFactory;
import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.rules.ClientVM;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.categories.ClientServerTest;
@Category({ClientServerTest.class})
public class ClientServerHostNameVerificationDistributedTest {
- private static MemberVM locator;
- private static MemberVM locator2;
- private static MemberVM server;
- private static MemberVM server2;
- private static ClientVM client;
-
@Rule
public ClusterStartupRule cluster = new ClusterStartupRule();
@@ -151,7 +144,8 @@ public class ClientServerHostNameVerificationDistributedTest {
private void validateClientConnection(CertificateBuilder locatorCertificate,
CertificateBuilder serverCertificate, CertificateBuilder clientCertificate,
boolean enableHostNameVerficiationForLocator, boolean enableHostNameVerificationForServer,
- boolean enableHostNameVerificationForClient, Class expectedExceptionOnClient)
+ boolean enableHostNameVerificationForClient,
+ Class<? extends Throwable> expectedExceptionOnClient)
throws GeneralSecurityException, IOException {
CertStores locatorStore = CertStores.locatorStore();
locatorStore.withCertificate(locatorCertificate);
@@ -180,10 +174,10 @@ public class ClientServerHostNameVerificationDistributedTest {
.propertiesWith(ALL, true, enableHostNameVerificationForClient);
// create a cluster
- locator = cluster.startLocatorVM(0, locatorSSLProps);
- locator2 = cluster.startLocatorVM(1, locatorSSLProps, locator.getPort());
- server = cluster.startServerVM(2, serverSSLProps, locator.getPort());
- server2 = cluster.startServerVM(3, serverSSLProps, locator.getPort());
+ MemberVM locator = cluster.startLocatorVM(0, locatorSSLProps);
+ MemberVM locator2 = cluster.startLocatorVM(1, locatorSSLProps, locator.getPort());
+ MemberVM server = cluster.startServerVM(2, serverSSLProps, locator.getPort());
+ MemberVM server2 = cluster.startServerVM(3, serverSSLProps, locator.getPort());
// create region
server.invoke(ClientServerHostNameVerificationDistributedTest::createServerRegion);
@@ -198,35 +192,32 @@ public class ClientServerHostNameVerificationDistributedTest {
clientCacheFactory.setPoolSubscriptionEnabled(true)
.addPoolLocator(locatorHost, locatorPort);
- ClientCache clientCache = clientCacheFactory.create();
-
- ClientRegionFactory<String, String> regionFactory =
- clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
-
- if (expectedExceptionOnClient != null) {
- IgnoredException.addIgnoredException("javax.net.ssl.SSLHandshakeException");
- IgnoredException.addIgnoredException("java.net.SocketException");
- IgnoredException.addIgnoredException("java.security.cert.CertificateException");
-
- Region<String, String> clientRegion = regionFactory.create("region");
- assertThatExceptionOfType(expectedExceptionOnClient)
- .isThrownBy(() -> clientRegion.put("1", "1"));
-
- // Close the client cache so the pool does not retry, CSRule tearDown
- // closes cache which eventually close pool. But pool can keep
- // retrying and fill logs between closing suspect log buffer
- // and closing cache
- clientCache.close();
- IgnoredException.removeAllExpectedExceptions();
- } else {
- // test client can read and write to server
- Region<String, String> clientRegion = regionFactory.create("region");
- assertThat("servervalue").isEqualTo(clientRegion.get("serverkey"));
- clientRegion.put("clientkey", "clientvalue");
-
- // test server can see data written by client
- server.invoke(ClientServerHostNameVerificationDistributedTest::doServerRegionTest);
+ // close clientCache when done to stop retries between closing suspect log buffer and closing
+ // cache
+ try (ClientCache clientCache = clientCacheFactory.create()) {
+
+ ClientRegionFactory<String, String> regionFactory =
+ clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
+
+ if (expectedExceptionOnClient != null) {
+ IgnoredException.addIgnoredException("javax.net.ssl.SSLHandshakeException");
+ IgnoredException.addIgnoredException("java.net.SocketException");
+ IgnoredException.addIgnoredException("java.security.cert.CertificateException");
+
+ Region<String, String> clientRegion = regionFactory.create("region");
+ assertThatExceptionOfType(expectedExceptionOnClient)
+ .isThrownBy(() -> clientRegion.put("1", "1"));
+ } else {
+ // test client can read and write to server
+ Region<String, String> clientRegion = regionFactory.create("region");
+ assertThat("servervalue").isEqualTo(clientRegion.get("serverkey"));
+ clientRegion.put("clientkey", "clientvalue");
+
+ // test server can see data written by client
+ server.invoke(ClientServerHostNameVerificationDistributedTest::doServerRegionTest);
+ }
+ } finally {
+ SocketCreatorFactory.close();
}
- SocketCreatorFactory.close();
}
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java
index c16349e..36efb7c 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java
@@ -14,6 +14,8 @@
*/
package org.apache.geode.distributed;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_AUTO_RECONNECT;
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_NETWORK_PARTITION_DETECTION;
@@ -36,11 +38,10 @@ import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTOR
import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD;
import static org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR;
import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
-import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -54,6 +55,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -78,19 +80,23 @@ import org.apache.geode.distributed.internal.membership.MembershipTestHook;
import org.apache.geode.distributed.internal.membership.NetView;
import org.apache.geode.distributed.internal.membership.gms.MembershipManagerHelper;
import org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeaveTestHelper;
+import org.apache.geode.distributed.internal.tcpserver.LocatorCancelException;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.logging.InternalLogWriter;
import org.apache.geode.internal.logging.LocalLogWriter;
+import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.security.SecurableCommunicationChannel;
import org.apache.geode.internal.tcp.Connection;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.DistributedTestUtils;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.LogWriterUtils;
import org.apache.geode.test.dunit.NetworkUtils;
+import org.apache.geode.test.dunit.RMIException;
import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.Wait;
@@ -106,52 +112,68 @@ import org.apache.geode.util.test.TestUtil;
*/
@Category({MembershipTest.class})
public class LocatorDUnitTest extends JUnit4DistributedTestCase {
-
- static volatile InternalDistributedSystem system = null;
-
+ private static final Logger logger = LogService.getLogger();
private static TestHook hook;
-
+ static volatile InternalDistributedSystem system = null;
protected int port1;
private int port2;
- @Override
- public final void postSetUp() throws Exception {
- port1 = -1;
- port2 = -1;
- IgnoredException.addIgnoredException("Removing shunned member");
+ private static void expectSystemToContainThisManyMembers(final int expectedMembers) {
+ InternalDistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+ assertThat(sys).isNotNull();
+ assertEquals(expectedMembers, sys.getDM().getViewMembers().size());
}
- @Override
- public final void preTearDown() throws Exception {
- if (Locator.hasLocator()) {
- Locator.getLocator().stop();
- }
- GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- if (cache != null && !cache.isClosed()) {
- cache.close();
- }
- // delete locator state files so they don't accidentally
- // get used by other tests
- if (port1 > 0) {
- DistributedTestUtils.deleteLocatorStateFile(port1);
- }
- if (port2 > 0) {
- DistributedTestUtils.deleteLocatorStateFile(port2);
- }
+ private static boolean isSystemConnected() {
+ DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+ return sys != null && sys.isConnected();
}
- @Override
- public final void postTearDown() throws Exception {
- disconnectAllFromDS();
- if (system != null) {
- system.disconnect();
- system = null;
+ private static void disconnectDistributedSystem() {
+ DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+ if (sys != null && sys.isConnected()) {
+ sys.disconnect();
}
+ MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
}
- // for child classes
- protected void addDSProps(Properties p) {
+ /**
+ * return the distributed member id for the ds on this vm
+ */
+ private static DistributedMember getDistributedMember(Properties props) {
+ props.put("name", "vm_" + VM.getCurrentVMNum());
+ DistributedSystem sys = getConnectedDistributedSystem(props);
+ sys.getLogWriter().info("<ExpectedException action=add>service failure</ExpectedException>");
+ sys.getLogWriter().info(
+ "<ExpectedException action=add>org.apache.geode.ConnectException</ExpectedException>");
+ sys.getLogWriter().info(
+ "<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
+ return sys.getDistributedMember();
+ }
+
+ /**
+ * find a running locator and return its distributed member id
+ */
+ private static DistributedMember getLocatorDistributedMember() {
+ return (Locator.getLocator()).getDistributedSystem().getDistributedMember();
+ }
+
+ /**
+ * find the lead member and return its id
+ */
+ private static DistributedMember getLeadMember() {
+ DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+ return MembershipManagerHelper.getLeadMember(sys);
+ }
+
+ protected static void stopLocator() {
+ MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
+ Locator loc = Locator.getLocator();
+ if (loc != null) {
+ loc.stop();
+ assertThat(Locator.hasLocator()).isFalse();
+ }
}
//////// Test Methods
@@ -163,38 +185,37 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
* become elder again because it put its address at the beginning of the new view it sent out.
*/
@Test
- public void testCollocatedLocatorWithSecurity() throws Exception {
+ public void testCollocatedLocatorWithSecurity() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
+
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
- final String locators = NetworkUtils.getServerHostName(host) + "[" + port1 + "]";
+ final String locators = NetworkUtils.getServerHostName() + "[" + port1 + "]";
final Properties properties = new Properties();
properties.put(MCAST_PORT, "0");
properties.put(START_LOCATOR, locators);
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ properties.put(LOG_LEVEL, logger.getLevel().name());
properties.put(SECURITY_PEER_AUTH_INIT, "org.apache.geode.distributed.AuthInitializer.create");
properties.put(SECURITY_PEER_AUTHENTICATOR,
"org.apache.geode.distributed.MyAuthenticator.create");
properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
properties.put(USE_CLUSTER_CONFIGURATION, "false");
addDSProps(properties);
- system = (InternalDistributedSystem) DistributedSystem.connect(properties);
- InternalDistributedMember mbr = system.getDistributedMember();
- assertEquals("expected the VM to have NORMAL vmKind", ClusterDistributionManager.NORMAL_DM_TYPE,
- system.getDistributedMember().getVmKind());
+ system = getConnectedDistributedSystem(properties);
+ assertThat(system.getDistributedMember().getVmKind())
+ .describedAs("expected the VM to have NORMAL vmKind")
+ .isEqualTo(ClusterDistributionManager.NORMAL_DM_TYPE);
properties.remove(START_LOCATOR);
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
properties.put(LOCATORS, locators);
SerializableRunnable startSystem = new SerializableRunnable("start system") {
public void run() {
- system = (InternalDistributedSystem) DistributedSystem.connect(properties);
+ system = getConnectedDistributedSystem(properties);
}
};
vm1.invoke(startSystem);
@@ -203,7 +224,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
// ensure that I, as a collocated locator owner, can create a cache region
Cache cache = CacheFactory.create(system);
Region r = cache.createRegionFactory(RegionShortcut.REPLICATE).create("test-region");
- assertNotNull("expected to create a region", r);
+ assertThat(r).describedAs("expected to create a region").isNotNull();
// create a lock service and have every vm get a lock
DistributedLockService service = DistributedLockService.create("test service", system);
@@ -224,24 +245,23 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedLockService serviceNamed =
DistributedLockService.getServiceNamed("test service");
serviceNamed.lock("foo3", 0, 0);
- await()
- .until(() -> serviceNamed.isLockGrantor());
- assertTrue(serviceNamed.isLockGrantor());
+ GeodeAwaitility.await()
+ .until(serviceNamed::isLockGrantor);
+ assertThat(serviceNamed.isLockGrantor()).isTrue();
});
properties.put(START_LOCATOR, locators);
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- system = (InternalDistributedSystem) DistributedSystem.connect(properties);
+ system = getConnectedDistributedSystem(properties);
System.out.println("done connecting distributed system. Membership view is "
+ MembershipManagerHelper.getMembershipManager(system).getView());
- assertEquals("should be the coordinator", system.getDistributedMember(),
- MembershipManagerHelper.getCoordinator(system));
+ assertThat(MembershipManagerHelper.getCoordinator(system))
+ .describedAs("should be the coordinator").isEqualTo(system.getDistributedMember());
NetView view = MembershipManagerHelper.getMembershipManager(system).getView();
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .info("view after becoming coordinator is " + view);
- assertNotSame("should not be the first member in the view (" + view + ")",
- system.getDistributedMember(), view.get(0));
+ logger.info("view after becoming coordinator is " + view);
+ assertThat(system.getDistributedMember())
+ .describedAs("should not be the first member in the view (" + view + ")")
+ .isNotSameAs(view.get(0));
service = DistributedLockService.create("test service", system);
@@ -250,7 +270,8 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedLockService.getServiceNamed("test service").lock("foo4", 0, 0);
});
- assertFalse("should not have become lock grantor", service.isLockGrantor());
+ assertThat(service.isLockGrantor()).describedAs("should not have become lock grantor")
+ .isFalse();
// Now demonstrate that a new member can join and use the lock service
properties.remove(START_LOCATOR);
@@ -272,9 +293,8 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testStartTwoLocators() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM loc1 = host.getVM(1);
- VM loc2 = host.getVM(2);
+ VM loc1 = VM.getVM(1);
+ VM loc2 = VM.getVM(2);
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = ports[0];
@@ -283,48 +303,22 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
this.port2 = port2; // for cleanup in tearDown2
DistributedTestUtils.deleteLocatorStateFile(port1);
DistributedTestUtils.deleteLocatorStateFile(port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "false");
addDSProps(properties);
startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
- // GEODE-3052 - split brain on restart from persistent view data
startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
}
- private void startLocatorWithPortAndProperties(final int port, final Properties properties)
- throws IOException {
- assertNotNull(Locator.startLocatorAndDS(port, new File(""), properties));
- }
-
- private String getSingleKeyKeystore() {
- return TestUtil.getResourcePath(getClass(), "/ssl/trusted.keystore");
- }
-
-
- private String getMultiKeyKeystore() {
- return TestUtil.getResourcePath(getClass(), "/org/apache/geode/internal/net/multiKey.jks");
- }
-
- private String getMultiKeyTruststore() {
- return TestUtil.getResourcePath(getClass(), "/org/apache/geode/internal/net/multiKeyTrust.jks");
- }
-
@Test
public void testStartTwoLocatorsWithSingleKeystoreSSL() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM loc1 = host.getVM(1);
- VM loc2 = host.getVM(2);
+
+ VM loc1 = VM.getVM(1);
+ VM loc2 = VM.getVM(2);
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = ports[0];
@@ -333,16 +327,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
this.port2 = port2; // for cleanup in tearDown2
DistributedTestUtils.deleteLocatorStateFile(port1);
DistributedTestUtils.deleteLocatorStateFile(port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "false");
properties.put(SSL_CIPHERS, "any");
properties.put(SSL_PROTOCOLS, "TLSv1,TLSv1.1,TLSv1.2");
properties.put(SSL_KEYSTORE, getSingleKeyKeystore());
@@ -358,9 +345,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testStartTwoLocatorsWithMultiKeystoreSSL() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM loc1 = host.getVM(1);
- VM loc2 = host.getVM(2);
+
+ VM loc1 = VM.getVM(1);
+ VM loc2 = VM.getVM(2);
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = ports[0];
@@ -369,16 +356,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
this.port2 = port2; // for cleanup in tearDown2
DistributedTestUtils.deleteLocatorStateFile(port1);
DistributedTestUtils.deleteLocatorStateFile(port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "false");
properties.put(SSL_CIPHERS, "any");
properties.put(SSL_PROTOCOLS, "any");
properties.put(SSL_KEYSTORE, getMultiKeyKeystore());
@@ -392,57 +372,23 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
}
- private void startVerifyAndStopLocator(VM loc1, VM loc2, int port1, int port2,
- Properties properties) throws Exception {
- try {
- getBlackboard().initBlackboard();
- AsyncInvocation<Void> async1 = loc1.invokeAsync("startLocator1", () -> {
- getBlackboard().signalGate("locator1");
- getBlackboard().waitForGate("go", 60, TimeUnit.SECONDS);
- startLocatorWithPortAndProperties(port1, properties);
- });
-
- AsyncInvocation<Void> async2 = loc2.invokeAsync("startLocator2", () -> {
- getBlackboard().signalGate("locator2");
- getBlackboard().waitForGate("go", 60, TimeUnit.SECONDS);
- startLocatorWithPortAndProperties(port2, properties);
- });
-
- getBlackboard().waitForGate("locator1", 60, TimeUnit.SECONDS);
- getBlackboard().waitForGate("locator2", 60, TimeUnit.SECONDS);
- getBlackboard().signalGate("go");
-
- async1.await();
- async2.await();
-
- // verify that they found each other
- loc2.invoke("expectSystemToContainThisManyMembers",
- () -> expectSystemToContainThisManyMembers(2));
- loc1.invoke("expectSystemToContainThisManyMembers",
- () -> expectSystemToContainThisManyMembers(2));
- } finally {
- loc2.invoke("stop locator", () -> stopLocator());
- loc1.invoke("stop locator", () -> stopLocator());
- }
- }
-
@Test
- public void testNonSSLLocatorDiesWhenConnectingToSSLLocator() throws Exception {
+ public void testNonSSLLocatorDiesWhenConnectingToSSLLocator() {
IgnoredException.addIgnoredException("Unrecognized SSL message, plaintext connection");
IgnoredException.addIgnoredException("LocatorCancelException");
disconnectAllFromDS();
- Host host = Host.getHost(0);
- final String hostname = NetworkUtils.getServerHostName(host);
- VM loc1 = host.getVM(1);
- VM loc2 = host.getVM(2);
-
+ final String hostname = NetworkUtils.getServerHostName();
+ VM loc1 = VM.getVM(1);
+ VM loc2 = VM.getVM(2);
+ port1 = -1;
+ port2 = -1;
final Properties properties = new Properties();
properties.put(MCAST_PORT, "0");
properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
properties.put(DISABLE_AUTO_RECONNECT, "true");
properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ properties.put(LOG_LEVEL, logger.getLevel().name());
properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
properties.put(SSL_CIPHERS, "any");
properties.put(SSL_PROTOCOLS, "any");
@@ -454,37 +400,27 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
properties.put(SSL_REQUIRE_AUTHENTICATION, "true");
properties.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.LOCATOR.getConstant());
- try {
- // we set port1 so that the state file gets cleaned up later.
- port1 = loc1.invoke(() -> startLocatorWithRandomPort(properties));
+ // we set port1 so that the state file gets cleaned up later.
+ port1 = startLocatorGetPort(loc1, properties, 0);
- loc1.invoke("expect only one member in system",
- () -> expectSystemToContainThisManyMembers(1));
+ loc1.invoke("expect only one member in system",
+ () -> expectSystemToContainThisManyMembers(1));
- properties.remove(SSL_ENABLED_COMPONENTS);
- properties.put(LOCATORS, hostname + "[" + port1 + "]");
- // we set port2 so that the state file gets cleaned up later.
- port2 = loc2.invoke("start Locator2", () -> {
- // Sometimes the LocatorCancelException becomes a SystemConnectException, which then causes
- // an RMIException. This is a normal part of the connect failing.
- int port;
- try {
- port = startLocatorWithRandomPort(properties);
- } catch (SystemConnectException expected_sometimes) {
- return 0;
- }
- return port;
- });
+ properties.remove(SSL_ENABLED_COMPONENTS);
+ properties.put(LOCATORS, hostname + "[" + port1 + "]");
- loc1.invoke("expect only one member in system",
- () -> expectSystemToContainThisManyMembers(1));
+ // we set port2 so that the state file gets cleaned up later.
+ loc2.invoke(() -> {
+ assertThatThrownBy(() -> startLocatorBase(properties, 0))
+ .isInstanceOfAny(LocatorCancelException.class, SystemConnectException.class);
- } finally {
- loc1.invoke("stop locator", () -> stopLocator());
- // loc2 should die from inability to connect.
- loc2.invoke(() -> await("locator2 dies")
- .until(() -> Locator.getLocator() == null));
- }
+ assertThat(Locator.getLocator()).isNull();
+ });
+
+ loc1.invoke("expect only one member in system",
+ () -> expectSystemToContainThisManyMembers(1));
+
+ loc1.invoke("stop locator", LocatorDUnitTest::stopLocator);
}
@Test
@@ -494,54 +430,46 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
IgnoredException.addIgnoredException("LocatorCancelException");
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM loc1 = host.getVM(1);
- VM loc2 = host.getVM(2);
- final String hostname = NetworkUtils.getServerHostName(host);
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ VM loc1 = VM.getVM(1);
+ VM loc2 = VM.getVM(2);
+
+ final String hostname = NetworkUtils.getServerHostName();
+ final Properties properties = getClusterProperties("", "false");
+ properties.remove(LOCATORS);
properties.put(SSL_CIPHERS, "any");
properties.put(SSL_PROTOCOLS, "any");
- try {
- // we set port1 so that the state file gets cleaned up later.
- port1 = loc1.invoke("start Locator1", () -> startLocatorWithRandomPort(properties));
- loc1.invoke("expectSystemToContainThisManyMembers",
- () -> expectSystemToContainThisManyMembers(1));
+ // we set port1 so that the state file gets cleaned up later.
+ port1 = startLocatorGetPort(loc1, properties, 0);
+ loc1.invoke("expectSystemToContainThisManyMembers",
+ () -> expectSystemToContainThisManyMembers(1));
+
+ properties.put(SSL_KEYSTORE, getSingleKeyKeystore());
+ properties.put(SSL_KEYSTORE_PASSWORD, "password");
+ properties.put(SSL_KEYSTORE_TYPE, "JKS");
+ properties.put(SSL_TRUSTSTORE, getSingleKeyKeystore());
+ properties.put(SSL_TRUSTSTORE_PASSWORD, "password");
+ properties.put(SSL_REQUIRE_AUTHENTICATION, "true");
+ properties.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.LOCATOR.getConstant());
- properties.put(SSL_KEYSTORE, getSingleKeyKeystore());
- properties.put(SSL_KEYSTORE_PASSWORD, "password");
- properties.put(SSL_KEYSTORE_TYPE, "JKS");
- properties.put(SSL_TRUSTSTORE, getSingleKeyKeystore());
- properties.put(SSL_TRUSTSTORE_PASSWORD, "password");
- properties.put(SSL_REQUIRE_AUTHENTICATION, "true");
- properties.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.LOCATOR.getConstant());
+ final String locators = hostname + "[" + port1 + "]";
+ properties.put(LOCATORS, locators);
- final String locators = hostname + "[" + port1 + "]";
- properties.put(LOCATORS, locators);
- // we set port2 so that the state file gets cleaned up later.
- port2 = loc2.invoke("start Locator2", () -> startLocatorWithRandomPort(properties));
- loc1.invoke("expectSystemToContainThisManyMembers",
- () -> expectSystemToContainThisManyMembers(1));
- } finally {
- // loc2 should die from inability to connect.
- loc2.invoke(() -> await("locator2 dies")
- .until(() -> Locator.getLocator() == null));
- loc1.invoke("expectSystemToContainThisManyMembers",
- () -> expectSystemToContainThisManyMembers(1));
- loc1.invoke("stop locator", () -> stopLocator());
- }
+ // we set port2 so that the state file gets cleaned up later.
+ assertThatThrownBy(() -> startLocatorGetPort(loc2, properties, 0))
+ .isInstanceOfAny(LocatorCancelException.class, RMIException.class);
+ assertThat(Locator.getLocator()).isNull();
+
+ loc1.invoke("expectSystemToContainThisManyMembers",
+ () -> expectSystemToContainThisManyMembers(1));
+
+ loc1.invoke("stop locator", LocatorDUnitTest::stopLocator);
}
@Test
- public void testStartTwoLocatorsWithDifferentSSLCertificates() throws Exception {
+ public void testStartTwoLocatorsWithDifferentSSLCertificates() {
IgnoredException.addIgnoredException("Remote host closed connection during handshake");
IgnoredException
.addIgnoredException("unable to find valid certification path to requested target");
@@ -550,9 +478,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
disconnectAllFromDS();
IgnoredException.addIgnoredException("Unrecognized SSL message, plaintext connection");
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM loc1 = host.getVM(1);
- VM loc2 = host.getVM(2);
+
+ VM loc1 = VM.getVM(1);
+ VM loc2 = VM.getVM(2);
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = ports[0];
@@ -561,16 +489,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
this.port2 = port2; // for cleanup in tearDown2
DistributedTestUtils.deleteLocatorStateFile(port1);
DistributedTestUtils.deleteLocatorStateFile(port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "false");
properties.put(SSL_CIPHERS, "any");
properties.put(SSL_PROTOCOLS, "any");
properties.put(SSL_KEYSTORE, getSingleKeyKeystore());
@@ -582,7 +503,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
properties.put(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.LOCATOR.getConstant());
try {
- loc1.invoke("start Locator1", () -> startLocator(port1, properties));
+ startLocator(loc1, properties, port1);
loc1.invoke("expectSystemToContainThisManyMembers",
() -> expectSystemToContainThisManyMembers(1));
@@ -590,71 +511,50 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
properties.put(SSL_TRUSTSTORE, getMultiKeyTruststore());
properties.put(SSL_LOCATOR_ALIAS, "locatorkey");
- loc2.invoke("start Locator2", () -> startLocator(port2, properties));
+ assertThatThrownBy(() -> startLocator(loc2, properties, port2))
+ .isInstanceOfAny(LocatorCancelException.class, RMIException.class);
+ assertThat(Locator.getLocator()).isNull();
+
+
+
} finally {
try {
loc1.invoke("expectSystemToContainThisManyMembers",
() -> expectSystemToContainThisManyMembers(1));
} finally {
- loc1.invoke("stop locator", () -> stopLocator());
+ loc1.invoke("stop locator", LocatorDUnitTest::stopLocator);
}
}
}
- private static void expectSystemToContainThisManyMembers(final int expectedMembers) {
- InternalDistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- assertNotNull(sys);
- assertEquals(expectedMembers, sys.getDM().getViewMembers().size());
- }
-
- private void startLocator(final int port, final Properties properties) throws IOException {
- startLocatorInternal(port, properties);
- }
-
- // Don't call this directly for RMI -- the locator isn't RMI serializable.
- private Locator startLocatorInternal(final int port, final Properties properties)
- throws IOException {
- Locator locator;
- locator = Locator.startLocatorAndDS(port, new File(""), properties);
- return locator;
- }
-
- private int startLocatorWithRandomPort(Properties properties) throws IOException {
- Locator locator = startLocatorInternal(0, properties);
- return locator.getPort();
- }
-
-
/**
* test lead member selection
*/
@Test
public void testLeadMemberSelection() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
+
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
- final String locators = NetworkUtils.getServerHostName(host) + "[" + port1 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
+ final String locators = NetworkUtils.getServerHostName() + "[" + port1 + "]";
+ final Properties properties = getBasicProperties(locators);
properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
properties.put(DISABLE_AUTO_RECONNECT, "true");
addDSProps(properties);
File logFile = new File("");
if (logFile.exists()) {
- logFile.delete();
+ assertThat(logFile.delete()).isTrue();
}
Locator locator = Locator.startLocatorAndDS(port1, logFile, properties);
try {
DistributedSystem sys = locator.getDistributedSystem();
- assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
+ assertThat(MembershipManagerHelper.getLeadMember(sys)).isNull();
// connect three vms and then watch the lead member selection as they
// are disconnected/reconnected
@@ -662,60 +562,48 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedMember mem1 = vm1.invoke(() -> getDistributedMember(properties));
- // assertTrue(MembershipManagerHelper.getLeadMember(sys) != null);
- assertLeadMember(mem1, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem1, sys);
properties.put("name", "vm2");
DistributedMember mem2 = vm2.invoke(() -> getDistributedMember(properties));
- assertLeadMember(mem1, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem1, sys);
properties.put("name", "vm3");
DistributedMember mem3 = vm3.invoke(() -> getDistributedMember(properties));
- assertLeadMember(mem1, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem1, sys);
// after disconnecting the first vm, the second one should become the leader
- vm1.invoke(() -> disconnectDistributedSystem());
+ vm1.invoke(LocatorDUnitTest::disconnectDistributedSystem);
MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem1);
- assertLeadMember(mem2, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem2, sys);
properties.put("name", "vm1");
mem1 = vm1.invoke(() -> getDistributedMember(properties));
- assertLeadMember(mem2, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem2, sys);
- vm2.invoke(() -> disconnectDistributedSystem());
+ vm2.invoke(LocatorDUnitTest::disconnectDistributedSystem);
MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem2);
- assertLeadMember(mem3, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem3, sys);
- vm1.invoke(() -> disconnectDistributedSystem());
+ vm1.invoke(LocatorDUnitTest::disconnectDistributedSystem);
MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem1);
- assertLeadMember(mem3, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem3, sys);
- vm3.invoke(() -> disconnectDistributedSystem());
+ vm3.invoke(LocatorDUnitTest::disconnectDistributedSystem);
MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem3);
- assertLeadMember(null, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(null, sys);
} finally {
locator.stop();
}
}
- private void assertLeadMember(final DistributedMember member, final DistributedSystem sys,
- long timeout) {
- await()
- .until(() -> {
- DistributedMember lead = MembershipManagerHelper.getLeadMember(sys);
- if (member != null) {
- return member.equals(lead);
- }
- return (lead == null);
- });
- }
/**
* test lead member and coordinator failure with network partition detection enabled. It would be
* nice for this test to have more than two "server" vms, to demonstrate that they all exit when
* the leader and potential- coordinator both disappear in the loss-correlation-window, but there
- * are only four vms available for dunit testing.
+ * are only four vms available for DUnit testing.
* <p>
* So, we start two locators with admin distributed systems, then start two regular distributed
* members.
@@ -730,10 +618,10 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
public void testLeadAndCoordFailure() throws Exception {
IgnoredException.addIgnoredException("Possible loss of quorum due");
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM locvm = host.getVM(3);
+
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM locatorVM = VM.getVM(3);
Locator locator = null;
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
@@ -741,63 +629,40 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
this.port1 = port1;
final int port2 = ports[1];
DistributedTestUtils.deleteLocatorStateFile(port1, port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- // properties.put("log-level", "fine");
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "true");
addDSProps(properties);
try {
- final String uname = getUniqueName();
File logFile = new File("");
locator = Locator.startLocatorAndDS(port1, logFile, properties);
final DistributedSystem sys = locator.getDistributedSystem();
sys.getLogWriter()
.info("<ExpectedException action=add>java.net.ConnectException</ExpectedException>");
MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
- locvm.invoke(new SerializableRunnable() {
- public void run() {
- File lf = new File("");
- try {
- Locator.startLocatorAndDS(port2, lf, properties);
- } catch (IOException ios) {
- throw new RuntimeException("Unable to start locator2", ios);
- }
- }
- });
+ startLocator(locatorVM, properties, port2);
- SerializableRunnable crashLocator = new SerializableRunnable("Crash locator") {
- public void run() {
- Locator loc = Locator.getLocators().iterator().next();
- DistributedSystem msys = loc.getDistributedSystem();
- MembershipManagerHelper.crashDistributedSystem(msys);
- loc.stop();
- }
- };
-
- assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
+ assertThat(MembershipManagerHelper.getLeadMember(sys)).isNull();
// properties.put("log-level", getDUnitLogLevel());
DistributedMember mem1 = vm1.invoke(() -> getDistributedMember(properties));
vm2.invoke(() -> getDistributedMember(properties));
- assertLeadMember(mem1, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(mem1, sys);
- assertEquals(sys.getDistributedMember(), MembershipManagerHelper.getCoordinator(sys));
+ assertThat(sys.getDistributedMember()).isEqualTo(MembershipManagerHelper.getCoordinator(sys));
// crash the second vm and the locator. Should be okay
DistributedTestUtils.crashDistributedSystem(vm2);
- locvm.invoke(crashLocator);
+ locatorVM.invoke(() -> {
+ Locator loc = Locator.getLocator();
+ MembershipManagerHelper.crashDistributedSystem(loc.getDistributedSystem());
+ loc.stop();
+ });
- assertTrue("Distributed system should not have disconnected",
- vm1.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ assertThat(vm1.invoke(LocatorDUnitTest::isSystemConnected))
+ .describedAs("Distributed system should not have disconnected").isTrue();
// ensure quorumLost is properly invoked
ClusterDistributionManager dm =
@@ -812,27 +677,25 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedTestUtils.crashDistributedSystem(vm1);
/*
- * This vm is watching vm1, which is watching vm2 which is watching locvm. It will take 3 * (3
+ * This vm is watching vm1, which is watching vm2 which is watching locatorVM. It will take 3
+ * * (3
* * member-timeout) milliseconds to detect the full failure and eject the lost members from
* the view.
*/
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .info("waiting for my distributed system to disconnect due to partition detection");
+ logger.info("waiting for my distributed system to disconnect due to partition detection");
- await()
- .until(() -> {
- return !sys.isConnected();
- });
+ GeodeAwaitility.await().until(() -> !sys.isConnected());
if (sys.isConnected()) {
fail(
"Distributed system did not disconnect as expected - network partition detection is broken");
}
// quorumLost should be invoked if we get a ForcedDisconnect in this situation
- assertTrue("expected quorumLost to be invoked", listener.quorumLostInvoked);
- assertTrue("expected suspect processing initiated by TCPConduit",
- listener.suspectReasons.contains(Connection.INITIATING_SUSPECT_PROCESSING));
+ assertThat(listener.quorumLostInvoked).describedAs("expected quorumLost to be invoked")
+ .isTrue();
+ assertThat(listener.suspectReasons.contains(Connection.INITIATING_SUSPECT_PROCESSING))
+ .describedAs("expected suspect processing initiated by TCPConduit").isTrue();
} finally {
if (locator != null) {
locator.stop();
@@ -861,10 +724,10 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testLeadFailureAndCoordShutdown() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM locvm = host.getVM(3);
+
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM locatorVM = VM.getVM(3);
Locator locator = null;
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
@@ -873,15 +736,9 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
final int port2 = ports[1];
this.port2 = port2;
DistributedTestUtils.deleteLocatorStateFile(port1, port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "true");
addDSProps(properties);
@@ -889,100 +746,72 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
File logFile = new File("");
locator = Locator.startLocatorAndDS(port1, logFile, properties);
DistributedSystem sys = locator.getDistributedSystem();
- locvm.invoke(new SerializableRunnable() {
- public void run() {
- File lf = new File("");
- try {
- Locator.startLocatorAndDS(port2, lf, properties);
- MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
- } catch (IOException ios) {
- throw new RuntimeException("Unable to start locator2", ios);
- }
+ locatorVM.invoke(() -> {
+ File lf = new File("");
+ try {
+ Locator.startLocatorAndDS(port2, lf, properties);
+ MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
+ } catch (IOException ios) {
+ throw new RuntimeException("Unable to start locator2", ios);
}
});
- SerializableRunnable crashSystem = new SerializableRunnable("Crash system") {
- public void run() {
- DistributedSystem msys = InternalDistributedSystem.getAnyInstance();
- msys.getLogWriter()
- .info("<ExpectedException action=add>service failure</ExpectedException>");
- msys.getLogWriter().info(
- "<ExpectedException action=add>org.apache.geode.ConnectException</ExpectedException>");
- msys.getLogWriter().info(
- "<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
- MembershipManagerHelper.crashDistributedSystem(msys);
- }
- };
-
- assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
+ assertThat(MembershipManagerHelper.getLeadMember(sys)).isNull();
DistributedMember mem1 = vm1.invoke(() -> getDistributedMember(properties));
DistributedMember mem2 = vm2.invoke(() -> getDistributedMember(properties));
- assertEquals(mem1, MembershipManagerHelper.getLeadMember(sys));
+ assertThat(mem1).isEqualTo(MembershipManagerHelper.getLeadMember(sys));
- assertEquals(sys.getDistributedMember(), MembershipManagerHelper.getCoordinator(sys));
+ assertThat(sys.getDistributedMember()).isEqualTo(MembershipManagerHelper.getCoordinator(sys));
MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
// crash the lead vm. Should be okay
- vm1.invoke(crashSystem);
-
- await().until(() -> isSystemConnected());
-
- assertTrue("Distributed system should not have disconnected", isSystemConnected());
-
- assertTrue("Distributed system should not have disconnected",
- vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
-
- assertTrue("Distributed system should not have disconnected",
- locvm.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ vm1.invoke(() -> {
+ DistributedSystem distributedSystem = InternalDistributedSystem.getAnyInstance();
+ LogWriter logWriter = distributedSystem.getLogWriter();
+ assertThat(logWriter).isNotNull();
+ logWriter
+ .info("<ExpectedException action=add>service failure</ExpectedException>");
+ logWriter.info(
+ "<ExpectedException action=add>org.apache.geode.ConnectException</ExpectedException>");
+ logWriter.info(
+ "<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
+ MembershipManagerHelper.crashDistributedSystem(distributedSystem);
+ });
+ waitUntilTheSystemIsConnected(vm2, locatorVM);
// stop the locator normally. This should also be okay
locator.stop();
- if (!Locator.getLocators().isEmpty()) {
- // log this for debugging purposes before throwing assertion error
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .warning("found locator " + Locator.getLocators().iterator().next());
- }
- assertTrue("locator is not stopped", Locator.getLocators().isEmpty());
+ GeodeAwaitility.await()
+ .until(() -> {
+ assertThat(Locator.getLocator()).describedAs("locator is not stopped").isNull();
+ return true;
+ });
- assertTrue("Distributed system should not have disconnected",
- vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
-
- assertTrue("Distributed system should not have disconnected",
- locvm.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ checkSystemConnectedInVMs(vm2, locatorVM);
// the remaining non-locator member should now be the lead member
assertEquals(
"This test sometimes fails. If the log contains "
+ "'failed to collect all ACKs' it is a false failure.",
- mem2, vm2.invoke(() -> LocatorDUnitTest.getLeadMember()));
-
- SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {
- public void run() {
- DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- if (sys != null && sys.isConnected()) {
- sys.disconnect();
- }
- }
- };
+ mem2, vm2.invoke(LocatorDUnitTest::getLeadMember));
// disconnect the first vm and demonstrate that the third vm and the
// locator notice the failure and exit
- vm2.invoke(() -> disconnectDistributedSystem());
- locvm.invoke(() -> stopLocator());
+ vm2.invoke(LocatorDUnitTest::disconnectDistributedSystem);
+ locatorVM.invoke(LocatorDUnitTest::stopLocator);
} finally {
MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
if (locator != null) {
locator.stop();
}
try {
- locvm.invoke(() -> stopLocator());
+ locatorVM.invoke(LocatorDUnitTest::stopLocator);
} catch (Exception e) {
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .severe("failed to stop locator in vm 3", e);
+ logger.error("failed to stop locator in vm 3", e);
}
}
}
@@ -998,15 +827,15 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
* We then shut down the group coordinator and observe the second locator pick up the job and the
* remaining member continues to operate normally.
*/
- // disabled on trunk - should be reenabled on cedar_dev_Oct12
+ // disabled on trunk - should be re-enabled on cedar_dev_Oct12
// this test leaves a CloserThread around forever that logs "pausing" messages every 500 ms
@Test
public void testForceDisconnectAndPeerShutdownCause() throws Exception {
disconnectAllFromDS();
Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM locvm = host.getVM(3);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM locvm = VM.getVM(3);
Locator locator = null;
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
@@ -1072,10 +901,6 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
assertEquals(sys.getDistributedMember(), MembershipManagerHelper.getCoordinator(sys));
- // crash the lead vm. Should be okay. it should hang in test hook thats
- // why call is asynchronous.
- // vm1.invokeAsync(crashSystem);
-
assertTrue("Distributed system should not have disconnected", isSystemConnected());
assertTrue("Distributed system should not have disconnected",
@@ -1088,6 +913,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
Wait.pause(1000); // 4 x the member-timeout
+
// request member removal for first peer from second peer.
vm2.invoke(new SerializableRunnable("Request Member Removal") {
@@ -1136,107 +962,123 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testLeadShutdownAndCoordFailure() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM locvm = host.getVM(3);
- Locator locator = null;
+ VM memberThatWillBeShutdownVM = VM.getVM(1);
+ VM memberVM = VM.getVM(2);
+ VM locatorThatWillBeShutdownVM = VM.getVM(3);
+ Locator locator = null;
int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = ports[0];
this.port1 = port1;
final int port2 = ports[1];
DistributedTestUtils.deleteLocatorStateFile(port1, port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties properties = new Properties();
- properties.put(MCAST_PORT, "0");
- properties.put(LOCATORS, locators);
- properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
- properties.put(DISABLE_AUTO_RECONNECT, "true");
- properties.put(MEMBER_TIMEOUT, "2000");
- properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ final Properties properties = getClusterProperties(locators, "true");
addDSProps(properties);
try {
- locvm.invoke(() -> {
- File lf = new File("");
+ locatorThatWillBeShutdownVM.invoke(() -> {
+ Locator localLocator;
try {
- Locator.startLocatorAndDS(port2, lf, properties);
+ localLocator = Locator.startLocatorAndDS(port2, new File(""), properties);
+ assertThat(localLocator.getDistributedSystem().isConnected()).isTrue();
} catch (IOException ios) {
throw new RuntimeException("Unable to start locator1", ios);
}
});
- File logFile = new File("");
- locator = Locator.startLocatorAndDS(port1, logFile, properties);
- DistributedSystem sys = locator.getDistributedSystem();
- sys.getLogWriter().info(
+ // Test runner will be locator 2
+ locator = Locator.startLocatorAndDS(port1, new File(""), properties);
+ assertThat(locator.getDistributedSystem().isConnected()).isTrue();
+ DistributedSystem testRunnerLocatorDS = locator.getDistributedSystem();
+ testRunnerLocatorDS.getLogWriter().info(
"<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
+ assertThat(MembershipManagerHelper.getLeadMember(testRunnerLocatorDS))
+ .describedAs("There was a lead member when there should not be.").isNull();
- assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
-
- DistributedMember mem1 = vm1.invoke(() -> getDistributedMember(properties));
-
- vm1.invoke(() -> MembershipManagerHelper.inhibitForcedDisconnectLogging(true));
+ DistributedMember distributedMemberThatWillBeShutdown =
+ memberThatWillBeShutdownVM.invoke(() -> getDistributedMember(properties));
+ memberThatWillBeShutdownVM
+ .invoke(() -> MembershipManagerHelper.inhibitForcedDisconnectLogging(true));
- DistributedMember mem2 = vm2.invoke(() -> getDistributedMember(properties));
+ DistributedMember distributedMember = memberVM.invoke(() -> getDistributedMember(properties));
- DistributedMember loc1Mbr = locvm.invoke(() -> this.getLocatorDistributedMember());
+ DistributedMember locatorMemberToBeShutdown =
+ locatorThatWillBeShutdownVM.invoke(LocatorDUnitTest::getLocatorDistributedMember);
- assertLeadMember(mem1, sys, 5000);
+ waitForMemberToBecomeLeadMemberOfDistributedSystem(distributedMemberThatWillBeShutdown,
+ testRunnerLocatorDS);
+ DistributedMember oldLeader = MembershipManagerHelper.getLeadMember(testRunnerLocatorDS);
- assertEquals(loc1Mbr, MembershipManagerHelper.getCoordinator(sys));
+ assertThat(locatorMemberToBeShutdown)
+ .isEqualTo(MembershipManagerHelper.getCoordinator(testRunnerLocatorDS));
+ DistributedMember oldCoordinator =
+ MembershipManagerHelper.getCoordinator(testRunnerLocatorDS);
// crash the lead locator. Should be okay
- locvm.invoke("crash locator", () -> {
- Locator loc = Locator.getLocators().iterator().next();
- DistributedSystem msys = loc.getDistributedSystem();
- msys.getLogWriter()
+ locatorThatWillBeShutdownVM.invoke("crash locator", () -> {
+ Locator loc = Locator.getLocator();
+ DistributedSystem distributedSystem = loc.getDistributedSystem();
+ LogWriter logWriter = distributedSystem.getLogWriter();
+ assertThat(logWriter).isNotNull();
+ logWriter
.info("<ExpectedException action=add>service failure</ExpectedException>");
- msys.getLogWriter().info(
+ logWriter.info(
"<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
- msys.getLogWriter().info(
+ logWriter.info(
"<ExpectedException action=add>org.apache.geode.ConnectException</ExpectedException>");
- MembershipManagerHelper.crashDistributedSystem(msys);
+ MembershipManagerHelper.crashDistributedSystem(distributedSystem);
loc.stop();
});
- await()
- .until(() -> sys.isConnected());
-
- assertTrue("Distributed system should not have disconnected", sys.isConnected());
-
- assertTrue("Distributed system should not have disconnected",
- vm1.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ GeodeAwaitility.await().until(testRunnerLocatorDS::isConnected);
- assertTrue("Distributed system should not have disconnected",
- vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ waitUntilTheSystemIsConnected(memberThatWillBeShutdownVM, memberVM);
// disconnect the first vm and demonstrate that the non-lead vm and the
// locator notice the failure and continue to run
- vm1.invoke(() -> disconnectDistributedSystem());
+ memberThatWillBeShutdownVM.invoke(LocatorDUnitTest::disconnectDistributedSystem);
+ GeodeAwaitility.await().until(
+ () -> memberThatWillBeShutdownVM.invoke(() -> !LocatorDUnitTest.isSystemConnected()));
+ GeodeAwaitility.await().until(() -> memberVM.invoke(LocatorDUnitTest::isSystemConnected));
- await()
- .until(() -> vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ assertThat(memberVM.invoke(LocatorDUnitTest::isSystemConnected))
+ .describedAs("Distributed system should not have disconnected").isTrue();
- assertTrue("Distributed system should not have disconnected",
- vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
+ GeodeAwaitility.await("waiting for the old coordinator to drop out").until(
+ () -> MembershipManagerHelper.getCoordinator(testRunnerLocatorDS) != oldCoordinator);
+
+ GeodeAwaitility.await().until(() -> {
+ DistributedMember survivingDistributedMember = testRunnerLocatorDS.getDistributedMember();
+ DistributedMember coordinator = MembershipManagerHelper.getCoordinator(testRunnerLocatorDS);
+ assertThat(survivingDistributedMember).isEqualTo(coordinator);
+ return true;
+ });
- await().untilAsserted(() -> assertEquals(sys.getDistributedMember(),
- MembershipManagerHelper.getCoordinator(sys)));
- await().untilAsserted(() -> assertEquals(mem2, MembershipManagerHelper.getLeadMember(sys)));
+ GeodeAwaitility.await("Waiting for the old leader to drop out")
+ .pollInterval(1, TimeUnit.SECONDS).until(() -> {
+ DistributedMember leader = MembershipManagerHelper.getLeadMember(testRunnerLocatorDS);
+ return leader != oldLeader;
+ });
+
+ GeodeAwaitility.await().until(() -> {
+ assertThat(distributedMember)
+ .isEqualTo(MembershipManagerHelper.getLeadMember(testRunnerLocatorDS));
+ return true;
+ });
} finally {
- vm2.invoke(() -> disconnectDistributedSystem());
+ memberVM.invoke(LocatorDUnitTest::disconnectDistributedSystem);
if (locator != null) {
locator.stop();
}
- locvm.invoke(() -> stopLocator());
+ locatorThatWillBeShutdownVM.invoke(LocatorDUnitTest::stopLocator);
}
}
+
/**
* Tests that attempting to connect to a distributed system in which no locator is defined throws
* an exception.
@@ -1244,13 +1086,11 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testNoLocator() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
+
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
- String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
+ String locators = NetworkUtils.getServerHostName() + "[" + port + "]";
+ Properties props = getBasicProperties(locators);
addDSProps(props);
final String expected = "java.net.ConnectException";
@@ -1263,7 +1103,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
boolean exceptionOccurred = true;
try {
- DistributedSystem.connect(props);
+ getConnectedDistributedSystem(props);
exceptionOccurred = false;
} catch (DistributionException ex) {
@@ -1271,7 +1111,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
} catch (GemFireConfigException ex) {
String s = ex.getMessage();
- assertTrue(s.indexOf("Locator does not exist") >= 0);
+ assertThat(s.contains("Locator does not exist")).isTrue();
} catch (Exception ex) {
// if you see this fail, determine if unexpected exception is expected
@@ -1294,82 +1134,63 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
* The locator is then restarted and is shown to take over the role of membership coordinator.
*/
@Test
- public void testOneLocator() throws Exception {
+ public void testOneLocator() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
+
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
- final String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
+ final String locators = NetworkUtils.getServerHostName() + "[" + port + "]";
- vm0.invoke("Start locator " + locators, () -> startLocator(port));
- try {
+ startLocatorWithSomeBasicProperties(vm0, port);
+ try {
SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {
public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
+ Properties props = getBasicProperties(locators);
props.setProperty(MEMBER_TIMEOUT, "1000");
addDSProps(props);
- DistributedSystem.connect(props);
+ getConnectedDistributedSystem(props);
}
};
+
vm1.invoke(connect);
vm2.invoke(connect);
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
+ Properties props = getBasicProperties(locators);
props.setProperty(MEMBER_TIMEOUT, "1000");
-
addDSProps(props);
- system = (InternalDistributedSystem) DistributedSystem.connect(props);
+ system = getConnectedDistributedSystem(props);
final DistributedMember coord = MembershipManagerHelper.getCoordinator(system);
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .info("coordinator before termination of locator is " + coord);
+ logger.info("coordinator before termination of locator is " + coord);
- vm0.invoke(() -> stopLocator());
+ vm0.invoke(LocatorDUnitTest::stopLocator);
// now ensure that one of the remaining members became the coordinator
- await()
+ GeodeAwaitility.await()
.until(() -> !coord.equals(MembershipManagerHelper.getCoordinator(system)));
DistributedMember newCoord = MembershipManagerHelper.getCoordinator(system);
- LogWriterUtils.getLogWriter().info("coordinator after shutdown of locator was " + newCoord);
+ logger.info("coordinator after shutdown of locator was " + newCoord);
if (coord.equals(newCoord)) {
fail("another member should have become coordinator after the locator was stopped");
}
system.disconnect();
- vm1.invoke(() -> disconnectDistributedSystem());
- vm2.invoke(() -> disconnectDistributedSystem());
+ vm1.invoke(LocatorDUnitTest::disconnectDistributedSystem);
+ vm2.invoke(LocatorDUnitTest::disconnectDistributedSystem);
} finally {
- vm0.invoke(() -> stopLocator());
+ vm0.invoke(LocatorDUnitTest::stopLocator);
}
}
- protected void startLocator(int port) {
- File logFile = new File("");
- try {
- Properties locProps = new Properties();
- locProps.setProperty(MCAST_PORT, "0");
- locProps.setProperty(MEMBER_TIMEOUT, "1000");
- locProps.put(ENABLE_CLUSTER_CONFIGURATION, "false");
-
- addDSProps(locProps);
- Locator.startLocatorAndDS(port, logFile, locProps);
- } catch (IOException ex) {
- throw new RuntimeException("While starting locator on port " + port, ex);
- }
- }
/**
* Tests starting one locator in a remote VM and having multiple members of the distributed system
@@ -1378,23 +1199,23 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
* group coordinator
*/
@Test
- public void testLocatorBecomesCoordinator() throws Exception {
+ public void testLocatorBecomesCoordinator() {
disconnectAllFromDS();
final String expected = "java.net.ConnectException";
final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
final String removeExpected =
"<ExpectedException action=remove>" + expected + "</ExpectedException>";
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
- final String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
+ final String locators = NetworkUtils.getServerHostName() + "[" + port + "]";
+
+ startLocatorPreferredCoordinators(vm0, port);
- vm0.invoke(getUniqueName() + 1, () -> startSBLocator(port));
try {
final Properties props = new Properties();
@@ -1415,17 +1236,16 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
system = getSystem(props);
final DistributedMember coord = MembershipManagerHelper.getCoordinator(system);
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .info("coordinator before termination of locator is " + coord);
+ logger.info("coordinator before termination of locator is " + coord);
- vm0.invoke(() -> stopLocator());
+ vm0.invoke(LocatorDUnitTest::stopLocator);
// now ensure that one of the remaining members became the coordinator
- await()
+ GeodeAwaitility.await()
.until(() -> !coord.equals(MembershipManagerHelper.getCoordinator(system)));
DistributedMember newCoord = MembershipManagerHelper.getCoordinator(system);
- LogWriterUtils.getLogWriter().info("coordinator after shutdown of locator was " + newCoord);
+ logger.info("coordinator after shutdown of locator was " + newCoord);
if (newCoord == null || coord.equals(newCoord)) {
fail("another member should have become coordinator after the locator was stopped: "
+ newCoord);
@@ -1434,60 +1254,36 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
// restart the locator to demonstrate reconnection & make disconnects faster
// it should also regain the role of coordinator, so we check to make sure
// that the coordinator has changed
- vm0.invoke(getUniqueName() + "2", () -> startSBLocator(port));
+ startLocatorPreferredCoordinators(vm0, port);
final DistributedMember tempCoord = newCoord;
- await()
+ GeodeAwaitility.await()
.until(() -> !tempCoord.equals(MembershipManagerHelper.getCoordinator(system)));
system.disconnect();
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(removeExpected);
- vm1.invoke(() -> {
- DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- if (sys != null && sys.isConnected()) {
- sys.disconnect();
- }
- // connectExceptions occur during disconnect, so we need the
- // expectedexception hint to be in effect until this point
- LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
- bLogger.info(removeExpected);
- });
- vm2.invoke(() -> {
- DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- if (sys != null && sys.isConnected()) {
- sys.disconnect();
- }
- // connectExceptions occur during disconnect, so we need the
- // expectedexception hint to be in effect until this point
- LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
- bLogger.info(removeExpected);
- });
- vm0.invoke(() -> stopLocator());
+ checkConnectionAndPrintInfo(vm1);
+ checkConnectionAndPrintInfo(vm2);
+ vm0.invoke(LocatorDUnitTest::stopLocator);
} finally {
- vm0.invoke(() -> stopLocator());
+ vm0.invoke(LocatorDUnitTest::stopLocator);
}
-
- }
-
- private static boolean isSystemConnected() {
- DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- return sys != null && sys.isConnected();
}
/**
* Tests starting multiple locators in multiple VMs.
*/
@Test
- public void testMultipleLocators() throws Exception {
+ public void testMultipleLocators() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
+
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = freeTCPPorts[0];
@@ -1495,65 +1291,55 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
final int port2 = freeTCPPorts[1];
this.port2 = port2;
DistributedTestUtils.deleteLocatorStateFile(port1, port2);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- final Properties dsProps = new Properties();
- dsProps.setProperty(LOCATORS, locators);
- dsProps.setProperty(MCAST_PORT, "0");
+ final Properties dsProps = getBasicProperties(locators);
dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
addDSProps(dsProps);
- vm0.invoke("start Locator1", () -> startLocator(port1, dsProps));
+ startLocator(vm0, dsProps, port1);
try {
-
- vm3.invoke("Start locator on " + port2, () -> startLocator(port2, dsProps));
+ startLocator(vm3, dsProps, port2);
try {
SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {
public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
+ Properties props = getBasicProperties(locators);
addDSProps(props);
- DistributedSystem.connect(props);
+ getConnectedDistributedSystem(props);
}
};
vm1.invoke(connect);
vm2.invoke(connect);
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
+ Properties props = getBasicProperties(locators);
addDSProps(props);
- system = (InternalDistributedSystem) DistributedSystem.connect(props);
+ system = getConnectedDistributedSystem(props);
- await()
- .until(() -> system.getDM().getViewMembers().size() >= 3);
+ GeodeAwaitility.await().until(() -> system.getDM().getViewMembers().size() >= 3);
// three applications plus
- assertEquals(5, system.getDM().getViewMembers().size());
+ assertThat(system.getDM().getViewMembers().size()).isEqualTo(5);
system.disconnect();
- vm1.invoke(() -> disconnectDistributedSystem());
- vm2.invoke(() -> disconnectDistributedSystem());
+ vm1.invoke(LocatorDUnitTest::disconnectDistributedSystem);
+ vm2.invoke(LocatorDUnitTest::disconnectDistributedSystem);
} finally {
- vm3.invoke(() -> stopLocator());
+ vm3.invoke(LocatorDUnitTest::stopLocator);
}
} finally {
- vm0.invoke(() -> stopLocator());
+ vm0.invoke(LocatorDUnitTest::stopLocator);
}
}
- private static void disconnectDistributedSystem() {
- DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- if (sys != null && sys.isConnected()) {
- sys.disconnect();
- }
- MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
+
+ private void waitUntilLocatorBecomesCoordinator() {
+ GeodeAwaitility.await().until(() -> GMSJoinLeaveTestHelper.getCurrentCoordinator()
+ .getVmKind() == ClusterDistributionManager.LOCATOR_DM_TYPE);
}
/**
@@ -1561,59 +1347,56 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
* have 1 master. GEODE-870
*/
@Test
- public void testMultipleLocatorsRestartingAtSameTime() throws Exception {
+ public void testMultipleLocatorsRestartingAtSameTime() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
- VM vm4 = host.getVM(4);
+
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
+ VM vm4 = VM.getVM(4);
int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(3);
this.port1 = freeTCPPorts[0];
this.port2 = freeTCPPorts[1];
int port3 = freeTCPPorts[2];
DistributedTestUtils.deleteLocatorStateFile(port1, port2, port3);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators =
host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]," + host0 + "[" + port3 + "]";
- final Properties dsProps = new Properties();
- dsProps.setProperty(LOCATORS, locators);
- dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ final Properties dsProps = getBasicProperties(locators);
+ dsProps.setProperty(LOG_LEVEL, logger.getLevel().name());
dsProps.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
- dsProps.setProperty(MCAST_PORT, "0");
addDSProps(dsProps);
- vm0.invoke(() -> startLocatorAsync(new Object[] {port1, dsProps}));
- vm1.invoke(() -> startLocatorAsync(new Object[] {port2, dsProps}));
- vm2.invoke(() -> startLocatorAsync(new Object[] {port3, dsProps}));
+ startLocator(vm0, dsProps, port1);
+ startLocator(vm1, dsProps, port2);
+ startLocator(vm2, dsProps, port3);
try {
vm3.invoke(() -> {
- DistributedSystem.connect(dsProps);
+ getConnectedDistributedSystem(dsProps);
return true;
});
vm4.invoke(() -> {
- DistributedSystem.connect(dsProps);
+ getConnectedDistributedSystem(dsProps);
return true;
});
- system = (InternalDistributedSystem) DistributedSystem.connect(dsProps);
+ system = getConnectedDistributedSystem(dsProps);
- await()
- .until(() -> system.getDM().getViewMembers().size() == 6);
+ GeodeAwaitility.await().until(() -> system.getDM().getViewMembers().size() == 6);
// three applications plus
- assertEquals(6, system.getDM().getViewMembers().size());
+ assertThat(system.getDM().getViewMembers().size()).isEqualTo(6);
- vm0.invoke(() -> stopLocator());
- vm1.invoke(() -> stopLocator());
- vm2.invoke(() -> stopLocator());
+ vm0.invoke(LocatorDUnitTest::stopLocator);
+ vm1.invoke(LocatorDUnitTest::stopLocator);
+ vm2.invoke(LocatorDUnitTest::stopLocator);
- await()
+ GeodeAwaitility.await()
.until(() -> system.getDM().getMembershipManager().getView().size() <= 3);
final String newLocators = host0 + "[" + port2 + "]," + host0 + "[" + port3 + "]";
@@ -1624,100 +1407,103 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedMember vm3ID = vm3.invoke(() -> GMSJoinLeaveTestHelper
.getInternalDistributedSystem().getDM().getDistributionManagerId());
assertTrue("View is " + system.getDM().getMembershipManager().getView() + " and vm3's ID is "
- + vm3ID, vm3.invoke(() -> GMSJoinLeaveTestHelper.isViewCreator()));
+ + vm3ID, vm3.invoke(GMSJoinLeaveTestHelper::isViewCreator));
- vm1.invoke(() -> startLocatorAsync(new Object[] {port2, dsProps}));
- vm2.invoke(() -> startLocatorAsync(new Object[] {port3, dsProps}));
+ startLocator(vm1, dsProps, port2);
+ startLocator(vm2, dsProps, port3);
- await()
+ GeodeAwaitility.await()
.until(() -> !GMSJoinLeaveTestHelper.getCurrentCoordinator().equals(currentCoordinator)
&& system.getDM().getAllHostedLocators().size() == 2);
- vm1.invoke("waitUntilLocatorBecomesCoordinator", () -> waitUntilLocatorBecomesCoordinator());
- vm2.invoke("waitUntilLocatorBecomesCoordinator", () -> waitUntilLocatorBecomesCoordinator());
- vm3.invoke("waitUntilLocatorBecomesCoordinator", () -> waitUntilLocatorBecomesCoordinator());
- vm4.invoke("waitUntilLocatorBecomesCoordinator", () -> waitUntilLocatorBecomesCoordinator());
-
- int netviewId = vm1.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.getViewId());
- assertEquals(netviewId,
- (int) vm2.invoke("checking ViewID", () -> GMSJoinLeaveTestHelper.getViewId()));
- assertEquals(netviewId,
- (int) vm3.invoke("checking ViewID", () -> GMSJoinLeaveTestHelper.getViewId()));
- assertEquals(netviewId,
- (int) vm4.invoke("checking ViewID", () -> GMSJoinLeaveTestHelper.getViewId()));
- assertFalse(vm4.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.isViewCreator()));
+ vm1.invoke("waitUntilLocatorBecomesCoordinator", this::waitUntilLocatorBecomesCoordinator);
+ vm2.invoke("waitUntilLocatorBecomesCoordinator", this::waitUntilLocatorBecomesCoordinator);
+ vm3.invoke("waitUntilLocatorBecomesCoordinator", this::waitUntilLocatorBecomesCoordinator);
+ vm4.invoke("waitUntilLocatorBecomesCoordinator", this::waitUntilLocatorBecomesCoordinator);
+
+ int netViewId = vm1.invoke("Checking ViewCreator", GMSJoinLeaveTestHelper::getViewId);
+ assertThat((int) vm2.invoke("checking ViewID", GMSJoinLeaveTestHelper::getViewId))
+ .isEqualTo(netViewId);
+ assertThat((int) vm3.invoke("checking ViewID", GMSJoinLeaveTestHelper::getViewId))
+ .isEqualTo(netViewId);
+ assertThat((int) vm4.invoke("checking ViewID", GMSJoinLeaveTestHelper::getViewId))
+ .isEqualTo(netViewId);
+ assertThat((boolean) vm4
+ .invoke("Checking ViewCreator", GMSJoinLeaveTestHelper::isViewCreator)).isFalse();
// Given the start up order of servers, this server is the elder server
- assertFalse(vm3.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.isViewCreator()));
- if (vm1.invoke(() -> GMSJoinLeaveTestHelper.isViewCreator())) {
- assertFalse(
- vm2.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.isViewCreator()));
+ assertFalse(vm3
+ .invoke("Checking ViewCreator", GMSJoinLeaveTestHelper::isViewCreator));
+ if (vm1.invoke(GMSJoinLeaveTestHelper::isViewCreator)) {
+ assertThat((boolean) vm2.invoke("Checking ViewCreator",
+ GMSJoinLeaveTestHelper::isViewCreator))
+ .isFalse();
} else {
- assertTrue(
- vm2.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.isViewCreator()));
+ assertThat((boolean) vm2.invoke("Checking ViewCreator",
+ GMSJoinLeaveTestHelper::isViewCreator))
+ .isTrue();
}
} finally {
system.disconnect();
- vm3.invoke(() -> disconnectDistributedSystem());
- vm4.invoke(() -> disconnectDistributedSystem());
- vm2.invoke(() -> stopLocator());
- vm1.invoke(() -> stopLocator());
+ vm3.invoke(LocatorDUnitTest::disconnectDistributedSystem);
+ vm4.invoke(LocatorDUnitTest::disconnectDistributedSystem);
+ vm2.invoke(LocatorDUnitTest::stopLocator);
+ vm1.invoke(LocatorDUnitTest::stopLocator);
}
}
+
@Test
public void testMultipleLocatorsRestartingAtSameTimeWithMissingServers() throws Exception {
disconnectAllFromDS();
IgnoredException.addIgnoredException("ForcedDisconnectException");
IgnoredException.addIgnoredException("Possible loss of quorum");
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
- VM vm4 = host.getVM(4);
+
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
+ VM vm4 = VM.getVM(4);
int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(3);
this.port1 = freeTCPPorts[0];
this.port2 = freeTCPPorts[1];
int port3 = freeTCPPorts[2];
DistributedTestUtils.deleteLocatorStateFile(port1, port2, port3);
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators =
host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]," + host0 + "[" + port3 + "]";
- final Properties dsProps = new Properties();
- dsProps.setProperty(LOCATORS, locators);
- dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ final Properties dsProps = getBasicProperties(locators);
+ dsProps.setProperty(LOG_LEVEL, logger.getLevel().name());
dsProps.setProperty(DISABLE_AUTO_RECONNECT, "true");
- dsProps.setProperty(MCAST_PORT, "0");
addDSProps(dsProps);
- vm0.invoke(() -> startLocatorAsync(new Object[] {port1, dsProps}));
- vm1.invoke(() -> startLocatorAsync(new Object[] {port2, dsProps}));
- vm2.invoke(() -> startLocatorAsync(new Object[] {port3, dsProps}));
+ startLocator(vm0, dsProps, port1);
+ startLocator(vm1, dsProps, port2);
+ startLocator(vm2, dsProps, port3);
try {
vm3.invoke(() -> {
- DistributedSystem.connect(dsProps);
+ getConnectedDistributedSystem(dsProps);
return true;
});
vm4.invoke(() -> {
- DistributedSystem.connect(dsProps);
+ getConnectedDistributedSystem(dsProps);
- await()
+ GeodeAwaitility.await()
.until(() -> InternalDistributedSystem.getConnectedInstance().getDM().getViewMembers()
.size() == 5);
return true;
});
- vm0.invoke(() -> forceDisconnect());
- vm1.invoke(() -> forceDisconnect());
- vm2.invoke(() -> forceDisconnect());
+ vm0.invoke(this::forceDisconnect);
+ vm1.invoke(this::forceDisconnect);
+ vm2.invoke(this::forceDisconnect);
SerializableRunnable waitForDisconnect = new SerializableRunnable("waitForDisconnect") {
public void run() {
- await()
+ GeodeAwaitility.await()
.until(() -> InternalDistributedSystem.getConnectedInstance() == null);
}
};
@@ -1726,62 +1512,45 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(() -> waitForDisconnect);
disconnectAllFromDS();
-
final String newLocators = host0 + "[" + port2 + "]," + host0 + "[" + port3 + "]";
dsProps.setProperty(LOCATORS, newLocators);
getBlackboard().initBlackboard();
AsyncInvocation async1 = vm1.invokeAsync(() -> {
getBlackboard().signalGate("vm1ready");
- getBlackboard().waitForGate("readyToConnect", 30, TimeUnit.SECONDS);
+ getBlackboard().waitForGate("readyToConnect", 30, SECONDS);
System.out.println("vm1 is ready to connect");
- startLocatorAsync(new Object[] {port2, dsProps});
+ startLocatorBase(dsProps, port2);
});
AsyncInvocation async2 = vm2.invokeAsync(() -> {
getBlackboard().signalGate("vm2ready");
- getBlackboard().waitForGate("readyToConnect", 30, TimeUnit.SECONDS);
+ getBlackboard().waitForGate("readyToConnect", 30, SECONDS);
System.out.println("vm2 is ready to connect");
- startLocatorAsync(new Object[] {port3, dsProps});
+ startLocatorBase(dsProps, port3);
});
- getBlackboard().waitForGate("vm1ready", 30, TimeUnit.SECONDS);
- getBlackboard().waitForGate("vm2ready", 30, TimeUnit.SECONDS);
+ getBlackboard().waitForGate("vm1ready", 30, SECONDS);
+ getBlackboard().waitForGate("vm2ready", 30, SECONDS);
getBlackboard().signalGate("readyToConnect");
async1.join();
async2.join();
- vm1.invoke("waitUntilLocatorBecomesCoordinator", () -> waitUntilLocatorBecomesCoordinator());
- vm2.invoke("waitUntilLocatorBecomesCoordinator", () -> waitUntilLocatorBecomesCoordinator());
+ vm1.invoke("waitUntilLocatorBecomesCoordinator", this::waitUntilLocatorBecomesCoordinator);
+ vm2.invoke("waitUntilLocatorBecomesCoordinator", this::waitUntilLocatorBecomesCoordinator);
- if (vm1.invoke(() -> GMSJoinLeaveTestHelper.isViewCreator())) {
+ if (vm1.invoke(GMSJoinLeaveTestHelper::isViewCreator)) {
assertFalse(
- vm2.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.isViewCreator()));
+ vm2.invoke("Checking ViewCreator", GMSJoinLeaveTestHelper::isViewCreator));
} else {
assertTrue(
- vm2.invoke("Checking ViewCreator", () -> GMSJoinLeaveTestHelper.isViewCreator()));
+ vm2.invoke("Checking ViewCreator", GMSJoinLeaveTestHelper::isViewCreator));
}
} finally {
- vm2.invoke(() -> stopLocator());
- vm1.invoke(() -> stopLocator());
+ vm2.invoke(LocatorDUnitTest::stopLocator);
+ vm1.invoke(LocatorDUnitTest::stopLocator);
}
}
- private void waitUntilLocatorBecomesCoordinator() {
- await()
- .until(() -> GMSJoinLeaveTestHelper.getCurrentCoordinator()
- .getVmKind() == ClusterDistributionManager.LOCATOR_DM_TYPE);
- }
-
- private void startLocatorAsync(Object[] args) {
- File logFile = new File("");
- Properties properties = (Properties) args[1];
- properties.put(NAME, "vm" + VM.getCurrentVMNum());
- try {
- Locator.startLocatorAndDS((int) args[0], logFile, properties);
- } catch (IOException ex) {
- throw new RuntimeException("While starting process on port " + args[0], ex);
- }
- }
/**
* Tests that a VM can connect to a locator that is hosted in its own VM.
@@ -1789,25 +1558,19 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testConnectToOwnLocator() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
- File logFile = new File("");
- Locator locator = Locator.startLocator(port1, logFile);
- try {
- final String locators = NetworkUtils.getServerHostName(host) + "[" + port1 + "]";
+ final String locators = NetworkUtils.getServerHostName() + "[" + port1 + "]";
+
+ Properties props = getBasicProperties(locators);
+ props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
+ Locator locator = Locator.startLocatorAndDS(port1, new File(""), props);
+ system = (InternalDistributedSystem) locator.getDistributedSystem();
+ system.disconnect();
+ locator.stop();
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
- system = (InternalDistributedSystem) DistributedSystem.connect(props);
- system.disconnect();
- } finally {
- locator.stop();
- }
}
/**
@@ -1816,7 +1579,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testHostingMultipleLocators() throws Exception {
disconnectAllFromDS();
- Host host = Host.getHost(0);
+
int[] randomAvailableTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
port1 = randomAvailableTCPPorts[0];
File logFile1 = new File("");
@@ -1826,29 +1589,20 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
try {
int port2 = randomAvailableTCPPorts[1];
- File logFile2 = new File("");
-
DistributedTestUtils.deleteLocatorStateFile(port2);
try {
- Locator locator2 = Locator.startLocator(port2, logFile2);
+ Locator.startLocator(port2, new File(""));
fail("expected second locator start to fail.");
} catch (IllegalStateException expected) {
}
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
- SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {
- public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- DistributedSystem.connect(props);
- }
- };
- connect.run();
+ Properties props = getBasicProperties(locators);
+ props.setProperty(LOG_LEVEL, logger.getLevel().name());
+ getConnectedDistributedSystem(props);
disconnectDistributedSystem();
@@ -1869,34 +1623,34 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedTestUtils.deleteLocatorStateFile(port1);
File logFile = new File("");
File stateFile = new File("locator" + port1 + "state.dat");
- VM vm0 = Host.getHost(0).getVM(0);
- final Properties p = new Properties();
- p.setProperty(LOCATORS, Host.getHost(0).getHostName() + "[" + port1 + "]");
- p.setProperty(MCAST_PORT, "0");
- p.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
- p.setProperty(LOG_LEVEL, DUnitLauncher.logLevel);
- addDSProps(p);
+ VM vm = VM.getVM(0);
+ final Properties properties =
+ getBasicProperties(Host.getHost(0).getHostName() + "[" + port1 + "]");
+ properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
+ properties.setProperty(LOG_LEVEL, DUnitLauncher.logLevel);
+ addDSProps(properties);
if (stateFile.exists()) {
- stateFile.delete();
+ assertThat(stateFile.delete()).isTrue();
+
}
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Starting locator");
- Locator locator = Locator.startLocatorAndDS(port1, logFile, p);
+ logger.info("Starting locator");
+ Locator locator = Locator.startLocatorAndDS(port1, logFile, properties);
try {
- vm0.invoke(() -> {
- DistributedSystem.connect(p);
- return null;
+ vm.invoke(() -> {
+ getConnectedDistributedSystem(properties);
+ return true;
});
- LogWriterUtils.getLogWriter().info("Stopping locator");
+ logger.info("Stopping locator");
locator.stop();
- LogWriterUtils.getLogWriter().info("Starting locator");
- locator = Locator.startLocatorAndDS(port1, logFile, p);
+ logger.info("Starting locator");
+ locator = Locator.startLocatorAndDS(port1, logFile, properties);
- vm0.invoke("disconnect", () -> {
- DistributedSystem.connect(p).disconnect();
+ vm.invoke("disconnect", () -> {
+ getConnectedDistributedSystem(properties).disconnect();
return null;
});
@@ -1916,38 +1670,37 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
DistributedTestUtils.deleteLocatorStateFile(port1);
File logFile = new File("");
File stateFile = new File("locator" + port1 + "state.dat");
- VM vm0 = Host.getHost(0).getVM(0);
- final Properties p = new Properties();
- p.setProperty(LOCATORS, Host.getHost(0).getHostName() + "[" + port1 + "]");
- p.setProperty(MCAST_PORT, "0");
- p.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
- p.setProperty(LOG_LEVEL, "finest");
- addDSProps(p);
+ VM vm = VM.getVM(0);
+ final Properties properties =
+ getBasicProperties(Host.getHost(0).getHostName() + "[" + port1 + "]");
+ properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
+ properties.setProperty(LOG_LEVEL, "finest");
+ addDSProps(properties);
if (stateFile.exists()) {
- stateFile.delete();
+ assertThat(stateFile.delete()).isTrue();
}
- Locator locator = Locator.startLocatorAndDS(port1, logFile, p);
+ Locator locator = Locator.startLocatorAndDS(port1, logFile, properties);
- vm0.invoke(() -> {
- DistributedSystem.connect(p);
+ vm.invoke(() -> {
+ getConnectedDistributedSystem(properties);
return null;
});
try {
locator.stop();
- locator = Locator.startLocatorAndDS(port1, logFile, p);
+ locator = Locator.startLocatorAndDS(port1, logFile, properties);
assertEquals(2, ((InternalDistributedSystem) locator.getDistributedSystem()).getDM()
.getViewMembers().size());
locator.stop();
- locator = Locator.startLocatorAndDS(port1, logFile, p);
+ locator = Locator.startLocatorAndDS(port1, logFile, properties);
assertEquals(2, ((InternalDistributedSystem) locator.getDistributedSystem()).getDM()
.getViewMembers().size());
} finally {
- vm0.invoke("disconnect", () -> {
- DistributedSystem.connect(p).disconnect();
+ vm.invoke("disconnect", () -> {
+ getConnectedDistributedSystem(properties).disconnect();
return null;
});
locator.stop();
@@ -1955,66 +1708,213 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
}
- /**
- * return the distributed member id for the ds on this vm
- */
- public static DistributedMember getDistributedMember(Properties props) {
- props.put("name", "vm_" + VM.getCurrentVMNum());
- DistributedSystem sys = DistributedSystem.connect(props);
- sys.getLogWriter().info("<ExpectedException action=add>service failure</ExpectedException>");
- sys.getLogWriter().info(
- "<ExpectedException action=add>org.apache.geode.ConnectException</ExpectedException>");
- sys.getLogWriter().info(
- "<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
- return DistributedSystem.connect(props).getDistributedMember();
+ @Override
+ public final void postSetUp() {
+ port1 = -1;
+ port2 = -1;
+ IgnoredException.addIgnoredException("Removing shunned member");
}
- /**
- * find a running locator and return its distributed member id
- */
- private static DistributedMember getLocatorDistributedMember() {
- return (Locator.getLocators().iterator().next()).getDistributedSystem().getDistributedMember();
+ @Override
+ public final void preTearDown() {
+ if (Locator.hasLocator()) {
+ Locator.getLocator().stop();
+ }
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ if (cache != null && !cache.isClosed()) {
+ cache.close();
+ }
+ // delete locator state files so they don't accidentally
+ // get used by other tests
+ if (port1 > 0) {
+ DistributedTestUtils.deleteLocatorStateFile(port1);
+ }
+ if (port2 > 0) {
+ DistributedTestUtils.deleteLocatorStateFile(port2);
+ }
}
- /**
- * find the lead member and return its id
- */
- private static DistributedMember getLeadMember() {
- DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
- return MembershipManagerHelper.getLeadMember(sys);
+ @Override
+ public final void postTearDown() {
+ disconnectAllFromDS();
+ if (system != null) {
+ system.disconnect();
+ system = null;
+ }
}
- protected static void stopLocator() {
- MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
- Locator loc = Locator.getLocator();
- if (loc != null) {
- loc.stop();
- assertFalse(Locator.hasLocator());
+ // for child classes
+ protected void addDSProps(Properties p) {}
+
+ protected static InternalDistributedSystem getConnectedDistributedSystem(Properties properties) {
+ return (InternalDistributedSystem) DistributedSystem.connect(properties);
+ }
+
+ private void startLocatorWithPortAndProperties(final int port, final Properties properties)
+ throws IOException {
+ assertThat(Locator.startLocatorAndDS(port, new File(""), properties)).isNotNull();
+ }
+
+ private String getSingleKeyKeystore() {
+ return TestUtil.getResourcePath(getClass(), "/ssl/trusted.keystore");
+ }
+
+ private String getMultiKeyKeystore() {
+ return TestUtil.getResourcePath(getClass(), "/org/apache/geode/internal/net/multiKey.jks");
+ }
+
+ private String getMultiKeyTruststore() {
+ return TestUtil.getResourcePath(getClass(), "/org/apache/geode/internal/net/multiKeyTrust.jks");
+ }
+
+ private void startVerifyAndStopLocator(VM loc1, VM loc2, int port1, int port2,
+ Properties properties) throws Exception {
+ try {
+ getBlackboard().initBlackboard();
+ AsyncInvocation<Void> async1 = loc1.invokeAsync("startLocator1", () -> {
+ getBlackboard().signalGate("locator1");
+ getBlackboard().waitForGate("go", 60, SECONDS);
+ startLocatorWithPortAndProperties(port1, properties);
+ });
+
+ AsyncInvocation<Void> async2 = loc2.invokeAsync("startLocator2", () -> {
+ getBlackboard().signalGate("locator2");
+ getBlackboard().waitForGate("go", 60, SECONDS);
+ startLocatorWithPortAndProperties(port2, properties);
+ });
+
+ getBlackboard().waitForGate("locator1", 60, SECONDS);
+ getBlackboard().waitForGate("locator2", 60, SECONDS);
+ getBlackboard().signalGate("go");
+
+ async1.await();
+ async2.await();
+
+ // verify that they found each other
+ loc2.invoke("expectSystemToContainThisManyMembers",
+ () -> expectSystemToContainThisManyMembers(2));
+ loc1.invoke("expectSystemToContainThisManyMembers",
+ () -> expectSystemToContainThisManyMembers(2));
+ } finally {
+ loc2.invoke("stop locator", LocatorDUnitTest::stopLocator);
+ loc1.invoke("stop locator", LocatorDUnitTest::stopLocator);
}
}
- private void forceDisconnect() {
- DistributedTestUtils.crashDistributedSystem(InternalDistributedSystem.getConnectedInstance());
+ private void waitForMemberToBecomeLeadMemberOfDistributedSystem(final DistributedMember member,
+ final DistributedSystem sys) {
+ GeodeAwaitility.await().until(() -> {
+ DistributedMember lead = MembershipManagerHelper.getLeadMember(sys);
+ if (member != null) {
+ return member.equals(lead);
+ }
+ return (lead == null);
+ });
}
- private void startSBLocator(final int port) {
- File logFile = new File("");
+ private int startLocatorGetPort(VM vm, Properties properties, int port) {
+ return vm.invoke(() -> startLocatorBase(properties, port).getPort());
+ }
+
+ private void startLocator(VM vm, Properties properties, int port) {
+ vm.invoke(() -> {
+ startLocatorBase(properties, port);
+ });
+ }
+
+ private Locator startLocatorBase(Properties properties, int port) {
+ File lf = new File("");
+ try {
+ properties.put(NAME, "vm" + VM.getCurrentVMNum());
+ return Locator.startLocatorAndDS(port, lf, properties);
+ } catch (IOException ios) {
+ throw new RuntimeException("Unable to start locator", ios);
+ }
+ }
+
+ void startLocatorWithSomeBasicProperties(VM vm, int port) {
+ Properties locProps = new Properties();
+ locProps.setProperty(MCAST_PORT, "0");
+ locProps.setProperty(MEMBER_TIMEOUT, "1000");
+ locProps.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ addDSProps(locProps);
+
+ startLocator(vm, locProps, port);
+ }
+
+ private void startLocatorPreferredCoordinators(VM vm0, int port) {
try {
System.setProperty(InternalLocator.LOCATORS_PREFERRED_AS_COORDINATORS, "true");
- Properties locProps = new Properties();
- locProps.put(MCAST_PORT, "0");
- locProps.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- addDSProps(locProps);
- Locator.startLocatorAndDS(port, logFile, locProps);
- } catch (IOException ex) {
- throw new RuntimeException("While starting locator on port " + port, ex);
+ Properties locProps1 = new Properties();
+ locProps1.put(MCAST_PORT, "0");
+ locProps1.put(LOG_LEVEL, logger.getLevel().name());
+
+ addDSProps(locProps1);
+
+ startLocator(vm0, locProps1, port);
} finally {
System.getProperties().remove(InternalLocator.LOCATORS_PREFERRED_AS_COORDINATORS);
}
}
+ private void checkSystemConnectedInVMs(VM vm1, VM vm2) {
+ assertThat(vm1.invoke(LocatorDUnitTest::isSystemConnected))
+ .describedAs("Distributed system should not have disconnected").isTrue();
+
+ assertThat(vm2.invoke(LocatorDUnitTest::isSystemConnected))
+ .describedAs("Distributed system should not have disconnected").isTrue();
+ }
+
+ private void checkConnectionAndPrintInfo(VM vm1) {
+ vm1.invoke(() -> {
+ DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+ if (sys != null && sys.isConnected()) {
+ sys.disconnect();
+ }
+ // connectExceptions occur during disconnect, so we need the
+ // ExpectedException hint to be in effect until this point
+ LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
+ bLogger
+ .info("<ExpectedException action=remove>java.net.ConnectException</ExpectedException>");
+ });
+ }
+
+ private void forceDisconnect() {
+ DistributedTestUtils.crashDistributedSystem(InternalDistributedSystem.getConnectedInstance());
+ }
+
+ Properties getBasicProperties(String locators) {
+ Properties props = new Properties();
+ props.setProperty(MCAST_PORT, "0");
+ props.setProperty(LOCATORS, locators);
+ return props;
+ }
+
+ private Properties getClusterProperties(String locators, String s) {
+ final Properties properties = getBasicProperties(locators);
+ properties.put(ENABLE_NETWORK_PARTITION_DETECTION, s);
+ properties.put(DISABLE_AUTO_RECONNECT, "true");
+ properties.put(MEMBER_TIMEOUT, "2000");
+ properties.put(LOG_LEVEL, logger.getLevel().name());
+ properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+ return properties;
+ }
+
+ private void waitUntilTheSystemIsConnected(VM vm2, VM locatorVM) {
+
+ GeodeAwaitility.await().until(() -> {
+ assertThat(isSystemConnected())
+ .describedAs("Distributed system should not have disconnected")
+ .isTrue();
+
+ checkSystemConnectedInVMs(vm2, locatorVM);
+ return true;
+ });
+ }
+
+
// New test hook which blocks before closing channel.
- private static class TestHook implements MembershipTestHook {
+ static class TestHook implements MembershipTestHook {
volatile boolean unboundedWait = true;
@@ -2034,16 +1934,16 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
@Override
public void afterMembershipFailure(String reason, Throwable cause) {}
- public void reset() {
+ void reset() {
unboundedWait = false;
}
}
- private static class MyMembershipListener implements MembershipListener {
+ static class MyMembershipListener implements MembershipListener {
boolean quorumLostInvoked;
- List<String> suspectReasons = new ArrayList<>(50);
+ final List<String> suspectReasons = new ArrayList<>(50);
public void memberJoined(DistributionManager distributionManager,
InternalDistributedMember id) {}
@@ -2057,10 +1957,10 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase {
}
public void quorumLost(DistributionManager distributionManager,
- Set<InternalDistributedMember> failures, List<InternalDistributedMember> remaining) {
+ Set<InternalDistributedMember> failures,
+ List<InternalDistributedMember> remaining) {
quorumLostInvoked = true;
- org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
- .info("quorumLost invoked in test code");
+ logger.info("quorumLost invoked in test code");
}
}
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
index 4788848..238528f 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
@@ -14,19 +14,17 @@
*/
package org.apache.geode.distributed;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.MEMBER_TIMEOUT;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_UDP_DHALGO;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import java.util.Properties;
-import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.geode.GemFireConfigException;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.test.dunit.DistributedTestUtils;
import org.apache.geode.test.dunit.NetworkUtils;
@@ -41,28 +39,25 @@ public class LocatorUDPSecurityDUnitTest extends LocatorDUnitTest {
}
@Test
- public void testLocatorWithUDPSecurityButServer() throws Exception {
+ public void testLocatorWithUDPSecurityButServer() {
disconnectAllFromDS();
- VM vm0 = VM.getVM(0);
+ VM vm = VM.getVM(0);
final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
final String locators = NetworkUtils.getServerHostName() + "[" + port + "]";
- vm0.invoke("Start locator " + locators, () -> startLocator(port));
- try {
+ startLocatorWithSomeBasicProperties(vm, port);
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
+ try {
+ Properties props = getBasicProperties(locators);
props.setProperty(MEMBER_TIMEOUT, "1000");
- // addDSProps(props);
- system = (InternalDistributedSystem) DistributedSystem.connect(props);
-
+ system = getConnectedDistributedSystem(props);
+ fail("Should not have reached this line, it should have caught the exception.");
} catch (GemFireConfigException gce) {
- Assert.assertTrue(gce.getMessage().contains("Rejecting findCoordinatorRequest"));
+ assertThat(gce.getMessage()).contains("Rejecting findCoordinatorRequest");
} finally {
- vm0.invoke(() -> stopLocator());
+ vm.invoke(LocatorDUnitTest::stopLocator);
}
}
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java
index 49c1e84..bcee1d7 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java
@@ -17,7 +17,8 @@ package org.apache.geode.distributed.internal.tcpserver;
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
@@ -26,8 +27,6 @@ import java.util.Properties;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache30.CacheSerializableRunnable;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
@@ -36,7 +35,6 @@ import org.apache.geode.distributed.internal.membership.gms.locator.FindCoordina
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.Version;
import org.apache.geode.internal.net.SocketCreator;
-import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.Invoke;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
@@ -51,169 +49,106 @@ public class TcpServerBackwardCompatDUnitTest extends JUnit4DistributedTestCase
@Override
public final void postSetUp() throws Exception {
disconnectAllFromDS();
- Invoke.invokeInEveryVM(new CacheSerializableRunnable("Set TcpServer.isTesting true") {
-
- @Override
- public void run2() throws CacheException {
- TcpServer.isTesting = true;
- }
+ Invoke.invokeInEveryVM("Set TcpServer.isTesting true", () -> {
+ TcpServer.isTesting = true;
});
}
@Override
public final void preTearDown() throws Exception {
- Invoke.invokeInEveryVM(new CacheSerializableRunnable("Set TcpServer.isTesting true") {
-
- @Override
- public void run2() throws CacheException {
- TcpServer.isTesting = false;
- }
+ Invoke.invokeInEveryVM("Set TcpServer.isTesting true", () -> {
+ TcpServer.isTesting = false;
});
}
/**
* This test starts two locators with current GOSSIPVERSION and then shuts down one of them and
- * restart it with new GOSSIPVERSION and verifies that it has recoverd the system View. Then we
+ * restart it with new GOSSIPVERSION and verifies that it has recovered the system View. Then we
* upgrade next locator.
*/
@Test
public void testGossipVersionBackwardCompatibility() {
- Host host = Host.getHost(0);
- final VM locator0 = host.getVM(0);
- final VM locator1 = host.getVM(1);
- final VM locatorRestart0 = host.getVM(2);
- final VM member = host.getVM(3);
+
+ final VM locator0 = VM.getVM(0);
+ final VM locator1 = VM.getVM(1);
+ final VM locatorRestart0 = VM.getVM(2);
+ final VM member = VM.getVM(3);
int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
// Create properties for locator0
final int port0 = ports[0];
- final File logFile0 = null;// new File("");
+ final File logFile0 = null;
// Create properties for locator1
final int port1 = ports[1];
- final File logFile1 = null;// new File("");
+ final File logFile1 = null;
final String locators =
- host.getHostName() + "[" + port0 + "]," + host.getHostName() + "[" + port1 + "]";
+ VM.getHostName() + "[" + port0 + "]," + VM.getHostName() + "[" + port1 + "]";
final Properties props = new Properties();
props.setProperty(LOCATORS, locators);
props.setProperty(MCAST_PORT, "0");
props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
- // props.setProperty(LOG_LEVEL, "finest");
-
- // Start locator0 with props.
- // props.setProperty(DistributionConfig.START_LOCATOR_NAME, host.getHostName() + "["+port0+"]");
- locator0.invoke(new CacheSerializableRunnable("Starting first locator on port " + port0) {
-
- @Override
- public void run2() throws CacheException {
- try {
- TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION - 100,
- Version.CURRENT_ORDINAL);
-
- Locator.startLocatorAndDS(port0, logFile0, props);
- } catch (IOException e) {
- org.apache.geode.test.dunit.Assert.fail(
- "Locator1 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
- }
- }
- });
- // Start a new member to add it to discovery set of locator0.
- member.invoke(new CacheSerializableRunnable("Start a member") {
-
- @Override
- public void run2() throws CacheException {
- disconnectFromDS();
+ locator0.invoke("Starting first locator on port " + port0, () -> {
+ try {
TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION - 100,
Version.CURRENT_ORDINAL);
- InternalDistributedSystem.connect(props);
+
+ Locator.startLocatorAndDS(port0, logFile0, props);
+ } catch (IOException e) {
+ fail("Locator1 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
}
});
- // Start locator1 with props.
- // props.setProperty(DistributionConfig.START_LOCATOR_NAME, host.getHostName() + "["+port1+"]");
- locator1.invoke(new CacheSerializableRunnable("Starting second locator on port " + port1) {
-
- @Override
- public void run2() throws CacheException {
- try {
- TcpServer.TESTVERSION -= 100;
- TcpServer.OLDTESTVERSION -= 100;
- TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION,
- Version.CURRENT_ORDINAL);
- TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.OLDTESTVERSION,
- Version.GFE_57.ordinal());
- // assertIndexDetailsEquals("Gossip Version and Test version are not same",
- // TcpServer.GOSSIPVERSION, TcpServer.TESTVERSION);
- // assertIndexDetailsEquals("Previous Gossip Version and Test version are not same",
- // TcpServer.OLDGOSSIPVERSION, TcpServer.OLDTESTVERSION);
-
- Locator.startLocatorAndDS(port1, logFile1, props);
-
- // Start a gossip client to connect to first locator "locator0".
- FindCoordinatorRequest req = new FindCoordinatorRequest(
- new InternalDistributedMember(SocketCreator.getLocalHost(), 1234));
- FindCoordinatorResponse response = null;
-
- response = (FindCoordinatorResponse) new TcpClient()
- .requestToServer(SocketCreator.getLocalHost(), port1, req, 5000);
- assertNotNull(response);
-
- } catch (Exception e) {
- org.apache.geode.test.dunit.Assert.fail(
- "Locator1 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
- }
- }
+ // Start a new member to add it to discovery set of locator0.
+ member.invoke("Start a member", () -> {
+ disconnectFromDS();
+ TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION - 100,
+ Version.CURRENT_ORDINAL);
+ InternalDistributedSystem.connect(props);
});
- // Stop first locator currently running in locator0 VM.
- locator0.invoke(new CacheSerializableRunnable("Stopping first locator") {
+ // Start locator1 with props.
+ locator1.invoke("Starting second locator on port " + port1,
+ () -> restartLocator(port1, logFile1, props));
- @Override
- public void run2() throws CacheException {
- Locator.getLocator().stop();
- disconnectFromDS();
- }
+ // Stop first locator currently running in locator0 VM.
+ locator0.invoke("Stopping first locator", () -> {
+ Locator.getLocator().stop();
+ disconnectFromDS();
});
// Restart first locator in new VM.
- // props.setProperty(DistributionConfig.START_LOCATOR_NAME, host.getHostName() + "["+port0+"]");
- locatorRestart0
- .invoke(new CacheSerializableRunnable("Restarting first locator on port " + port0) {
-
- @Override
- public void run2() throws CacheException {
- try {
- TcpServer.TESTVERSION -= 100;
- TcpServer.OLDTESTVERSION -= 100;
- TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION,
- Version.CURRENT_ORDINAL);
- TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.OLDTESTVERSION,
- Version.GFE_57.ordinal());
- // assertIndexDetailsEquals("Gossip Version and Test version are not same",
- // TcpServer.GOSSIPVERSION, TcpServer.TESTVERSION);
- // assertIndexDetailsEquals("Previous Gossip Version and Test version are not same",
- // TcpServer.OLDGOSSIPVERSION, TcpServer.OLDTESTVERSION);
-
- Locator.startLocatorAndDS(port0, logFile0, props);
-
- // Start a gossip client to connect to first locator "locator0".
- FindCoordinatorRequest req = new FindCoordinatorRequest(
- new InternalDistributedMember(SocketCreator.getLocalHost(), 1234));
- FindCoordinatorResponse response = null;
-
- response = (FindCoordinatorResponse) new TcpClient()
- .requestToServer(SocketCreator.getLocalHost(), port0, req, 5000);
- assertNotNull(response);
-
- } catch (Exception e) {
- org.apache.geode.test.dunit.Assert.fail(
- "Locator0 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
- }
- }
- });
+ locatorRestart0.invoke(() -> restartLocator(port0, logFile0, props));
+ }
+
+ private void restartLocator(int port0, File logFile0, Properties props) {
+ try {
+ TcpServer.TESTVERSION -= 100;
+ TcpServer.OLDTESTVERSION -= 100;
+ TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION,
+ Version.CURRENT_ORDINAL);
+ TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.OLDTESTVERSION,
+ Version.GFE_57.ordinal());
+
+ Locator.startLocatorAndDS(port0, logFile0, props);
+
+ // Start a gossip client to connect to first locator "locator0".
+ FindCoordinatorRequest req = new FindCoordinatorRequest(
+ new InternalDistributedMember(SocketCreator.getLocalHost(), 1234));
+ FindCoordinatorResponse response;
+
+ response = (FindCoordinatorResponse) new TcpClient()
+ .requestToServer(SocketCreator.getLocalHost(), port0, req, 5000);
+ assertThat(response).isNotNull();
+
+ } catch (LocatorCancelException e) {
+ fail("a Locator start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
+ } catch (Exception e) {
+ fail("b Locator start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
+ }
}
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java
index 575ef63..7c8f866 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java
@@ -19,7 +19,7 @@ import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -30,6 +30,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Properties;
+import org.apache.logging.log4j.Logger;
+import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.apache.geode.cache.Cache;
@@ -38,13 +40,11 @@ import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.DistributionAdvisee;
import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.tcpserver.LocatorCancelException;
import org.apache.geode.internal.AvailablePort.Keeper;
import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
+import org.apache.geode.internal.logging.LogService;
import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
@@ -55,32 +55,21 @@ import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
*/
public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
-
+ private final Logger logger = LogService.getLogger();
private static InternalCache cache;
- private void createCache(String locators, String groups) {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- if (groups != null) {
- props.setProperty(GROUPS, groups);
- }
- props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- cache = (InternalCache) new CacheFactory(props).create();
- }
/**
* Tests 2 controllers and 2 cache servers
*/
@Test
- public void test2by2() throws Exception {
+ public void test2by2() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
List<Keeper> freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPortKeepers(6);
final Keeper keeper1 = freeTCPPorts.get(0);
@@ -96,491 +85,130 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
final Keeper bsKeeper4 = freeTCPPorts.get(5);
final int bsPort4 = bsKeeper4.getPort();
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]" + "," + host0 + "[" + port2 + "]";
final Properties dsProps = new Properties();
dsProps.setProperty(LOCATORS, locators);
dsProps.setProperty(MCAST_PORT, "0");
- dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ dsProps.setProperty(LOG_LEVEL, String.valueOf(logger.getLevel()));
dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
keeper1.release();
- vm0.invoke(new SerializableRunnable("Start locator on " + port1) {
- public void run() {
- File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
- try {
- Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, null);
- } catch (IOException ex) {
- Assert.fail("While starting locator on port " + port1, ex);
- }
- }
- });
-
- // try { Thread.currentThread().sleep(4000); } catch (InterruptedException ie) { }
+ vm0.invoke(() -> startLocatorOnPort(port1, dsProps, null));
keeper2.release();
- vm3.invoke(new SerializableRunnable("Start locators on " + port2) {
- public void run() {
- File logFile = new File(getUniqueName() + "-locator" + port2 + ".log");
- try {
- Locator.startLocatorAndDS(port2, logFile, null, dsProps, true, true, "locator2HNFC");
-
- } catch (IOException ex) {
- Assert.fail("While starting locator on port " + port2, ex);
- }
- }
- });
+ vm3.invoke(() -> startLocatorOnPort(port2, dsProps, "locator2HNFC"));
- SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {
- public void run() {
- createCache(locators, null);
- }
- };
- vm1.invoke(connect);
- vm2.invoke(connect);
- SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort1);
- bs.setGroups(new String[] {"bs1Group1", "bs1Group2"});
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- };
- SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort3);
- bs.setGroups(new String[] {"bs3Group1", "bs3Group2"});
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- };
+ vm1.invoke(() -> createCache(locators, null));
+ vm2.invoke(() -> createCache(locators, null));
bsKeeper1.release();
- vm1.invoke(startBS1);
+ vm1.invoke(() -> startBridgeServerOnPort(bsPort1, "bs1Group1", "bs1Group2"));
bsKeeper3.release();
- vm1.invoke(startBS3);
+ vm1.invoke(() -> startBridgeServerOnPort(bsPort3, "bs3Group1", "bs3Group2"));
bsKeeper2.release();
- vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort2);
- bs.setGroups(new String[] {"bs2Group1", "bs2Group2"});
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- });
+ vm2.invoke(() -> startBridgeServerOnPort(bsPort2, "bs2Group1", "bs2Group2"));
bsKeeper4.release();
- vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort4);
- bs.setGroups(new String[] {"bs4Group1", "bs4Group2"});
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- });
+ vm2.invoke(() -> startBridgeServerOnPort(bsPort4, "bs4Group1", "bs4Group2"));
// verify that locators know about each other
- vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port2, cp.getPort());
- assertEquals("locator2HNFC", cp.getHost());
- }
-
- others = ca.fetchBridgeServers();
- assertEquals(4, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort1) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs3Group1", "bs3Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs4Group1", "bs4Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
- }
- });
- vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port1, cp.getPort());
- }
- others = ca.fetchBridgeServers();
- assertEquals(4, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort1) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs3Group1", "bs3Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs4Group1", "bs4Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
+ vm0.invoke(() -> {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ List others = ca.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) others.get(0);
+ assertThat(cp.getPort()).isEqualTo(port2);
+ assertThat(cp.getHost()).isEqualTo("locator2HNFC");
+ }
+
+ others = ca.fetchBridgeServers();
+ assertThat(others.size()).isEqualTo(4);
+ for (Object other : others) {
+ CacheServerAdvisor.CacheServerProfile bsp =
+ (CacheServerAdvisor.CacheServerProfile) other;
+ if (bsp.getPort() == bsPort1) {
+ assertThat(new String[] {"bs1Group1", "bs1Group2"}).isEqualTo(bsp.getGroups());
+ } else {
+ comparePortGroups(bsp, bsPort2, bsPort3, bsPort4);
}
}
});
+
+ vm3.invoke(
+ () -> verifyLocatorOnOtherPort(port1, bsPort1, bsPort2, bsPort3, bsPort4, "bs3Group1",
+ "bs3Group2", "bs4Group1",
+ "bs4Group2"));
vm1.invoke(
- new SerializableRunnable("Verify cache server view on " + bsPort1 + " and on " + bsPort3) {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchBridgeServers();
- LogWriterUtils.getLogWriter()
- .info("found these bridgeservers in " + advisee + ": " + others);
- assertEquals(3, others.size());
- others = bsa.fetchControllers();
- assertEquals(2, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port1) {
- // ok
- } else if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
+ () -> verifyBridgeServerViewOnTwoPorts(port1, port2));
vm2.invoke(
- new SerializableRunnable("Verify cache server view on " + bsPort2 + " and on " + bsPort4) {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchBridgeServers();
- LogWriterUtils.getLogWriter()
- .info("found these bridgeservers in " + advisee + ": " + others);
- assertEquals(3, others.size());
- others = bsa.fetchControllers();
- assertEquals(2, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port1) {
- // ok
- } else if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
-
- SerializableRunnable stopBS = new SerializableRunnable("stop cache server") {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- CacheServer bs = (CacheServer) bslist.get(0);
- bs.stop();
- }
- };
- vm1.invoke(stopBS);
+ () -> verifyBridgeServerViewOnTwoPorts(port1, port2));
- // now check to see if everyone else noticed it going away
- vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port2, cp.getPort());
- assertEquals("locator2HNFC", cp.getHost());
- }
+ vm1.invoke(this::stopBridgeServer);
- others = ca.fetchBridgeServers();
- assertEquals(3, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs3Group1", "bs3Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs4Group1", "bs4Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
- }
- });
- vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port1, cp.getPort());
- }
- others = ca.fetchBridgeServers();
- assertEquals(3, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs3Group1", "bs3Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs4Group1", "bs4Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
+ // now check to see if everyone else noticed it going away
+ vm0.invoke(() -> verifyOtherLocatorOnPortWithName(port2, bsPort2, bsPort3, bsPort4, "bs3Group1",
+ "bs3Group2",
+ "bs4Group1", "bs4Group2"));
+
+ vm3.invoke(() -> {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ List others = ca.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) others.get(0);
+ assertThat(cp.getPort()).isEqualTo(port1);
+ }
+ others = ca.fetchBridgeServers();
+ assertThat(others.size()).isEqualTo(3);
+ for (Object other : others) {
+ CacheServerAdvisor.CacheServerProfile bsp =
+ (CacheServerAdvisor.CacheServerProfile) other;
+ comparePortGroups(bsp, bsPort2, bsPort3, bsPort4);
}
});
- SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {
- public void run() {
- if (cache != null) {
- cache.close();
- }
- }
- };
- SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
- public void run() {
- assertTrue(Locator.hasLocator());
- Locator.getLocator().stop();
- assertFalse(Locator.hasLocator());
- }
- };
-
- vm0.invoke(stopLocator);
+ vm0.invoke(() -> stopLocatorAndCheckIt());
// now make sure everyone else saw the locator go away
- vm3.invoke(new SerializableRunnable("Verify locator stopped ") {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(0, others.size());
- }
- });
- vm2.invoke(new SerializableRunnable("Verify cache server saw locator stop") {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchControllers();
- assertEquals(1, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
- vm1.invoke(new SerializableRunnable("Verify cache server saw locator stop") {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- if (i == 0) {
- // skip this one since it is stopped
- continue;
- }
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchControllers();
- assertEquals(1, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
+ vm3.invoke(() -> verifyLocatorStopped());
+ vm2.invoke(() -> verifyBridgeServerSawLocatorStop(port2));
+ vm1.invoke(() -> verifyBridgeServerSawLocatorStopWithName(port2));
- SerializableRunnable restartBS = new SerializableRunnable("restart cache server") {
- public void run() {
- try {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- CacheServer bs = (CacheServer) bslist.get(0);
- bs.setHostnameForClients("nameForClients");
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- };
- // restart cache server 1 and see if controller sees it
- vm1.invoke(restartBS);
-
- vm3.invoke(new SerializableRunnable("Verify cache server restart ") {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- assertEquals(0, ca.fetchControllers().size());
- List others = ca.fetchBridgeServers();
- assertEquals(4, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort1) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- assertEquals("nameForClients", bsp.getHost());
- } else if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- assertFalse(bsp.getHost().equals("nameForClients"));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs3Group1", "bs3Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs4Group1", "bs4Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
- }
- });
+ // restart bridge server 1 and see if controller sees it
+ vm1.invoke(() -> restartBridgeServer());
- vm1.invoke(disconnect);
- vm2.invoke(disconnect);
- // now make sure controller saw all cache servers stop
-
- vm3.invoke(new SerializableRunnable("Verify locator stopped ") {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- assertEquals(0, ca.fetchControllers().size());
- assertEquals(0, ca.fetchBridgeServers().size());
- }
- });
- vm3.invoke(stopLocator);
+ vm3.invoke(() -> verifyBridgeServerRestart(bsPort1, bsPort2, bsPort3, bsPort4, "bs3Group1",
+ "bs3Group2",
+ "bs4Group1",
+ "bs4Group2"));
+
+ vm1.invoke("Disconnect from " + locators, this::safeCloseCache);
+ vm2.invoke("Disconnect from " + locators, this::safeCloseCache);
+ // now make sure controller saw all bridge servers stop
+
+ vm3.invoke(() -> verifyLocatorsAndBridgeServersStoppped());
+ vm3.invoke(() -> stopLocatorAndCheckIt());
}
+
@Test
- public void test2by2usingGroups() throws Exception {
+ public void test2by2usingGroups() {
disconnectAllFromDS();
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
- VM vm2 = host.getVM(2);
- VM vm3 = host.getVM(3);
+ VM vm0 = VM.getVM(0);
+ VM vm1 = VM.getVM(1);
+ VM vm2 = VM.getVM(2);
+ VM vm3 = VM.getVM(3);
List<Keeper> freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPortKeepers(6);
final Keeper keeper1 = freeTCPPorts.get(0);
@@ -596,479 +224,381 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
final Keeper bsKeeper4 = freeTCPPorts.get(5);
final int bsPort4 = bsKeeper4.getPort();
- final String host0 = NetworkUtils.getServerHostName(host);
+ final String host0 = NetworkUtils.getServerHostName();
final String locators = host0 + "[" + port1 + "]" + "," + host0 + "[" + port2 + "]";
final Properties dsProps = new Properties();
dsProps.setProperty(LOCATORS, locators);
dsProps.setProperty(MCAST_PORT, "0");
- dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ dsProps.setProperty(LOG_LEVEL, String.valueOf(logger.getLevel()));
dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
keeper1.release();
- vm0.invoke(new SerializableRunnable("Start locators on " + port1) {
- public void run() {
- File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
- try {
- Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, null);
- } catch (IOException ex) {
- Assert.fail("While starting locator on port " + port1, ex);
- }
- }
- });
-
- // try { Thread.currentThread().sleep(4000); } catch (InterruptedException ie) { }
+ vm0.invoke(() -> startLocatorOnPort(port1, dsProps, null));
keeper2.release();
- vm3.invoke(new SerializableRunnable("Start locators on " + port2) {
- public void run() {
- File logFile = new File(getUniqueName() + "-locator" + port2 + ".log");
- try {
- Locator.startLocatorAndDS(port2, logFile, null, dsProps, true, true, "locator2HNFC");
-
- } catch (IOException ex) {
- Assert.fail("While starting locator on port " + port2, ex);
- }
- }
- });
+ vm3.invoke(() -> startLocatorOnPort(port2, dsProps, "locator2HNFC"));
- vm1.invoke(new SerializableRunnable("Connect to " + locators) {
- public void run() {
- createCache(locators, "bs1Group1, bs1Group2");
- }
- });
- vm2.invoke(new SerializableRunnable("Connect to " + locators) {
- public void run() {
- createCache(locators, "bs2Group1, bs2Group2");
- }
- });
-
- SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort1);
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- };
- SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort3);
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- };
+ vm1.invoke(() -> createCache(locators, "bs1Group1, bs1Group2"));
+ vm2.invoke(() -> createCache(locators, "bs2Group1, bs2Group2"));
bsKeeper1.release();
- vm1.invoke(startBS1);
+ vm1.invoke(() -> startBridgeServerOnPort(bsPort1));
bsKeeper3.release();
- vm1.invoke(startBS3);
+ vm1.invoke(() -> startBridgeServerOnPort(bsPort3));
bsKeeper2.release();
- vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort2);
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- });
+ vm2.invoke(() -> startBridgeServerOnPort(bsPort2));
bsKeeper4.release();
- vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {
- public void run() {
- try {
- Cache c = cache;
- CacheServer bs = c.addCacheServer();
- bs.setPort(bsPort4);
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
- }
- });
+ vm2.invoke(() -> startBridgeServerOnPort(bsPort4));
// verify that locators know about each other
- vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port2, cp.getPort());
- assertEquals("locator2HNFC", cp.getHost());
- }
+ vm0.invoke(
+ () -> verifyLocatorOnOtherPort(port2, bsPort1, bsPort2, bsPort3, bsPort4, "bs1Group1",
+ "bs1Group2", "bs2Group1", "bs2Group2"));
+ vm3.invoke(
+ () -> verifyLocatorOnOtherPort(port1, bsPort1, bsPort2, bsPort3, bsPort4, "bs1Group1",
+ "bs1Group2", "bs2Group1", "bs2Group2"));
- others = ca.fetchBridgeServers();
- assertEquals(4, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort1) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
- }
- });
- vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port1, cp.getPort());
- }
- others = ca.fetchBridgeServers();
- assertEquals(4, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort1) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
- }
- });
vm1.invoke(
- new SerializableRunnable("Verify cache server view on " + bsPort1 + " and on " + bsPort3) {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchBridgeServers();
- LogWriterUtils.getLogWriter()
- .info("found these bridgeservers in " + advisee + ": " + others);
- assertEquals(3, others.size());
- others = bsa.fetchControllers();
- assertEquals(2, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port1) {
- // ok
- } else if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
+ () -> verifyBridgeServerViewOnTwoPorts(port1, port2));
vm2.invoke(
- new SerializableRunnable("Verify cache server view on " + bsPort2 + " and on " + bsPort4) {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchBridgeServers();
- LogWriterUtils.getLogWriter()
- .info("found these bridgeservers in " + advisee + ": " + others);
- assertEquals(3, others.size());
- others = bsa.fetchControllers();
- assertEquals(2, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port1) {
- // ok
- } else if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
-
- SerializableRunnable stopBS = new SerializableRunnable("stop cache server") {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- CacheServer bs = (CacheServer) bslist.get(0);
- bs.stop();
- }
- };
- vm1.invoke(stopBS);
+ () -> verifyBridgeServerViewOnTwoPorts(port1, port2));
- // now check to see if everyone else noticed it going away
- vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port2, cp.getPort());
- assertEquals("locator2HNFC", cp.getHost());
- }
+ vm1.invoke(this::stopBridgeServer);
- others = ca.fetchBridgeServers();
- assertEquals(3, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
+ // now check to see if everyone else noticed it going away
+ vm0.invoke(() -> verifyOtherLocatorOnPortWithName(port2, bsPort2, bsPort3, bsPort4, "bs1Group1",
+ "bs1Group2",
+ "bs2Group1",
+ "bs2Group2"));
+
+ vm3.invoke(() -> {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ List others = ca.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) others.get(0);
+ assertThat(cp.getPort()).isEqualTo(port1);
+ }
+ others = ca.fetchBridgeServers();
+ assertThat(others.size()).isEqualTo(3);
+ for (Object other : others) {
+ CacheServerAdvisor.CacheServerProfile bsp =
+ (CacheServerAdvisor.CacheServerProfile) other;
+ if (bsp.getPort() == bsPort2) {
+ assertThat(new String[] {"bs2Group1", "bs2Group2"}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort3) {
+ assertThat(new String[] {"bs1Group1", "bs1Group2"}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort4) {
+ assertThat(new String[] {"bs2Group1", "bs2Group2"}).isEqualTo(bsp.getGroups());
+ } else {
+ fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
}
});
- vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(1, others.size());
- {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(0);
- assertEquals(port1, cp.getPort());
- }
- others = ca.fetchBridgeServers();
- assertEquals(3, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
+
+ vm0.invoke(() -> stopLocatorAndCheckIt());
+
+ // now make sure everyone else saw the locator go away
+ vm3.invoke(() -> verifyLocatorStopped());
+ vm2.invoke(() -> verifyBridgeServerSawLocatorStop(port2));
+ vm1.invoke(() -> verifyBridgeServerSawLocatorStopWithName(port2));
+
+ // restart bridge server 1 and see if controller sees it
+ vm1.invoke(() -> restartBridgeServer());
+
+ vm3.invoke(() -> verifyBridgeServerRestart(bsPort1, bsPort2, bsPort3, bsPort4, "bs1Group1",
+ "bs1Group2",
+ "bs2Group1", "bs2Group2"));
+
+ vm1.invoke("Disconnect from " + locators, this::safeCloseCache);
+ vm2.invoke("Disconnect from " + locators, this::safeCloseCache);
+ // now make sure controller saw all bridge servers stop
+
+ vm3.invoke(() -> verifyLocatorsAndBridgeServersStoppped());
+ vm3.invoke(() -> stopLocatorAndCheckIt());
+ }
+
+ private void createCache(String locators, String groups) {
+ Properties props = new Properties();
+ props.setProperty(MCAST_PORT, "0");
+ props.setProperty(LOCATORS, locators);
+ if (groups != null) {
+ props.setProperty(GROUPS, groups);
+ }
+ props.setProperty(LOG_LEVEL, String.valueOf(logger.getLevel()));
+ cache = (InternalCache) new CacheFactory(props).create();
+ }
+
+
+ private void comparePortGroups(CacheServerAdvisor.CacheServerProfile bsp, int bsPort2,
+ int bsPort3, int bsPort4) {
+ if (bsp.getPort() == bsPort2) {
+ assertThat(new String[] {"bs2Group1", "bs2Group2"}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort3) {
+ assertThat(new String[] {"bs3Group1", "bs3Group2"}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort4) {
+ assertThat(new String[] {"bs4Group1", "bs4Group2"}).isEqualTo(bsp.getGroups());
+ } else {
+ fail("unexpected port " + bsp.getPort() + " in " + bsp);
+ }
+ }
+
+ private void stopLocatorAndCheckIt() {
+ assertTrue(Locator.hasLocator());
+ Locator.getLocator().stop();
+ assertFalse(Locator.hasLocator());
+ }
+
+
+ private void verifyBridgeServerViewOnTwoPorts(int port1, int port2) {
+ Cache c = cache;
+ List bslist = c.getCacheServers();
+ assertThat(bslist.size()).isEqualTo(2);
+ for (Object aBslist : bslist) {
+ DistributionAdvisee advisee = (DistributionAdvisee) aBslist;
+ CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
+ List others = bsa.fetchBridgeServers();
+ logger.info("found these bridgeservers in " + advisee + ": " + others);
+ assertThat(others.size()).isEqualTo(3);
+ others = bsa.fetchControllers();
+ assertThat(others.size()).isEqualTo(2);
+ for (Object other : others) {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) other;
+ if (cp.getPort() != port1) {
+ if (cp.getPort() == port2) {
+ assertThat(cp.getHost()).isEqualTo("locator2HNFC");
+ // ok
} else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
+ fail("unexpected port " + cp.getPort() + " in " + cp);
}
}
}
- });
+ }
+ }
- SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {
- public void run() {
- if (cache != null) {
- cache.close();
- }
+ private void verifyBridgeServerRestart(int bsPort1, int bsPort2, int bsPort3, int bsPort4,
+ String bs3Group1, String bs3Group2, String bs4Group1,
+ String bs4Group2) {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ assertThat(ca.fetchControllers().size()).isEqualTo(0);
+ List others = ca.fetchBridgeServers();
+ assertThat(others.size()).isEqualTo(4);
+ for (Object other : others) {
+ CacheServerAdvisor.CacheServerProfile bsp =
+ (CacheServerAdvisor.CacheServerProfile) other;
+ if (bsp.getPort() == bsPort1) {
+ assertThat(new String[] {"bs1Group1", "bs1Group2"}).isEqualTo(bsp.getGroups());
+ assertThat(bsp.getHost()).isEqualTo("nameForClients");
+ } else if (bsp.getPort() == bsPort2) {
+ assertThat(new String[] {"bs2Group1", "bs2Group2"}).isEqualTo(bsp.getGroups());
+ assertThat(bsp.getHost()).isNotEqualTo("nameForClients");
+ } else {
+ comparePortGroupsTwo(bsPort3, bsPort4, bs3Group1, bs3Group2, bs4Group1, bs4Group2, bsp);
}
- };
- SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
- public void run() {
- assertTrue(Locator.hasLocator());
- Locator.getLocator().stop();
- assertFalse(Locator.hasLocator());
- }
- };
+ }
+ }
- vm0.invoke(stopLocator);
+ private void comparePortGroupsTwo(int bsPort3, int bsPort4, String bs3Group1, String bs3Group2,
+ String bs4Group1, String bs4Group2,
+ CacheServerAdvisor.CacheServerProfile bsp) {
+ if (bsp.getPort() == bsPort3) {
+ assertThat(Arrays.asList(bsp.getGroups())).isEqualTo(Arrays.asList(bs3Group1, bs3Group2));
+ } else if (bsp.getPort() == bsPort4) {
+ assertThat(Arrays.asList(bsp.getGroups())).isEqualTo(Arrays.asList(bs4Group1, bs4Group2));
+ } else {
+ fail("unexpected port " + bsp.getPort() + " in " + bsp);
+ }
+ }
- // now make sure everyone else saw the locator go away
- vm3.invoke(new SerializableRunnable("Verify locator stopped ") {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- List others = ca.fetchControllers();
- assertEquals(0, others.size());
- }
- });
- vm2.invoke(new SerializableRunnable("Verify cache server saw locator stop") {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchControllers();
- assertEquals(1, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
- vm1.invoke(new SerializableRunnable("Verify cache server saw locator stop") {
- public void run() {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- for (int i = 0; i < bslist.size(); i++) {
- DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
- if (i == 0) {
- // skip this one since it is stopped
- continue;
- }
- CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
- List others = bsa.fetchControllers();
- assertEquals(1, others.size());
- for (int j = 0; j < others.size(); j++) {
- ControllerAdvisor.ControllerProfile cp =
- (ControllerAdvisor.ControllerProfile) others.get(j);
- if (cp.getPort() == port2) {
- assertEquals("locator2HNFC", cp.getHost());
- // ok
- } else {
- fail("unexpected port " + cp.getPort() + " in " + cp);
- }
- }
- }
- }
- });
+ private void verifyLocatorStopped() {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ List others = ca.fetchControllers();
+ assertThat(others.size()).isEqualTo(0);
+ }
- SerializableRunnable restartBS = new SerializableRunnable("restart cache server") {
- public void run() {
- try {
- Cache c = cache;
- List bslist = c.getCacheServers();
- assertEquals(2, bslist.size());
- CacheServer bs = (CacheServer) bslist.get(0);
- bs.setHostnameForClients("nameForClients");
- bs.start();
- } catch (IOException ex) {
- RuntimeException re = new RuntimeException();
- re.initCause(ex);
- throw re;
- }
+ private void verifyBridgeServerSawLocatorStop(int port2) {
+ Cache c = cache;
+ List bslist = c.getCacheServers();
+ assertThat(bslist.size()).isEqualTo(2);
+ for (Object aBslist : bslist) {
+ DistributionAdvisee advisee = (DistributionAdvisee) aBslist;
+ CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
+ List others = bsa.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ verifyHostNameForPort(port2, others);
+ }
+ }
+
+ private void verifyHostNameForPort(int port2, List others) {
+ for (Object other : others) {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) other;
+ if (cp.getPort() == port2) {
+ assertThat(cp.getHost()).isEqualTo("locator2HNFC");
+ // ok
+ } else {
+ fail("unexpected port " + cp.getPort() + " in " + cp);
}
- };
- // restart cache server 1 and see if controller sees it
- vm1.invoke(restartBS);
-
- vm3.invoke(new SerializableRunnable("Verify cache server restart ") {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- assertEquals(0, ca.fetchControllers().size());
- List others = ca.fetchBridgeServers();
- assertEquals(4, others.size());
- for (int j = 0; j < others.size(); j++) {
- CacheServerAdvisor.CacheServerProfile bsp =
- (CacheServerAdvisor.CacheServerProfile) others.get(j);
- if (bsp.getPort() == bsPort1) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- assertEquals("nameForClients", bsp.getHost());
- } else if (bsp.getPort() == bsPort2) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- assertFalse(bsp.getHost().equals("nameForClients"));
- } else if (bsp.getPort() == bsPort3) {
- assertEquals(Arrays.asList(new String[] {"bs1Group1", "bs1Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else if (bsp.getPort() == bsPort4) {
- assertEquals(Arrays.asList(new String[] {"bs2Group1", "bs2Group2"}),
- Arrays.asList(bsp.getGroups()));
- } else {
- fail("unexpected port " + bsp.getPort() + " in " + bsp);
- }
- }
+ }
+ }
+
+ private void verifyLocatorOnOtherPort(int port1, int bsPort1, int bsPort2, int bsPort3,
+ int bsPort4, String bs3Group1, String bs3Group2,
+ String bs4Group1, String bs4Group2) {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ List others = ca.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) others.get(0);
+ assertThat(cp.getPort()).isEqualTo(port1);
+ }
+ others = ca.fetchBridgeServers();
+ assertThat(others.size()).isEqualTo(4);
+ for (Object other : others) {
+ CacheServerAdvisor.CacheServerProfile bsp =
+ (CacheServerAdvisor.CacheServerProfile) other;
+ if (bsp.getPort() == bsPort1) {
+ assertThat(new String[] {"bs1Group1", "bs1Group2"}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort2) {
+ assertThat(new String[] {"bs2Group1", "bs2Group2"}).isEqualTo(bsp.getGroups());
+ } else {
+ comparePortGroupsTwo(bsPort3, bsPort4, bs3Group1, bs3Group2, bs4Group1, bs4Group2, bsp);
}
- });
+ }
+ }
- vm1.invoke(disconnect);
- vm2.invoke(disconnect);
- // now make sure controller saw all cache servers stop
-
- vm3.invoke(new SerializableRunnable("Verify locator stopped ") {
- public void run() {
- assertTrue(Locator.hasLocator());
- InternalLocator l = (InternalLocator) Locator.getLocator();
- DistributionAdvisee advisee = l.getServerLocatorAdvisee();
- ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
- assertEquals(0, ca.fetchControllers().size());
- assertEquals(0, ca.fetchBridgeServers().size());
+ private void startBridgeServerOnPort(int bsPort1, String bs1Group1, String bs1Group2) {
+ try {
+ Cache c = cache;
+ CacheServer bs = c.addCacheServer();
+ bs.setPort(bsPort1);
+ bs.setGroups(new String[] {bs1Group1, bs1Group2});
+ bs.start();
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private void startLocatorOnPort(int port1, Properties dsProps, String name) {
+ File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
+ try {
+ Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, name);
+ } catch (LocatorCancelException | IOException ex) {
+ Assertions.fail("While starting locator on port " + port1, ex);
+ }
+ }
+
+
+ private void safeCloseCache() {
+ if (cache != null) {
+ cache.close();
+ }
+ }
+
+ private void startBridgeServerOnPort(int bsPort4) {
+ try {
+ Cache c = cache;
+ CacheServer bs = c.addCacheServer();
+ bs.setPort(bsPort4);
+ bs.start();
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private void stopBridgeServer() {
+ Cache c = cache;
+ List bslist = c.getCacheServers();
+ assertThat(bslist.size()).isEqualTo(2);
+ CacheServer bs = (CacheServer) bslist.get(0);
+ bs.stop();
+ }
+
+ private void verifyLocatorsAndBridgeServersStoppped() {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ assertThat(ca.fetchControllers().size()).isEqualTo(0);
+ assertThat(ca.fetchBridgeServers().size()).isEqualTo(0);
+ }
+
+ private void restartBridgeServer() {
+ try {
+ Cache c = cache;
+ List bslist = c.getCacheServers();
+ assertThat(bslist.size()).isEqualTo(2);
+ CacheServer bs = (CacheServer) bslist.get(0);
+ bs.setHostnameForClients("nameForClients");
+ bs.start();
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private void verifyBridgeServerSawLocatorStopWithName(int port2) {
+ Cache c = cache;
+ List bslist = c.getCacheServers();
+ assertThat(bslist.size()).isEqualTo(2);
+ for (int i = 0; i < bslist.size(); i++) {
+ DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
+ if (i == 0) {
+ // skip this one since it is stopped
+ continue;
+ }
+ CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
+ List others = bsa.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ verifyHostNameForPort(port2, others);
+ }
+ }
+
+ private void verifyOtherLocatorOnPortWithName(int port2, int bsPort2, int bsPort3, int bsPort4,
+ String bs1Group1, String bs1Group2,
+ String bs2Group1, String bs2Group2) {
+ assertTrue(Locator.hasLocator());
+ InternalLocator l = (InternalLocator) Locator.getLocator();
+ DistributionAdvisee advisee = l.getServerLocatorAdvisee();
+ ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
+ List others = ca.fetchControllers();
+ assertThat(others.size()).isEqualTo(1);
+ {
+ ControllerAdvisor.ControllerProfile cp =
+ (ControllerAdvisor.ControllerProfile) others.get(0);
+ assertThat(cp.getPort()).isEqualTo(port2);
+ assertThat(cp.getHost()).isEqualTo("locator2HNFC");
+ }
+
+ others = ca.fetchBridgeServers();
+ assertThat(others.size()).isEqualTo(3);
+ for (Object other : others) {
+ CacheServerAdvisor.CacheServerProfile bsp =
+ (CacheServerAdvisor.CacheServerProfile) other;
+ if (bsp.getPort() == bsPort2) {
+ assertThat(new String[] {"bs2Group1", "bs2Group2"}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort3) {
+ assertThat(new String[] {bs1Group1, bs1Group2}).isEqualTo(bsp.getGroups());
+ } else if (bsp.getPort() == bsPort4) {
+ assertThat(new String[] {bs2Group1, bs2Group2}).isEqualTo(bsp.getGroups());
+ } else {
+ fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
- });
- vm3.invoke(stopLocator);
+ }
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java b/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
index 9f821d8..ac5f266 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/DistributedSystem.java
@@ -206,7 +206,7 @@ public abstract class DistributedSystem implements StatisticsFactory {
// This should not happen: existingSystem.isConnected()==false &&
// existingSystem.isDisconnecting()==false
throw new AssertionError(
- "system should not be disconnecting==false and isConnected==falsed");
+ "system should not have both disconnecting==false and isConnected==false");
}
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
index e2ea6b8..33494e2 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
@@ -280,6 +280,7 @@ public class InternalLocator extends Locator implements ConnectListener, LogConf
throw new IllegalStateException(
"A locator can not be created because one already exists in this JVM.");
}
+
InternalLocator.locator = locator;
}
}
@@ -301,7 +302,6 @@ public class InternalLocator extends Locator implements ConnectListener, LogConf
public static InternalLocator startLocator(int port, File logFile, InternalLogWriter logger,
InternalLogWriter securityLogger, InetAddress bindAddress, boolean startDistributedSystem,
Properties dsProperties, String hostnameForClients) throws IOException {
-
System.setProperty(FORCE_LOCATOR_DM_TYPE, "true");
InternalLocator newLocator = null;
@@ -322,23 +322,24 @@ public class InternalLocator extends Locator implements ConnectListener, LogConf
newLocator.startPeerLocation();
if (startDistributedSystem) {
+
try {
newLocator.startDistributedSystem();
} catch (RuntimeException e) {
newLocator.stop();
throw e;
}
- // fix bug #46324
+
final InternalDistributedSystem ids = newLocator.myDs;
if (ids != null) {
ids.getDistributionManager().addHostedLocators(ids.getDistributedMember(),
getLocatorStrings(), newLocator.isSharedConfigurationEnabled());
}
}
- } catch (final LocatorCancelException ignored) {
+ } catch (final LocatorCancelException lce) {
newLocator.stop();
+ throw lce;
}
-
InternalDistributedSystem sys = InternalDistributedSystem.getConnectedInstance();
if (sys != null) {
try {
@@ -355,11 +356,12 @@ public class InternalLocator extends Locator implements ConnectListener, LogConf
} finally {
System.getProperties().remove(FORCE_LOCATOR_DM_TYPE);
+
if (!startedLocator) {
- // fix for bug 46314
removeLocator(newLocator);
}
}
+
}
/***
@@ -816,7 +818,6 @@ public class InternalLocator extends Locator implements ConnectListener, LogConf
removeLocator(this);
handleShutdown();
-
logger.info("{} is stopped", this);
if (this.stoppedForReconnect) {
@@ -1014,6 +1015,7 @@ public class InternalLocator extends Locator implements ConnectListener, LogConf
private void restartWithDS(InternalDistributedSystem newSystem, InternalCache newCache)
throws IOException {
+
synchronized (locatorLock) {
if (locator != this && hasLocator()) {
throw new IllegalStateException(
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
index f83dc8c..44263f0 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpClient.java
@@ -14,11 +14,13 @@
*/
package org.apache.geode.distributed.internal.tcpserver;
+import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -56,8 +58,8 @@ public class TcpClient {
private static final int DEFAULT_REQUEST_TIMEOUT = 60 * 2 * 1000;
- private static Map<InetSocketAddress, Short> serverVersions =
- new HashMap<InetSocketAddress, Short>();
+ private static final Map<InetSocketAddress, Short> serverVersions =
+ new HashMap<>();
private final SocketCreator socketCreator;
@@ -108,8 +110,8 @@ public class TcpClient {
/**
* Contacts the Locator running on the given host, and port and gets information about it. Two
- * <code>String</code>s are returned: the first string is the working directory of the locator and
- * the second string is the product directory of the locator.
+ * <code>String</code>s are returned: the first string is the working directory of the locator
+ * and the second string is the product directory of the locator.
*/
public String[] getInfo(InetAddress addr, int port) {
try {
@@ -134,9 +136,7 @@ public class TcpClient {
* @param port The locator's tcp/ip port
* @param request The request message
* @param timeout Timeout for sending the message and receiving a reply
- *
* @return the reply
- *
*/
public Object requestToServer(InetAddress addr, int port, Object request, int timeout)
throws IOException, ClassNotFoundException {
@@ -152,9 +152,7 @@ public class TcpClient {
* @param request The request message
* @param timeout Timeout for sending the message and receiving a reply
* @param replyExpected Whether to wait for a reply
- *
* @return the reply
- *
*/
public Object requestToServer(InetAddress addr, int port, Object request, int timeout,
boolean replyExpected) throws IOException, ClassNotFoundException {
@@ -174,21 +172,14 @@ public class TcpClient {
* @param request The request message
* @param timeout Timeout for sending the message and receiving a reply
* @param replyExpected Whether to wait for a reply
- *
* @return The reply, or null if no reply is expected
- *
*/
public Object requestToServer(InetSocketAddress ipAddr, Object request, int timeout,
boolean replyExpected) throws IOException, ClassNotFoundException {
- /*
- * InetSocketAddress ipAddr; if (addr == null) { ipAddr = new InetSocketAddress(port); } else {
- * ipAddr = new InetSocketAddress(addr, port); // fix for bug 30810 }
- */
-
long giveupTime = System.currentTimeMillis() + timeout;
// Get the GemFire version of the TcpServer first, before sending any other request.
- short serverVersion = getServerVersion(ipAddr, timeout).shortValue();
+ short serverVersion = getServerVersion(ipAddr, timeout);
if (serverVersion > Version.CURRENT_ORDINAL) {
serverVersion = Version.CURRENT_ORDINAL;
@@ -213,7 +204,8 @@ public class TcpClient {
sock.setSoTimeout((int) newTimeout);
DataOutputStream out = null;
try {
- out = new DataOutputStream(sock.getOutputStream());
+
+ out = new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
if (serverVersion < Version.CURRENT_ORDINAL) {
out = new VersionedDataOutputStream(out, Version.fromOrdinalNoThrow(serverVersion, false));
@@ -274,20 +266,24 @@ public class TcpClient {
private Short getServerVersion(InetSocketAddress ipAddr, int timeout)
throws IOException, ClassNotFoundException {
- int gossipVersion = TcpServer.getCurrentGossipVersion();
- Short serverVersion = null;
+ int gossipVersion;
+ Short serverVersion;
+ Socket sock;
+
+ final String locatorCancelExceptionString =
+ "This could be the result of trying to connect a non-SSL-enabled client to an SSL-enabled locator.";
// Get GemFire version of TcpServer first, before sending any other request.
synchronized (serverVersions) {
serverVersion = serverVersions.get(ipAddr);
}
+
if (serverVersion != null) {
return serverVersion;
}
gossipVersion = TcpServer.getOldGossipVersion();
- Socket sock = null;
try {
sock = socketCreator.connect(ipAddr.getAddress(), ipAddr.getPort(), timeout, null, false);
sock.setSoTimeout(timeout);
@@ -296,8 +292,9 @@ public class TcpClient {
}
try {
- DataOutputStream out = new DataOutputStream(sock.getOutputStream());
- out = new VersionedDataOutputStream(out, Version.GFE_57);
+ OutputStream outputStream = new BufferedOutputStream(sock.getOutputStream());
+ DataOutputStream out =
+ new VersionedDataOutputStream(new DataOutputStream(outputStream), Version.GFE_57);
out.writeInt(gossipVersion);
@@ -312,14 +309,17 @@ public class TcpClient {
Object readObject = DataSerializer.readObject(in);
if (!(readObject instanceof VersionResponse)) {
throw new LocatorCancelException(
- "Unrecognisable response received: This could be the result of trying to connect a non-SSL-enabled client to an SSL-enabled locator.");
+ "Server version response invalid: " + locatorCancelExceptionString);
}
+
VersionResponse response = (VersionResponse) readObject;
- serverVersion = Short.valueOf(response.getVersionOrdinal());
+ serverVersion = response.getVersionOrdinal();
synchronized (serverVersions) {
serverVersions.put(ipAddr, serverVersion);
}
+
return serverVersion;
+
} catch (EOFException ex) {
// old locators will not recognize the version request and will close the connection
}
@@ -330,10 +330,7 @@ public class TcpClient {
} catch (Exception e) {
logger.error("Error closing socket ", e);
}
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Locator " + ipAddr
- + " did not respond to a request for its version. I will assume it is using v5.7 for safety.");
+
}
synchronized (serverVersions) {
serverVersions.put(ipAddr, Version.GFE_57.ordinal());
@@ -341,6 +338,7 @@ public class TcpClient {
return Short.valueOf(Version.GFE_57.ordinal());
}
+
/**
* Clear static class information concerning Locators. This is used in unit tests. It will force
* TcpClient to send version-request messages to locators to reestablish knowledge of their
@@ -351,5 +349,4 @@ public class TcpClient {
serverVersions.clear();
}
}
-
}
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
index 3abcc5c..72e4f2d 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
@@ -101,7 +101,7 @@ public class TcpServer {
// GossipServer.
public static final int OLDGOSSIPVERSION = 1001;
- private static final Map GOSSIP_TO_GEMFIRE_VERSION_MAP = new HashMap();
+ private static final Map<Integer, Short> GOSSIP_TO_GEMFIRE_VERSION_MAP = new HashMap<>();
// For test purpose only
public static boolean isTesting = false;
@@ -556,7 +556,7 @@ public class TcpServer {
return TcpServer.isTesting ? TcpServer.OLDTESTVERSION : TcpServer.OLDGOSSIPVERSION;
}
- public static Map getGossipVersionMapForTestOnly() {
+ public static Map<Integer, Short> getGossipVersionMapForTestOnly() {
return GOSSIP_TO_GEMFIRE_VERSION_MAP;
}