use of org.spf4j.perf.impl.MeasurementsInfoImpl in project spf4j by zolyfarkas.
the class TSDBTxtMeasurementStoreTest method testCreateAppend.
@Test
public void testCreateAppend() throws IOException {
Path tmpFile = Paths.get(org.spf4j.base.Runtime.TMP_FOLDER, "testM.txt");
File file = tmpFile.toFile();
TSDBTxtMeasurementStore store = new TSDBTxtMeasurementStore(file);
long id = store.alocateMeasurements(new MeasurementsInfoImpl("test", "bla", new String[] { "a", "b" }, new String[] { "ms", "ms" }, MeasurementType.GAUGE), 10000);
store.saveMeasurements(id, System.currentTimeMillis(), 3L, 4L);
store.close();
String content = Files.lines(tmpFile, StandardCharsets.UTF_8).collect(Collectors.joining("\n"));
LOG.debug("File Content: {}", content);
Assert.assertThat(content, Matchers.containsString("a,3,b,4"));
TSDBTxtMeasurementStore store2 = new TSDBTxtMeasurementStore(file);
store2.saveMeasurements(id, System.currentTimeMillis(), 5L, 6L);
store2.close();
content = Files.lines(tmpFile, StandardCharsets.UTF_8).collect(Collectors.joining("\n"));
Assert.assertThat(content, Matchers.containsString("a,3,b,4"));
Assert.assertThat(content, Matchers.containsString("a,5,b,6"));
}
use of org.spf4j.perf.impl.MeasurementsInfoImpl in project spf4j by zolyfarkas.
the class AvroMeasurementStoreTest method testStore.
@Test
@SuppressFBWarnings({ "PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS", "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN" })
public void testStore() throws IOException {
AvroMeasurementStore store = new AvroMeasurementStore(org.spf4j.base.Runtime.TMP_FOLDER_PATH, "testMetrics", Compressor.ZSTANDARD);
try {
long mid = store.alocateMeasurements(new MeasurementsInfoImpl("test", "test", new String[] { "v1", "v2" }, new String[] { "t1", "t2" }, new Aggregation[] { Aggregation.SUM, Aggregation.LAST }, MeasurementType.GAUGE), 1000);
store.saveMeasurements(mid, 0L, 1, 2);
store.saveMeasurements(mid, 1000L, 3, 4);
store.saveMeasurements(mid, 2000L, 5, 6);
store.saveMeasurements(mid, 2000L, 7, 8);
store.saveMeasurements(mid, 3000L, 9, 10);
store.saveMeasurements(mid, 4000L, 11, 12);
store.flush();
MeasurementStoreQuery query = store.query();
Collection<Schema> measurements = query.getMeasurements((x) -> true);
Schema metric = measurements.iterator().next();
Assert.assertEquals("test", metric.getName());
List<TimeSeriesRecord> results = getMetrics(query, metric, Instant.EPOCH, Instant.now());
Assert.assertEquals(6, results.size());
TimeSeriesRecord rec = results.get(0);
Assert.assertEquals(Instant.ofEpochMilli(0L), rec.getTimeStamp());
Assert.assertEquals(1L, rec.getLongValue("v1"));
Assert.assertEquals(2L, rec.getLongValue("v2"));
rec = results.get(5);
Assert.assertEquals(Instant.ofEpochMilli(4000L), rec.getTimeStamp());
Assert.assertEquals(11L, rec.getLongValue("v1"));
Assert.assertEquals(12L, rec.getLongValue("v2"));
results = getMetrics(query, metric, Instant.ofEpochMilli(2000L), Instant.ofEpochMilli(2000L));
Assert.assertEquals(2, results.size());
rec = results.get(0);
Assert.assertEquals(Instant.ofEpochMilli(2000L), rec.getTimeStamp());
Assert.assertEquals(5L, rec.getLongValue("v1"));
Assert.assertEquals(6L, rec.getLongValue("v2"));
rec = results.get(1);
Assert.assertEquals(Instant.ofEpochMilli(2000L), rec.getTimeStamp());
Assert.assertEquals(7L, rec.getLongValue("v1"));
Assert.assertEquals(8L, rec.getLongValue("v2"));
List<TimeSeriesRecord> aggr = getMetrics(query, metric, Instant.EPOCH, Instant.now(), 1000);
Assert.assertEquals(5, aggr.size());
rec = aggr.get(0);
Assert.assertEquals(Instant.ofEpochMilli(0L), rec.getTimeStamp());
Assert.assertEquals(1L, rec.getLongValue("v1"));
Assert.assertEquals(2L, rec.getLongValue("v2"));
rec = aggr.get(2);
Assert.assertEquals(Instant.ofEpochMilli(2000L), rec.getTimeStamp());
Assert.assertEquals(12L, rec.getLongValue("v1"));
Assert.assertEquals(8L, rec.getLongValue("v2"));
aggr = getMetrics(query, metric, Instant.EPOCH, Instant.now(), 1500);
Assert.assertEquals(5, aggr.size());
aggr = getMetrics(query, metric, Instant.EPOCH, Instant.now(), 0);
Assert.assertEquals(6, aggr.size());
try (AvroCloseableIterable<TimeSeriesRecord> it = query.getAggregatedMeasurementData(metric, Instant.EPOCH, Instant.now(), Duration.between(Instant.EPOCH, Instant.now()).getSeconds(), TimeUnit.SECONDS)) {
Iterator<TimeSeriesRecord> iterator = it.iterator();
TimeSeriesRecord next = iterator.next();
LOG.debug("The aggregate", next);
Assert.assertFalse(iterator.hasNext());
Assert.assertEquals(36L, next.getLongValue("v1"));
Assert.assertEquals(12L, next.getLongValue("v2"));
}
} finally {
store.close();
Files.delete(store.getInfoFile());
Files.delete(store.getDataFile());
}
}
Aggregations