Search in sources :

Example 36 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestTransformFunctions method testCube.

@Test
public void testCube() {
    Function f = new CubeFunction();
    List<SeriesOutput> series = new ArrayList<>();
    SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 3), new DataPoint(1L, 4)));
    series.add(s);
    List<SeriesOutput> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(27, apply.get(0).getDataPoints().get(0).getLongValue());
    assertEquals(64, apply.get(0).getDataPoints().get(1).getLongValue());
}
Also used : Function(com.srotya.sidewinder.core.functions.list.Function) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Test(org.junit.Test)

Example 37 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestGRPWriterServiceImpl method testSingleDataPointWrites.

// @Test
public void testSingleDataPointWrites() throws Exception {
    WriterServiceBlockingStub client = WriterServiceGrpc.newBlockingStub(channel);
    long sts = 1497720452566L;
    Point point = Point.newBuilder().setDbName("test").addFp(false).setMeasurementName("cpu").addTags(Tag.newBuilder().setTagKey("host").setTagValue("1").build()).setTimestamp(sts).addValue(1L).addValueFieldName("usage").build();
    client.writeSingleDataPoint(SingleData.newBuilder().setMessageId(point.getTimestamp()).setPoint(point).build());
    assertTrue(engine.checkIfExists("test"));
    assertTrue(engine.checkIfExists("test", "cpu"));
    assertEquals("host=1", engine.getTagKeysForMeasurement("test", "cpu").iterator().next());
    List<SeriesOutput> result = engine.queryDataPoints("test", "cpu", "usage", sts, sts + 1, null);
    assertEquals(1, result.size());
    assertEquals(1, result.iterator().next().getDataPoints().size());
    assertEquals(1L, result.iterator().next().getDataPoints().iterator().next().getLongValue());
}
Also used : WriterServiceBlockingStub(com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput)

Example 38 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestPersistentMeasurement method testDataPointsRecoveryPTR.

@Test
public void testDataPointsRecoveryPTR() throws Exception {
    long ts = System.currentTimeMillis();
    List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("test").setTagValue("1").build(), Tag.newBuilder().setTagKey("test").setTagValue("2").build());
    Map<String, String> conf = new HashMap<>();
    conf.put(DiskMalloc.CONF_MEASUREMENT_FILE_MAX, String.valueOf(2 * 1024 * 1024));
    conf.put("malloc.ptrfile.increment", String.valueOf(2 * 1024));
    measurement.configure(conf, null, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    int LIMIT = 100;
    for (int i = 0; i < LIMIT; i++) {
        measurement.addPointWithLocking(MiscUtils.buildDataPoint(DBNAME, "m1", "value" + i, tags, ts, 1L), true);
    }
    measurement.close();
    measurement.configure(conf, null, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    List<SeriesOutput> resultMap = new ArrayList<>();
    measurement.queryDataPoints("value.*", ts, ts + 1000, null, null, resultMap, null);
    assertEquals(LIMIT, resultMap.size());
    measurement.close();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Tag(com.srotya.sidewinder.core.rpc.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 39 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestPersistentMeasurement method testDataPointsRecovery.

@Test
public void testDataPointsRecovery() throws Exception {
    long ts = System.currentTimeMillis();
    List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("test").setTagValue("1").build(), Tag.newBuilder().setTagKey("test").setTagValue("2").build());
    conf.put(DiskMalloc.CONF_MEASUREMENT_FILE_MAX, String.valueOf(1024 * 1024));
    try {
        measurement.configure(conf, null, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
        fail("Must throw invalid file max size exception");
    } catch (Exception e) {
    }
    conf.put(DiskMalloc.CONF_MEASUREMENT_FILE_MAX, String.valueOf(2 * 1024 * 1024));
    measurement.configure(conf, null, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    int LIMIT = 100000;
    for (int i = 0; i < LIMIT; i++) {
        measurement.addPointWithLocking(TestMeasurement.build("value", tags, ts + i * 1000, 1L), false);
    }
    measurement.close();
    measurement.configure(conf, null, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    List<SeriesOutput> resultMap = new ArrayList<>();
    measurement.queryDataPoints("value", ts, ts + 1000 * LIMIT, null, null, resultMap, null);
    Iterator<SeriesOutput> iterator = resultMap.iterator();
    assertEquals(LIMIT, iterator.next().getDataPoints().size());
    resultMap.clear();
    TagFilter filter = MiscUtils.buildTagFilter("test=1&test=2");
    measurement.queryDataPoints("value", ts, ts + 1000 * LIMIT, filter, null, resultMap, null);
    iterator = resultMap.iterator();
    assertEquals(LIMIT, iterator.next().getDataPoints().size());
    measurement.close();
}
Also used : TagFilter(com.srotya.sidewinder.core.filters.TagFilter) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Tag(com.srotya.sidewinder.core.rpc.Tag) IOException(java.io.IOException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 40 with SeriesOutput

use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.

the class TestDiskStorageEngine method testQueryDataPointsRecovery.

@Test
public void testQueryDataPointsRecovery() throws Exception {
    try {
        List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("test").setTagValue("e").build());
        DiskStorageEngine engine = new DiskStorageEngine();
        File file = new File("target/db201/");
        MiscUtils.delete(file);
        MiscUtils.ls(file);
        Map<String, String> map = new HashMap<>();
        map.put("index.dir", "target/db201/index");
        map.put("data.dir", "target/db201/data");
        engine.configure(map, bgTasks);
        long ts = System.currentTimeMillis();
        Map<String, Measurement> db = engine.getOrCreateDatabase("test3");
        assertEquals(0, db.size());
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test3", "cpu", "value", tagd, ts, 1), false);
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test3", "cpu", "value", tagd, ts + (400 * 60000), 4), false);
        Measurement measurement = engine.getOrCreateMeasurement("test3", "cpu");
        assertEquals(1, measurement.getSeriesKeys().size());
        MiscUtils.ls(file);
        engine = new DiskStorageEngine();
        engine.configure(map, bgTasks);
        assertTrue(!engine.isMeasurementFieldFP("test3", "cpu", "value"));
        List<SeriesOutput> queryDataPoints = engine.queryDataPoints("test3", "cpu", "value", ts, ts + (400 * 60000), null, null);
        try {
            engine.isMeasurementFieldFP("test3", "test", "test");
            fail("Measurement should not exist");
        } catch (Exception e) {
        }
        assertEquals(1, queryDataPoints.size());
        assertEquals(2, queryDataPoints.iterator().next().getDataPoints().size());
        assertEquals(ts, queryDataPoints.iterator().next().getDataPoints().get(0).getTimestamp());
        assertEquals(ts + (400 * 60000), queryDataPoints.iterator().next().getDataPoints().get(1).getTimestamp());
        TagFilter filter = MiscUtils.buildTagFilter("test=e");
        queryDataPoints = engine.queryDataPoints("test3", "cpu", "value", ts, ts + (400 * 60000), filter, null);
        assertEquals(1, queryDataPoints.size());
        assertEquals(2, queryDataPoints.iterator().next().getDataPoints().size());
        assertEquals(ts, queryDataPoints.iterator().next().getDataPoints().get(0).getTimestamp());
        assertEquals(ts + (400 * 60000), queryDataPoints.iterator().next().getDataPoints().get(1).getTimestamp());
        filter = MiscUtils.buildTagFilter("test=2");
        queryDataPoints = engine.queryDataPoints("test3", "cpu", "value", ts, ts + (400 * 60000), filter, null);
        assertEquals(0, queryDataPoints.size());
        try {
            engine.dropDatabase("test3");
        } catch (Exception e) {
            e.printStackTrace();
            fail("Database delete must succeed");
        }
        assertTrue(!new File("target/db201/data/test3").exists());
        assertEquals(0, engine.getOrCreateMeasurement("test3", "cpu").getSeriesKeys().size());
        engine.shutdown();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) HashMap(java.util.HashMap) TagFilter(com.srotya.sidewinder.core.filters.TagFilter) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) IOException(java.io.IOException) Tag(com.srotya.sidewinder.core.rpc.Tag) File(java.io.File) Test(org.junit.Test)

Aggregations

SeriesOutput (com.srotya.sidewinder.core.storage.SeriesOutput)40 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)35 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)31 WindowedAggregator (com.srotya.sidewinder.core.functions.list.WindowedAggregator)10 Function (com.srotya.sidewinder.core.functions.list.Function)7 IOException (java.io.IOException)6 TagFilter (com.srotya.sidewinder.core.filters.TagFilter)4 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)4 Tag (com.srotya.sidewinder.core.rpc.Tag)3 WriterServiceBlockingStub (com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)3 BadRequestException (javax.ws.rs.BadRequestException)3 NotFoundException (javax.ws.rs.NotFoundException)3 WindowedMean (com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean)2 ChainFunction (com.srotya.sidewinder.core.functions.list.ChainFunction)2 ReduceFunction (com.srotya.sidewinder.core.functions.list.ReduceFunction)2 Point (com.srotya.sidewinder.core.rpc.Point)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 List (java.util.List)2