use of de.invesdwin.util.concurrent.reference.VolatileReference in project invesdwin-context-persistence by subes.
the class InfluxDBPerformanceTest method testInfluxDbPerformanceAsync.
@Test
public void testInfluxDbPerformanceAsync() throws Exception {
final int freeHttpPort = Network.getFreeServerPort();
final int freeUdpPort = Network.getFreeServerPort();
final InfluxServer server = startInfluxDB(freeHttpPort, freeUdpPort);
server.start();
try {
Thread.sleep(10 * 1000);
final String dbname = "influxDbPerformance";
final String policyname = "defaultPolicy";
final String measurementName = "measurementsPerformance";
final InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:" + freeHttpPort);
influxDB.createDatabase(dbname);
influxDB.createRetentionPolicy(policyname, dbname, "9999d", 1, true);
BatchPoints batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
final Instant writesStart = new Instant();
int i = 0;
for (final FDate date : newValues()) {
final Point point = Point.measurement(measurementName).time(date.millisValue(), TimeUnit.MILLISECONDS).tag("hashKey", HASH_KEY).addField("value", date.millisValue()).build();
batch.point(point);
i++;
if (i % FLUSH_INTERVAL == 0) {
printProgress("Writes", writesStart, i, VALUES);
influxDB.write(batch);
batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
}
}
influxDB.write(batch);
batch = null;
printProgress("WritesFinished", writesStart, VALUES, VALUES);
TimeUnit.SECONDS.sleep(1);
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
final IMutableReference<FDate> prevValueRef = new VolatileReference<>();
final AtomicBoolean finished = new AtomicBoolean();
final int readsFinal = reads;
final AtomicInteger count = new AtomicInteger();
influxDB.query(new Query("Select value from " + measurementName + " where hashKey = '" + HASH_KEY + "'", dbname), 10_000, new Consumer<QueryResult>() {
@Override
public void accept(final QueryResult queryResult) {
try {
final List<Result> range = queryResult.getResults();
if (range == null || range.isEmpty()) {
return;
}
final Result firstResult = range.get(0);
if (firstResult == null) {
return;
}
final List<Series> series = firstResult.getSeries();
if (series == null || series.isEmpty()) {
return;
}
final List<List<Object>> firstSeries = series.get(0).getValues();
if (firstSeries == null) {
return;
}
for (int result = 0; result < firstSeries.size(); result++) {
final Double valueDouble = (Double) firstSeries.get(result).get(1);
final FDate value = new FDate(valueDouble.longValue());
final FDate prevValue = prevValueRef.get();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValueRef.set(value);
count.incrementAndGet();
}
} catch (final Throwable t) {
Err.process(t);
}
}
}, () -> finished.set(true));
while (!finished.get() && count.get() != VALUES) {
TimeUnit.NANOSECONDS.sleep(1);
}
Assertions.checkEquals(count.get(), VALUES);
printProgress("Reads", readsStart, VALUES * readsFinal, VALUES * READS);
}
printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
} finally {
server.stop();
}
}
Aggregations