public void testGetStoreEntry() throws Exception { cleanUpDataFolder(); LocalHistoryTestStore store = createStore(); LogHandler lh = new LogHandler("copied file", LogHandler.Compare.STARTS_WITH); File folder = dataDir; folder.mkdirs(); File file1 = new File(folder, "file1"); File file2 = new File(folder, "file2"); createFile(store, file1, System.currentTimeMillis(), "data1"); createFile(store, file2, System.currentTimeMillis(), "data2"); // change the file lh.reset(); changeFile(store, file1, System.currentTimeMillis(), "data1.1"); lh.waitUntilDone(); // rewrite the file write(file1, "data1.2".getBytes()); assertDataInFile(file1, "data1.2".getBytes()); // get the files last state StoreEntry entry = store.getStoreEntry(file1, System.currentTimeMillis()); assertNotNull(entry); assertDataInStream(entry.getStoreFileInputStream(), "data1.1".getBytes()); }
public void testFileChange() throws Exception { LocalHistoryTestStore store = createStore(); LogHandler lh = new LogHandler("copied file", LogHandler.Compare.STARTS_WITH); long ts = System.currentTimeMillis(); // create file in store File file = new File(dataDir, "file1"); createFile(store, file, ts, "data"); File storefile = store.getStoreFile(file, ts, false); // change file with same ts // XXX // if(store.lastModified(file) != ts) { // changeFile(store, file, ts, "data2"); // } // check that nothing changed assertFile(file, store, ts, storefile.lastModified(), 1, 1, "data", TOUCHED); // change file with new ts ts = System.currentTimeMillis(); lh.reset(); changeFile(store, file, ts, "data2"); lh.waitUntilDone(); // check the change assertFile(file, store, ts, -1, 2, 1, "data2", TOUCHED); }
@Override protected void setUp() throws Exception { super.setUp(); System.setProperty("netbeans.localhistory.storeChangesAsynchronously", "true"); cleanUpDataFolder(); LocalHistoryTestStore store = createStore(); store.cleanUp(1); store.getReleasedLocks().clear(); dataDir = new File(getDataDir(), getName()); FileUtils.deleteRecursively(dataDir); }
public void testWrite2StoreVsCleanUp() throws Exception { LocalHistoryTestStore store = createStore(); long ts = System.currentTimeMillis(); File file = new File(dataDir, "crapfile"); File storefile = store.getStoreFile(file, ts, true); assertTrue(storefile.getParentFile().exists()); assertFalse(storefile.exists()); store.cleanUp(ts); // shouldn't remove the storefiles parent even if it's still empty assertTrue(storefile.getParentFile().exists()); OutputStream os1 = StoreEntry.createStoreFileOutputStream(storefile); }
public void testGetStoreEntries() throws Exception { LocalHistoryTestStore store = createStore(); LogHandler lh = new LogHandler("copied file", LogHandler.Compare.STARTS_WITH); File folder = new File(dataDir, "datafolder"); folder.mkdirs(); // create the file File file1 = new File(folder, "file1"); // lets create some history long ts = System.currentTimeMillis() - 4 * 24 * 60 * 60 * 1000; createFile(store, file1, ts + 1000, "data1"); lh.reset(); changeFile(store, file1, ts + 2000, "data1.1"); lh.waitUntilDone(); lh.reset(); changeFile(store, file1, ts + 3000, "data1.2"); lh.waitUntilDone(); lh.reset(); changeFile(store, file1, ts + 4000, "data1.3"); lh.waitUntilDone(); lh.reset(); changeFile(store, file1, ts + 5000, "data1.4"); lh.waitUntilDone(); StoreEntry[] se = store.getStoreEntries(file1); assertEntries( se, file1, new long[] {ts + 1000, ts + 2000, ts + 3000, ts + 4000, ts + 5000}, new String[] {"data1", "data1.1", "data1.2", "data1.3", "data1.4"}); // delete an entry store.deleteEntry(file1, ts + 3000); se = store.getStoreEntries(file1); assertEntries( se, file1, new long[] {ts + 1000, ts + 2000, ts + 4000, ts + 5000}, new String[] {"data1", "data1.1", "data1.3", "data1.4"}); }
public void testFileDelete() throws Exception { cleanUpDataFolder(); LocalHistoryTestStore store = createStore(); long ts = System.currentTimeMillis(); // create file in store File file = new File(dataDir, "file1"); createFile(store, file, ts, "data"); store.fileDelete(file, ts); // check File storefile = store.getStoreFile(file, ts, false); assertFile(file, store, ts, storefile.lastModified(), 1, 1, "data", DELETED); file = new File(dataDir, "file2"); createFile(store, file, ts, "data"); store.fileDelete(file, ts); // check storefile = store.getStoreFile(file, ts, false); assertFile(file, store, ts, storefile.lastModified(), 1, 1, "data", DELETED); }
public void testNoEntryInZipStoreFile() throws Exception { final LocalHistoryTestStore store = createStore(); final LogHandler lhBlock = new LogHandler("created storage file", LogHandler.Compare.STARTS_WITH); LogHandler lh = new LogHandler("finnished copy file", LogHandler.Compare.STARTS_WITH); ExceptionHandler h = new ExceptionHandler(); final long ts = System.currentTimeMillis(); final File file = new File(dataDir, "file"); final Exception[] e = new Exception[1]; final boolean event[] = new boolean[] {false}; store.addVersioningListener( new VersioningListener() { @Override public void versioningEvent(VersioningEvent evt) { event[0] = true; StoreEntry entry = store.getStoreEntry(file, ts); try { entry.getStoreFileOutputStream(); } catch (IOException ex) { e[0] = ex; } } }); lhBlock.block( 1000000); // start blocking so that we can try to access after created, but before filed // with data changeFile(store, file, ts, "data2"); long ts1 = System.currentTimeMillis(); while (!event[0] && !(System.currentTimeMillis() - ts1 < 10000)) { Thread.sleep(200); } lhBlock.unblock(); lh.waitUntilDone(); }
public void testGetDeletedFiles() throws Exception { cleanUpDataFolder(); LocalHistoryTestStore store = createStore(); LogHandler lh = new LogHandler("copied file", LogHandler.Compare.STARTS_WITH); cleanUpDataFolder(); File folder = dataDir; folder.mkdirs(); // create the files File file1 = new File(folder, "file1"); File file2 = new File(folder, "file2"); File file3 = new File(folder, "file3"); File file4 = new File(folder, "file4"); createFile(store, file1, System.currentTimeMillis(), "data1"); createFile(store, file2, System.currentTimeMillis(), "data2"); createFile(store, file3, System.currentTimeMillis(), "data3"); createFile(store, file4, System.currentTimeMillis(), "data4"); // touch the files lh.reset(); changeFile(store, file1, System.currentTimeMillis(), "data1.1"); lh.waitUntilDone(); lh.reset(); changeFile(store, file2, System.currentTimeMillis(), "data2.1"); lh.waitUntilDone(); lh.reset(); changeFile(store, file3, System.currentTimeMillis(), "data3.1"); lh.waitUntilDone(); lh.reset(); changeFile(store, file4, System.currentTimeMillis(), "data4.1"); lh.waitUntilDone(); // delete one of them store.fileDelete(file2, System.currentTimeMillis()); StoreEntry[] entries = store.getDeletedFiles(folder); assertEntries(entries, new File[] {file2}, new String[] {"data2.1"}); // delete one of them store.fileDelete(file3, System.currentTimeMillis()); entries = store.getDeletedFiles(folder); assertEntries(entries, new File[] {file2, file3}, new String[] {"data2.1", "data3.1"}); // delete without entry - only via .delete() file4.delete(); entries = store.getDeletedFiles(folder); assertEntries( entries, new File[] {file2, file3, file4}, new String[] {"data2.1", "data3.1", "data4.1"}); }
public void testSetLabel() throws Exception { LocalHistoryTestStore store = createStore(); LogHandler lh = new LogHandler("copied file", LogHandler.Compare.STARTS_WITH); File folder = new File(dataDir, "datafolder"); folder.mkdirs(); // create the file File file1 = new File(folder, "file1"); // lets create some history long ts = System.currentTimeMillis() - 4 * 24 * 60 * 60 * 1000; createFile(store, file1, ts + 1000, "data1"); lh.reset(); changeFile(store, file1, ts + 2000, "data1.1"); lh.waitUntilDone(); lh.reset(); changeFile(store, file1, ts + 3000, "data1.2"); lh.waitUntilDone(); assertFile(file1, store, ts + 3000, -1, 3, 1, "data1.2", TOUCHED); String label = "My most beloved label"; store.setLabel(file1, ts + 2000, label); assertFile(file1, store, ts + 3000, -1, 3, 1, "data1.2", TOUCHED, true); File labelsFile = store.getLabelsFile(file1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeLong(ts + 2000); dos.writeInt(label.length()); dos.writeChars(label); dos.flush(); assertDataInFile(labelsFile, baos.toByteArray()); label = "My second most beloved label"; store.setLabel(file1, ts + 1000, label); dos.writeLong(ts + 1000); dos.writeInt(label.length()); dos.writeChars(label); dos.flush(); labelsFile = store.getLabelsFile(file1); assertDataInFile(labelsFile, baos.toByteArray()); store.setLabel(file1, ts + 2000, null); baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); dos.writeLong(ts + 1000); dos.writeInt(label.length()); dos.writeChars(label); dos.flush(); labelsFile = store.getLabelsFile(file1); assertDataInFile(labelsFile, baos.toByteArray()); dos.close(); }
public void testGetFolderState() throws Exception { LocalHistoryTestStore store = createStore(); // check for deleted root folder File folder = new File(dataDir, "datafolder"); setupFirstFolderToRevert(store, folder); File[] files = folder.listFiles(); assertEquals(files.length, 7); // fileNotInStorage // fileUnchanged // fileChangedAfterRevert // X fileDeletedAfterRevert // fileDeletedBeforeRevert // fileUndeletedBeforeRevert // fileCreatedToLate // folderCreatedAfterRevert store.fileDelete(folder, System.currentTimeMillis()); Thread.sleep(1000); // give me some time long revertToTS = System.currentTimeMillis(); StoreEntry[] entries = store.getFolderState(folder, files, revertToTS); assertEquals(entries.length, 0); // all are deleted store.cleanUp(1); cleanUpDataFolder(); folder = new File(dataDir, "datafolder"); revertToTS = setupFirstFolderToRevert(store, folder); files = folder.listFiles(); assertEquals(files.length, 7); // fileNotInStorage // fileUnchanged // fileChangedAfterRevert // X fileDeletedAfterRevert // fileDeletedBeforeRevert // fileUndeletedBeforeRevert // fileCreatedToLate // X folderDeletedAfterRevert // folderCreatedAfterRevert entries = store.getFolderState(folder, files, revertToTS); assertEquals(entries.length, 8); // * returned, X as to be deleted // fileNotInStorage - // * fileUnchanged - * // * fileChangedAfterRevert - * previous revision // * fileDeletedAfterRevert - * // * fileUndeletedBeforeRevert - * // X fileCreatedAfterRevert - * X // * X fileDeletedBeforeRevert - * X // * folderDeletedAfterRevert - * // folderCreatedAfterRevert - * X Map<String, StoreEntry> entriesMap = new HashMap<String, StoreEntry>(); for (StoreEntry se : entries) { entriesMap.put(se.getFile().getName(), se); } assertNull(entriesMap.get("fileNotInStorage")); assertNotNull(entriesMap.get("fileUnchanged")); assertNotNull(entriesMap.get("fileChangedAfterRevert")); assertNotNull(entriesMap.get("fileDeletedAfterRevert")); assertNotNull(entriesMap.get("fileUndeletedBeforeRevert")); assertNotNull(entriesMap.get("fileCreatedAfterRevert")); assertNotNull(entriesMap.get("fileDeletedBeforeRevert")); assertNotNull(entriesMap.get("folderDeletedAfterRevert")); assertNotNull(entriesMap.get("folderCreatedAfterRevert")); assertNotNull(entriesMap.get("fileUnchanged").getStoreFile()); assertNotNull(entriesMap.get("fileChangedAfterRevert").getStoreFile()); assertNotNull(entriesMap.get("fileDeletedAfterRevert").getStoreFile()); assertNotNull(entriesMap.get("fileUndeletedBeforeRevert").getStoreFile()); assertNotNull(entriesMap.get("folderDeletedAfterRevert").getStoreFile()); assertNull(entriesMap.get("fileCreatedAfterRevert").getStoreFile()); assertNull(entriesMap.get("fileDeletedBeforeRevert").getStoreFile()); assertNull(entriesMap.get("folderCreatedAfterRevert").getStoreFile()); String strStore = read(entriesMap.get("fileChangedAfterRevert").getStoreFileInputStream(), 1024); // String strFile = read(new // FileInputStream(entriesMap.get("fileChangedAfterRevert").getFile()), 1024); assertNotSame("BEFORE change", strStore); }