use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.
the class TestMultiplySeries method multiplyOneSeriesEach.
@Test
public void multiplyOneSeriesEach() throws Exception {
SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, true, 10, 1);
DataPoints dps2 = PowerMockito.mock(DataPoints.class);
when(dps2.iterator()).thenReturn(view2);
when(dps2.metricName()).thenReturn("sys.mem");
when(dps2.metricUID()).thenReturn(new byte[] { 0, 0, 2 });
group_bys = new DataPoints[] { dps2 };
query_results.add(group_bys);
final DataPoints[] results = func.evaluate(data_query, query_results, params);
assertEquals(1, results.length);
assertEquals(METRIC_STRING, results[0].metricName());
final int[] vals = new int[] { 10, 22, 36, 52, 70 };
int i = 0;
long ts = START_TIME;
for (DataPoint dp : results[0]) {
assertEquals(ts, dp.timestamp());
assertEquals(vals[i++], dp.toDouble(), 0.001);
ts += INTERVAL;
}
}
use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.
the class TestScale method evaluateFactor1point5GroupBy.
@Test
public void evaluateFactor1point5GroupBy() throws Exception {
params.add("1.5");
SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, true, 10, 1);
DataPoints dps2 = PowerMockito.mock(DataPoints.class);
when(dps2.iterator()).thenReturn(view2);
when(dps2.metricNameAsync()).thenReturn(Deferred.fromResult("sys.mem"));
group_bys = new DataPoints[] { dps, dps2 };
query_results.clear();
query_results.add(group_bys);
final DataPoints[] results = func.evaluate(data_query, query_results, params);
assertEquals(2, results.length);
assertEquals(METRIC, results[0].metricName());
assertEquals("sys.mem", results[1].metricName());
long ts = START_TIME;
double v = 1.5;
for (DataPoint dp : results[0]) {
System.out.println(dp.timestamp() + " : " + dp.toDouble());
assertEquals(ts, dp.timestamp());
assertFalse(dp.isInteger());
assertEquals(v, dp.doubleValue(), 0.001);
ts += INTERVAL;
v += 1.5;
}
ts = START_TIME;
v = 15;
for (DataPoint dp : results[1]) {
assertEquals(ts, dp.timestamp());
assertFalse(dp.isInteger());
assertEquals(v, dp.doubleValue(), 0.001);
ts += INTERVAL;
v += 1.5;
}
}
use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.
the class TestSumSeries method sumOneSeriesEach.
@Test
public void sumOneSeriesEach() throws Exception {
SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, true, 10, 1);
DataPoints dps2 = PowerMockito.mock(DataPoints.class);
when(dps2.iterator()).thenReturn(view2);
when(dps2.metricName()).thenReturn("sys.mem");
when(dps2.metricUID()).thenReturn(new byte[] { 0, 0, 2 });
group_bys = new DataPoints[] { dps2 };
query_results.add(group_bys);
final DataPoints[] results = func.evaluate(data_query, query_results, params);
assertEquals(1, results.length);
assertEquals(METRIC_STRING, results[0].metricName());
long ts = START_TIME;
double v = 11;
for (DataPoint dp : results[0]) {
assertEquals(ts, dp.timestamp());
assertEquals(v, dp.toDouble(), 0.001);
v += 2;
ts += INTERVAL;
}
}
use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.
the class TestSumSeries method sumMultipleSeriesEach.
@Test
public void sumMultipleSeriesEach() throws Exception {
oneExtraSameE();
queryAB_Dstar();
query_results.clear();
query_results.add(results.get("1").getValue());
query_results.add(results.get("0").getValue());
final DataPoints[] results = func.evaluate(data_query, query_results, params);
assertEquals(3, results.length);
final int[] vals = new int[] { 12, 18, 17 };
for (int i = 0; i < results.length; i++) {
long ts = 1431561600000l;
final SeekableView it = results[i].iterator();
while (it.hasNext()) {
final DataPoint dp = it.next();
assertEquals(ts, dp.timestamp());
assertEquals(vals[i], dp.toDouble(), 0.0001);
if (i < 2) {
vals[i] += 2;
} else {
vals[i]++;
}
ts += INTERVAL;
}
}
}
use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.
the class TestHighestCurrent method evaluateTopN2with2SeriesLong.
@Test
public void evaluateTopN2with2SeriesLong() throws Exception {
params.add("2");
SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, true, 10, 1);
DataPoints dps2 = PowerMockito.mock(DataPoints.class);
when(dps2.iterator()).thenReturn(view2);
when(dps2.metricNameAsync()).thenReturn(Deferred.fromResult("sys.mem"));
group_bys = new DataPoints[] { dps, dps2 };
query_results.clear();
query_results.add(group_bys);
final DataPoints[] results = func.evaluate(data_query, query_results, params);
assertEquals(2, results.length);
assertEquals("sys.mem", results[0].metricName());
assertEquals(METRIC, results[1].metricName());
long ts = START_TIME;
long v = 10;
for (DataPoint dp : results[0]) {
assertEquals(ts, dp.timestamp());
assertTrue(dp.isInteger());
assertEquals(v, dp.longValue());
ts += INTERVAL;
v += 1;
}
ts = START_TIME;
v = 1;
for (DataPoint dp : results[1]) {
assertEquals(ts, dp.timestamp());
assertTrue(dp.isInteger());
assertEquals(v, dp.longValue());
ts += INTERVAL;
v += 1;
}
}
Aggregations