@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 }
System.out.println("transientCacheSize " + mock.transientCache.size()); System.out.println("transientCacheStorage " + mock.transientCache.storageSize());
(long) MAX_SPACE_KiB * 1024 - 1)); // 1 KiB per resource, less a byte for the first assertThat(transCache.size(), is(MAX_SPACE_KiB)); Resource r = new ByteArrayResource(new byte[2]); // 2 bytes will go over the maximum transCache.put("foo" + MAX_SPACE_KiB, r); + 2)); // 1 KiB for each of the resources except the first should be assertThat(transCache.size(), is(MAX_SPACE_KiB));