@Test
public void testRemoveWhenMaxSpace() throws Exception {
for (long i = 0; i<MAX_SPACE_KiB; i++) {
Resource r = new ByteArrayResource(new byte[i==0?1023:1024]); // make the first one 1 byte less than a KiB
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);
}
assertThat(transCache.storageSize(), is((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);
assertThat(transCache.storageSize(), is((long)(MAX_SPACE_KiB-1)*1024+2)); // 1 KiB for each of the resources except the first should be removed, and the last is only 2 bytes.
assertThat(transCache.size(), is(MAX_SPACE_KiB));
ticker.advanceMilli(1);