Search in sources :

Example 6 with MicrosecondClock

use of io.questdb.std.datetime.microtime.MicrosecondClock in project questdb by bluestreak01.

the class LogFactoryTest method testRollingFileWriterDateParsePushFilesMid.

@Test
public void testRollingFileWriterDateParsePushFilesMid() throws Exception {
    String base = temp.getRoot().getAbsolutePath() + Files.SEPARATOR;
    String expectedLogFile = base + "mylog-2015-05-03.log";
    try (LogFactory factory = new LogFactory()) {
        String logFile = base + "mylog-${date:yyyy-MM-dd}.log";
        final MicrosecondClock clock = new TestMicrosecondClock(TimestampFormatUtils.parseTimestamp("2015-05-03T10:35:00.000Z"), 1);
        try (Path path = new Path()) {
            path.of(base);
            Assert.assertTrue(Files.touch(path.concat("mylog-2015-05-03.log").$()));
            path.of(base);
            Assert.assertTrue(Files.touch(path.concat("mylog-2015-05-03.log.1").$()));
            path.of(base);
            Assert.assertTrue(Files.touch(path.concat("mylog-2015-05-03.log.2").$()));
            // there is a gap here, .3 is available
            path.of(base);
            Assert.assertTrue(Files.touch(path.concat("mylog-2015-05-03.log.4").$()));
        }
        factory.add(new LogWriterConfig(LogLevel.LOG_LEVEL_INFO, (ring, seq, level) -> {
            LogRollingFileWriter w = new LogRollingFileWriter(FilesFacadeImpl.INSTANCE, clock, ring, seq, level);
            w.setLocation(logFile);
            w.setSpinBeforeFlush("1000000");
            return w;
        }));
        factory.bind();
        factory.startThread();
        try {
            Log logger = factory.create("x");
            for (int i = 0; i < 100000; i++) {
                logger.xinfo().$("test ").$(' ').$(i).$();
            }
            Os.sleep(1000);
        } finally {
            factory.haltThread();
        }
    }
    Assert.assertTrue(new File(expectedLogFile).length() > 0);
}
Also used : Path(io.questdb.std.str.Path) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) File(java.io.File) RingQueue(io.questdb.mp.RingQueue) LockSupport(java.util.concurrent.locks.LockSupport) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) Rule(org.junit.Rule) SCSequence(io.questdb.mp.SCSequence) Path(io.questdb.std.str.Path) TestUtils(io.questdb.test.tools.TestUtils) NativeLPSZ(io.questdb.std.str.NativeLPSZ) TimestampFormatUtils(io.questdb.std.datetime.microtime.TimestampFormatUtils) Assert(org.junit.Assert) io.questdb.std(io.questdb.std) TemporaryFolder(org.junit.rules.TemporaryFolder) SPSequence(io.questdb.mp.SPSequence) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) File(java.io.File) Test(org.junit.Test)

Aggregations

MicrosecondClock (io.questdb.std.datetime.microtime.MicrosecondClock)6 RingQueue (io.questdb.mp.RingQueue)4 SCSequence (io.questdb.mp.SCSequence)4 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)4 SPSequence (io.questdb.mp.SPSequence)4 Path (io.questdb.std.str.Path)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.Test)4 io.questdb.std (io.questdb.std)3 TimestampFormatUtils (io.questdb.std.datetime.microtime.TimestampFormatUtils)3 NativeLPSZ (io.questdb.std.str.NativeLPSZ)3 TestUtils (io.questdb.test.tools.TestUtils)3 File (java.io.File)3 LockSupport (java.util.concurrent.locks.LockSupport)3 Assert (org.junit.Assert)3 Rule (org.junit.Rule)3 TemporaryFolder (org.junit.rules.TemporaryFolder)3 TableWriter (io.questdb.cairo.TableWriter)1 Sequence (io.questdb.mp.Sequence)1 NanosecondClock (io.questdb.std.NanosecondClock)1