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 2017/05/31 17:01:36 UTC
[31/32] geode git commit: 1279: rename tests with old bug system
numbers
http://git-wip-us.apache.org/repos/asf/geode/blob/64404037/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
index 5a679bb..352b6cf 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/internal/JUnit4DistributedTestCase.java
@@ -18,6 +18,11 @@ import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_ARCHIVE_FILE;
+import static org.apache.geode.test.dunit.DistributedTestUtils.getAllDistributedSystemProperties;
+import static org.apache.geode.test.dunit.DistributedTestUtils.unregisterInstantiatorsInThisVM;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.Invoke.invokeInLocator;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
import static org.junit.Assert.assertNotNull;
import org.apache.geode.admin.internal.AdminDistributedSystemImpl;
@@ -50,11 +55,8 @@ import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.net.SocketCreatorFactory;
import org.apache.geode.management.internal.cli.LogWrapper;
import org.apache.geode.test.dunit.DUnitBlackboard;
-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.Invoke;
-import org.apache.geode.test.dunit.LogWriterUtils;
import org.apache.geode.test.dunit.standalone.DUnitLauncher;
import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
import org.apache.logging.log4j.Logger;
@@ -64,10 +66,8 @@ import org.junit.BeforeClass;
import org.junit.Rule;
import java.io.Serializable;
-import java.text.DecimalFormat;
-import java.util.Iterator;
import java.util.LinkedHashSet;
-import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
@@ -75,10 +75,9 @@ import java.util.Set;
* This class is the base class for all distributed tests using JUnit 4.
*/
public abstract class JUnit4DistributedTestCase implements DistributedTestFixture, Serializable {
-
private static final Logger logger = LogService.getLogger();
- private static final Set<String> testHistory = new LinkedHashSet<String>();
+ private static final Set<String> testHistory = new LinkedHashSet<>();
/** This VM's connection to the distributed system */
private static InternalDistributedSystem system;
@@ -86,10 +85,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
private static Properties lastSystemProperties;
private static volatile String testMethodName;
- /** For formatting timing info */
- private static final DecimalFormat format = new DecimalFormat("###.###");
-
- private static boolean reconnect = false;
+ private static DUnitBlackboard blackboard;
private static final boolean logPerTest = Boolean.getBoolean("dunitLogPerTest");
@@ -116,17 +112,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
@Rule
public SerializableTestName testNameForDistributedTestCase = new SerializableTestName();
- private static DUnitBlackboard blackboard;
-
- /**
- * Returns a DUnitBlackboard that can be used to pass data between VMs and synchronize actions.
- *
- * @return the blackboard
- */
- public DUnitBlackboard getBlackboard() {
- return blackboard;
- }
-
@BeforeClass
public static final void initializeDistributedTestCase() {
DUnitLauncher.launchIfNeeded();
@@ -147,19 +132,12 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
return this.distributedTestFixture.getClass();
}
- // ---------------------------------------------------------------------------
- // methods for tests
- // ---------------------------------------------------------------------------
-
/**
* @deprecated Please override {@link #getDistributedSystemProperties()} instead.
*/
@Deprecated
- public final void setSystem(final Properties props, final DistributedSystem ds) { // TODO:
- // override
- // getDistributedSystemProperties
- // and then
- // delete
+ public final void setSystem(final Properties props, final DistributedSystem ds) {
+ // TODO: override getDistributedSystemProperties and then delete
system = (InternalDistributedSystem) ds;
lastSystemProperties = props;
lastSystemCreatedInTest = getTestClass(); // used to be getDeclaringClass()
@@ -183,9 +161,10 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
if (system == null) {
system = InternalDistributedSystem.getAnyInstance();
}
+
if (system == null || !system.isConnected()) {
// Figure out our distributed system properties
- Properties p = DistributedTestUtils.getAllDistributedSystemProperties(props);
+ Properties p = getAllDistributedSystemProperties(props);
lastSystemCreatedInTest = getTestClass(); // used to be getDeclaringClass()
if (logPerTest) {
String testMethod = getTestMethodName();
@@ -197,36 +176,37 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
}
system = (InternalDistributedSystem) DistributedSystem.connect(p);
lastSystemProperties = p;
+
} else {
boolean needNewSystem = false;
if (!getTestClass().equals(lastSystemCreatedInTest)) { // used to be getDeclaringClass()
- Properties newProps = DistributedTestUtils.getAllDistributedSystemProperties(props);
+ Properties newProps = getAllDistributedSystemProperties(props);
needNewSystem = !newProps.equals(lastSystemProperties);
if (needNewSystem) {
- LogWriterUtils.getLogWriter()
+ getLogWriter()
.info("Test class has changed and the new DS properties are not an exact match. "
+ "Forcing DS disconnect. Old props = " + lastSystemProperties + "new props="
+ newProps);
}
+
} else {
Properties activeProps = system.getProperties();
- for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry) iter.next();
+ for (Entry<Object, Object> entry : props.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if (!value.equals(activeProps.getProperty(key))) {
needNewSystem = true;
- LogWriterUtils.getLogWriter().info("Forcing DS disconnect. For property " + key
- + " old value = " + activeProps.getProperty(key) + " new value = " + value);
+ getLogWriter().info("Forcing DS disconnect. For property " + key + " old value = "
+ + activeProps.getProperty(key) + " new value = " + value);
break;
}
}
}
+
if (needNewSystem) {
// the current system does not meet our needs to disconnect and
// call recursively to get a new system.
- LogWriterUtils.getLogWriter()
- .info("Disconnecting from current DS in order to make a new one");
+ getLogWriter().info("Disconnecting from current DS in order to make a new one");
disconnectFromDS();
getSystem(props);
}
@@ -305,14 +285,13 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
public static final void disconnectAllFromDS() {
disconnectFromDS();
- Invoke.invokeInEveryVM("disconnectFromDS", () -> disconnectFromDS());
+ invokeInEveryVM("disconnectFromDS", () -> disconnectFromDS());
}
/**
* Disconnects this VM from the distributed system
*/
public static final void disconnectFromDS() {
- // setTestMethodName(null);
GemFireCacheImpl.testCacheXml = null;
if (system != null) {
system.disconnect();
@@ -326,20 +305,24 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
}
try {
ds.disconnect();
- } catch (Exception e) {
- // ignore
+ } catch (Exception ignore) {
}
}
AdminDistributedSystemImpl ads = AdminDistributedSystemImpl.getConnectedInstance();
- if (ads != null) {// && ads.isConnected()) {
+ if (ads != null) {
ads.disconnect();
}
}
- // ---------------------------------------------------------------------------
- // name methods
- // ---------------------------------------------------------------------------
+ /**
+ * Returns a DUnitBlackboard that can be used to pass data between VMs and synchronize actions.
+ *
+ * @return the blackboard
+ */
+ public DUnitBlackboard getBlackboard() {
+ return blackboard;
+ }
public static final String getTestMethodName() {
return testMethodName;
@@ -358,10 +341,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
return getTestClass().getSimpleName() + "_" + getName();
}
- // ---------------------------------------------------------------------------
- // setup methods
- // ---------------------------------------------------------------------------
-
/**
* Sets up the DistributedTestCase.
*
@@ -370,7 +349,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
* setUp() or override {@link #postSetUp()} with work that needs to occur after setUp().
*/
@Before
- public final void setUp() throws Exception {
+ public final void setUpJUnit4DistributedTestCase() throws Exception {
preSetUp();
setUpDistributedTestCase();
postSetUp();
@@ -455,11 +434,10 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
.set(new InternalDistributedSystem.CreationStackGenerator() {
@Override
public Throwable generateCreationStack(final DistributionConfig config) {
- final StringBuilder sb = new StringBuilder();
- final String[] validAttributeNames = config.getAttributeNames();
- for (int i = 0; i < validAttributeNames.length; i++) {
- final String attName = validAttributeNames[i];
- final Object actualAtt = config.getAttributeObject(attName);
+ StringBuilder sb = new StringBuilder();
+ String[] validAttributeNames = config.getAttributeNames();
+ for (String attName : validAttributeNames) {
+ Object actualAtt = config.getAttributeObject(attName);
String actualAttStr = actualAtt.toString();
sb.append(" ");
sb.append(attName);
@@ -487,10 +465,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
System.out.println("Previously run tests: " + testHistory);
}
- // ---------------------------------------------------------------------------
- // teardown methods
- // ---------------------------------------------------------------------------
-
/**
* Tears down the DistributedTestCase.
*
@@ -515,8 +489,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
}
private final void tearDownDistributedTestCase() throws Exception {
- Invoke.invokeInEveryVM("tearDownCreationStackGenerator",
- () -> tearDownCreationStackGenerator());
+ invokeInEveryVM("tearDownCreationStackGenerator", () -> tearDownCreationStackGenerator());
if (logPerTest) {
disconnectAllFromDS();
}
@@ -524,7 +497,6 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
if (!getDistributedSystemProperties().isEmpty()) {
disconnectAllFromDS();
}
-
}
/**
@@ -569,10 +541,10 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
private static final void cleanupAllVms() {
tearDownVM();
- Invoke.invokeInEveryVM("tearDownVM", () -> tearDownVM());
- Invoke.invokeInLocator(() -> {
+ invokeInEveryVM("tearDownVM", () -> tearDownVM());
+ invokeInLocator(() -> {
DistributionMessageObserver.setInstance(null);
- DistributedTestUtils.unregisterInstantiatorsInThisVM();
+ unregisterInstantiatorsInThisVM();
});
DUnitLauncher.closeAndCheckForSuspects();
}
@@ -580,6 +552,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
private static final void tearDownVM() {
closeCache();
disconnectFromDS();
+
// keep alphabetized to detect duplicate lines
CacheCreation.clearThreadLocals();
CacheServerLauncher.clearStatics();
@@ -588,7 +561,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
ClientServerTestCase.AUTO_LOAD_BALANCE = false;
ClientStatsManager.cleanupForTests();
DiskStoreObserver.setInstance(null);
- DistributedTestUtils.unregisterInstantiatorsInThisVM();
+ unregisterInstantiatorsInThisVM();
DistributionMessageObserver.setInstance(null);
GlobalLockingDUnitTest.region_testBug32356 = null;
InitialImageOperation.slowImageProcessing = 0;
@@ -614,7 +587,8 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
SocketCreatorFactory.close();
}
- private static final void closeCache() { // TODO: this should move to CacheTestCase
+ // TODO: this should move to CacheTestCase
+ private static final void closeCache() {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
if (cache != null && !cache.isClosed()) {
destroyRegions(cache);
@@ -622,12 +596,11 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
}
}
- protected static final void destroyRegions(final Cache cache) { // TODO: this should move to
- // CacheTestCase
+ // TODO: this should move to CacheTestCase
+ protected static final void destroyRegions(final Cache cache) {
if (cache != null && !cache.isClosed()) {
// try to destroy the root regions first so that we clean up any persistent files.
- for (Iterator itr = cache.rootRegions().iterator(); itr.hasNext();) {
- Region root = (Region) itr.next();
+ for (Region<?, ?> root : cache.rootRegions()) {
String regionFullPath = root == null ? null : root.getFullPath();
// for colocated regions you can't locally destroy a partitioned region.
if (root.isDestroyed() || root instanceof HARegion || root instanceof PartitionedRegion) {
http://git-wip-us.apache.org/repos/asf/geode/blob/64404037/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java
new file mode 100644
index 0000000..5557f1b
--- /dev/null
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/serializable/SerializableErrorCollector.java
@@ -0,0 +1,22 @@
+/*
+ * 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.test.junit.rules.serializable;
+
+import org.junit.rules.ErrorCollector;
+
+import java.io.Serializable;
+
+public class SerializableErrorCollector extends ErrorCollector implements Serializable {
+}