You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/05/06 23:55:13 UTC
[14/18] incubator-geode git commit: GEODE-1276: Change UnitTests file
system to IntegrationTest category GEODE-1307: Rename
HeterogenousLuceneSerializer to HeterogeneousLuceneSerializer GEODE-1279:
Tests for old TRAC bugs should be renamed to useful name
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLauncherTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLauncherTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLauncherTest.java
index cabb5ff..0ebd4b6 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLauncherTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractLauncherTest.java
@@ -42,7 +42,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class AbstractLauncherTest {
- protected AbstractLauncher<?> createAbstractLauncher(final String memberName, final String memberId) {
+ private AbstractLauncher<?> createAbstractLauncher(final String memberName, final String memberId) {
return new FakeServiceLauncher(memberName, memberId);
}
@@ -249,7 +249,7 @@ public class AbstractLauncherTest {
TimeUnit.DAYS.toMillis(2) + TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30) + TimeUnit.SECONDS.toMillis(1)));
}
- protected static final class FakeServiceLauncher extends AbstractLauncher<String> {
+ private static final class FakeServiceLauncher extends AbstractLauncher<String> {
private final String memberId;
private final String memberName;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
index 252b5aa..897d0fa 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalIntegrationTest.java
@@ -289,7 +289,7 @@ public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncher
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
- assertEquals(getPid(), pid);
+ assertIndexDetailsEquals(getPid(), pid);
// validate log file was created
final String logFileName = getUniqueName()+".log";
@@ -303,7 +303,7 @@ public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncher
}
try {
- assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+ assertIndexDetailsEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
logger.error(e);
@@ -433,7 +433,7 @@ public class LocatorLauncherLocalIntegrationTest extends AbstractLocatorLauncher
expected = e;
assertNotNull(expected.getMessage());
assertTrue(expected.getMessage(), expected.getMessage().contains("A PID file already exists and a Locator may be running in"));
- assertEquals(RuntimeException.class, expected.getClass());
+ assertIndexDetailsEquals(RuntimeException.class, expected.getClass());
} catch (Throwable e) {
logger.error(e);
if (failure == null) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
index 8550a35..a5b8831 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherRemoteIntegrationTest.java
@@ -93,7 +93,7 @@ public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLaunche
Thread waiting = new Thread(new Runnable() {
public void run() {
try {
- assertEquals(0, process.waitFor());
+ assertIndexDetailsEquals(0, process.waitFor());
}
catch (InterruptedException ignore) {
logger.error("Interrupted while waiting for process!", ignore);
@@ -114,8 +114,8 @@ public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLaunche
LocatorLauncher locatorLauncher = new Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
- assertEquals(Status.ONLINE, locatorLauncher.status().getStatus());
- assertEquals(Status.STOPPED, locatorLauncher.stop().getStatus());
+ assertIndexDetailsEquals(Status.ONLINE, locatorLauncher.status().getStatus());
+ assertIndexDetailsEquals(Status.STOPPED, locatorLauncher.stop().getStatus());
}
*/
@@ -556,7 +556,7 @@ public class LocatorLauncherRemoteIntegrationTest extends AbstractLocatorLaunche
// check the status
final LocatorState locatorState = dirLauncher.status();
assertNotNull(locatorState);
- assertEquals(Status.NOT_RESPONDING, locatorState.getStatus());
+ assertIndexDetailsEquals(Status.NOT_RESPONDING, locatorState.getStatus());
final String logFileName = getUniqueName()+".log";
assertFalse("Log file should not exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorStateTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorStateTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorStateTest.java
index 55d7d6a..5693460 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorStateTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorStateTest.java
@@ -40,6 +40,22 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class LocatorStateTest {
+ private String classpath = "test_classpath";
+ private String gemFireVersion = "test_gemfireversion";
+ private String host = "test_host";
+ private String javaVersion = "test_javaversion";
+ private String jvmArguments = "test_jvmarguments";
+ private String serviceLocation = "test_location";
+ private String logFile = "test_logfile";
+ private String memberName = "test_membername";
+ private Integer pid = 6396;
+ private String port = "test_port";
+ private String statusDescription = Status.NOT_RESPONDING.getDescription();
+ private String statusMessage = "test_statusmessage";
+ private Long timestampTime = 1450728233024L;
+ private Long uptime = 1629L;
+ private String workingDirectory = "test_workingdirectory";
+
@Test
public void fromJsonWithEmptyStringThrowsIllegalArgumentException() throws Exception {
// given: empty string
@@ -122,66 +138,64 @@ public class LocatorStateTest {
return LocatorState.fromJson(value);
}
- private String classpath = "test_classpath";
- private String gemFireVersion = "test_gemfireversion";
- private String host = "test_host";
- private String javaVersion = "test_javaversion";
- private String jvmArguments = "test_jvmarguments";
- private String serviceLocation = "test_location";
- private String logFile = "test_logfile";
- private String memberName = "test_membername";
- private Integer pid = 6396;
- private String port = "test_port";
- private String statusDescription = Status.NOT_RESPONDING.getDescription();
- private String statusMessage = "test_statusmessage";
- private Long timestampTime = 1450728233024L;
- private Long uptime = 1629L;
- private String workingDirectory = "test_workingdirectory";
-
private String getClasspath() {
return this.classpath;
}
+
private String getGemFireVersion() {
return this.gemFireVersion;
}
+
private String getHost() {
return this.host;
}
+
private String getJavaVersion() {
return this.javaVersion;
}
+
private List<String> getJvmArguments() {
List<String> list = new ArrayList<String>();
list.add(this.jvmArguments);
return list;
}
+
private String getServiceLocation() {
return this.serviceLocation;
}
+
private String getLogFile() {
return this.logFile;
}
+
private String getMemberName() {
return this.memberName;
}
+
private Integer getPid() {
return this.pid;
}
+
private String getPort() {
return this.port;
}
+
private String getStatusDescription() {
return this.statusDescription;
}
+
private String getStatusMessage() {
return this.statusMessage;
}
+
private Long getTimestampTime() {
return this.timestampTime;
}
+
private Long getUptime() {
return this.uptime;
}
+
private String getWorkingDirectory() {
return this.workingDirectory;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
index 911bfab..85bfe0a 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
@@ -432,7 +432,7 @@ public class ServerLauncherLocalIntegrationTest extends AbstractServerLauncherIn
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
- assertEquals(getPid(), pid);
+ assertIndexDetailsEquals(getPid(), pid);
// validate log file was created
final String logFileName = getUniqueName()+".log";
@@ -446,7 +446,7 @@ public class ServerLauncherLocalIntegrationTest extends AbstractServerLauncherIn
}
try {
- assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+ assertIndexDetailsEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
logger.error(e);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteIntegrationTest.java
index 4cd21a2..06c6bd1 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherRemoteIntegrationTest.java
@@ -111,7 +111,7 @@ public class ServerLauncherRemoteIntegrationTest extends AbstractServerLauncherR
// @Override
// public void run() {
// try {
-// assertEquals(0, process.waitFor());
+// assertIndexDetailsEquals(0, process.waitFor());
// } catch (InterruptedException e) {
// logger.error("Interrupted while waiting for process", e);
// }
@@ -932,7 +932,7 @@ public class ServerLauncherRemoteIntegrationTest extends AbstractServerLauncherR
// check the status
final ServerState serverState = dirLauncher.status();
assertNotNull(serverState);
- assertEquals(Status.NOT_RESPONDING, serverState.getStatus());
+ assertIndexDetailsEquals(Status.NOT_RESPONDING, serverState.getStatus());
final String logFileName = getUniqueName()+".log";
assertFalse("Log file should not exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
index 25e9528..ac331e2 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
@@ -739,6 +739,7 @@ public class ServerLauncherTest {
assertFalse(serverLauncher.isDisableDefaultServer());
assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
}
+
@Test
public void testIsDefaultServerEnabledWhenNoCacheServersExistAndDefaultServerDisabled() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
@@ -821,12 +822,6 @@ public class ServerLauncherTest {
serverLauncher.startCacheServer(mockCache);
}
- public static void main(final String... args) {
- System.err.printf("Thread (%1$s) is daemon (%2$s)%n", Thread.currentThread().getName(),
- Thread.currentThread().isDaemon());
- new Builder(args).setCommand(Command.START).build().run();
- }
-
private final class ServerWaitMultiThreadedTestCase extends MultithreadedTestCase {
private final AtomicBoolean connectionStateHolder = new AtomicBoolean(true);
@@ -840,7 +835,8 @@ public class ServerLauncherTest {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final DistributedSystem mockDistributedSystem = new DistributedSystemAdapter() {
- @Override public boolean isConnected() {
+ @Override
+ public boolean isConnected() {
return connectionStateHolder.get();
}
};
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/AtomicLongWithTerminalStateJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/AtomicLongWithTerminalStateJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/AtomicLongWithTerminalStateJUnitTest.java
index aca6874..eec4730 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/AtomicLongWithTerminalStateJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/AtomicLongWithTerminalStateJUnitTest.java
@@ -16,18 +16,17 @@
*/
package com.gemstone.gemfire.distributed.internal;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
-/**
- *
- */
@Category(UnitTest.class)
-public class AtomicLongWithTerminalStateJUnitTest extends TestCase {
-
+public class AtomicLongWithTerminalStateJUnitTest {
+
+ @Test
public void test() {
AtomicLongWithTerminalState al = new AtomicLongWithTerminalState();
assertEquals(23, al.compareAddAndGet(-1, 23));
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
index 31acc47..8e1031f 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
@@ -29,39 +29,47 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import com.gemstone.gemfire.InternalGemFireException;
import com.gemstone.gemfire.UnmodifiableException;
import com.gemstone.gemfire.internal.ConfigSource;
import com.gemstone.gemfire.management.internal.security.JSONAuthorization;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-
@Category(UnitTest.class)
public class DistributionConfigJUnitTest {
- static Map<String, ConfigAttribute> attributes;
- static Map<String, Method> setters;
- static Map<String, Method> getters;
- static Map<String, Method> isModifiables;
- static Map<String, Method> checkers;
- static String[] attNames;
- DistributionConfigImpl config;
-
- @BeforeClass
- public static void beforeClass() {
+
+ private Map<Class<?>, Class<?>> classMap;
+
+ private Map<String, ConfigAttribute> attributes;
+ private Map<String, Method> setters;
+ private Map<String, Method> getters;
+ private Map<String, Method> checkers;
+ private String[] attNames;
+
+ private DistributionConfigImpl config;
+
+ @Before
+ public void before() {
+ classMap = new HashMap<Class<?>, Class<?>>();
+ classMap.put(boolean.class, Boolean.class);
+ classMap.put(byte.class, Byte.class);
+ classMap.put(short.class, Short.class);
+ classMap.put(char.class, Character.class);
+ classMap.put(int.class, Integer.class);
+ classMap.put(long.class, Long.class);
+ classMap.put(float.class, Float.class);
+ classMap.put(double.class, Double.class);
+
attributes = DistributionConfig.attributes;
setters = DistributionConfig.setters;
getters = DistributionConfig.getters;
attNames = DistributionConfig.dcValidAttributeNames;
checkers = AbstractDistributionConfig.checkers;
- }
- @Before
- public void before() {
config = new DistributionConfigImpl(new Properties());
}
@@ -99,6 +107,7 @@ public class DistributionConfigJUnitTest {
System.out.println("filelList: " + fileList);
System.out.println();
System.out.println("otherList: " + otherList);
+
assertEquals(boolList.size(), 30);
assertEquals(intList.size(), 33);
assertEquals(stringList.size(), 70);
@@ -245,6 +254,7 @@ public class DistributionConfigJUnitTest {
modifiables.add(attName);
}
}
+
assertEquals(modifiables.size(), 10);
assertEquals(modifiables.get(0), "archive-disk-space-limit");
assertEquals(modifiables.get(1), "archive-file-size-limit");
@@ -256,7 +266,6 @@ public class DistributionConfigJUnitTest {
assertEquals(modifiables.get(7), "statistic-archive-file");
assertEquals(modifiables.get(8), "statistic-sample-rate");
assertEquals(modifiables.get(9), "statistic-sampling-enabled");
-
}
@Test(expected = IllegalArgumentException.class)
@@ -343,17 +352,4 @@ public class DistributionConfigJUnitTest {
DistributionConfig config = new DistributionConfigImpl(props);
assertEquals(config.getSecurityProps().size(), 4);
}
-
- public final static Map<Class<?>, Class<?>> classMap = new HashMap<Class<?>, Class<?>>();
-
- static {
- classMap.put(boolean.class, Boolean.class);
- classMap.put(byte.class, Byte.class);
- classMap.put(short.class, Short.class);
- classMap.put(char.class, Character.class);
- classMap.put(int.class, Integer.class);
- classMap.put(long.class, Long.class);
- classMap.put(float.class, Float.class);
- classMap.put(double.class, Double.class);
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
index 2024bf2..8832459 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystemJUnitTest.java
@@ -132,7 +132,7 @@ public class InternalDistributedSystemJUnitTest
assertEquals(DistributionConfig.DEFAULT_LOG_FILE, config.getLogFile());
//default log level gets overrided by the gemfire.properties created for unit tests.
-// assertEquals(DistributionConfig.DEFAULT_LOG_LEVEL, config.getLogLevel());
+// assertIndexDetailsEquals(DistributionConfig.DEFAULT_LOG_LEVEL, config.getLogLevel());
assertEquals(DistributionConfig.DEFAULT_STATISTIC_SAMPLING_ENABLED,
config.getStatisticSamplingEnabled());
@@ -145,7 +145,7 @@ public class InternalDistributedSystemJUnitTest
// ack-wait-threadshold is overridden on VM's command line using a
// system property. This is not a valid test. Hrm.
-// assertEquals(DistributionConfig.DEFAULT_ACK_WAIT_THRESHOLD, config.getAckWaitThreshold());
+// assertIndexDetailsEquals(DistributionConfig.DEFAULT_ACK_WAIT_THRESHOLD, config.getAckWaitThreshold());
assertEquals(DistributionConfig.DEFAULT_ACK_SEVERE_ALERT_THRESHOLD, config.getAckSevereAlertThreshold());
@@ -683,7 +683,7 @@ public class InternalDistributedSystemJUnitTest
Locator locator = (Locator) locators.iterator().next();
Assert.assertTrue(locator.isPeerLocator());
// Assert.assertFalse(locator.isServerLocator()); server location is forced on while licensing is disabled in GemFire
-// Assert.assertEquals("127.0.0.1", locator.getBindAddress().getHostAddress()); removed this check for ipv6 testing
+// Assert.assertIndexDetailsEquals("127.0.0.1", locator.getBindAddress().getHostAddress()); removed this check for ipv6 testing
Assert.assertEquals(unusedPort, locator.getPort());
deleteStateFile(unusedPort);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotIntegrationTest.java
new file mode 100644
index 0000000..08648d9
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotIntegrationTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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 com.gemstone.gemfire.distributed.internal;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.cache.server.ServerLoad;
+import com.gemstone.gemfire.test.junit.categories.FlakyTest;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests extracted from LocatorLoadSnapshotJUnitTest
+ */
+@Category(IntegrationTest.class)
+public class LocatorLoadSnapshotIntegrationTest {
+
+ /**
+ * A basic test of concurrent functionality. Starts a number of
+ * threads making requests and expects the load to be balanced between
+ * three servers.
+ * @throws InterruptedException
+ */
+ @Category(FlakyTest.class) // GEODE-613: lots of threads, async action, IntegrationTest-not-UnitTest, thread joins, time sensitive
+ @Test
+ public void testConcurrentBalancing() throws InterruptedException {
+ int NUM_THREADS = 50;
+ final int NUM_REQUESTS = 10000;
+ int ALLOWED_THRESHOLD = 50; //We should never be off by more than
+ //the number of concurrent threads.
+
+ final LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
+ final ServerLocation l1 = new ServerLocation("localhost", 1);
+ final ServerLocation l2 = new ServerLocation("localhost", 2);
+ final ServerLocation l3 = new ServerLocation("localhost", 3);
+
+ int initialLoad1 = (int) (Math.random() * (NUM_REQUESTS / 2));
+ int initialLoad2 = (int) (Math.random() * (NUM_REQUESTS / 2));
+ int initialLoad3 = (int) (Math.random() * (NUM_REQUESTS / 2));
+
+ sn.addServer(l1, new String[0], new ServerLoad(initialLoad1, 1, 0, 1));
+ sn.addServer(l2, new String[0], new ServerLoad(initialLoad2, 1, 0, 1));
+ sn.addServer(l3, new String[0], new ServerLoad(initialLoad3, 1, 0, 1));
+
+ final Map loadCounts = new HashMap();
+ loadCounts.put(l1, new AtomicInteger(initialLoad1));
+ loadCounts.put(l2, new AtomicInteger(initialLoad2));
+ loadCounts.put(l3, new AtomicInteger(initialLoad3));
+
+ Thread[] threads = new Thread[NUM_THREADS];
+// final Object lock = new Object();
+ for(int i =0; i < NUM_THREADS; i++) {
+ threads[i] = new Thread("Thread-" + i) {
+ public void run() {
+ for(int ii = 0; ii < NUM_REQUESTS; ii++) {
+ ServerLocation location;
+// synchronized(lock) {
+ location = sn.getServerForConnection(null, Collections.EMPTY_SET);
+// }
+ AtomicInteger count = (AtomicInteger) loadCounts.get(location);
+ count.incrementAndGet();
+ }
+ }
+ };
+ }
+
+ for(int i =0; i < NUM_THREADS; i++) {
+ threads[i].start();
+ }
+
+ for(int i =0; i < NUM_THREADS; i++) {
+ Thread t = threads[i];
+ long ms = 30 * 1000;
+ t.join(30 * 1000);
+ if (t.isAlive()) {
+ for(int j =0; j < NUM_THREADS; j++) {
+ threads[j].interrupt();
+ }
+ fail("Thread did not terminate after " + ms + " ms: " + t);
+ }
+ }
+
+ double expectedPerServer = ( initialLoad1 + initialLoad2 + initialLoad3 +
+ NUM_REQUESTS * NUM_THREADS) / (double) loadCounts.size();
+// for(Iterator itr = loadCounts.entrySet().iterator(); itr.hasNext(); ) {
+// Map.Entry entry = (Entry) itr.next();
+// ServerLocation location = (ServerLocation) entry.getKey();
+// AI count= (AI) entry.getValue();
+// }
+
+ for(Iterator itr = loadCounts.entrySet().iterator(); itr.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) itr.next();
+ ServerLocation location = (ServerLocation) entry.getKey();
+ AtomicInteger count= (AtomicInteger) entry.getValue();
+ int difference = (int) Math.abs(count.get() - expectedPerServer);
+ assertTrue("Count " + count + " for server " + location + " is not within " + ALLOWED_THRESHOLD + " of " + expectedPerServer, difference < ALLOWED_THRESHOLD);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotJUnitTest.java
index 34ac767..fb391f9 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/LocatorLoadSnapshotJUnitTest.java
@@ -22,23 +22,18 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.cache.server.ServerLoad;
-import com.gemstone.gemfire.test.junit.categories.FlakyTest;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
* Tests the functionality of the LocatorLoadSnapshot, which
* is the data structure that is used in the locator to compare
* the load between multiple servers.
- *
*/
@Category(UnitTest.class)
public class LocatorLoadSnapshotJUnitTest {
@@ -61,7 +56,6 @@ public class LocatorLoadSnapshotJUnitTest {
* and then we test that after several requests, the
* load balancer starts sending connections to the second
* server.
- *
*/
@Test
public void testTwoServers() {
@@ -174,7 +168,7 @@ public class LocatorLoadSnapshotJUnitTest {
* servers with interecting groups correctly.
*/
@Test
- public void testInterectingGroups() {
+ public void testIntersectingGroups() {
LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
ServerLocation l1 = new ServerLocation("localhost", 1);
ServerLocation l2 = new ServerLocation("localhost", 2);
@@ -258,88 +252,6 @@ public class LocatorLoadSnapshotJUnitTest {
assertEquals(Arrays.asList(new ServerLocation[] {} ), sn.getServersForQueue(null, excludeAll, 3));
}
- /**
- * A basic test of concurrent functionality. Starts a number of
- * threads making requests and expects the load to be balanced between
- * three servers.
- * @throws InterruptedException
- */
- @Category(FlakyTest.class) // GEODE-613: lots of threads, async action, IntegrationTest-not-UnitTest, thread joins, time sensitive
- @Test
- public void testConcurrentBalancing() throws InterruptedException {
- int NUM_THREADS = 50;
- final int NUM_REQUESTS = 10000;
- int ALLOWED_THRESHOLD = 50; //We should never be off by more than
- //the number of concurrent threads.
-
- final LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
- final ServerLocation l1 = new ServerLocation("localhost", 1);
- final ServerLocation l2 = new ServerLocation("localhost", 2);
- final ServerLocation l3 = new ServerLocation("localhost", 3);
-
- int initialLoad1 = (int) (Math.random() * (NUM_REQUESTS / 2));
- int initialLoad2 = (int) (Math.random() * (NUM_REQUESTS / 2));
- int initialLoad3 = (int) (Math.random() * (NUM_REQUESTS / 2));
-
- sn.addServer(l1, new String[0], new ServerLoad(initialLoad1, 1, 0, 1));
- sn.addServer(l2, new String[0], new ServerLoad(initialLoad2, 1, 0, 1));
- sn.addServer(l3, new String[0], new ServerLoad(initialLoad3, 1, 0, 1));
-
- final Map loadCounts = new HashMap();
- loadCounts.put(l1, new AtomicInteger(initialLoad1));
- loadCounts.put(l2, new AtomicInteger(initialLoad2));
- loadCounts.put(l3, new AtomicInteger(initialLoad3));
-
- Thread[] threads = new Thread[NUM_THREADS];
-// final Object lock = new Object();
- for(int i =0; i < NUM_THREADS; i++) {
- threads[i] = new Thread("Thread-" + i) {
- public void run() {
- for(int ii = 0; ii < NUM_REQUESTS; ii++) {
- ServerLocation location;
-// synchronized(lock) {
- location = sn.getServerForConnection(null, Collections.EMPTY_SET);
-// }
- AtomicInteger count = (AtomicInteger) loadCounts.get(location);
- count.incrementAndGet();
- }
- }
- };
- }
-
- for(int i =0; i < NUM_THREADS; i++) {
- threads[i].start();
- }
-
- for(int i =0; i < NUM_THREADS; i++) {
- Thread t = threads[i];
- long ms = 30 * 1000;
- t.join(30 * 1000);
- if (t.isAlive()) {
- for(int j =0; j < NUM_THREADS; j++) {
- threads[j].interrupt();
- }
- fail("Thread did not terminate after " + ms + " ms: " + t);
- }
- }
-
- double expectedPerServer = ( initialLoad1 + initialLoad2 + initialLoad3 +
- NUM_REQUESTS * NUM_THREADS) / (double) loadCounts.size();
-// for(Iterator itr = loadCounts.entrySet().iterator(); itr.hasNext(); ) {
-// Map.Entry entry = (Entry) itr.next();
-// ServerLocation location = (ServerLocation) entry.getKey();
-// AI count= (AI) entry.getValue();
-// }
-
- for(Iterator itr = loadCounts.entrySet().iterator(); itr.hasNext(); ) {
- Map.Entry entry = (Entry) itr.next();
- ServerLocation location = (ServerLocation) entry.getKey();
- AtomicInteger count= (AtomicInteger) entry.getValue();
- int difference = (int) Math.abs(count.get() - expectedPerServer);
- assertTrue("Count " + count + " for server " + location + " is not within " + ALLOWED_THRESHOLD + " of " + expectedPerServer, difference < ALLOWED_THRESHOLD);
- }
- }
-
@Test
public void testAreBalanced() {
final LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
@@ -367,19 +279,5 @@ public class LocatorLoadSnapshotJUnitTest {
assertTrue(sn.hasBalancedConnections("a"));
assertFalse(sn.hasBalancedConnections("b"));
}
-
- public void _test2() { // delete this method?
- final LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
- sn.addServer(new ServerLocation("hs20h.gemstone.com",28543), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20l.gemstone.com",22385), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20n.gemstone.com",23482), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20m.gemstone.com",23429), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20e.gemstone.com",20154), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20j.gemstone.com",24273), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20g.gemstone.com",27125), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20i.gemstone.com",25201), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20k.gemstone.com",23711), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- sn.addServer(new ServerLocation("hs20f.gemstone.com",21025), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f));
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogJUnitTest.java
index ffcf09c..7e23f7b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogJUnitTest.java
@@ -16,71 +16,92 @@
*/
package com.gemstone.gemfire.distributed.internal;
+import static org.junit.Assert.*;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
+@Category(UnitTest.class) // Fails on Windows -- see GEODE-373
+public class ProductUseLogJUnitTest {
-@Category(UnitTest.class)
-public class ProductUseLogJUnitTest extends TestCase {
+ private long oldMax;
+ private File logFile;
+ private ProductUseLog log;
- public void testBasics() throws Exception {
- File logFile = new File("ProductUseLogTest_testBasics.log");
- if (logFile.exists()) {
- logFile.delete();
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public TestName testName = new TestName();
+
+ @Before
+ public void setUp() throws Exception {
+ oldMax = ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE;
+ logFile = temporaryFolder.newFile(getClass().getSimpleName() + "_" + testName.getMethodName() + ".log");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE = oldMax;
+ if (log != null) {
+ log.close();
}
- ProductUseLog log = new ProductUseLog(logFile);
+ }
+
+ @Test
+ public void testBasics() throws Exception {
+ assertTrue(logFile.delete());
+
+ log = new ProductUseLog(logFile);
+
assertTrue(logFile.exists());
+
log.log("test message");
log.close();
log.log("shouldn't be logged");
log.reopen();
log.log("test message");
log.close();
+
BufferedReader reader = new BufferedReader(new FileReader(logFile));
- try {
- String line = reader.readLine();
- assertTrue(line.length() == 0);
- line = reader.readLine();
- assertTrue("expected first line to contain 'test message'", line.contains("test message"));
-
- line = reader.readLine();
- assertTrue(line.length() == 0);
- line = reader.readLine();
- assertTrue("expected second line to contain 'test message'", line.contains("test message"));
-
- line = reader.readLine();
- assertTrue("expected only two non-empty lines in the file", line == null);
- } finally {
- reader.close();
- }
+
+ String line = reader.readLine();
+ assertTrue(line.length() == 0);
+ line = reader.readLine();
+ assertTrue("expected first line to contain 'test message'", line.contains("test message"));
+
+ line = reader.readLine();
+ assertTrue(line.length() == 0);
+ line = reader.readLine();
+ assertTrue("expected second line to contain 'test message'", line.contains("test message"));
+
+ line = reader.readLine();
+ assertTrue("expected only two non-empty lines in the file", line == null);
}
+ @Test
public void testSizeLimit() throws Exception {
- long oldMax = ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE;
ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE = 2000L;
- try {
- File logFile = new File("ProductUseLogTest_testSizeLimit.log");
- assertTrue(logFile.createNewFile());
- ProductUseLog log = new ProductUseLog(logFile);
- try {
- String logEntry = "log entry";
- for (long i=0; i<ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE; i++) {
- log.log(logEntry);
- assertTrue("expected " + logFile.getPath() + " to remain under "+
- ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE + " bytes in length",
- logFile.length() < ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE);
- }
- } finally {
- log.close();
- }
- } finally {
- ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE = oldMax;
+
+ ProductUseLog log = new ProductUseLog(logFile);
+
+ String logEntry = "log entry";
+ for (long i=0; i<ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE; i++) {
+ log.log(logEntry);
+ assertTrue("expected " + logFile.getPath() + " to remain under "+
+ ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE + " bytes in length",
+ logFile.length() < ProductUseLog.MAX_PRODUCT_USE_FILE_SIZE);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ServerLocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ServerLocatorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ServerLocatorJUnitTest.java
index 7690c87..bb83df9 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ServerLocatorJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ServerLocatorJUnitTest.java
@@ -20,33 +20,30 @@ import static org.junit.Assert.*;
import java.io.IOException;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import com.gemstone.gemfire.cache.client.internal.locator.LocatorStatusRequest;
import com.gemstone.gemfire.cache.client.internal.locator.LocatorStatusResponse;
import com.gemstone.gemfire.i18n.LogWriterI18n;
-import com.gemstone.gemfire.internal.logging.LocalLogWriter;
import com.gemstone.gemfire.internal.logging.InternalLogWriter;
+import com.gemstone.gemfire.internal.logging.LocalLogWriter;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
/**
* The ServerLocatorJUnitTest class is a test suite of test cases testing the contract and functionality of the
* ServerLocator class.
* </p>
+ * TODO: write more unit tests for this class...
+ * </p>
* @see com.gemstone.gemfire.distributed.internal.ServerLocator
* @see org.junit.Assert
* @see org.junit.Test
* @since 7.0
*/
-// TODO Dan, write more unit tests for this class...
@Category(UnitTest.class)
public class ServerLocatorJUnitTest {
- protected ServerLocator createServerLocator() throws IOException {
- return new TestServerLocator();
- }
-
@Test
public void testProcessRequestProcessesLocatorStatusRequest() throws IOException {
final ServerLocator serverLocator = createServerLocator();
@@ -56,7 +53,11 @@ public class ServerLocatorJUnitTest {
assertTrue(response instanceof LocatorStatusResponse);
}
- protected static class TestServerLocator extends ServerLocator {
+ private ServerLocator createServerLocator() throws IOException {
+ return new TestServerLocator();
+ }
+
+ private static class TestServerLocator extends ServerLocator {
TestServerLocator() throws IOException {
super();
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/SharedConfigurationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/SharedConfigurationJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/SharedConfigurationJUnitTest.java
index f308855..8af42b6 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/SharedConfigurationJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/SharedConfigurationJUnitTest.java
@@ -31,7 +31,6 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
* Unit tests for {@link SharedConfiguration}.
- *
*
* @since 8.1
*/
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/StartupMessageDataJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/StartupMessageDataJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/StartupMessageDataJUnitTest.java
index aa0a88e..ee3f99e 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/StartupMessageDataJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/StartupMessageDataJUnitTest.java
@@ -16,6 +16,8 @@
*/
package com.gemstone.gemfire.distributed.internal;
+import static org.junit.Assert.*;
+
import java.io.DataInput;
import java.io.DataOutputStream;
import java.util.ArrayList;
@@ -24,6 +26,7 @@ import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.DataSerializer;
@@ -33,21 +36,15 @@ import com.gemstone.gemfire.internal.ByteArrayData;
import com.gemstone.gemfire.internal.admin.remote.DistributionLocatorId;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
/**
* Tests {@link StartupMessageData}.
*
* @since 7.0
*/
@Category(UnitTest.class)
-public class StartupMessageDataJUnitTest extends TestCase {
-
- public StartupMessageDataJUnitTest(String name) {
- super(name);
- }
-
+public class StartupMessageDataJUnitTest {
+ @Test
public void testWriteHostedLocatorsWithEmpty() throws Exception {
Collection<String> hostedLocators = new ArrayList<String>();
StartupMessageData data = new StartupMessageData();
@@ -55,6 +52,7 @@ public class StartupMessageDataJUnitTest extends TestCase {
assertTrue(data.getOptionalFields().isEmpty());
}
+ @Test
public void testWriteHostedLocatorsWithNull() throws Exception {
Collection<String> hostedLocators = null;
StartupMessageData data = new StartupMessageData();
@@ -62,6 +60,7 @@ public class StartupMessageDataJUnitTest extends TestCase {
assertTrue(data.getOptionalFields().isEmpty());
}
+ @Test
public void testWriteHostedLocatorsWithOne() throws Exception {
String locatorString = createOneLocatorString();
@@ -74,6 +73,7 @@ public class StartupMessageDataJUnitTest extends TestCase {
assertEquals(locatorString, data.getOptionalFields().get(StartupMessageData.HOSTED_LOCATORS));
}
+ @Test
public void testWriteHostedLocatorsWithThree() throws Exception {
String[] locatorStrings = createManyLocatorStrings(3);
List<String> hostedLocators = new ArrayList<String>();
@@ -94,7 +94,8 @@ public class StartupMessageDataJUnitTest extends TestCase {
assertEquals(locatorStrings[i], st.nextToken());
}
}
-
+
+ @Test
public void testReadHostedLocatorsWithThree() throws Exception {
// set up the data
String[] locatorStrings = createManyLocatorStrings(3);
@@ -116,7 +117,8 @@ public class StartupMessageDataJUnitTest extends TestCase {
i++;
}
}
-
+
+ @Test
public void testToDataWithEmptyHostedLocators() throws Exception {
Collection<String> hostedLocators = new ArrayList<String>();
StartupMessageData data = new StartupMessageData();
@@ -134,6 +136,7 @@ public class StartupMessageDataJUnitTest extends TestCase {
assertNull(props);
}
+ @Test
public void testToDataWithNullHostedLocators() throws Exception {
Collection<String> hostedLocators = null;
StartupMessageData data = new StartupMessageData();
@@ -150,7 +153,8 @@ public class StartupMessageDataJUnitTest extends TestCase {
Properties props = (Properties) DataSerializer.readObject(in);
assertNull(props);
}
-
+
+ @Test
public void testToDataWithOneHostedLocator() throws Exception {
String locatorString = createOneLocatorString();
@@ -176,6 +180,7 @@ public class StartupMessageDataJUnitTest extends TestCase {
assertEquals(locatorString, hostedLocatorsString);
}
+ @Test
public void testToDataWithThreeHostedLocators() throws Exception {
String[] locatorStrings = createManyLocatorStrings(3);
List<String> hostedLocators = new ArrayList<String>();
@@ -215,6 +220,7 @@ public class StartupMessageDataJUnitTest extends TestCase {
}
}
+ @Test
public void testNullHostedLocator() throws Exception {
String locatorString = null;
DataInput in = getDataInputWithOneHostedLocator(locatorString);
@@ -223,7 +229,8 @@ public class StartupMessageDataJUnitTest extends TestCase {
Collection<String> readHostedLocators = dataToRead.readHostedLocators();
assertNull(readHostedLocators);
}
-
+
+ @Test
public void testEmptyHostedLocator() throws Exception {
String locatorString = "";
DataInput in = getDataInputWithOneHostedLocator(locatorString);
@@ -232,7 +239,8 @@ public class StartupMessageDataJUnitTest extends TestCase {
Collection<String> readHostedLocators = dataToRead.readHostedLocators();
assertNull(readHostedLocators);
}
-
+
+ @Test
public void testOneHostedLocator() throws Exception {
String locatorString = createOneLocatorString();
DataInput in = getDataInputWithOneHostedLocator(locatorString);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorIntegrationTest.java
new file mode 100644
index 0000000..4eaf9cb
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorIntegrationTest.java
@@ -0,0 +1,299 @@
+/*
+ * 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 com.gemstone.gemfire.distributed.internal.deadlock;
+
+import static org.junit.Assert.*;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * TODO: can we get rid of the Thread.sleep calls?
+ */
+@Category(IntegrationTest.class)
+public class DeadlockDetectorIntegrationTest {
+
+ private volatile Set<Thread> stuckThreads;
+
+ @Before
+ public void setUp() throws Exception {
+ stuckThreads = Collections.synchronizedSet(new HashSet<Thread>());
+ }
+
+ /**
+ * IntegrationTests are forkEvery 1 so cleanup is not necessary
+ */
+ @After
+ public void tearDown() throws Exception {
+ for (Thread thread: stuckThreads) {
+ thread.interrupt();
+ }
+
+ stuckThreads.clear();
+ }
+
+ /**
+ * must be IntegrationTest because: "we can't clean up the threads deadlocked on monitors"
+ */
+ @Test
+ public void testMonitorDeadlock() throws Exception {
+ final Object lock1 = new Object();
+ final Object lock2 = new Object();
+
+ Thread thread1 = new Thread() {
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+
+ synchronized(lock1) {
+ Thread thread2 = new Thread() {
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+ synchronized(lock2) {
+ synchronized(lock1) {
+ System.out.println("we won't get here");
+ }
+ }
+ }
+ };
+
+ thread2.start();
+
+ try {
+ Thread.sleep(1000);
+ synchronized(lock2) {
+ System.out.println("We won't get here");
+ }
+ } catch (InterruptedException ignore) {
+ }
+ }
+ }
+ };
+
+ thread1.start();
+
+ Thread.sleep(2000);
+
+ DeadlockDetector detector = new DeadlockDetector();
+ detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
+ LinkedList<Dependency> deadlocks = detector.findDeadlock();
+
+ System.out.println("deadlocks=" + DeadlockDetector.prettyFormat(deadlocks));
+
+ assertEquals(4, detector.findDeadlock().size());
+ }
+
+ /**
+ * Make sure that we can detect a deadlock between two threads
+ * that are trying to acquire a two different syncs in the different orders.
+ */
+ @Test
+ public void testSyncDeadlock() throws Exception {
+ final Lock lock1 = new ReentrantLock();
+ final Lock lock2 = new ReentrantLock();
+
+ Thread thread1 = new Thread() {
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+
+ lock1.lock();
+
+ Thread thread2 = new Thread() {
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+ lock2.lock();
+ try {
+ lock1.tryLock(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ lock2.unlock();
+ }
+ };
+
+ thread2.start();
+
+ try {
+ Thread.sleep(1000);
+ lock2.tryLock(10, TimeUnit.SECONDS);
+ } catch (InterruptedException ignore) {
+ }
+
+ lock1.unlock();
+ }
+ };
+
+ thread1.start();
+
+ Thread.sleep(2000);
+
+ DeadlockDetector detector = new DeadlockDetector();
+ detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
+ LinkedList<Dependency> deadlocks = detector.findDeadlock();
+
+ System.out.println("deadlocks=" + DeadlockDetector.prettyFormat(deadlocks));
+
+ assertEquals(4, detector.findDeadlock().size());
+ }
+
+ @Ignore("Semaphore deadlock detection is not supported by the JDK")
+ @Test
+ public void testSemaphoreDeadlock() throws Exception {
+ final Semaphore lock1 = new Semaphore(1);
+ final Semaphore lock2 = new Semaphore(1);
+
+ Thread thread1 = new Thread() {
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+
+ try {
+ lock1.acquire();
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+
+ Thread thread2 = new Thread() {
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+ try {
+ lock2.acquire();
+ lock1.tryAcquire(10, TimeUnit.SECONDS);
+ } catch (InterruptedException ignore) {
+ }
+ lock2.release();
+ }
+ };
+
+ thread2.start();
+
+ try {
+ Thread.sleep(1000);
+ lock2.tryAcquire(10, TimeUnit.SECONDS);
+ } catch (InterruptedException ignore) {
+ }
+
+ lock1.release();
+ }
+ };
+
+ thread1.start();
+
+ Thread.sleep(2000);
+
+ DeadlockDetector detector = new DeadlockDetector();
+ detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
+ LinkedList<Dependency> deadlocks = detector.findDeadlock();
+
+ System.out.println("deadlocks=" + DeadlockDetector.prettyFormat(deadlocks));
+
+ assertEquals(4, detector.findDeadlock().size());
+ }
+
+ @Ignore("ReadWriteLock deadlock detection is not currently supported by DeadlockDetector")
+ @Test
+ public void testReadLockDeadlock() throws Exception {
+ final ReadWriteLock lock1 = new ReentrantReadWriteLock();
+ final ReadWriteLock lock2 = new ReentrantReadWriteLock();
+
+ Thread thread1 = new Thread() {
+ @Override
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+
+ lock1.readLock().lock();
+
+ Thread thread2 = new Thread() {
+ @Override
+ public void run() {
+ stuckThreads.add(Thread.currentThread());
+ lock2.readLock().lock();
+ try {
+ lock1.writeLock().tryLock(10, TimeUnit.SECONDS);
+ } catch (InterruptedException ignore) {
+ }
+ lock2.readLock().unlock();
+ }
+ };
+
+ thread2.start();
+
+ try {
+ Thread.sleep(1000);
+ lock2.writeLock().tryLock(10, TimeUnit.SECONDS);
+ } catch (InterruptedException ignore) {
+ }
+
+ lock1.readLock().unlock();
+ }
+ };
+
+ thread1.start();
+
+ Thread.sleep(2000);
+
+ DeadlockDetector detector = new DeadlockDetector();
+ detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
+ LinkedList<Dependency> deadlocks = detector.findDeadlock();
+
+ System.out.println("deadlocks=" + deadlocks);
+
+ assertEquals(4, detector.findDeadlock().size());
+ }
+
+ /**
+ * A fake dependency monitor.
+ */
+ private static class MockDependencyMonitor implements DependencyMonitor {
+
+ Set<Dependency<Thread, Serializable>> blockedThreads = new HashSet<>();
+ Set<Dependency<Serializable, Thread>> held = new HashSet<>();
+
+ @Override
+ public Set<Dependency<Thread, Serializable>> getBlockedThreads(Thread[] allThreads) {
+ return blockedThreads;
+ }
+
+ public void addDependency(String resource, Thread thread) {
+ held.add(new Dependency<>(resource, thread));
+ }
+
+ public void addDependency(Thread thread, String resource) {
+ blockedThreads.add(new Dependency<>(thread, resource));
+ }
+
+ @Override
+ public Set<Dependency<Serializable, Thread>> getHeldResources(Thread[] allThreads) {
+ return held;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorJUnitTest.java
deleted file mode 100644
index d27aa2c..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorJUnitTest.java
+++ /dev/null
@@ -1,331 +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 com.gemstone.gemfire.distributed.internal.deadlock;
-
-import static org.junit.Assert.*;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.junit.After;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-/**
- *
- */
-@Category(UnitTest.class)
-public class DeadlockDetectorJUnitTest {
-
- private final Set<Thread> stuckThreads = Collections.synchronizedSet(new HashSet<Thread>());
-
- @After
- public void tearDown() {
- for(Thread thread: stuckThreads) {
- thread.interrupt();
- try {
- thread.join(20 * 1000);
- } catch (InterruptedException e) {
- throw new RuntimeException("interrupted", e);
- }
- if(thread.isAlive()) {
- fail("Couldn't kill" + thread);
- }
- }
- stuckThreads.clear();
- }
-
- @Test
- public void testNoDeadlocks() {
- DeadlockDetector detector = new DeadlockDetector();
- detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
- assertEquals(null, detector.findDeadlock());
- }
-
- //this is commented out, because we can't
- //clean up the threads deadlocked on monitors.
- @Ignore
- @Test
- public void testMonitorDeadlock() throws InterruptedException {
- final Object lock1 = new Object();
- final Object lock2 = new Object();
- Thread thread1 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- synchronized(lock1) {
- Thread thread2 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- synchronized(lock2) {
- synchronized(lock1) {
- System.out.println("we won't get here");
- }
- }
- }
- };
- thread2.start();
- try {
- Thread.sleep(1000);
- synchronized(lock2) {
- System.out.println("We won't get here");
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- };
-
- thread1.start();
- Thread.sleep(2000);
- DeadlockDetector detector = new DeadlockDetector();
- detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
- LinkedList<Dependency> deadlocks = detector.findDeadlock();
- System.out.println("deadlocks=" + DeadlockDetector.prettyFormat(deadlocks));
- assertEquals(4, detector.findDeadlock().size());
- }
-
- /**
- * Make sure that we can detect a deadlock between two threads
- * that are trying to acquire a two different syncs in the different orders.
- * @throws InterruptedException
- */
- @Test
- public void testSyncDeadlock() throws InterruptedException {
-
- final Lock lock1 = new ReentrantLock();
- final Lock lock2 = new ReentrantLock();
- Thread thread1 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- lock1.lock();
- Thread thread2 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- lock2.lock();
- try {
- lock1.tryLock(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- //ignore
- }
- lock2.unlock();
- }
- };
- thread2.start();
- try {
- Thread.sleep(1000);
- lock2.tryLock(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- //ignore
- }
- lock1.unlock();
- }
- };
-
- thread1.start();
- Thread.sleep(2000);
- DeadlockDetector detector = new DeadlockDetector();
- detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
- LinkedList<Dependency> deadlocks = detector.findDeadlock();
- System.out.println("deadlocks=" + DeadlockDetector.prettyFormat(deadlocks));
- assertEquals(4, detector.findDeadlock().size());
- }
-
- //Semaphore are also not supported by the JDK
- @Ignore
- @Test
- public void testSemaphoreDeadlock() throws InterruptedException {
-
- final Semaphore lock1 = new Semaphore(1);
- final Semaphore lock2 = new Semaphore(1);
- Thread thread1 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- try {
- lock1.acquire();
- } catch (InterruptedException e1) {
- e1.printStackTrace();
- }
- Thread thread2 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- try {
- lock2.acquire();
- lock1.tryAcquire(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- //ignore
- }
- lock2.release();
- }
- };
- thread2.start();
- try {
- Thread.sleep(1000);
- lock2.tryAcquire(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- //ignore
- }
- lock1.release();
- }
- };
-
- thread1.start();
- Thread.sleep(2000);
- DeadlockDetector detector = new DeadlockDetector();
- detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
- LinkedList<Dependency> deadlocks = detector.findDeadlock();
- System.out.println("deadlocks=" + DeadlockDetector.prettyFormat(deadlocks));
- assertEquals(4, detector.findDeadlock().size());
- }
-
- /**
- * This type of deadlock is currently not detected
- * @throws InterruptedException
- */
- @Ignore
- @Test
- public void testReadLockDeadlock() throws InterruptedException {
-
- final ReadWriteLock lock1 = new ReentrantReadWriteLock();
- final ReadWriteLock lock2 = new ReentrantReadWriteLock();
- Thread thread1 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- lock1.readLock().lock();
- Thread thread2 = new Thread() {
- public void run() {
- stuckThreads.add(Thread.currentThread());
- lock2.readLock().lock();
- try {
- lock1.writeLock().tryLock(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- lock2.readLock().unlock();
- }
- };
- thread2.start();
- try {
- Thread.sleep(1000);
- lock2.writeLock().tryLock(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- lock1.readLock().unlock();
- }
- };
-
- thread1.start();
- Thread.sleep(2000);
- DeadlockDetector detector = new DeadlockDetector();
- detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
- LinkedList<Dependency> deadlocks = detector.findDeadlock();
- System.out.println("deadlocks=" + deadlocks);
- assertEquals(4, detector.findDeadlock().size());
- }
-
- /**
- * Test that the deadlock detector will find deadlocks
- * that are reported by the {@link DependencyMonitorManager}
- */
- @Test
- public void testProgramaticDependencies() {
- final CountDownLatch cdl = new CountDownLatch(1);
- MockDependencyMonitor mock = new MockDependencyMonitor();
- DependencyMonitorManager.addMonitor(mock);
-
- Thread t1 = startAThread(cdl);
- Thread t2 = startAThread(cdl);
-
- String resource1 = "one";
- String resource2 = "two";
-
- mock.addDependency(t1, resource1);
- mock.addDependency(resource1, t2);
- mock.addDependency(t2, resource2);
- mock.addDependency(resource2, t1);
-
-
- DeadlockDetector detector = new DeadlockDetector();
- detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
- LinkedList<Dependency> deadlocks = detector.findDeadlock();
- System.out.println("deadlocks=" + deadlocks);
- assertEquals(4, deadlocks.size());
- cdl.countDown();
- DependencyMonitorManager.removeMonitor(mock);
- }
-
- private Thread startAThread(final CountDownLatch cdl) {
- Thread thread = new Thread() {
- public void run() {
- try {
- cdl.await();
- } catch (InterruptedException e) {
- }
- }
- };
- thread.start();
-
- return thread;
- }
-
- /**
- * A fake dependency monitor.
- *
- */
- private static class MockDependencyMonitor implements DependencyMonitor {
-
- Set<Dependency<Thread, Serializable>> blockedThreads = new HashSet<Dependency<Thread, Serializable>>();
- Set<Dependency<Serializable, Thread>> held = new HashSet<Dependency<Serializable, Thread>>();
-
- public Set<Dependency<Thread, Serializable>> getBlockedThreads(
- Thread[] allThreads) {
- return blockedThreads;
- }
-
- public void addDependency(String resource, Thread thread) {
- held.add(new Dependency<Serializable, Thread>(resource, thread));
-
- }
-
- public void addDependency(Thread thread, String resource) {
- blockedThreads.add(new Dependency<Thread, Serializable>(thread, resource));
- }
-
- public Set<Dependency<Serializable, Thread>> getHeldResources(
- Thread[] allThreads) {
- return held;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorTest.java
new file mode 100644
index 0000000..9490f47
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DeadlockDetectorTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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 com.gemstone.gemfire.distributed.internal.deadlock;
+
+import static org.junit.Assert.*;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class DeadlockDetectorTest {
+
+ private volatile Set<Thread> stuckThreads;
+
+ @Before
+ public void setUp() throws Exception {
+ stuckThreads = Collections.synchronizedSet(new HashSet<Thread>());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ for (Thread thread: stuckThreads) {
+ thread.interrupt();
+ thread.join(20 * 1000);
+ if (thread.isAlive()) {
+ fail("Couldn't kill" + thread);
+ }
+ }
+
+ stuckThreads.clear();
+ }
+
+ @Test
+ public void testNoDeadlocks() {
+ DeadlockDetector detector = new DeadlockDetector();
+ detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
+ assertEquals(null, detector.findDeadlock());
+ }
+
+ /**
+ * Test that the deadlock detector will find deadlocks
+ * that are reported by the {@link DependencyMonitorManager}
+ */
+ @Test
+ public void testProgrammaticDependencies() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ MockDependencyMonitor mockDependencyMonitor = new MockDependencyMonitor();
+ DependencyMonitorManager.addMonitor(mockDependencyMonitor);
+
+ Thread thread1 = startAThread(latch);
+ Thread thread2 = startAThread(latch);
+
+ String resource1 = "one";
+ String resource2 = "two";
+
+ mockDependencyMonitor.addDependency(thread1, resource1);
+ mockDependencyMonitor.addDependency(resource1, thread2);
+ mockDependencyMonitor.addDependency(thread2, resource2);
+ mockDependencyMonitor.addDependency(resource2, thread1);
+
+ DeadlockDetector detector = new DeadlockDetector();
+ detector.addDependencies(DeadlockDetector.collectAllDependencies("here"));
+ LinkedList<Dependency> deadlocks = detector.findDeadlock();
+
+ System.out.println("deadlocks=" + deadlocks);
+
+ assertEquals(4, deadlocks.size());
+
+ latch.countDown();
+ DependencyMonitorManager.removeMonitor(mockDependencyMonitor);
+ }
+
+ private Thread startAThread(final CountDownLatch latch) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ latch.await();
+ } catch (InterruptedException ignore) {
+ }
+ }
+ };
+
+ thread.start();
+
+ return thread;
+ }
+
+ /**
+ * A fake dependency monitor.
+ */
+ private static class MockDependencyMonitor implements DependencyMonitor {
+
+ Set<Dependency<Thread, Serializable>> blockedThreads = new HashSet<>();
+ Set<Dependency<Serializable, Thread>> held = new HashSet<>();
+
+ @Override
+ public Set<Dependency<Thread, Serializable>> getBlockedThreads(Thread[] allThreads) {
+ return blockedThreads;
+ }
+
+ public void addDependency(String resource, Thread thread) {
+ held.add(new Dependency<>(resource, thread));
+ }
+
+ public void addDependency(Thread thread, String resource) {
+ blockedThreads.add(new Dependency<>(thread, resource));
+ }
+
+ @Override
+ public Set<Dependency<Serializable, Thread>> getHeldResources(Thread[] allThreads) {
+ return held;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DependencyGraphJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DependencyGraphJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DependencyGraphJUnitTest.java
index b93ea09..93f47f0 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DependencyGraphJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/DependencyGraphJUnitTest.java
@@ -16,23 +16,21 @@
*/
package com.gemstone.gemfire.distributed.internal.deadlock;
+import static org.junit.Assert.*;
+
import java.util.HashSet;
import java.util.Set;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
-/**
- *
- */
@Category(UnitTest.class)
-public class DependencyGraphJUnitTest extends TestCase {
-
+public class DependencyGraphJUnitTest {
+
+ @Test
public void testFindCycle() {
-
DependencyGraph graph = new DependencyGraph();
graph.addEdge(new Dependency("A", "B"));
graph.addEdge(new Dependency("A", "F"));
@@ -47,9 +45,9 @@ public class DependencyGraphJUnitTest extends TestCase {
expected.add(new Dependency("E", "A"));
assertEquals(expected, new HashSet(graph.findCycle()));
}
-
+
+ @Test
public void testSubGraph() {
-
DependencyGraph graph = new DependencyGraph();
graph.addEdge(new Dependency("A", "B"));
graph.addEdge(new Dependency("B", "C"));
@@ -68,7 +66,8 @@ public class DependencyGraphJUnitTest extends TestCase {
DependencyGraph sub2 = graph.getSubGraph("E");
assertEquals(null, sub2.findCycle());
}
-
+
+ @Test
public void testTwoPaths() {
DependencyGraph graph = new DependencyGraph();
graph.addEdge(new Dependency("A", "B"));
@@ -78,7 +77,8 @@ public class DependencyGraphJUnitTest extends TestCase {
assertEquals(null, graph.findCycle());
}
-
+
+ @Test
public void testEmptySet() {
DependencyGraph graph = new DependencyGraph();
assertEquals(null, graph.findCycle());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/UnsafeThreadLocalJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/UnsafeThreadLocalJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/UnsafeThreadLocalJUnitTest.java
index 7c7a7fc..41e2ff7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/UnsafeThreadLocalJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/UnsafeThreadLocalJUnitTest.java
@@ -16,45 +16,62 @@
*/
package com.gemstone.gemfire.distributed.internal.deadlock;
+import static org.junit.Assert.*;
+
import java.util.concurrent.CountDownLatch;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
-/**
- *
- */
@Category(UnitTest.class)
-public class UnsafeThreadLocalJUnitTest extends TestCase {
+public class UnsafeThreadLocalJUnitTest {
+
+ private static final long INTERVAL = 10;
+
+ private volatile boolean sleep;
+
+ @Before
+ public void setUp() throws Exception {
+ sleep = true;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ sleep = false;
+ }
/**
* Test that we can get the value of a thread local from another thread.
- *
- * @throws InterruptedException
*/
+ @Test
public void test() throws InterruptedException {
- final UnsafeThreadLocal<String> utl = new UnsafeThreadLocal<String>();
+ final UnsafeThreadLocal<String> unsafeThreadLocal = new UnsafeThreadLocal<String>();
final CountDownLatch localSet = new CountDownLatch(1);
Thread test = new Thread() {
public void run() {
- utl.set("hello");
+ unsafeThreadLocal.set("hello");
localSet.countDown();
try {
- Thread.sleep(100 * 1000);
+ while (sleep) {
+ Thread.sleep(INTERVAL);
+ }
} catch (InterruptedException e) {
- e.printStackTrace();
+ throw new AssertionError(e);
}
}
};
+
test.setDaemon(true);
test.start();
+
localSet.await();
- assertEquals("hello", utl.get(test));
- assertEquals(null, utl.get(Thread.currentThread()));
- }
+ assertEquals("hello", unsafeThreadLocal.get(test));
+ assertEquals(null, unsafeThreadLocal.get(Thread.currentThread()));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
index dd7b432..5caf997 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
@@ -1,54 +1,42 @@
+/*
+ * 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 com.gemstone.gemfire.distributed.internal.membership;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
-import java.io.IOException;
-import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.Timer;
-import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import com.gemstone.gemfire.distributed.internal.DistributionManager;
-import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
-import com.gemstone.gemfire.distributed.internal.membership.NetView;
import com.gemstone.gemfire.internal.SocketCreator;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-/*
- * 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.
- */
@Category(UnitTest.class)
public class NetViewJUnitTest {
- List<InternalDistributedMember> members;
+
+ private List<InternalDistributedMember> members;
@Before
public void initMembers() throws Exception {
@@ -205,7 +193,6 @@ public class NetViewJUnitTest {
/**
* Test that failed weight calculations are correctly performed. See bug #47342
- * @throws Exception
*/
@Test
public void testFailedWeight() throws Exception {