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