@Test public void testRemoveWhenMaxTiles() throws Exception { for (byte i = 0; i < MAX_TILES; i++) { Resource r = new ByteArrayResource( new byte[] {(byte) (i + 1), (byte) (i + 2), (byte) (i + 3)}); transCache.put("foo" + i, r); assertThat(transCache.size(), is(i + 1)); } assertThat(transCache.storageSize(), is((long) MAX_TILES * 3)); Resource r = new ByteArrayResource(new byte[] {(byte) (MAX_TILES + 1), (byte) (MAX_TILES + 2)}); transCache.put("foo" + MAX_TILES, r); assertThat(transCache.size(), is(MAX_TILES)); assertThat( transCache.storageSize(), is((long) MAX_TILES * 3 - 1)); // remove a 3 byte and add a 2 byte ticker.advanceMilli(1); Resource result1 = transCache.get("foo0"); assertThat(result1, nullValue()); // Should have expired Resource result2 = transCache.get("foo1"); assertThat(result2, notNullValue()); // Should still be cached }
transCache.put("foo" + i, r); assertThat( transCache.storageSize(), is((i + 1) * 1024 - 1)); // 1 KiB per resource, less a byte for the first ticker.advanceMilli(1); transCache.storageSize(), is( (long) MAX_SPACE_KiB * 1024 transCache.put("foo" + MAX_SPACE_KiB, r); assertThat( transCache.storageSize(), is( (long) (MAX_SPACE_KiB - 1) * 1024
System.out.println("transientCacheStorage " + mock.transientCache.storageSize());