Search in sources :

Example 26 with SeriesOutput

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

the class QADataIntegrity method testParallelInsert.

@Test
public void testParallelInsert() throws Exception {
    engine.configure(conf, bgTasks);
    ExecutorService es = Executors.newCachedThreadPool();
    long ts = System.currentTimeMillis();
    final AtomicBoolean b = new AtomicBoolean(false);
    String measurementName = "cpu";
    String dbName = "db1";
    for (int k = 0; k < 10; k++) {
        final int p = k;
        es.submit(() -> {
            while (!b.get()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                for (int i = 0; i < 10000; i++) {
                    long tso = System.currentTimeMillis() + p * 10;
                    for (int l = 0; l < 10; l++) {
                        Point dp = Point.newBuilder().setDbName(dbName).setMeasurementName(measurementName).addTags(Tag.newBuilder().setTagKey("host").setTagValue(String.valueOf(l)).build()).addFp(false).addValueFieldName("user").addValue(2112).setTimestamp(tso + i * 1000).build();
                        engine.writeDataPointWithLock(dp, false);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
    b.set(true);
    es.shutdown();
    es.awaitTermination(100, TimeUnit.SECONDS);
    // check fields
    Set<String> fields = engine.getFieldsForMeasurement(dbName, measurementName);
    assertEquals(2, fields.size());
    assertTrue(fields.contains("user"));
    // check tag keys
    Set<String> tagKeys = engine.getTagKeysForMeasurement(dbName, measurementName);
    assertEquals(1, tagKeys.size());
    assertEquals("host", tagKeys.iterator().next());
    // check tag filters
    TagFilter filter = MiscUtils.buildSimpleFilter("host~.*");
    Set<String> rowKeys = engine.getTagFilteredRowKeys(dbName, measurementName, filter);
    assertEquals(10, rowKeys.size());
    // check dataset
    List<SeriesOutput> all = engine.queryDataPoints(dbName, measurementName, "user", ts - 1000 * 10, ts + 1000 * 100, filter);
    assertEquals(10, all.size());
    for (SeriesOutput s : all) {
        assertEquals(s.getTags() + " bad datapoints", 1000, s.getDataPoints().size());
    }
    for (int i = 0; i < 10; i++) {
        filter = MiscUtils.buildSimpleFilter("host=" + i);
        List<SeriesOutput> points = engine.queryDataPoints(dbName, measurementName, "user", ts - 1000 * 10, ts + 1000 * 100, filter);
        assertEquals(1, points.size());
        SeriesOutput next = points.iterator().next();
        assertEquals(next.getTags() + " bad datapoints", 1000, next.getDataPoints().size());
        for (DataPoint dp : next.getDataPoints()) {
            assertEquals(2112, dp.getLongValue());
        }
    }
}
Also used : TagFilter(com.srotya.sidewinder.core.filters.TagFilter) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 27 with SeriesOutput

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

the class TestSingleValueAggregators method testFirstFunction.

@Test
public void testFirstFunction() {
    FirstFunction f = new FirstFunction();
    double[] values = { 2.2, 1.1, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (double d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    SeriesOutput result = f.apply(series);
    assertEquals(2.2, result.getDataPoints().get(0).getValue(), 0);
// List<long[]> data = new ArrayList<>();
// for(double d:values) {
// data.add(new long[] {ts, Double.doubleToLongBits(d)});
// }
// List<long[]> aggregatePoints = f.aggregatePoints(data, true);
// assertEquals(1, aggregatePoints.size());
// assertEquals(2.2, Double.longBitsToDouble(aggregatePoints.get(0)[1]), 0);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Test(org.junit.Test)

Example 28 with SeriesOutput

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

the class TestSingleValueAggregators method testSumAggregator.

@Test
public void testSumAggregator() {
    double[] values = { 2.2, 1.1, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (double d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    ReduceFunction sva = new SumFunction();
    SeriesOutput series = new SeriesOutput();
    series.setFp(true);
    series.setDataPoints(dps);
    SeriesOutput result = sva.apply(series);
    assertEquals(11, result.getDataPoints().get(0).getValue(), 0.01);
    dps.clear();
    long[] vals = { 1, 2, 3, 4, 5 };
    for (long l : vals) {
        dps.add(MiscUtils.buildDataPoint(ts, l));
    }
    series.setFp(false);
    result = sva.apply(series);
    assertEquals(15, result.getDataPoints().get(0).getLongValue(), 0.01);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) ReduceFunction(com.srotya.sidewinder.core.functions.list.ReduceFunction) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Test(org.junit.Test)

Example 29 with SeriesOutput

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

the class TestSingleValueAggregators method testLastFunction.

@Test
public void testLastFunction() {
    LastFunction f = new LastFunction();
    double[] values = { 2.2, 1.1, 3.3, 4.4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (double d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    SeriesOutput result = f.apply(series);
    assertEquals(4.4, result.getDataPoints().get(0).getValue(), 0);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) Test(org.junit.Test)

Example 30 with SeriesOutput

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

the class TestSingleValueAggregators method testFirstFunctionLong.

@Test
public void testFirstFunctionLong() {
    FirstFunction f = new FirstFunction();
    long[] values = { 2, 1, 3, 4 };
    List<DataPoint> dps = new ArrayList<>();
    long ts = System.currentTimeMillis();
    for (long d : values) {
        dps.add(MiscUtils.buildDataPoint(ts, d));
    }
    SeriesOutput series = new SeriesOutput();
    series.setDataPoints(dps);
    SeriesOutput result = f.apply(series);
    assertEquals(2, result.getDataPoints().get(0).getLongValue());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) 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