use of com.srotya.sidewinder.core.storage.DataPoint in project sidewinder by srotya.
the class TestMemStorageEngine method testAddAndReadDataPoints.
@Test
public void testAddAndReadDataPoints() throws Exception {
MemStorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), bgTasks);
long curr = System.currentTimeMillis();
String dbName = "test";
String measurementName = "cpu";
String valueFieldName = "value";
try {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, null, curr, 2 * 0));
fail("Must reject the above datapoint due to missing tags");
} catch (Exception e) {
}
String tag = "host=123123";
for (int i = 1; i <= 3; i++) {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, Arrays.asList(tag), curr + i, 2 * i));
}
assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr, curr + 3, null, null);
assertEquals(1, queryDataPoints.size());
int i = 1;
assertEquals(3, queryDataPoints.iterator().next().getDataPoints().size());
for (Series list : queryDataPoints) {
for (DataPoint dataPoint : list.getDataPoints()) {
assertEquals(curr + i, dataPoint.getTimestamp());
i++;
}
}
Set<String> tags = engine.getTagKeysForMeasurement(dbName, measurementName);
assertEquals(new HashSet<>(Arrays.asList("host")), tags);
Set<String> fieldsForMeasurement = engine.getFieldsForMeasurement(dbName, measurementName);
assertEquals(new HashSet<>(Arrays.asList(valueFieldName)), fieldsForMeasurement);
try {
engine.getTagKeysForMeasurement(dbName + "1", measurementName);
fail("This measurement should not exist");
} catch (Exception e) {
}
try {
engine.getTagKeysForMeasurement(dbName, measurementName + "1");
fail("This measurement should not exist");
} catch (Exception e) {
}
try {
engine.getFieldsForMeasurement(dbName + "1", measurementName);
fail("This measurement should not exist");
} catch (Exception e) {
}
try {
engine.getFieldsForMeasurement(dbName, measurementName + "1");
fail("This measurement should not exist");
} catch (Exception e) {
}
assertEquals(1, engine.getFieldsForMeasurement(dbName, "c.*").size());
assertEquals(1, engine.getFieldsForMeasurement(dbName, ".*").size());
try {
engine.getFieldsForMeasurement(dbName, "d.*");
fail("This measurement should not exist");
} catch (Exception e) {
}
}
use of com.srotya.sidewinder.core.storage.DataPoint in project sidewinder by srotya.
the class TestMemStorageEngine method testCompactionThreadSafety.
@Test
public void testCompactionThreadSafety() throws IOException, InterruptedException {
MemStorageEngine engine = new MemStorageEngine();
HashMap<String, String> conf2 = new HashMap<>();
conf2.put("default.bucket.size", "409600");
conf2.put("compaction.enabled", "true");
conf2.put("use.query.pool", "false");
engine.configure(conf2, bgTasks);
final long curr = 1497720652566L;
String dbName = "test";
String measurementName = "cpu";
String valueFieldName = "value";
String tag = "host=123123";
List<String> tags = Arrays.asList(tag);
for (int i = 1; i <= 10000; i++) {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, curr + i * 1000, i * 1.1));
}
long ts = System.nanoTime();
List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1000, curr + 10000 * 1000 + 1, null, null);
ts = System.nanoTime() - ts;
System.out.println("Before compaction:" + ts / 1000 + "us");
assertEquals(1, queryDataPoints.size());
assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
List<DataPoint> dataPoints = queryDataPoints.iterator().next().getDataPoints();
for (int i = 1; i <= 10000; i++) {
DataPoint dp = dataPoints.get(i - 1);
assertEquals("Bad ts:" + i, curr + i * 1000, dp.getTimestamp());
assertEquals(dp.getValue(), i * 1.1, 0.001);
}
final TimeSeries series = engine.getOrCreateTimeSeries(dbName, measurementName, valueFieldName, tags, 409600, false);
SortedMap<String, List<Writer>> bucketRawMap = series.getBucketRawMap();
assertEquals(1, bucketRawMap.size());
int size = bucketRawMap.values().iterator().next().size();
assertTrue(series.getCompactionSet().size() < size);
assertTrue(size > 2);
final AtomicBoolean bool = new AtomicBoolean(false);
bgTasks.execute(() -> {
while (!bool.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
try {
series.addDataPoint(TimeUnit.MILLISECONDS, curr + 1000 * 10001, 1.11);
bool.set(false);
} catch (IOException e) {
e.printStackTrace();
return;
}
});
series.compact(l -> {
bool.set(true);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!bool.get()) {
throw new RuntimeException("Synchronized block failed");
}
});
Thread.sleep(100);
assertTrue(!bool.get());
}
use of com.srotya.sidewinder.core.storage.DataPoint in project sidewinder by srotya.
the class TestMemStorageEngine method testSeriesToDataPointConversion.
@Test
public void testSeriesToDataPointConversion() throws IOException {
List<DataPoint> points = new ArrayList<>();
long headerTimestamp = System.currentTimeMillis();
ByteBuffer buf = ByteBuffer.allocate(1024);
Writer timeSeries = new ByzantineWriter();
timeSeries.configure(conf, buf, true, 1, false);
timeSeries.setHeaderTimestamp(headerTimestamp);
timeSeries.addValue(headerTimestamp, 1L);
TimeSeries.seriesToDataPoints("value", Arrays.asList("test=2"), points, timeSeries, null, null, false);
assertEquals(1, points.size());
points.clear();
Predicate timepredicate = new BetweenPredicate(Long.MAX_VALUE, Long.MAX_VALUE);
TimeSeries.seriesToDataPoints("value", Arrays.asList("test=2"), points, timeSeries, timepredicate, null, false);
assertEquals(0, points.size());
}
use of com.srotya.sidewinder.core.storage.DataPoint in project sidewinder by srotya.
the class TestTransformFunctions method testCubeRoot.
@Test
public void testCubeRoot() {
Function f = new CbrtFunction();
List<Series> series = new ArrayList<>();
Series s = new Series(Arrays.asList(new DataPoint(1L, 27), new DataPoint(1L, 64)));
series.add(s);
List<Series> apply = f.apply(series);
assertEquals(2, apply.get(0).getDataPoints().size());
assertEquals(3, apply.get(0).getDataPoints().get(0).getLongValue());
assertEquals(4, apply.get(0).getDataPoints().get(1).getLongValue());
}
use of com.srotya.sidewinder.core.storage.DataPoint in project sidewinder by srotya.
the class TestTransformFunctions method testCube.
@Test
public void testCube() {
Function f = new CubeFunction();
List<Series> series = new ArrayList<>();
Series s = new Series(Arrays.asList(new DataPoint(1L, 3), new DataPoint(1L, 4)));
series.add(s);
List<Series> 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());
}
Aggregations