Search in sources :

Example 1 with NoLock

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

the class TestDownSamplingIFunction method testBasicSumDownSampling.

@Test
public void testBasicSumDownSampling() throws IOException {
    Field tField = new TimeField(measurement, new LinkedByteString().concat(new ByteString("time")), 121213, new HashMap<>());
    long ts = 1546755994280L;
    for (int i = 0; i < 100; i++) {
        tField.addDataPoint(measurement, ts + i * 1000);
    }
    Field vField = new ValueField(measurement, new LinkedByteString().concat(new ByteString("field1")), 121213, new HashMap<>());
    for (int i = 0; i < 100; i++) {
        vField.addDataPoint(measurement, i);
    }
    DataPointIterator itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
    DownsampleFunction f = new DownsampleFunction(itr, 5, TimeUnit.SECONDS, ((x, y) -> (x + y)));
    int c = 0;
    while (f.hasNext()) {
        DataPoint next = f.next();
        if (c < 20) {
            assertEquals(ts + c * 1000 * 5, next.getTimestamp());
        }
        c++;
    }
    assertEquals(21, c);
    itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
    f = new DownsampleFunction(itr, 10, TimeUnit.SECONDS, ((x, y) -> (x + y) / 2));
    c = 0;
    while (f.hasNext()) {
        DataPoint next = f.next();
        if (c < 10) {
            assertEquals(ts + c * 1000 * 10, next.getTimestamp());
        }
        c++;
    }
    assertEquals(10, c, 1);
}
Also used : DownsampleFunction(com.srotya.sidewinder.core.functions.iterative.DownsampleFunction) NoLock(com.srotya.sidewinder.core.storage.NoLock) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) TimeUnit(java.util.concurrent.TimeUnit) Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) CompressionFactory(com.srotya.sidewinder.core.storage.compression.CompressionFactory) ByteString(com.srotya.sidewinder.core.storage.ByteString) MockMeasurement(com.srotya.sidewinder.core.storage.MockMeasurement) Assert.assertEquals(org.junit.Assert.assertEquals) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) TimeField(com.srotya.sidewinder.core.storage.TimeField) Before(org.junit.Before) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) TimeField(com.srotya.sidewinder.core.storage.TimeField) TimeField(com.srotya.sidewinder.core.storage.TimeField) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) NoLock(com.srotya.sidewinder.core.storage.NoLock) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ValueField(com.srotya.sidewinder.core.storage.ValueField) DownsampleFunction(com.srotya.sidewinder.core.functions.iterative.DownsampleFunction) Test(org.junit.Test)

Example 2 with NoLock

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

the class TestBasicSingleFunctions method before.

@Before
public void before() throws IOException {
    measurement = new MockMeasurement(32768, 100);
    TimeField.compressionClass = CompressionFactory.getTimeClassByName("byzantine");
    Field tField = new TimeField(measurement, new LinkedByteString().concat(new ByteString("time")), 121213, new HashMap<>());
    long ts = 1546755991280L;
    for (int i = 0; i < 200; i++) {
        tField.addDataPoint(measurement, ts + i * 1000);
    }
    Field vField = new ValueField(measurement, new LinkedByteString().concat(new ByteString("field1")), 121213, new HashMap<>());
    for (int i = 0; i < 100; i++) {
        vField.addDataPoint(measurement, i * 1L);
    }
    for (int i = 100; i > 0; i--) {
        vField.addDataPoint(measurement, i * 1L);
    }
    itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
}
Also used : Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) TimeField(com.srotya.sidewinder.core.storage.TimeField) TimeField(com.srotya.sidewinder.core.storage.TimeField) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) MockMeasurement(com.srotya.sidewinder.core.storage.MockMeasurement) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) NoLock(com.srotya.sidewinder.core.storage.NoLock) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ValueField(com.srotya.sidewinder.core.storage.ValueField) Before(org.junit.Before)

Example 3 with NoLock

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

the class TestDownSamplingIFunction method testAverageDownsampling.

@Test
public void testAverageDownsampling() throws IOException {
    Field tField = new TimeField(measurement, new LinkedByteString().concat(new ByteString("time")), 121213, new HashMap<>());
    long ts = 1546755994280L;
    for (int i = 0; i < 100; i++) {
        tField.addDataPoint(measurement, ts + i * 1000);
    }
    Field vField = new ValueField(measurement, new LinkedByteString().concat(new ByteString("field1")), 121213, new HashMap<>());
    for (int i = 0; i < 100; i++) {
        vField.addDataPoint(measurement, 1L);
    }
    DataPointIterator itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
    DownsampleFunction f = new DownsampleFunction(itr, 5, TimeUnit.SECONDS, ((x, y) -> (x + y)));
    int c = 0;
    while (f.hasNext()) {
        DataPoint next = f.next();
        if (c < 20) {
            assertEquals(ts + c * 1000 * 5, next.getTimestamp());
            assertEquals(5, next.getLongValue());
        }
        c++;
    }
    assertEquals(21, c);
    itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
    f = new DownsampleFunction(itr, 10, TimeUnit.SECONDS, ((x, y) -> (x + y) / 2));
    c = 0;
    while (f.hasNext()) {
        DataPoint next = f.next();
        if (c < 10) {
            assertEquals(ts + c * 1000 * 10, next.getTimestamp());
            assertEquals(1, next.getLongValue());
        }
        c++;
    }
    assertEquals(10, c, 1);
}
Also used : DownsampleFunction(com.srotya.sidewinder.core.functions.iterative.DownsampleFunction) NoLock(com.srotya.sidewinder.core.storage.NoLock) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) TimeUnit(java.util.concurrent.TimeUnit) Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) CompressionFactory(com.srotya.sidewinder.core.storage.compression.CompressionFactory) ByteString(com.srotya.sidewinder.core.storage.ByteString) MockMeasurement(com.srotya.sidewinder.core.storage.MockMeasurement) Assert.assertEquals(org.junit.Assert.assertEquals) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) TimeField(com.srotya.sidewinder.core.storage.TimeField) Before(org.junit.Before) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) TimeField(com.srotya.sidewinder.core.storage.TimeField) TimeField(com.srotya.sidewinder.core.storage.TimeField) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) NoLock(com.srotya.sidewinder.core.storage.NoLock) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ValueField(com.srotya.sidewinder.core.storage.ValueField) DownsampleFunction(com.srotya.sidewinder.core.functions.iterative.DownsampleFunction) Test(org.junit.Test)

Example 4 with NoLock

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

the class TestTumblingWindowFunction method testBasicMinDownSampling.

@Test
public void testBasicMinDownSampling() throws Exception {
    Field tField = new TimeField(measurement, new LinkedByteString().concat(new ByteString("time")), 121213, new HashMap<>());
    long ts = 1546755991280L;
    for (int i = 0; i < 100; i++) {
        tField.addDataPoint(measurement, ts + i * 1000);
    }
    Field vField = new ValueField(measurement, new LinkedByteString().concat(new ByteString("field1")), 121213, new HashMap<>());
    for (int i = 0; i < 100; i++) {
        vField.addDataPoint(measurement, i);
    }
    DataPointIterator itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
    TumblingWindowFunction tumblingWindowFunction = new TumblingWindowFunction(itr, false);
    tumblingWindowFunction.init(new Object[] { 10, "smin" });
    int c = 0;
    while (tumblingWindowFunction.hasNext()) {
        tumblingWindowFunction.next();
        c++;
    }
    assertEquals(11, c);
}
Also used : Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) TimeField(com.srotya.sidewinder.core.storage.TimeField) TimeField(com.srotya.sidewinder.core.storage.TimeField) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) NoLock(com.srotya.sidewinder.core.storage.NoLock) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ValueField(com.srotya.sidewinder.core.storage.ValueField) Test(org.junit.Test)

Example 5 with NoLock

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

the class TestTumblingWindowFunction method testBasicSumDownSampling.

@Test
public void testBasicSumDownSampling() throws Exception {
    Field tField = new TimeField(measurement, new LinkedByteString().concat(new ByteString("time")), 121213, new HashMap<>());
    long ts = 1546755991280L;
    for (int i = 0; i < 100; i++) {
        tField.addDataPoint(measurement, ts + i * 1000);
    }
    Field vField = new ValueField(measurement, new LinkedByteString().concat(new ByteString("field1")), 121213, new HashMap<>());
    for (int i = 0; i < 100; i++) {
        vField.addDataPoint(measurement, 1L);
    }
    DataPointIterator itr = new DataPointIterator(tField.queryReader(null, new NoLock()), vField.queryReader(null, new NoLock()));
    TumblingWindowFunction tumblingWindowFunction = new TumblingWindowFunction(itr, false);
    tumblingWindowFunction.init(new Object[] { 10, "ssum" });
    int c = 0;
    while (tumblingWindowFunction.hasNext()) {
        tumblingWindowFunction.next();
        c++;
    }
    assertEquals(11, c);
}
Also used : Field(com.srotya.sidewinder.core.storage.Field) ValueField(com.srotya.sidewinder.core.storage.ValueField) TimeField(com.srotya.sidewinder.core.storage.TimeField) TimeField(com.srotya.sidewinder.core.storage.TimeField) DataPointIterator(com.srotya.sidewinder.core.storage.DataPointIterator) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) NoLock(com.srotya.sidewinder.core.storage.NoLock) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ValueField(com.srotya.sidewinder.core.storage.ValueField) Test(org.junit.Test)

Aggregations

ByteString (com.srotya.sidewinder.core.storage.ByteString)5 DataPointIterator (com.srotya.sidewinder.core.storage.DataPointIterator)5 Field (com.srotya.sidewinder.core.storage.Field)5 LinkedByteString (com.srotya.sidewinder.core.storage.LinkedByteString)5 NoLock (com.srotya.sidewinder.core.storage.NoLock)5 TimeField (com.srotya.sidewinder.core.storage.TimeField)5 ValueField (com.srotya.sidewinder.core.storage.ValueField)5 Test (org.junit.Test)4 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)3 MockMeasurement (com.srotya.sidewinder.core.storage.MockMeasurement)3 Before (org.junit.Before)3 DownsampleFunction (com.srotya.sidewinder.core.functions.iterative.DownsampleFunction)2 CompressionFactory (com.srotya.sidewinder.core.storage.compression.CompressionFactory)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assert.assertEquals (org.junit.Assert.assertEquals)2