@Test public void testDiskBackedMap() { MergedRowFactory mergedRowFactory = new MergedRowFactory(); LessFiles.deleteDir(new File("/tmp/testDiskBackedMap")); DiskBackedMap<MergedRow> diskBackedMap = new DiskBackedMap<>("/tmp/testDiskBackedMap", mergedRowFactory, 16 * 1024 * 1024L); MergedRow row1 = new MergedRow(); row1.mergedRow[0] = ValueFactory.create(1.7); row1.mergedRow[1] = ValueFactory.create("Hello"); row1.mergedRow[2] = ValueFactory.create((long) 1); row1.mergedRow[3] = ValueFactory.create(new byte[]{5, 6, 7, 100}); row1.mergedRow[4] = ValueFactory.create(700); diskBackedMap.put("row1", row1); MergedRow row2 = diskBackedMap.get("row1"); assertTrue(row1.mergedRow[0].asDouble().getDouble() == row2.mergedRow[0].asDouble().getDouble()); assertTrue(row1.mergedRow[1].asString().asNative().equals(row2.mergedRow[1].asString().asNative())); assertTrue(row1.mergedRow[2].asLong().getLong() == row2.mergedRow[2].asLong().getLong()); byte[] row2bytes = row1.mergedRow[3].asBytes().asNative(); assertTrue(row2bytes.length == 4); assertTrue(row2bytes[0] == 5); assertTrue(row2bytes[1] == 6); assertTrue(row2bytes[2] == 7); assertTrue(row2bytes[3] == 100); assertTrue(row1.mergedRow[4].asLong().getLong() == row2.mergedRow[4].asLong().getLong()); try { diskBackedMap.close(); } catch (IOException e) { e.printStackTrace(); } assertFalse((new File("/tmp/testDiskBackedMap")).exists()); }
public DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize) { this.diskStoragePath = diskStoragePath; this.factory = factory; this.cacheSize = cacheSize; if (this.cacheSize < 1024 * 1024) { this.cacheSize = 1024 * 1024L; } try { diskStoragePathFile = new File(diskStoragePath).getCanonicalFile(); } catch (IOException e) { log.warn("Error while retrieving the canonical file for: {}", diskStoragePath); throw new RuntimeException(e); } if (diskStoragePathFile.exists()) { try { FileUtils.deleteDirectory(diskStoragePathFile); } catch (IOException e) { throw new RuntimeException(e); } } if (!diskStoragePathFile.mkdirs()) { log.warn("Error while creating the directory: {}", diskStoragePath); throw new RuntimeException("Error while creating the directory: " + diskStoragePath); } try { db = new PageDB.Builder<>(diskStoragePathFile, CodableDiskObject.class, 1000, 1000) .dbname("DiskBackedMap.db").pageFactory(ConcurrentPage.ConcurrentPageFactory.singleton).build(); db.setCacheMem(cacheSize); } catch (IOException e) { throw new RuntimeException(e); } }
DiskBackedMap implements Map<String, T>, Closeable { public DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize) { this.diskStoragePath = diskStoragePath; this.factory = factory; this.cacheSize = cacheSize; if (this.cacheSize < 1024 * 1024) { this.cacheSize = 1024 * 1024L; } try { diskStoragePathFile = new File(diskStoragePath).getCanonicalFile(); } catch (IOException e) { log.warn("Error while retrieving the canonical file for: {}", diskStoragePath); throw new RuntimeException(e); } if (diskStoragePathFile.exists()) { try { FileUtils.deleteDirectory(diskStoragePathFile); } catch (IOException e) { throw new RuntimeException(e); } } if (!diskStoragePathFile.mkdirs()) { log.warn("Error while creating the directory: {}", diskStoragePath); throw new RuntimeException("Error while creating the directory: " + diskStoragePath); } try { db = new PageDB.Builder<>(diskStoragePathFile, CodableDiskObject.class, 1000, 1000) .dbname("DiskBackedMap.db").pageFactory(ConcurrentPage.ConcurrentPageFactory.singleton).build(); db.setCacheMem(cacheSize); } catch (IOException e) { throw new RuntimeException(e); } } }
DiskBackedMap implements Map<String, T>, Closeable { public DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize) { this.diskStoragePath = diskStoragePath; this.factory = factory; this.cacheSize = cacheSize; if (this.cacheSize < 1024 * 1024) { this.cacheSize = 1024 * 1024L; } try { diskStoragePathFile = new File(diskStoragePath).getCanonicalFile(); } catch (IOException e) { log.warn("Error while retrieving the canonical file for: {}", diskStoragePath); throw new RuntimeException(e); } if (diskStoragePathFile.exists()) { try { FileUtils.deleteDirectory(diskStoragePathFile); } catch (IOException e) { throw new RuntimeException(e); } } if (!diskStoragePathFile.mkdirs()) { log.warn("Error while creating the directory: {}", diskStoragePath); throw new RuntimeException("Error while creating the directory: " + diskStoragePath); } try { db = new PageDB.Builder<>(diskStoragePathFile, CodableDiskObject.class, 1000, 1000) .dbname("DiskBackedMap.db").pageFactory(ConcurrentPage.ConcurrentPageFactory.singleton).build(); db.setCacheMem(cacheSize); } catch (IOException e) { throw new RuntimeException(e); } } DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize); }
DiskBackedMap implements Map<String, T>, Closeable { public DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize) { this.diskStoragePath = diskStoragePath; this.factory = factory; this.cacheSize = cacheSize; if (this.cacheSize < 1024 * 1024) { this.cacheSize = 1024 * 1024L; } try { diskStoragePathFile = new File(diskStoragePath).getCanonicalFile(); } catch (IOException e) { log.warn("Error while retrieving the canonical file for: {}", diskStoragePath); throw new RuntimeException(e); } if (diskStoragePathFile.exists()) { try { FileUtils.deleteDirectory(diskStoragePathFile); } catch (IOException e) { throw new RuntimeException(e); } } if (!diskStoragePathFile.mkdirs()) { log.warn("Error while creating the directory: {}", diskStoragePath); throw new RuntimeException("Error while creating the directory: " + diskStoragePath); } try { db = new PageDB.Builder<>(diskStoragePathFile, CodableDiskObject.class, 1000, 1000) .dbname("DiskBackedMap.db").pageFactory(ConcurrentPage.ConcurrentPageFactory.singleton).build(); db.setCacheMem(cacheSize); } catch (IOException e) { throw new RuntimeException(e); } } DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object o); @Override boolean containsValue(Object o); @Override T get(Object o); @Override T put(String s, T t); @Override T remove(Object o); @Override void putAll(Map<? extends String, ? extends T> map); @Override void clear(); @Override Set<String> keySet(); @Override Set<Entry<String, T>> entrySet(); @Override Collection<T> values(); @Override void close(); }
DiskBackedMap implements Map<String, T>, Closeable { public DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize) { this.diskStoragePath = diskStoragePath; this.factory = factory; this.cacheSize = cacheSize; if (this.cacheSize < 1024 * 1024) { this.cacheSize = 1024 * 1024L; } try { diskStoragePathFile = new File(diskStoragePath).getCanonicalFile(); } catch (IOException e) { log.warn("Error while retrieving the canonical file for: {}", diskStoragePath); throw new RuntimeException(e); } if (diskStoragePathFile.exists()) { try { FileUtils.deleteDirectory(diskStoragePathFile); } catch (IOException e) { throw new RuntimeException(e); } } if (!diskStoragePathFile.mkdirs()) { log.warn("Error while creating the directory: {}", diskStoragePath); throw new RuntimeException("Error while creating the directory: " + diskStoragePath); } try { db = new PageDB.Builder<>(diskStoragePathFile, CodableDiskObject.class, 1000, 1000) .dbname("DiskBackedMap.db").pageFactory(ConcurrentPage.ConcurrentPageFactory.singleton).build(); db.setCacheMem(cacheSize); } catch (IOException e) { throw new RuntimeException(e); } } DiskBackedMap(String diskStoragePath, DiskObjectFactory factory, long cacheSize); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object o); @Override boolean containsValue(Object o); @Override T get(Object o); @Override T put(String s, T t); @Override T remove(Object o); @Override void putAll(Map<? extends String, ? extends T> map); @Override void clear(); @Override Set<String> keySet(); @Override Set<Entry<String, T>> entrySet(); @Override Collection<T> values(); @Override void close();  }