Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use Testcontainer for InfluxExporterIntTest #1673

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package rocks.inspectit.ocelot.core.exporter;

import de.flapdoodle.embed.process.runtime.Network;
import io.apisense.embed.influx.InfluxServer;
import io.apisense.embed.influx.configuration.InfluxConfigurationWriter;
import io.github.netmikey.logunit.api.LogCapturer;
import io.opencensus.common.Scope;
import io.opencensus.stats.*;
Expand All @@ -12,49 +9,53 @@
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.InfluxDBIOException;
import org.influxdb.dto.Pong;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.test.annotation.DirtiesContext;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import rocks.inspectit.ocelot.core.SpringTestBase;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

@Testcontainers
public class InfluxExporterServiceIntTest extends SpringTestBase {

private InfluxServer influx;

private String url;

private static final String DATABASE = "ocelot_test";

@RegisterExtension
LogCapturer warnLogs = LogCapturer.create().captureForType(InfluxExporterService.class, org.slf4j.event.Level.WARN);

@Container
private final GenericContainer influx = new GenericContainer(DockerImageName.parse("influxdb:1.8"))
.withExposedPorts(8086)
.withEnv("INFLUXDB_DB", DATABASE)
.withEnv("INFLUXDB_USER", "w00t")
.withEnv("INFLUXDB_USER_PASSWORD", "password");

@BeforeEach
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
.build();
builder.setInfluxConfiguration(influxConfig);
influx = builder.build();
influx.start();
url = "http://localhost:" + freeHttpPort;
void startInfluxDB() {
String address = influx.getHost();
Integer port = influx.getFirstMappedPort();
this.url = "http://" + address + ":" + port;
}

@AfterEach
void shutdownInfluxDB() throws Exception {
influx.cleanup();
void shutdownInfluxDB() {
influx.stop();
}

private final String user = "w00t";
Expand All @@ -75,8 +76,7 @@ void verifyInfluxDataWritten() {

TagKey testTag = TagKey.create("my_tag");
Measure.MeasureDouble testMeasure = Measure.MeasureDouble.create("my/test/measure", "foo", "bars");
View testView = View.create(View.Name.create("my/test/measure/cool%data"), "", testMeasure, Aggregation.Sum.create(), Arrays
.asList(testTag));
View testView = View.create(View.Name.create("my/test/measure/cool%data"), "", testMeasure, Aggregation.Sum.create(), Collections.singletonList(testTag));
Stats.getViewManager().registerView(testView);

try (Scope tc = Tags.getTagger().emptyBuilder().putLocal(testTag, TagValue.create("myval")).buildScoped()) {
Expand Down
Loading