Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWKMETRICS-13]Adding InfluxDB java client support test
- Loading branch information
Showing
5 changed files
with
285 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
rest-tests/src/test/java/org/hawkular/metrics/test/InfluxDBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.test; | ||
|
||
import java.util.UUID; | ||
|
||
import org.influxdb.InfluxDB; | ||
import org.influxdb.InfluxDBFactory; | ||
import org.junit.BeforeClass; | ||
/** | ||
* @author Jeeva Kandasamy | ||
*/ | ||
public class InfluxDBTest { | ||
static String baseURI = System.getProperty("hawkular-metrics.base-uri","127.0.0.1:8080/hawkular-metrics"); | ||
static final String DB_PREFIX = UUID.randomUUID().toString(); | ||
static InfluxDB influxDB = null; | ||
|
||
@BeforeClass | ||
public static void initClient() { | ||
if(influxDB == null){ | ||
influxDB = InfluxDBFactory.connect("http://"+baseURI+"/", "hawkular", "hawkular"); | ||
} | ||
} | ||
} |
231 changes: 231 additions & 0 deletions
231
rest-tests/src/test/java/org/hawkular/metrics/test/InfluxDatabaseITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.test; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.influxdb.dto.Serie; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
/** | ||
* @author Jeeva Kandasamy | ||
*/ | ||
public class InfluxDatabaseITest extends InfluxDBTest{ | ||
private static String dbName = DB_PREFIX+"influxdbjavaclienttest"; | ||
|
||
/** | ||
* Test that writing of a simple Serie works. | ||
*/ | ||
@Test | ||
public void testWrite() { | ||
String timeSeries = "writeTest"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
List<Serie> series = influxDB.query(dbName, "select * from "+timeSeries, TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
} | ||
|
||
@Test | ||
public void testQueryOrderedAsc(){ | ||
String timeSeries = "queryTestOrderedAsc"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "value") | ||
.values(new Double(startTime), 10.9) | ||
.values(new Double(startTime+1000L), 11.9) | ||
.values(new Double(startTime+2000L), 12.9) | ||
.values(new Double(startTime+3000L), 13.9) | ||
.values(new Double(startTime+4000L), 14.9) | ||
.values(new Double(startTime+5000L), 15.9) | ||
.values(new Double(startTime+6000L), 16.9) | ||
.values(new Double(startTime+7000L), 17.9) | ||
.values(new Double(startTime+8000L), 18.9) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select value from "+timeSeries+" order asc", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQueryOrderedDesc(){ | ||
String timeSeries = "queryTestOrderedDesc"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "value") | ||
.values(new Double(startTime+8000L), 18.9) | ||
.values(new Double(startTime+7000L), 17.9) | ||
.values(new Double(startTime+6000L), 16.9) | ||
.values(new Double(startTime+5000L), 15.9) | ||
.values(new Double(startTime+4000L), 14.9) | ||
.values(new Double(startTime+3000L), 13.9) | ||
.values(new Double(startTime+2000L), 12.9) | ||
.values(new Double(startTime+1000L), 11.9) | ||
.values(new Double(startTime), 10.9) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select value from "+timeSeries+" order desc", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQueryLimitClause(){ | ||
String timeSeries = "queryTestLimitClause"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "value") | ||
.values(new Double(startTime), 10.9) | ||
.values(new Double(startTime+1000L), 11.9) | ||
.values(new Double(startTime+2000L), 12.9) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select value from "+timeSeries+" limit 3 order asc", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQueryTop(){ | ||
String timeSeries = "queryTestTop"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "top") | ||
.values(new Double(startTime+8000L), 18.9) | ||
.values(new Double(startTime+7000L), 17.9) | ||
.values(new Double(startTime+6000L), 16.9) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select top(value, 3) from "+timeSeries | ||
+" where time > now() - 30s group by time(30s)", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQueryBottom(){ | ||
String timeSeries = "queryTestBottom"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "bottom") | ||
.values(new Double(startTime), 10.9) | ||
.values(new Double(startTime+1000L), 11.9) | ||
.values(new Double(startTime+2000L), 12.9) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select bottom(value, 3) from "+timeSeries | ||
+" where time > now() - 30s group by time(30s)", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQueryStddev(){ | ||
String timeSeries = "queryTestStddev"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "stddev") | ||
.values(new Double(startTime+8000L), 2.7386127875258297) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select stddev(value) from "+timeSeries | ||
+" where time > now() - 30s group by time(30s)", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQueryMean(){ | ||
String timeSeries = "queryTestMean"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "mean") | ||
.values(new Double(startTime+8000L), 14.9D) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select mean(value) from "+timeSeries | ||
+" where time > now() - 30s group by time(30s)", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void testQuerySum(){ | ||
String timeSeries = "queryTestSum"; | ||
long startTime = System.currentTimeMillis(); | ||
Serie generatedSerie = getSerie(timeSeries, startTime); | ||
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie); | ||
startTime = startTime-9000L; | ||
Serie serieSource = new Serie.Builder(timeSeries) | ||
.columns("time", "sum") | ||
.values(new Double(startTime+8000L), 134.1D) | ||
.build(); | ||
List<Serie> series = influxDB.query(dbName, | ||
"select sum(value) from "+timeSeries | ||
+" where time > now() - 30s group by time(30s)", | ||
TimeUnit.MILLISECONDS); | ||
Assert.assertNotNull(series); | ||
Assert.assertEquals(serieSource.toString(), series.get(0).toString()); | ||
} | ||
|
||
private static Serie getSerie(String timeSeries, long startTime){ | ||
startTime = startTime-9000L;//Minus N milliseconds from 'start time' based on number of rows going to write. | ||
Serie serie = new Serie.Builder(timeSeries) | ||
.columns("time", "value") | ||
.values(startTime, 10.9) | ||
.values(startTime+1000L, 11.9) | ||
.values(startTime+2000L, 12.9) | ||
.values(startTime+3000L, 13.9) | ||
.values(startTime+4000L, 14.9) | ||
.values(startTime+5000L, 15.9) | ||
.values(startTime+6000L, 16.9) | ||
.values(startTime+7000L, 17.9) | ||
.values(startTime+8000L, 18.9) | ||
.build(); | ||
return serie; | ||
} | ||
} |