ReaderCache { ReaderCache() { this(Duration.standardMinutes(1)); } ReaderCache();   ReaderCache(Duration cacheDuration);   }
@Test public void testReaderCache() throws IOException { readerCache.cacheReader(WindmillComputationKey.create(C_ID, KEY_1, SHARDING_KEY), 1, reader1); readerCache.cacheReader(WindmillComputationKey.create(C_ID, KEY_2, SHARDING_KEY), 2, reader2); assertEquals( reader1, readerCache.acquireReader(WindmillComputationKey.create(C_ID, KEY_1, SHARDING_KEY), 1)); assertNull( readerCache.acquireReader(WindmillComputationKey.create(C_ID_1, KEY_1, SHARDING_KEY), 1)); assertNull( readerCache.acquireReader(WindmillComputationKey.create(C_ID, KEY_1, SHARDING_KEY_1), 1)); try { readerCache.cacheReader(WindmillComputationKey.create(C_ID, KEY_2, SHARDING_KEY), 2, reader1); fail("Exception should have been thrown"); } catch (RuntimeException expected) { } assertEquals( reader2, readerCache.acquireReader(WindmillComputationKey.create(C_ID, KEY_2, SHARDING_KEY), 2)); assertNull( "acquireReader(WindmillComputationKey.create() should remove matching entry", readerCache.acquireReader(WindmillComputationKey.create(C_ID, KEY_2, SHARDING_KEY), 2)); readerCache.cacheReader(WindmillComputationKey.create(C_ID_1, KEY_1, SHARDING_KEY), 1, reader2); assertEquals( reader2, readerCache.acquireReader(WindmillComputationKey.create(C_ID_1, KEY_1, SHARDING_KEY), 1)); readerCache.cacheReader(WindmillComputationKey.create(C_ID, KEY_1, SHARDING_KEY_1), 1, reader3); assertEquals( reader3, readerCache.acquireReader(WindmillComputationKey.create(C_ID, KEY_1, SHARDING_KEY_1), 1)); }
@Test public void testReaderCache() throws IOException { readerCache.cacheReader(C_ID, KEY_1, 1, reader1); readerCache.cacheReader(C_ID, KEY_2, 2, reader2); assertEquals(reader1, readerCache.acquireReader(C_ID, KEY_1, 1)); try { readerCache.cacheReader(C_ID, KEY_2, 2, reader1); fail("Exception should have been thrown"); } catch (RuntimeException expected) { } assertEquals(reader2, readerCache.acquireReader(C_ID, KEY_2, 2)); assertNull( "acquireReader() should remove matching entry", readerCache.acquireReader(C_ID, KEY_2, 2)); readerCache.cacheReader(C_ID_1, KEY_1, 1, reader2); assertEquals(reader2, readerCache.acquireReader(C_ID_1, KEY_1, 1)); }