Search in sources :

Example 1 with TSDBWriter

use of org.spf4j.tsdb2.TSDBWriter in project spf4j by zolyfarkas.

the class FileMonitorAspectTest method testFileIOMonitoring.

/**
 * Test of nioReadLong method, of class FileMonitorAspect.
 */
@Test
public void testFileIOMonitoring() throws Exception {
    System.setProperty("spf4j.perf.file.sampleTimeMillis", "1000");
    File tempFile = File.createTempFile("test", ".tmp");
    tempFile.deleteOnExit();
    try (Writer fw = new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()), StandardCharsets.UTF_8)) {
        for (int i = 0; i < 10; i++) {
            fw.write("bla bla test\n");
            Thread.sleep(500);
        }
    }
    Thread.sleep(1000);
    try (BufferedReader fr = new BufferedReader(new InputStreamReader(Files.newInputStream(tempFile.toPath()), StandardCharsets.UTF_8))) {
        String line = fr.readLine();
        while (line != null) {
            LOG.debug("Read: {}", line);
            line = fr.readLine();
            Thread.sleep(500);
        }
    }
    TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
    dbWriter.flush();
    final File file = dbWriter.getFile();
    ListMultimap<String, TableDefEx> allTables = TSDBQuery.getAllTablesWithDataRanges(file);
    LOG.debug("Tables {}", allTables);
    Map<String, Collection<TableDefEx>> asMap = allTables.asMap();
    Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest"));
    Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-read,org.spf4j.perf.aspects.FileMonitorAspectTest"));
    List<TableDefEx> get = allTables.get("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest");
    Assert.assertTrue(get.get(0).getStartTime() != 0);
    Assert.assertTrue(OperatingSystem.getOpenFileDescriptorCount() > 0);
}
Also used : InputStreamReader(java.io.InputStreamReader) TableDefEx(org.spf4j.tsdb2.TSDBQuery.TableDefEx) TSDBWriter(org.spf4j.tsdb2.TSDBWriter) BufferedReader(java.io.BufferedReader) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) TSDBWriter(org.spf4j.tsdb2.TSDBWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Test(org.junit.Test)

Example 2 with TSDBWriter

use of org.spf4j.tsdb2.TSDBWriter in project spf4j by zolyfarkas.

the class RecorderFactoryTest method assertData.

@SuppressFBWarnings("CLI_CONSTANT_LIST_INDEX")
public static void assertData(final String forWhat, final long expectedValue) throws IOException {
    TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
    dbWriter.flush();
    final File file = dbWriter.getFile();
    List<TableDef> tableDefs = TSDBQuery.getTableDef(file, forWhat);
    TableDef tableDef = tableDefs.get(0);
    TimeSeries timeSeries = TSDBQuery.getTimeSeries(file, new long[] { tableDef.id }, 0, Long.MAX_VALUE);
    long sum = 0;
    long[][] values = timeSeries.getValues();
    for (long[] row : values) {
        sum += row[0];
    }
    Assert.assertEquals(expectedValue, sum);
}
Also used : TSDBWriter(org.spf4j.tsdb2.TSDBWriter) TimeSeries(org.spf4j.tsdb2.TimeSeries) File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with TSDBWriter

use of org.spf4j.tsdb2.TSDBWriter in project spf4j by zolyfarkas.

the class AllocationMonitorAspectTest method testAfterAllocation.

/**
 * Test of afterAllocation method, of class AllocationMonitorAspect.
 */
@Test
public void testAfterAllocation() throws InterruptedException, IOException {
    System.setProperty("spf4j.perf.allocations.sampleTimeMillis", "1000");
    MemoryUsageSampler.start(500);
    OpenFilesSampler.start(500, 512, 1000, false);
    for (int i = 0; i < 1000; i++) {
        LOG.debug("T{}", i);
        if (i % 100 == 0) {
            Thread.sleep(500);
        }
    }
    testAllocInStaticContext();
    TestClass.testAllocInStaticContext();
    final TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
    dbWriter.flush();
    File file = dbWriter.getFile();
    List<TableDef> tableDef = TSDBQuery.getTableDef(file, "heap-used");
    Assert.assertFalse(tableDef.isEmpty());
    MemoryUsageSampler.stop();
    OpenFilesSampler.stop();
}
Also used : TSDBWriter(org.spf4j.tsdb2.TSDBWriter) File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Test(org.junit.Test)

Example 4 with TSDBWriter

use of org.spf4j.tsdb2.TSDBWriter in project spf4j by zolyfarkas.

the class TSDBReaderTest method testTsdb.

@Test
@SuppressFBWarnings({ "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", "NP_LOAD_OF_KNOWN_NULL_VALUE", "CLI_CONSTANT_LIST_INDEX" })
// try with resources trips up findbugs sometimes.
@SuppressWarnings("checkstyle:EmptyBlock")
public void testTsdb() throws IOException {
    File testFile = File.createTempFile("test", ".tsdb2");
    long tableId;
    try (TSDBWriter writer = new TSDBWriter(testFile, 4, "test", false)) {
    }
    try (TSDBWriter writer = new TSDBWriter(testFile, 4, "test", false)) {
        tableId = writer.writeTableDef(tableDef);
        final long time = System.currentTimeMillis();
        writer.writeDataRow(tableId, time, 0, 1, 2);
        writer.writeDataRow(tableId, time + 10, 1, 1, 2);
        writer.writeDataRow(tableId, time + 20, 2, 1, 2);
        writer.writeDataRow(tableId, time + 30, 3, 1, 2);
        writer.writeDataRow(tableId, time + 40, 4, 1, 2);
    }
    try (TSDBReader reader = new TSDBReader(testFile, 1024)) {
        Either<TableDef, DataBlock> read;
        while ((read = reader.read()) != null) {
            LOG.debug("TSDB block: {}", read);
        }
    }
    ListMultimap<String, TableDef> allTables = TSDBQuery.getAllTables(testFile);
    Assert.assertEquals(1, allTables.size());
    Assert.assertTrue(allTables.containsKey(tableDef.name));
    TimeSeries timeSeries = TSDBQuery.getTimeSeries(testFile, new long[] { tableId }, 0, Long.MAX_VALUE);
    Assert.assertEquals(2L, timeSeries.getValues()[2][0]);
}
Also used : File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) DataBlock(org.spf4j.tsdb2.avro.DataBlock) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with TSDBWriter

use of org.spf4j.tsdb2.TSDBWriter in project spf4j by zolyfarkas.

the class TSDBReaderTest method testTailing.

@Test
public void testTailing() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    File testFile = File.createTempFile("test", ".tsdb2");
    try (TSDBWriter writer = new TSDBWriter(testFile, 4, "test", true);
        TSDBReader reader = new TSDBReader(testFile, 1024)) {
        writer.flush();
        final BlockingQueue<Either<TableDef, DataBlock>> queue = new ArrayBlockingQueue<>(100);
        Future<Void> bgWatch = reader.bgWatch((Either<TableDef, DataBlock> object, long deadline) -> {
            queue.put(object);
        }, TSDBReader.EventSensitivity.HIGH);
        long tableId = writer.writeTableDef(tableDef);
        writer.flush();
        final long time = System.currentTimeMillis();
        writer.writeDataRow(tableId, time, 0, 1, 2);
        writer.writeDataRow(tableId, time + 10, 1, 1, 2);
        writer.flush();
        Either<TableDef, DataBlock> td = queue.take();
        Assert.assertEquals(tableDef, td.getLeft());
        Either<TableDef, DataBlock> take = queue.take();
        Assert.assertEquals(2, take.getRight().getValues().size());
        writer.writeDataRow(tableId, time + 20, 2, 1, 2);
        writer.writeDataRow(tableId, time + 30, 3, 1, 2);
        writer.writeDataRow(tableId, time + 40, 4, 1, 2);
        writer.flush();
        Assert.assertEquals(3, queue.take().getRight().getValues().size());
        reader.stopWatching();
        bgWatch.get(10000, TimeUnit.MILLISECONDS);
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Either(org.spf4j.base.Either) File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) DataBlock(org.spf4j.tsdb2.avro.DataBlock) Test(org.junit.Test)

Aggregations

File (java.io.File)5 Test (org.junit.Test)4 TableDef (org.spf4j.tsdb2.avro.TableDef)4 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)3 TSDBWriter (org.spf4j.tsdb2.TSDBWriter)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 DataBlock (org.spf4j.tsdb2.avro.DataBlock)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 Either (org.spf4j.base.Either)1 TableDefEx (org.spf4j.tsdb2.TSDBQuery.TableDefEx)1 TimeSeries (org.spf4j.tsdb2.TimeSeries)1