@AfterClass public static void afterClass() { for (File file : pathsToDelete) { IOTools.shallowDeleteDirWithFiles(file); } }
@After public void teardown() { try { IOTools.shallowDeleteDirWithFiles(chroniclePath); } catch (Exception e) { if (e instanceof AccessDeniedException && OS.isWindows()) System.err.println(e); else throw e; } }
@Test public void testNoHeader() throws IOException { @NotNull File dir = new File(OS.TARGET + "/deleteme-" + System.nanoTime()); dir.mkdir(); File file = new File(dir, "19700101" + SingleChronicleQueue.SUFFIX); try (FileOutputStream fos = new FileOutputStream(file)) { byte[] bytes = new byte[1024]; for (int i = 0; i < 128; i++) { fos.write(bytes); } } @NotNull ChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST4_DAILY) .testBlockSize() .build(); testQueue(queue); queue.close(); try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testEmptyDirectory() { @NotNull File dir = new File(OS.TARGET, getClass().getSimpleName() + "-" + System.nanoTime()); dir.mkdir(); @NotNull RollingChronicleQueue queue = binary(dir).testBlockSize().build(); assertEquals(Integer.MAX_VALUE, queue.firstCycle()); assertEquals(Long.MAX_VALUE, queue.firstIndex()); assertEquals(Integer.MIN_VALUE, queue.lastCycle()); queue.close(); IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); }
@Test public void testInvalidFile() throws FileNotFoundException { @NotNull File dir = new File(OS.TARGET + "/deleteme-" + System.nanoTime()); dir.mkdir(); try (@NotNull MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700102" + SingleChronicleQueue.SUFFIX), 64 << 10)) { bytes.write8bit("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"); try (@NotNull RollingChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST4_DAILY) .testBlockSize() .build()) { assertEquals(1, queue.firstCycle()); assertEquals(1, queue.lastCycle()); try { @NotNull ExcerptTailer tailer = queue.createTailer(); tailer.toEnd(); fail(); } catch (Exception e) { assertEquals("java.io.StreamCorruptedException: Unexpected magic number 783f3c37", e.toString()); } } } System.gc(); try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } }
IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace();
@Test public void tailerToEndIncreasesRefCount() throws Exception { String path = OS.TARGET + "/toEndIncRefCount-" + System.nanoTime(); IOTools.shallowDeleteDirWithFiles(path); SetTimeProvider time = new SetTimeProvider(); long now = System.currentTimeMillis(); time.currentTimeMillis(now); ChronicleQueue queue = SingleChronicleQueueBuilder.binary(path) .testBlockSize() .rollCycle(RollCycles.TEST_SECONDLY) .timeProvider(time) .build(); final SingleChronicleQueueExcerpts.StoreAppender appender = (SingleChronicleQueueExcerpts.StoreAppender) queue.acquireAppender(); Field storeF1 = SingleChronicleQueueExcerpts.StoreAppender.class.getDeclaredField("store"); Jvm.setAccessible(storeF1); SingleChronicleQueueStore store1 = (SingleChronicleQueueStore) storeF1.get(appender); System.out.println(store1); appender.writeDocument(wire -> wire.write(() -> "msg").int32(1)); final SingleChronicleQueueExcerpts.StoreTailer tailer = (SingleChronicleQueueExcerpts.StoreTailer) queue.createTailer(); System.out.println(tailer); tailer.toEnd(); System.out.println(tailer); Field storeF2 = SingleChronicleQueueExcerpts.StoreTailer.class.getDeclaredField("store"); Jvm.setAccessible(storeF2); SingleChronicleQueueStore store2 = (SingleChronicleQueueStore) storeF2.get(tailer); // the reference count here is 1, the queue itself assertEquals(1, store2.refCount()); }
queue.close(); try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace();
IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace();
@Test public void toEndBeforeWriteTest() { File baseDir = DirectoryUtils.tempDir("toEndBeforeWriteTest"); IOTools.shallowDeleteDirWithFiles(baseDir); try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(baseDir) .testBlockSize() .build()) { checkOneFile(baseDir); // if this appender isn't created, the tailer toEnd doesn't cause a roll. ExcerptAppender appender = queue.acquireAppender(); checkOneFile(baseDir); ExcerptTailer tailer = queue.createTailer(); checkOneFile(baseDir); ExcerptTailer tailer2 = queue.createTailer(); checkOneFile(baseDir); tailer.toEnd(); checkOneFile(baseDir); tailer2.toEnd(); checkOneFile(baseDir); } System.gc(); /*for (int i = 0; i < 10; i++) { final int j = i; appender.writeDocument(wire -> wire.write(() -> "msg").int32(j)); }*/ pathsToDelete.add(baseDir); }
IOTools.shallowDeleteDirWithFiles(queuePath); IOTools.shallowDeleteDirWithFiles(queuePath2); IOTools.shallowDeleteDirWithFiles(queuePath3); } catch (Exception e) {
IOTools.shallowDeleteDirWithFiles(queuePath); IOTools.shallowDeleteDirWithFiles(queuePath2); } catch (Exception ignore) {
IOTools.shallowDeleteDirWithFiles(queuePath); IOTools.shallowDeleteDirWithFiles(queuePath2); } catch (Exception e) {
@Test public void toEndAfterWriteTest() { File file = DirectoryUtils.tempDir("toEndAfterWriteTest"); IOTools.shallowDeleteDirWithFiles(file);
@Test public void missingCyclesToEndTest() throws InterruptedException { String path = OS.TARGET + "/missingCyclesToEndTest-" + System.nanoTime(); IOTools.shallowDeleteDirWithFiles(path);
public static boolean shallowDeleteDirWithFiles(@NotNull String directory) throws IORuntimeException { return shallowDeleteDirWithFiles(new File(directory)); }
public static boolean shallowDeleteDirWithFiles(@NotNull String directory) throws IORuntimeException { return shallowDeleteDirWithFiles(new File(directory)); }