@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "loader returned null value") public void testDisallowsNulls() { new ThreadLocalCache<>(10, key -> null).get("foo"); } }
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "loader returned null value") public void testDisallowsNulls() { new ThreadLocalCache<>(10, key -> null).get("foo"); } }
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "loader returned null value") public void testDisallowsNulls() { new ThreadLocalCache<>(10, key -> null).get("foo"); } }
@Test public void testSanity() throws Exception { AtomicInteger count = new AtomicInteger(0); ThreadLocalCache<String, String> cache = new ThreadLocalCache<>(2, key -> { // Concatenate key with counter return key + count.getAndAdd(1); }); // Load first key assertEquals(cache.get("abc"), "abc0"); assertEquals(cache.get("abc"), "abc0"); // Load second key assertEquals(cache.get("def"), "def1"); // First key should still be there assertEquals(cache.get("abc"), "abc0"); // Expire first key by exceeding max size assertEquals(cache.get("ghi"), "ghi2"); // First key should now be regenerated assertEquals(cache.get("abc"), "abc3"); // TODO: add tests for multiple threads }
@Test public void testSanity() throws Exception { AtomicInteger count = new AtomicInteger(0); ThreadLocalCache<String, String> cache = new ThreadLocalCache<>(2, key -> { // Concatenate key with counter return key + count.getAndAdd(1); }); // Load first key assertEquals(cache.get("abc"), "abc0"); assertEquals(cache.get("abc"), "abc0"); // Load second key assertEquals(cache.get("def"), "def1"); // First key should still be there assertEquals(cache.get("abc"), "abc0"); // Expire first key by exceeding max size assertEquals(cache.get("ghi"), "ghi2"); // First key should now be regenerated assertEquals(cache.get("abc"), "abc3"); // TODO: add tests for multiple threads }
@Test public void testSanity() throws Exception { AtomicInteger count = new AtomicInteger(0); ThreadLocalCache<String, String> cache = new ThreadLocalCache<>(2, key -> { // Concatenate key with counter return key + count.getAndAdd(1); }); // Load first key assertEquals(cache.get("abc"), "abc0"); assertEquals(cache.get("abc"), "abc0"); // Load second key assertEquals(cache.get("def"), "def1"); // First key should still be there assertEquals(cache.get("abc"), "abc0"); // Expire first key by exceeding max size assertEquals(cache.get("ghi"), "ghi2"); // First key should now be regenerated assertEquals(cache.get("abc"), "abc3"); // TODO: add tests for multiple threads }