You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2019/06/15 04:37:12 UTC
[accumulo] branch 2.0 updated: Fix bad unit tests found while
building on Java 11 (#1213)
This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch 2.0
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.0 by this push:
new 862f321 Fix bad unit tests found while building on Java 11 (#1213)
862f321 is described below
commit 862f32120b4dad722fc058c776f74b774db7a320
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Sat Jun 15 00:37:08 2019 -0400
Fix bad unit tests found while building on Java 11 (#1213)
* Fix bad unit tests found while building on Java 11
* Primarily fixes some bad unit tests
* But also helps build and run unit tests on Java 11
* Fixes #1195 Updates EasyMock and PowerMock
* Fixes #1194 Remove assumptions in AccumuloVFSClassLoader about the
type of the system class loader and the system's app class loader
(specifically, stop assuming they are a URLClassloader instance by
accounting for some other instances they could also be)
---
.../apache/accumulo/core/data/NamespaceIdTest.java | 57 +++++++++---------
.../org/apache/accumulo/core/data/TableIdTest.java | 67 +++++++++++++---------
pom.xml | 4 +-
.../classloader/vfs/AccumuloVFSClassLoader.java | 7 ++-
.../vfs/AccumuloVFSClassLoaderTest.java | 2 +-
5 files changed, 76 insertions(+), 61 deletions(-)
diff --git a/core/src/test/java/org/apache/accumulo/core/data/NamespaceIdTest.java b/core/src/test/java/org/apache/accumulo/core/data/NamespaceIdTest.java
index f590944..036f4d6 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/NamespaceIdTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/NamespaceIdTest.java
@@ -20,30 +20,25 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.apache.accumulo.core.clientImpl.Namespace;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Tests the NamespaceId class, mainly the internal cache.
*/
public class NamespaceIdTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NamespaceIdTest.class);
+
@Rule
public TestName name = new TestName();
@Test
- public void testCacheIncreases() {
- String namespaceString = "namespace-" + name.getMethodName();
- long initialSize = NamespaceId.cache.asMap().entrySet().stream().count();
- NamespaceId nsId = NamespaceId.of(namespaceString);
- assertEquals(initialSize + 1, NamespaceId.cache.asMap().entrySet().stream().count());
- assertEquals(namespaceString, nsId.canonical());
- }
-
- @Test
public void testCacheNoDuplicates() {
// the next line just preloads the built-ins, since they now exist in a separate class from
// NamespaceId, and aren't preloaded when the NamespaceId class is referenced
@@ -68,27 +63,31 @@ public class NamespaceIdTest {
assertSame(nsId, nsId2);
}
- @Test(timeout = 60_000)
- public void testCacheDecreasesAfterGC() {
- Long initialSize = NamespaceId.cache.asMap().entrySet().stream().count();
- generateJunkCacheEntries();
- Long postGCSize;
- do {
- System.gc();
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- fail("Thread interrupted while waiting for GC");
- }
- postGCSize = NamespaceId.cache.asMap().entrySet().stream().count();
- } while (postGCSize > initialSize);
+ @Test(timeout = 30_000)
+ public void testCacheIncreasesAndDecreasesAfterGC() {
+ long initialSize = NamespaceId.cache.asMap().entrySet().stream().count();
+ assertTrue(initialSize < 20); // verify initial amount is reasonably low
+ LOG.info("Initial cache size: {}", initialSize);
+ LOG.info(NamespaceId.cache.asMap().toString());
- assertTrue("Cache did not decrease with GC.",
- NamespaceId.cache.asMap().entrySet().stream().count() < initialSize);
- }
+ // add one and check increase
+ String namespaceString = "namespace-" + name.getMethodName();
+ NamespaceId nsId = NamespaceId.of(namespaceString);
+ assertEquals(initialSize + 1, NamespaceId.cache.asMap().entrySet().stream().count());
+ assertEquals(namespaceString, nsId.canonical());
- private void generateJunkCacheEntries() {
- for (int i = 0; i < 1000; i++)
+ // create a bunch more and throw them away
+ for (int i = 0; i < 999; i++) {
NamespaceId.of(new String("namespace" + i));
+ }
+ long preGCSize = NamespaceId.cache.asMap().entrySet().stream().count();
+ LOG.info("Entries before System.gc(): {}", preGCSize);
+ assertTrue(preGCSize > 500); // verify amount increased significantly
+ long postGCSize = preGCSize;
+ while (postGCSize >= preGCSize) {
+ TableIdTest.tryToGc();
+ postGCSize = NamespaceId.cache.asMap().entrySet().stream().count();
+ LOG.info("Entries after System.gc(): {}", postGCSize);
+ }
}
}
diff --git a/core/src/test/java/org/apache/accumulo/core/data/TableIdTest.java b/core/src/test/java/org/apache/accumulo/core/data/TableIdTest.java
index 8619285..62e4a56 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/TableIdTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/TableIdTest.java
@@ -28,24 +28,22 @@ import org.apache.accumulo.core.replication.ReplicationTable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Tests the Table ID class, mainly the internal cache.
*/
public class TableIdTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TableIdTest.class);
+
@Rule
public TestName name = new TestName();
@Test
- public void testCacheIncreases() {
- long initialSize = TableId.cache.asMap().entrySet().stream().count();
- String tableString = "table-" + name.getMethodName();
- TableId table1 = TableId.of(tableString);
- assertEquals(initialSize + 1, TableId.cache.asMap().entrySet().stream().count());
- assertEquals(tableString, table1.canonical());
- }
-
- @Test
public void testCacheNoDuplicates() {
// the next two lines just preloads the built-ins, since they now exist in a separate class from
// TableId, and aren't preloaded when the TableId class is referenced
@@ -74,28 +72,41 @@ public class TableIdTest {
assertSame(table1, table2);
}
- @Test(timeout = 60_000)
- public void testCacheDecreasesAfterGC() {
- Long initialSize = TableId.cache.asMap().entrySet().stream().count();
- generateJunkCacheEntries();
- Long postGCSize;
- do {
- System.gc();
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- fail("Thread interrupted while waiting for GC");
- }
- postGCSize = TableId.cache.asMap().entrySet().stream().count();
- } while (postGCSize > initialSize);
+ @Test(timeout = 30_000)
+ public void testCacheIncreasesAndDecreasesAfterGC() {
+ long initialSize = TableId.cache.asMap().entrySet().stream().count();
+ assertTrue(initialSize < 20); // verify initial amount is reasonably low
+ LOG.info("Initial cache size: {}", initialSize);
+ LOG.info(TableId.cache.asMap().toString());
- assertTrue("Cache did not decrease with GC.",
- TableId.cache.asMap().entrySet().stream().count() < initialSize);
- }
+ // add one and check increase
+ String tableString = "table-" + name.getMethodName();
+ TableId table1 = TableId.of(tableString);
+ assertEquals(initialSize + 1, TableId.cache.asMap().entrySet().stream().count());
+ assertEquals(tableString, table1.canonical());
- private void generateJunkCacheEntries() {
- for (int i = 0; i < 1000; i++)
+ // create a bunch more and throw them away
+ for (int i = 0; i < 999; i++) {
TableId.of(new String("table" + i));
+ }
+ long preGCSize = TableId.cache.asMap().entrySet().stream().count();
+ LOG.info("Entries before System.gc(): {}", preGCSize);
+ assertTrue(preGCSize > 500); // verify amount increased significantly
+ long postGCSize = preGCSize;
+ while (postGCSize >= preGCSize) {
+ tryToGc();
+ postGCSize = TableId.cache.asMap().entrySet().stream().count();
+ LOG.info("Entries after System.gc(): {}", postGCSize);
+ }
}
+ @SuppressFBWarnings(value = "DM_GC", justification = "gc is okay for test")
+ static void tryToGc() {
+ System.gc();
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ fail("Thread interrupted while waiting for GC");
+ }
+ }
}
diff --git a/pom.xml b/pom.xml
index fc842df..a592801 100644
--- a/pom.xml
+++ b/pom.xml
@@ -136,7 +136,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<!-- surefire/failsafe plugin option -->
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
- <powermock.version>1.7.4</powermock.version>
+ <powermock.version>2.0.2</powermock.version>
<!-- surefire/failsafe plugin option -->
<reuseForks>false</reuseForks>
<servlet.api.version>3.1.0</servlet.api.version>
@@ -545,7 +545,7 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
- <version>3.6</version>
+ <version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
diff --git a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
index 9390475..0696ce6 100644
--- a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
+++ b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
@@ -382,7 +382,12 @@ public class AccumuloVFSClassLoader {
}
boolean sawFirst = false;
- if (classLoader instanceof URLClassLoader) {
+ if (classLoader.getClass().getName().startsWith("jdk.internal")) {
+ if (debug) {
+ out.print("Level " + classLoaderDescription + " " + classLoader.getClass().getName()
+ + " configuration not inspectable.\n");
+ }
+ } else if (classLoader instanceof URLClassLoader) {
if (debug) {
out.print("Level " + classLoaderDescription + " URL classpath items are:\n");
}
diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
index 2600948..172e90f 100644
--- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
+++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
@@ -46,7 +46,7 @@ import org.powermock.reflect.Whitebox;
"org.apache.log4j.LogManager"})
@PowerMockIgnore({"org.apache.log4j.*", "org.apache.hadoop.log.metrics",
"org.apache.commons.logging.*", "org.xml.*", "javax.xml.*", "org.w3c.dom.*",
- "org.apache.hadoop.*"})
+ "org.apache.hadoop.*", "com.sun.org.apache.xerces.*"})
public class AccumuloVFSClassLoaderTest {
private TemporaryFolder folder1 =