MapLoader { public ChronicleMap<K, V> get(File f) throws Exception { Preconditions.checkNotNull(f); return maps.get(f); } MapLoader(Class<K> keyClass,
                   Class<V> valueClass,
                   long entries,
                   double avgKeySize,
                   double avgValueSize,
                   KM keyMarshaller,
                   VM valueMarshaller,
                   boolean doPersist); ChronicleMap<K, V> get(File f); @Override String toString();  }
@Test public void testReconfigureMap() throws Exception { ChronicleMap<HistogramKey, AgentDigest> map = loader.get(file); map.put(key, digest); map.close(); loader = new MapLoader<>(HistogramKey.class, AgentDigest.class, 50, 100, 500, HistogramKeyMarshaller.get(), AgentDigestMarshaller.get(), true); map = loader.get(file); assertThat(map).containsKey(key); }
@Test public void testPersistence() throws Exception { ChronicleMap<HistogramKey, AgentDigest> map = loader.get(file); map.put(key, digest); map.close(); loader = new MapLoader<>(HistogramKey.class, AgentDigest.class, 100, 200, 1000, HistogramKeyMarshaller.get(), AgentDigestMarshaller.get(), true); map = loader.get(file); assertThat(map).containsKey(key); }
@Test public void testFileDoesNotExist() throws Exception { file.delete(); ConcurrentMap<HistogramKey, AgentDigest> map = loader.get(file); assertThat(((VanillaChronicleMap)map).file()).isNotNull(); testPutRemove(map); }
@Test public void testDoNotPersist() throws Exception { loader = new MapLoader<>( HistogramKey.class, AgentDigest.class, 100, 200, 1000, HistogramKeyMarshaller.get(), AgentDigestMarshaller.get(), false); ConcurrentMap<HistogramKey, AgentDigest> map = loader.get(file); assertThat(((VanillaChronicleMap)map).file()).isNull(); testPutRemove(map); }
@Test public void testCorruptedFileThrows() throws Exception { try (FileOutputStream fos = new FileOutputStream(file)) { fos.write(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 127}); fos.flush(); } try { loader.get(file); fail(); } catch (RuntimeException e) { assertTrue(e.getCause().getCause() instanceof ChronicleHashRecoveryFailedException); } }