accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubbsii <...@git.apache.org>
Subject [GitHub] accumulo pull request #292: ACCUMULO-4681 Created Table & Namespace WeakRefe...
Date Wed, 16 Aug 2017 22:28:07 GMT
Github user ctubbsii commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/292#discussion_r133582248
  
    --- Diff: core/src/test/java/org/apache/accumulo/core/client/impl/NamespaceTest.java ---
    @@ -17,38 +17,73 @@
     package org.apache.accumulo.core.client.impl;
     
     import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertSame;
    +import static org.junit.Assert.assertTrue;
    +import static org.junit.Assert.fail;
     
    +import org.junit.Rule;
     import org.junit.Test;
    +import org.junit.rules.TestName;
     
     /**
    - * Tests the Namespace ID class, mainly the internal WeakHashMap.
    + * Tests the Namespace ID class, mainly the internal cache.
      */
     public class NamespaceTest {
    +  @Rule
    +  public TestName name = new TestName();
     
       @Test
    -  public void testWeakHashMapIncreases() {
    -    String namespaceString = "namespace-testWeakHashMapIncreases";
    -    Integer initialSize = Namespace.ID.cache.asMap().size();
    +  public void testCacheIncreases() {
    +    String namespaceString = "namespace-" + name.getMethodName();
    +    Long initialSize = Namespace.ID.cache.asMap().entrySet().stream().count();
         Namespace.ID nsId = Namespace.ID.of(namespaceString);
    -    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().size());
    +    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count());
         assertEquals(namespaceString, nsId.canonicalID());
       }
     
       @Test
    -  public void testWeakHashMapNoDuplicates() {
    -    String namespaceString = "namespace-testWeakHashMapNoDuplicates";
    -    Integer initialSize = Namespace.ID.cache.asMap().size();
    +  public void testCacheNoDuplicates() {
    +    String namespaceString = "namespace-" + name.getMethodName();
    +    Long initialSize = Namespace.ID.cache.asMap().entrySet().stream().count();
         Namespace.ID nsId = Namespace.ID.of(namespaceString);
    -    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().size());
    +    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count());
         assertEquals(namespaceString, nsId.canonicalID());
     
         // ensure duplicates are not created
         Namespace.ID builtInNamespaceId = Namespace.ID.of("+accumulo");
    -    assertEquals(Namespace.ID.ACCUMULO, builtInNamespaceId);
    +    assertSame(Namespace.ID.ACCUMULO, builtInNamespaceId);
         builtInNamespaceId = Namespace.ID.of("+default");
    -    assertEquals(Namespace.ID.DEFAULT, builtInNamespaceId);
    +    assertSame(Namespace.ID.DEFAULT, builtInNamespaceId);
         nsId = Namespace.ID.of(namespaceString);
    -    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().size());
    +    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count());
         assertEquals(namespaceString, nsId.canonicalID());
    +    Namespace.ID nsId2 = Namespace.ID.of(namespaceString);
    +    assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count());
    +    assertSame(nsId, nsId2);
    +  }
    +
    +  @Test(timeout = 60_000)
    +  public void testCacheDecreasesAfterGC() {
    +    generateJunkCacheEntries();
    +    Long initialSize = Namespace.ID.cache.asMap().entrySet().stream().count();
    +    Long postGCSize;
    +    System.out.println("Namespace.ID.cache.asMap().entrySet().stream().count() = " +
initialSize);
    +    do {
    +      System.gc();
    +      try {
    +        Thread.sleep(5000);
    --- End diff --
    
    Could shorten this to 1 second or 500ms, since there's a good chance it the condition
will be met quickly.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message