Java Code Examples for net.openhft.chronicle.core.io.IOTools#createTempDirectory()

The following examples show how to use net.openhft.chronicle.core.io.IOTools#createTempDirectory() . 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: ChronicleAppenderCycleTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
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 2
Source File: FileUtilTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: MoveToWrongIndexThenToEndTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
public MoveToWrongIndexThenToEndTest() throws IOException {
    basePath = IOTools.createTempDirectory("MoveToWrongIndexThenToEndTest");
    basePath.toFile().deleteOnExit();

    queue = createChronicle(basePath);
    appender = queue.acquireAppender();
    outbound = Bytes.elasticByteBuffer();
}
 
Example 4
Source File: ChronicleQueuePeekDocumentTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@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 5
Source File: TestDeleteQueueFile.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws IOException {
    tempQueueDir = IOTools.createTempDirectory("unitTestQueueDir");
}