Skip to content

Commit

Permalink
inspectIT#1269: Fixed InfluxExporterServiceIntTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Holz committed Jan 17, 2022
1 parent f07db85 commit 8a826dc
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagValue;
import io.opencensus.tags.Tags;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
Expand Down Expand Up @@ -37,11 +38,9 @@ public class InfluxExporterServiceIntTest extends SpringTestBase {
void startInfluxDB() throws Exception {
InfluxServer.Builder builder = new InfluxServer.Builder();
int freeHttpPort = Network.getFreeServerPort();
InfluxConfigurationWriter influxConfig = new InfluxConfigurationWriter.Builder()
.setHttp(freeHttpPort) // by default auth is disabled
InfluxConfigurationWriter influxConfig = new InfluxConfigurationWriter.Builder().setHttp(freeHttpPort) // by default auth is disabled
.build();
builder.setInfluxConfiguration(influxConfig);

influx = builder.build();
influx.start();
url = "http://localhost:" + freeHttpPort;
Expand All @@ -52,12 +51,20 @@ void shutdownInfluxDB() throws Exception {
influx.cleanup();
}

private final String user = "w00t";

private final String password = "password";

@Test
void verifyInfluxDataWritten() {
updateProperties(props -> {
props.setProperty("inspectit.exporters.metrics.influx.enabled", true);
props.setProperty("inspectit.exporters.metrics.influx.export-interval", "1s");
props.setProperty("inspectit.exporters.metrics.influx.url", url);
props.setProperty("inspectit.exporters.metrics.influx.database", DATABASE);
// note: user and password are mandatory as of v1.15.0
props.setProperty("inspectit.exporters.metrics.influx.user", user);
props.setProperty("inspectit.exporters.metrics.influx.password", password);
});

TagKey testTag = TagKey.create("my_tag");
Expand All @@ -76,20 +83,18 @@ void verifyInfluxDataWritten() {
}

await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
QueryResult result = InfluxDBFactory.connect(url).query(new Query("SELECT LAST(cool_data) FROM " + DATABASE + ".autogen.my_test_measure GROUP BY *"));
InfluxDB iDB = InfluxDBFactory.connect(url, user, password); // note: user and password are mandatory as of v1.15.0
QueryResult result = iDB.query(new Query("SELECT LAST(cool_data) FROM " + DATABASE + ".autogen.my_test_measure GROUP BY *"));

List<QueryResult.Result> results = result.getResults();
assertThat(results).hasSize(1);
QueryResult.Result data = results.get(0);
assertThat(data.getSeries()).hasSize(1);
QueryResult.Series series = data.getSeries().get(0);
assertThat(series.getTags())
.hasSize(1)
.containsEntry("my_tag", "myval");
assertThat(series.getTags()).hasSize(1).containsEntry("my_tag", "myval");
assertThat(series.getValues().get(0).get(1)).isEqualTo(42.0);

});
}


}

0 comments on commit 8a826dc

Please sign in to comment.