net.openhft.chronicle.core.io.IOTools Java Examples
The following examples show how to use
net.openhft.chronicle.core.io.IOTools.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LatencyDistributionMain.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
public void run(String[] args) throws InterruptedException { File tmpDir = getTmpDir(); SingleChronicleQueueBuilder builder = SingleChronicleQueueBuilder .fieldlessBinary(tmpDir) .blockSize(128 << 20); try (ChronicleQueue queue = builder .writeBufferMode(BUFFER_MODE) .readBufferMode(BufferMode.None) .build(); ChronicleQueue queue2 = builder .writeBufferMode(BufferMode.None) .readBufferMode(BUFFER_MODE) .build()) { runTest(queue, queue2); } IOTools.deleteDirWithFiles(tmpDir, 2); }
Example #2
Source File: SingleCQFormatTest.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
@Test(expected = TimeoutException.class) public void testDeadHeader() throws IOException { @NotNull File dir = DirectoryUtils.tempDir("testDeadHeader"); dir.mkdirs(); File file = new File(dir, "19700101" + SingleChronicleQueue.SUFFIX); file.createNewFile(); @NotNull MappedBytes bytes = MappedBytes.mappedBytes(file, ChronicleQueue.TEST_BLOCK_SIZE); bytes.writeInt(Wires.NOT_COMPLETE | Wires.META_DATA); bytes.releaseLast(); @Nullable ChronicleQueue queue = null; try { queue = binary(dir).timeoutMS(500L) .testBlockSize() .blockSize(ChronicleQueue.TEST_BLOCK_SIZE) .build(); testQueue(queue); } finally { Closeable.closeQuietly(queue); IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } }
Example #3
Source File: RollEOFTest.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
@Test(timeout = 5000L) public void testRollWritesEOF() throws IOException { final File path = DirectoryUtils.tempDir(getClass().getName()); try { path.mkdirs(); final SetTimeProvider timeProvider = new SetTimeProvider(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -1); timeProvider.currentTimeMillis(cal.getTimeInMillis()); createQueueAndWriteData(timeProvider, path); assertEquals(1, getNumberOfQueueFiles(path)); // adjust time timeProvider.currentTimeMillis(System.currentTimeMillis()); createQueueAndWriteData(timeProvider, path); assertEquals(2, getNumberOfQueueFiles(path)); List<String> l = new LinkedList<>(); new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).execute(); // 2 entries per message assertEquals(4, l.size()); } finally { IOTools.deleteDirWithFiles(path, 20); } }
Example #4
Source File: QueueMultiThreadedJLBHBenchmark.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
@Override public void init(JLBH jlbh) { IOTools.deleteDirWithFiles("replica", 10); sourceQueue = single("replica").build(); sinkQueue = single("replica").build(); appender = sourceQueue.acquireAppender(); tailer = sinkQueue.createTailer(); new Thread(() -> { Datum datum2 = new Datum(); while (true) { try (DocumentContext dc = tailer.readingDocument()) { if (dc.wire() == null) continue; datum2.readMarshallable(dc.wire().bytes()); jlbh.sample(System.nanoTime() - datum2.ts); } } }).start(); }
Example #5
Source File: QueueSingleThreadedJLBHBenchmark.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
@Override public void init(JLBH jlbh) { IOTools.deleteDirWithFiles("replica", 10); Byteable byteable = (Byteable) datum; long capacity = byteable.maxSize(); byteable.bytesStore(NativeBytesStore.nativeStore(capacity), 0, capacity); datumBytes = ((Byteable) datum).bytesStore(); datumWrite = datumBytes.bytesForWrite(); sourceQueue = single("replica").build(); sinkQueue = single("replica").build(); appender = sourceQueue.acquireAppender(); tailer = sinkQueue.createTailer(); this.jlbh = jlbh; }
Example #6
Source File: ChronicleAppenderCycleTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
private void runTest(String id, Bytes msg) throws IOException { Path path = IOTools.createTempDirectory(id); try { CountDownLatch steady = new CountDownLatch(2); CountDownLatch go = new CountDownLatch(1); CountDownLatch done = new CountDownLatch(1); int n = 468; AtomicReference<Throwable> thr1 = useAppender(path, appender -> { appender.cycle(); for (int i = 0; i < n; ++i) appender.writeBytes(msg); steady.countDown(); await(go, "go"); for (int i = 0; i < n; ++i) appender.writeBytes(msg); }, done); AtomicReference<Throwable> thr2 = useAppender(path, appender -> { steady.countDown(); await(go, "go"); int m = 2 * n; for (int i = 0; i < m; ++i) appender.cycle(); }, done); await(steady, "steady"); go.countDown(); await(done, "done"); assertNull(thr1.get()); assertNull(thr2.get()); } finally { DirectoryUtils.deleteDir(path.toFile()); } }
Example #7
Source File: MarshallableTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testWriteText() { File dir = DirectoryUtils.tempDir("testWriteText"); try (ChronicleQueue queue = binary(dir) .testBlockSize() .build()) { ExcerptAppender appender = queue.acquireAppender(); ExcerptTailer tailer = queue.createTailer(); ExcerptTailer tailer2 = queue.createTailer(); int runs = 1000; for (int i = 0; i < runs; i++) appender.writeText("" + i); for (int i = 0; i < runs; i++) assertEquals("" + i, tailer.readText()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < runs; i++) { assertTrue(tailer2.readText(sb)); assertEquals("" + i, sb.toString()); } } finally { try { IOTools.deleteDirWithFiles(dir, 2); } catch (IORuntimeException e) { // ignored } } }
Example #8
Source File: ToEndTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@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. @SuppressWarnings("unused") 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); }
Example #9
Source File: ToEndTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void tailerToEndIncreasesRefCount() throws NoSuchFieldException, IllegalAccessException { String path = OS.TARGET + "/toEndIncRefCount-" + System.nanoTime(); IOTools.shallowDeleteDirWithFiles(path); SetTimeProvider time = new SetTimeProvider(); long now = System.currentTimeMillis(); time.currentTimeMillis(now); try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(path) .testBlockSize() .rollCycle(RollCycles.TEST_SECONDLY) .timeProvider(time) .build()) { final StoreAppender appender = (StoreAppender) queue.acquireAppender(); Field storeF1 = 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 StoreTailer tailer = (StoreTailer) queue.createTailer(); System.out.println(tailer); tailer.toEnd(); System.out.println(tailer); Field storeF2 = StoreTailer.class.getDeclaredField("store"); Jvm.setAccessible(storeF2); SingleChronicleQueueStore store2 = (SingleChronicleQueueStore) storeF2.get(tailer); // the reference count here is 1, the queue itself assertFalse(store2.isClosed()); } }
Example #10
Source File: SingleCQFormatTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test(expected = TimeoutException.class) 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); } } try (@NotNull ChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST4_DAILY) .timeoutMS(500L) .testBlockSize() .build()) { testQueue(queue); } finally { try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } } }
Example #11
Source File: SingleCQFormatTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@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()); }
Example #12
Source File: SingleChronicleQueueBuilderTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void shouldDetermineQueueDirectoryFromQueueFile() { final Path path = Paths.get(OS.USER_DIR, TEST_QUEUE_FILE); try (final ChronicleQueue queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .build()) { assertFalse(queue.createTailer().readingDocument().isPresent()); } finally { IOTools.deleteDirWithFiles(path.toFile(), 20); } }
Example #13
Source File: MoveToWrongIndexThenToEndTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
public MoveToWrongIndexThenToEndTest() throws IOException { basePath = IOTools.createTempDirectory("MoveToWrongIndexThenToEndTest"); basePath.toFile().deleteOnExit(); queue = createChronicle(basePath); appender = queue.acquireAppender(); outbound = Bytes.elasticByteBuffer(); }
Example #14
Source File: FileUtilTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void state() throws IOException { // TODO FIX AbstractCloseable.disableCloseableTracing(); assumeFalse(OS.isWindows()); final Path dir = IOTools.createTempDirectory("openByAnyProcess"); dir.toFile().mkdir(); try { final File testFile = dir.resolve("tmpFile").toFile(); Files.write(testFile.toPath(), "A".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND); // The file is created but not open assertEquals(FileState.CLOSED, FileUtil.state(testFile)); try (BufferedReader br = new BufferedReader(new FileReader(testFile))) { // The file is now held open assertEquals(FileState.OPEN, FileUtil.state(testFile)); } // The file is now released again assertEquals(FileState.CLOSED, FileUtil.state(testFile)); } finally { deleteDir(dir.toFile()); } }
Example #15
Source File: BridgeMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 5 votes |
public static void main(String[] args) { IOTools.deleteDirWithFiles("in", 2); IOTools.deleteDirWithFiles("out", 2); long events = 0, lastPrint = 0; try (ChronicleQueue queue = ChronicleQueue.singleBuilder("in").sourceId(1).build()) { try (ChronicleQueue queue2 = ChronicleQueue.singleBuilder("out").sourceId(2).build()) { Events out = queue2.methodWriterBuilder(Events.class).recordHistory(true).build(); Events bridge = new BridgeEvents(out); MethodReader methodReader = queue.createTailer("bridge") .methodReader(bridge); System.out.println("Started"); long last = 0; while (running) { if (methodReader.readOne()) { events++; } else { long now = System.currentTimeMillis(); if (lastPrint != events && now > last + 250) { System.out.println("events: " + events); lastPrint = events; last = now; } else { Thread.yield(); } } } } } System.out.println("... finished"); }
Example #16
Source File: DirectoryUtils.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
public static void deleteDir(@NotNull File dir) { try { IOTools.deleteDirWithFiles(dir, 20); } catch (Throwable e) { e.printStackTrace(); } }
Example #17
Source File: RollEOFTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test(timeout = 5000L) public void testRollWithoutEOF() throws IOException { final File path = DirectoryUtils.tempDir(getClass().getName()); try { path.mkdirs(); final SetTimeProvider timeProvider = new SetTimeProvider(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -3); timeProvider.currentTimeMillis(cal.getTimeInMillis()); createQueueAndWriteData(timeProvider, path); assertEquals(1, getNumberOfQueueFiles(path)); // adjust time timeProvider.currentTimeMillis(System.currentTimeMillis()); createQueueAndWriteData(timeProvider, path); assertEquals(2, getNumberOfQueueFiles(path)); Optional<Path> firstQueueFile = Files.list(path.toPath()).filter(p -> p.toString().endsWith(SUFFIX)).sorted().findFirst(); assertTrue(firstQueueFile.isPresent()); // remove EOF from first file removeEOF(firstQueueFile.get()); List<String> l = new LinkedList<>(); new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).withReadOnly(false).execute(); // 2 entries per message assertEquals(4, l.size()); } finally { IOTools.deleteDirWithFiles(path, 20); } }
Example #18
Source File: RollEOFTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test(timeout = 5000L) public void testRollWithoutEOFDoesntBlowup() throws IOException { final File path = DirectoryUtils.tempDir(getClass().getName()); try { path.mkdirs(); final SetTimeProvider timeProvider = new SetTimeProvider(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -1); timeProvider.currentTimeMillis(cal.getTimeInMillis()); createQueueAndWriteData(timeProvider, path); assertEquals(1, getNumberOfQueueFiles(path)); // adjust time timeProvider.currentTimeMillis(System.currentTimeMillis()); createQueueAndWriteData(timeProvider, path); assertEquals(2, getNumberOfQueueFiles(path)); Optional<Path> firstQueueFile = Files.list(path.toPath()).filter(p -> p.toString().endsWith(SUFFIX)).sorted().findFirst(); assertTrue(firstQueueFile.isPresent()); // remove EOF from first file removeEOF(firstQueueFile.get()); List<String> l = new LinkedList<>(); new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).execute(); // 2 entries per message assertEquals(4, l.size()); } finally { IOTools.deleteDirWithFiles(path, 20); } }
Example #19
Source File: OvertakeTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@After public void after() { try { IOTools.deleteDirWithFiles(path, 2); } catch (Exception ignored) { } }
Example #20
Source File: ReadWriteTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@After public void teardown() { try { IOTools.shallowDeleteDirWithFiles(chroniclePath); } catch (Exception e) { if (e instanceof AccessDeniedException && OS.isWindows()) System.err.println(e); else throw e; } }
Example #21
Source File: QueueLargeMessageJLBHBenchmark.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Override public void init(JLBH jlbh) { IOTools.deleteDirWithFiles("large", 3); sourceQueue = single("large").blockSize(1L << 30).build(); sinkQueue = single("large").blockSize(1L << 30).build(); appender = sourceQueue.acquireAppender(); tailer = sinkQueue.createTailer(); this.jlbh = jlbh; }
Example #22
Source File: WriteBytesTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testWriteBytes() { File dir = DirectoryUtils.tempDir("WriteBytesTest"); try (ChronicleQueue queue = binary(dir) .testBlockSize() .build()) { ExcerptAppender appender = queue.acquireAppender(); ExcerptTailer tailer = queue.createTailer(); outgoingMsgBytes[0] = 'A'; outgoingBytes.write(outgoingMsgBytes); postOneMessage(appender); fetchOneMessage(tailer, incomingMsgBytes); System.out.println(new String(incomingMsgBytes)); outgoingBytes.clear(); outgoingMsgBytes[0] = 'A'; outgoingMsgBytes[1] = 'B'; outgoingBytes.write(outgoingMsgBytes); postOneMessage(appender); fetchOneMessage(tailer, incomingMsgBytes); System.out.println(new String(incomingMsgBytes)); } finally { try { IOTools.deleteDirWithFiles(dir, 2); } catch (IORuntimeException e) { // ignored } } }
Example #23
Source File: SingleCQFormatTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Test public void testCompleteHeader() throws FileNotFoundException { // too many hacks are required to make the (artificial) code below release resources correctly AbstractCloseable.disableCloseableTracing(); @NotNull File dir = DirectoryUtils.tempDir("testCompleteHeader"); dir.mkdirs(); @NotNull MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700101" + SingleChronicleQueue.SUFFIX), ChronicleQueue.TEST_BLOCK_SIZE * 2); @NotNull Wire wire = new BinaryWire(bytes); try (DocumentContext dc = wire.writingDocument(true)) { dc.wire().writeEventName(() -> "header").typePrefix(SingleChronicleQueueStore.class).marshallable(w -> { w.write(() -> "wireType").object(WireType.BINARY); w.write(() -> "writePosition").int64forBinding(0); w.write(() -> "roll").typedMarshallable(new SCQRoll(RollCycles.TEST4_DAILY, 0, null, null)); w.write(() -> "indexing").typedMarshallable(new SCQIndexing(WireType.BINARY, 32, 4)); w.write(() -> "lastAcknowledgedIndexReplicated").int64forBinding(0); }); } assertEquals("--- !!meta-data #binary\n" + "header: !SCQStore {\n" + " wireType: !WireType BINARY,\n" + " writePosition: 0,\n" + " roll: !SCQSRoll {\n" + " length: !int 86400000,\n" + " format: yyyyMMdd'T4',\n" + " epoch: 0\n" + " },\n" + " indexing: !SCQSIndexing {\n" + " indexCount: 32,\n" + " indexSpacing: 4,\n" + " index2Index: 0,\n" + " lastIndex: 0\n" + " },\n" + " lastAcknowledgedIndexReplicated: 0\n" + "}\n", Wires.fromSizePrefixedBlobs(bytes.readPosition(0))); bytes.releaseLast(); try (@NotNull ChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST4_DAILY) .testBlockSize() .build()) { testQueue(queue); } try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } }
Example #24
Source File: JDBCServiceTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
private void doCreateTable(int repeats, int noUpdates) { for (int t = 0; t < repeats; t++) { long start = System.nanoTime(), written; File path1 = DirectoryUtils.tempDir("createTable1"); File path2 = DirectoryUtils.tempDir("createTable2"); File file = new File(OS.TARGET, "hsqldb-" + System.nanoTime()); file.deleteOnExit(); try (ChronicleQueue in = SingleChronicleQueueBuilder .binary(path1) .testBlockSize() .build(); ChronicleQueue out = SingleChronicleQueueBuilder .binary(path2) .testBlockSize() .build()) { JDBCService service = new JDBCService(in, out, () -> DriverManager.getConnection("jdbc:hsqldb:file:" + file.getAbsolutePath(), "SA", "")); JDBCStatement writer = service.createWriter(); writer.executeUpdate("CREATE TABLE tableName (\n" + "name VARCHAR(64) NOT NULL,\n" + "num INT\n" + ")\n"); for (int i = 1; i < (long) noUpdates; i++) writer.executeUpdate("INSERT INTO tableName (name, num)\n" + "VALUES (?, ?)", "name", i); written = System.nanoTime() - start; AtomicLong queries = new AtomicLong(); AtomicLong updates = new AtomicLong(); CountingJDBCResult countingJDBCResult = new CountingJDBCResult(queries, updates); MethodReader methodReader = service.createReader(countingJDBCResult); while (updates.get() < noUpdates) { if (!methodReader.readOne()) Thread.yield(); } Closeable.closeQuietly(service); long time = System.nanoTime() - start; System.out.printf("Average time to write each update %.1f us, average time to perform each update %.1f us%n", written / noUpdates / 1e3, time / noUpdates / 1e3); } finally { try { IOTools.deleteDirWithFiles(path1, 2); IOTools.deleteDirWithFiles(path2, 2); } catch (Exception e) { e.printStackTrace(); } } } }
Example #25
Source File: ChronicleQueuePeekDocumentTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Test public void testUsingPeekDocument() throws IOException { Path tempDir = null; try { tempDir = IOTools.createTempDirectory("ChronicleQueueLoggerTest"); // Read back the data try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(tempDir).build()) { ExcerptTailer tailer = queue.createTailer(); try (ChronicleQueue writeQueue = SingleChronicleQueueBuilder.binary(tempDir).build()) { ExcerptAppender appender = writeQueue.acquireAppender(); try (DocumentContext dc = appender.writingDocument()) { dc.wire().write("field1").int32(123534) .write("field2").float64(123.423) .write("time").int64(12053432432L); } try (DocumentContext dc = appender.writingDocument()) { dc.wire().write("field1").int32(323242) .write("field2").float64(543.1233) .write("time").int64(12053432900L); } } assertEquals("field1: !int 123534\n" + "field2: 123.423\n" + "time: 12053432432\n", read(tailer)); assertEquals("field1: !int 323242\n" + "field2: 543.1233\n" + "time: 12053432900\n", read(tailer)); } } finally { if (tempDir != null) { IOTools.deleteDirWithFiles(tempDir.toFile(), 2); } } }
Example #26
Source File: ToEndTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Test public void toEndAfterWriteTest() { File file = DirectoryUtils.tempDir("toEndAfterWriteTest"); IOTools.shallowDeleteDirWithFiles(file); final SetTimeProvider stp = new SetTimeProvider(); stp.currentTimeMillis(1470757797000L); try (ChronicleQueue wqueue = SingleChronicleQueueBuilder .binary(file) .testBlockSize() .rollCycle(RollCycles.TEST_SECONDLY) .timeProvider(stp) .build()) { ExcerptAppender appender = wqueue.acquireAppender(); for (int i = 0; i < 10; i++) { try (DocumentContext dc = appender.writingDocument()) { dc.wire().getValueOut().text("hi-" + i); lastCycle = wqueue.rollCycle().toCycle(dc.index()); } stp.currentTimeMillis(stp.currentTimeMillis() + 1000); } } try (ChronicleQueue rqueue = SingleChronicleQueueBuilder .binary(file) .testBlockSize() .rollCycle(RollCycles.TEST_SECONDLY) .timeProvider(stp) .build()) { ExcerptTailer tailer = rqueue.createTailer(); stp.currentTimeMillis(stp.currentTimeMillis() + 1000); //noinspection StatementWithEmptyBody while (tailer.readText() != null) ; assertNull(tailer.readText()); stp.currentTimeMillis(stp.currentTimeMillis() + 1000); ExcerptTailer tailer1 = rqueue.createTailer(); ExcerptTailer excerptTailer = tailer1.toEnd(); assertNull(excerptTailer.readText()); } System.gc(); pathsToDelete.add(file); }
Example #27
Source File: TestDeleteQueueFile.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Before public void setUp() throws IOException { tempQueueDir = IOTools.createTempDirectory("unitTestQueueDir"); }
Example #28
Source File: ToEndTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@AfterClass public static void afterClass() { for (File file : pathsToDelete) { IOTools.shallowDeleteDirWithFiles(file); } }
Example #29
Source File: SingleCQFormatTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Test public void testCompleteHeader2() throws FileNotFoundException { @NotNull File dir = new File(OS.TARGET, getClass().getSimpleName() + "-" + System.nanoTime()); dir.mkdir(); @NotNull MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700101-02" + SingleChronicleQueue.SUFFIX), ChronicleQueue.TEST_BLOCK_SIZE * 2); @NotNull Wire wire = new BinaryWire(bytes); try (final SingleChronicleQueueStore store = new SingleChronicleQueueStore(RollCycles.HOURLY, WireType.BINARY, bytes, 4 << 10, 4)) { try (DocumentContext dc = wire.writingDocument(true)) { dc.wire().write("header").typedMarshallable(store); } assertEquals("--- !!meta-data #binary\n" + "header: !SCQStore {\n" + " writePosition: [\n" + " 0,\n" + " 0\n" + " ],\n" + " indexing: !SCQSIndexing {\n" + " indexCount: !short 4096,\n" + " indexSpacing: 4,\n" + " index2Index: 0,\n" + " lastIndex: 0\n" + " },\n" + " dataFormat: 1\n" + "}\n", Wires.fromSizePrefixedBlobs(bytes.readPosition(0))); } @NotNull RollingChronicleQueue queue = binary(dir) .testBlockSize() .rollCycle(RollCycles.HOURLY) .build(); testQueue(queue); assertEquals(2, queue.firstCycle()); queue.close(); try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } }
Example #30
Source File: HelloWorldTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Test @Ignore("TODO FIX") public void testWithAsQueueService() { // acts as three processes in one test // process A writes to the HelloWorld interface. // process B read fromt he HelloWorld interface and writes to the String input = OS.TARGET + "/input-" + System.nanoTime(); String output = OS.TARGET + "/output-" + System.nanoTime(); HelloReplier replier = createMock(HelloReplier.class); replier.reply("Hello April"); replier.reply("Hello June"); replay(replier); ServiceWrapperBuilder<HelloReplier> builder = ServiceWrapperBuilder .serviceBuilder(input, output, HelloReplier.class, HelloWorldImpl::new) .inputSourceId(1).outputSourceId(2); try (CloseableHelloWorld helloWorld = builder.inputWriter(CloseableHelloWorld.class); MethodReader replyReader = builder.outputReader(replier); ServiceWrapper helloWorldService = builder.get()) { helloWorld.hello("April"); helloWorld.hello("June"); // System.out.println(helloWorldService.inputQueues()[0].dump()); for (int i = 0; i < 2; i++) { while (!replyReader.readOne()) { Thread.yield(); } } // System.out.println(helloWorldService.outputQueue().dump()); verify(replier); } finally { builder.closeQueues(); try { IOTools.deleteDirWithFiles(new File(input), 2); IOTools.deleteDirWithFiles(new File(output), 2); } catch (IORuntimeException e) { e.printStackTrace(); } } }