@Test public void testReadingExistentFileByCallingList() throws IOException, DatabaseCorruptedException { filePath.getParent().toFile().mkdir(); try (DataOutputStream file = new DataOutputStream(new FileOutputStream(filePath.toString()))) { file.write(correctKey1.getBytes(encoding)); file.write('\0'); file.writeInt(correctKey1.length() + correctKey2.length() + 2 + offsetLength * 2); file.write(correctKey2.getBytes(encoding)); file.write('\0'); file.writeInt( correctKey2.length() + correctKey2.length() + 2 + offsetLength * 2 + testStringValue.length()); file.write(testStringValue.getBytes(encoding)); file.write(testStringValue.getBytes(encoding)); } DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); Set<String> expectedKeySet = new HashSet<>(); expectedKeySet.add(correctKey1); expectedKeySet.add(correctKey2); assertEquals(expectedKeySet, test.list()); }
@Test public void testSavingEmptyDataFileToDisk() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, testStoreableValue); test.remove(correctKey1); test.commit(); test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); assertTrue(test.list().isEmpty()); }
@Test public void testWritingNewFileToDiskAndThenReadingIt() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); String[] keyList = {correctKey1, correctKey2}; test.put(keyList[0], testStoreableValue); test.put(keyList[1], testStoreableValue); test.commit(); assertArrayEquals(keyList, test.list().toArray()); }
@Test public void testPutKeysAndThenCallList() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, testStoreableValue); test.put(correctKey2, testStoreableValue); Set<String> expectedKeySet = new HashSet<>(); expectedKeySet.add(correctKey1); expectedKeySet.add(correctKey2); Set<String> actualKeySet = new HashSet<>(); actualKeySet.addAll(test.list()); assertEquals(expectedKeySet, actualKeySet); }
@Test public void testListCalledForEmptyDataFile() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); assertTrue(test.list().isEmpty()); }