@Test(timeout = 30_000) public void testCacheIncreasesAndDecreasesAfterGC() { long initialSize = NamespaceId.cache.asMap().entrySet().stream().count(); assertTrue(initialSize < 20); LOG.info("Initial cache size: {}", initialSize); LOG.info(NamespaceId.cache.asMap().toString()); String namespaceString = "namespace-" + name.getMethodName(); NamespaceId nsId = NamespaceId.of(namespaceString); assertEquals(initialSize + 1, NamespaceId.cache.asMap().entrySet().stream().count()); assertEquals(namespaceString, nsId.canonical()); 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); long postGCSize = preGCSize; while (postGCSize >= preGCSize) { TableIdTest.tryToGc(); postGCSize = NamespaceId.cache.asMap().entrySet().stream().count(); LOG.info("Entries after System.gc(): {}", postGCSize); } }
public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  NamespaceId(String canonical); }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  NamespaceId(String canonical); static NamespaceId of(final String canonical); }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  NamespaceId(String canonical); static NamespaceId of(final String canonical);  }