This is an automated email from the ASF dual-hosted git repository.
upthewaterspout 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 cd3602b GEODE-5877: Make multithreaded test single-threaded
cd3602b is described below
commit cd3602b3e518547770eb958f36847cc24539c910
Author: Dale Emery <[email protected]>
AuthorDate: Mon Oct 15 17:56:41 2018 -0700
GEODE-5877: Make multithreaded test single-threaded
Rewrite ServerLauncherWaitOnServerTest to be single-threaded. Instead of
using a second thread to signal the termination conditions, we signal
the conditions by mocking collaborators.
Add tests for other conditions that cause waitOnServer() to exit.
Remove MultiThreadedTC library.
Co-Authored-By: Dan Smith <[email protected]>
---
.../apache/geode/distributed/ServerLauncher.java | 5 -
...erverLauncherWaitOnServerMultiThreadedTest.java | 108 ------------------
.../ServerLauncherWaitOnServerTest.java | 121 +++++++++++++++++++++
gradle/dependency-versions.properties | 1 -
gradle/test.gradle | 2 -
5 files changed, 121 insertions(+), 116 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
index ec2e6e7..0d7b848 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
@@ -1272,11 +1272,6 @@ public class ServerLauncher extends
AbstractLauncher<String> {
}
}
- // For testing purposes only!
- void setIsRunningForTest() {
- this.running.set(true);
- }
-
private ServerState createNoResponseState(final Exception cause, final
String errorMessage) {
debug(ExceptionUtils.getFullStackTrace(cause) + errorMessage);
return new ServerState(this, Status.NOT_RESPONDING, errorMessage);
diff --git
a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherWaitOnServerMultiThreadedTest.java
b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherWaitOnServerMultiThreadedTest.java
deleted file mode 100644
index 69aa325..0000000
---
a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherWaitOnServerMultiThreadedTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
- * agreements. See the NOTICE file distributed with this work for additional
information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
- * or implied. See the License for the specific language governing permissions
and limitations under
- * the License.
- */
-package org.apache.geode.distributed;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import edu.umd.cs.mtc.MultithreadedTestCase;
-import edu.umd.cs.mtc.TestFramework;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.geode.cache.Cache;
-
-/**
- * Multithreaded unit tests for {@link ServerLauncher}. Extracted from {@link
ServerLauncherTest}.
- */
-public class ServerLauncherWaitOnServerMultiThreadedTest {
-
- private final AtomicBoolean connectionStateHolder = new AtomicBoolean(true);
-
- private Cache cache;
- private ServerLauncher serverLauncher;
-
- @Before
- public void setUp() throws Exception {
- DistributedSystem system = mock(DistributedSystem.class,
"DistributedSystem");
- when(system.isConnected()).thenAnswer(invocation ->
connectionStateHolder.get());
-
- cache = mock(Cache.class, "Cache");
- when(cache.getDistributedSystem()).thenReturn(system);
- when(cache.isReconnecting()).thenReturn(false);
- when(cache.getCacheServers()).thenReturn(Collections.emptyList());
- }
-
- @Test
- public void waitOnServer() {
- runTest(new ServerWaitMultiThreadedTestCase());
- }
-
- private static void runTest(final MultithreadedTestCase test) {
- try {
- TestFramework.runOnce(test);
- } catch (Throwable t) {
- throw new AssertionError(t);
- }
- }
-
- /**
- * Implementation of MultithreadedTestCase.
- */
- private class ServerWaitMultiThreadedTestCase extends MultithreadedTestCase {
-
- @Override
- public void initialize() {
- serverLauncher = new ServerLauncher.Builder().setMemberName("dataMember")
- .setDisableDefaultServer(true).setCache(cache).build();
-
- assertThat(connectionStateHolder.get()).isTrue();
- }
-
- public void thread1() {
- assertTick(0);
-
- Thread.currentThread().setName("GemFire Data Member 'main' Thread");
- serverLauncher.running.set(true);
-
- assertThat(serverLauncher.isRunning()).isTrue();
-
assertThat(serverLauncher.isServing(serverLauncher.getCache())).isFalse();
- assertThat(serverLauncher.isWaiting(serverLauncher.getCache())).isTrue();
-
- serverLauncher.waitOnServer();
-
- assertTick(1); // NOTE the tick does not advance when the other Thread
terminates
- }
-
- public void thread2() {
- waitForTick(1);
-
- Thread.currentThread().setName("GemFire 'shutdown' Thread");
-
- assertThat(serverLauncher.isRunning()).isTrue();
-
- connectionStateHolder.set(false);
- }
-
- @Override
- public void finish() {
- assertThat(serverLauncher.isRunning()).isFalse();
- }
- }
-}
diff --git
a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherWaitOnServerTest.java
b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherWaitOnServerTest.java
new file mode 100644
index 0000000..50d8832
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherWaitOnServerTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.distributed;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.server.CacheServer;
+
+public class ServerLauncherWaitOnServerTest {
+ @Mock
+ DistributedSystem system;
+
+ @Mock
+ Cache cache;
+
+ private ServerLauncher serverLauncher;
+
+ @Before
+ public void setup() {
+ initMocks(this);
+ serverLauncher = new ServerLauncher.Builder()
+ .setMemberName("dataMember")
+ .setDisableDefaultServer(true)
+ .setCache(cache)
+ .build();
+
+ when(cache.getDistributedSystem()).thenReturn(system);
+ }
+
+ @Test(timeout = 60_000)
+ public void returnsWhenLauncherIsRunningAndSystemIsNotConnected() {
+ serverLauncher.running.set(true);
+ when(cache.getCacheServers()).thenReturn(emptyList());
+ when(cache.isReconnecting()).thenReturn(false);
+
+ when(system.isConnected())
+ .thenReturn(true, true, true) // Connected for a while...
+ .thenReturn(false); // ... then not
+
+ serverLauncher.waitOnServer();
+
+ // Four times: false, false, false, true
+ verify(system, times(4)).isConnected();
+ }
+
+ @Test(timeout = 60_000)
+ public void returnsWhenLauncherIsRunningAndCacheIsNotReconnecting() {
+ serverLauncher.running.set(true);
+ when(cache.getCacheServers()).thenReturn(emptyList());
+ when(system.isConnected()).thenReturn(false);
+
+ when(cache.isReconnecting())
+ .thenReturn(true, true, true) // Reconnecting for a while...
+ .thenReturn(false); // ... then not
+
+ serverLauncher.waitOnServer();
+
+ // Four times: true, true, true, false
+ verify(cache, times(4)).isReconnecting();
+ }
+
+ @Test(timeout = 60_000)
+ public void returnsWhenLauncherIsNotRunning() {
+ when(cache.getCacheServers()).thenReturn(emptyList());
+ when(system.isConnected()).thenReturn(true);
+ when(cache.isReconnecting()).thenReturn(false);
+
+ // Running at first...
+ serverLauncher.running.set(true);
+
+ // Using isReconnecting() as a test hook to change running state
+ // while we're in the while loop.
+ when(cache.isReconnecting())
+ .thenReturn(false, false, false)
+ .thenAnswer(invocation -> {
+ serverLauncher.running.set(false); // ... then not running
+ return false;
+ });
+
+ serverLauncher.waitOnServer();
+
+ assertThat(serverLauncher.isRunning()).isFalse();
+ }
+
+ @Test(timeout = 60_000)
+ public void returnsImmediatelyIfCacheHasServers() {
+ serverLauncher.running.set(true);
+ List<CacheServer> servers = singletonList(mock(CacheServer.class));
+ when(cache.getCacheServers()).thenReturn(servers);
+ when(system.isConnected()).thenReturn(true);
+ when(cache.isReconnecting()).thenReturn(false);
+
+ serverLauncher.waitOnServer();
+ }
+}
diff --git a/gradle/dependency-versions.properties
b/gradle/dependency-versions.properties
index b9e8dfc..da0429e 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -74,7 +74,6 @@ lucene.version = 6.6.2
mockito-core.version = 2.19.1
mockrunner.version = 1.1.2
mortbay-jetty-servlet-api.version=3.0.20100224
-multithreadedtc.version = 1.01
mx4j.version = 3.0.2
mx4j-remote.version = 3.0.2
mx4j-tools.version = 3.0.1
diff --git a/gradle/test.gradle b/gradle/test.gradle
index 8b59aab..93fef58 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -118,7 +118,6 @@ subprojects {
}
testCompile 'com.google.code.tempus-fugit:tempus-fugit:' +
project.'tempus-fugit.version'
testCompile 'org.awaitility:awaitility:' + project.'awaitility.version'
- testCompile 'edu.umd.cs.mtc:multithreadedtc:' +
project.'multithreadedtc.version'
testCompile 'junit:junit:' + project.'junit.version'
testCompile 'org.assertj:assertj-core:' + project.'assertj-core.version'
testCompile 'org.hamcrest:hamcrest-all:' + project.'hamcrest-all.version'
@@ -285,4 +284,3 @@ classes.dependsOn subprojects.compileAcceptanceTestJava
classes.dependsOn subprojects.compileUiTestJava
classes.dependsOn subprojects.compilePerformanceTestJava
classes.dependsOn subprojects.compileUpgradeTestJava
-