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());
}
}
}
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);
}
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);
}
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);
}
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());
}
Aggregations