|
|
@ -19,9 +19,7 @@ package org.springframework.boot.autoconfigure.influx;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
import org.influxdb.BatchOptions;
|
|
|
|
|
|
|
|
import org.influxdb.InfluxDB;
|
|
|
|
import org.influxdb.InfluxDB;
|
|
|
|
import org.influxdb.impl.BatchProcessor;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import retrofit2.Retrofit;
|
|
|
|
import retrofit2.Retrofit;
|
|
|
|
|
|
|
|
|
|
|
@ -48,21 +46,21 @@ class InfluxDbAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void influxDbRequiresUrl() {
|
|
|
|
void influxDbRequiresUrl() {
|
|
|
|
this.contextRunner.run((context) -> assertThat(context.getBeansOfType(InfluxDB.class)).isEmpty());
|
|
|
|
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfluxDB.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void influxDbCanBeCustomized() {
|
|
|
|
void influxDbCanBeCustomized() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.password:password",
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.user=user",
|
|
|
|
"spring.influx.user:user")
|
|
|
|
"spring.influx.password=password")
|
|
|
|
.run(((context) -> assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1)));
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(InfluxDB.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void influxDbCanBeCreatedWithoutCredentials() {
|
|
|
|
void influxDbCanBeCreatedWithoutCredentials() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost").run((context) -> {
|
|
|
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost").run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(InfluxDB.class);
|
|
|
|
int readTimeout = getReadTimeoutProperty(context);
|
|
|
|
int readTimeout = getReadTimeoutProperty(context);
|
|
|
|
assertThat(readTimeout).isEqualTo(10_000);
|
|
|
|
assertThat(readTimeout).isEqualTo(10_000);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -72,87 +70,20 @@ class InfluxDbAutoConfigurationTests {
|
|
|
|
void influxDbWithOkHttpClientBuilderProvider() {
|
|
|
|
void influxDbWithOkHttpClientBuilderProvider() {
|
|
|
|
this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderProviderConfig.class)
|
|
|
|
this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderProviderConfig.class)
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost").run((context) -> {
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost").run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(InfluxDB.class);
|
|
|
|
int readTimeout = getReadTimeoutProperty(context);
|
|
|
|
int readTimeout = getReadTimeoutProperty(context);
|
|
|
|
assertThat(readTimeout).isEqualTo(40_000);
|
|
|
|
assertThat(readTimeout).isEqualTo(40_000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void influxDbWithDatabase() {
|
|
|
|
void influxDbWithCustomizer() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.database:sample-db")
|
|
|
|
this.contextRunner.withBean(InfluxDbCustomizer.class, () -> (influxDb) -> influxDb.setDatabase("test"))
|
|
|
|
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.database=sample-db")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(InfluxDB.class);
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
String database = (String) ReflectionTestUtils.getField(influxDb, "database");
|
|
|
|
assertThat(influxDb).hasFieldOrPropertyWithValue("database", "test");
|
|
|
|
assertThat(database).isEqualTo("sample-db");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void influxDbWithRetentionPolicy() {
|
|
|
|
|
|
|
|
this.contextRunner
|
|
|
|
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.retention-policy:two_hours")
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
|
|
|
|
String retentionPolicy = (String) ReflectionTestUtils.getField(influxDb, "retentionPolicy");
|
|
|
|
|
|
|
|
assertThat(retentionPolicy).isEqualTo("two_hours");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void influxDbWithLogLevel() {
|
|
|
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.log:basic")
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
|
|
|
|
InfluxDB.LogLevel log = (InfluxDB.LogLevel) ReflectionTestUtils.getField(influxDb, "logLevel");
|
|
|
|
|
|
|
|
assertThat(log).isEqualTo(InfluxDB.LogLevel.BASIC);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void influxDbWithConsistency() {
|
|
|
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.consistency:all")
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
|
|
|
|
InfluxDB.ConsistencyLevel consistency = (InfluxDB.ConsistencyLevel) ReflectionTestUtils
|
|
|
|
|
|
|
|
.getField(influxDb, "consistency");
|
|
|
|
|
|
|
|
assertThat(consistency).isEqualTo(InfluxDB.ConsistencyLevel.ALL);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void influxDbWithBatchOptions() {
|
|
|
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.batch.enabled:true",
|
|
|
|
|
|
|
|
"spring.influx.batch.actions:50", "spring.influx.batch.flush-duration:50").run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
|
|
|
|
BatchProcessor batchProcessor = (BatchProcessor) ReflectionTestUtils.getField(influxDb,
|
|
|
|
|
|
|
|
"batchProcessor");
|
|
|
|
|
|
|
|
int actions = (int) ReflectionTestUtils.getField(batchProcessor, "actions");
|
|
|
|
|
|
|
|
int flushInterval = (int) ReflectionTestUtils.getField(batchProcessor, "flushInterval");
|
|
|
|
|
|
|
|
assertThat(actions).isEqualTo(50);
|
|
|
|
|
|
|
|
assertThat(flushInterval).isEqualTo(50);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void influxDbWithBatchOptionsCustomizer() {
|
|
|
|
|
|
|
|
this.contextRunner.withUserConfiguration(CustomInfluxDbBatchOptionsCustomizerConfig.class)
|
|
|
|
|
|
|
|
.withPropertyValues("spring.influx.url=http://localhost").run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
|
|
|
|
|
|
|
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
|
|
|
|
|
|
|
BatchProcessor batchProcessor = (BatchProcessor) ReflectionTestUtils.getField(influxDb,
|
|
|
|
|
|
|
|
"batchProcessor");
|
|
|
|
|
|
|
|
int actions = (int) ReflectionTestUtils.getField(batchProcessor, "actions");
|
|
|
|
|
|
|
|
int flushInterval = (int) ReflectionTestUtils.getField(batchProcessor, "flushInterval");
|
|
|
|
|
|
|
|
int jitterInterval = (int) ReflectionTestUtils.getField(batchProcessor, "jitterInterval");
|
|
|
|
|
|
|
|
assertThat(actions).isEqualTo(20);
|
|
|
|
|
|
|
|
assertThat(flushInterval).isEqualTo(20);
|
|
|
|
|
|
|
|
assertThat(jitterInterval).isEqualTo(20);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -173,17 +104,4 @@ class InfluxDbAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
|
|
|
static class CustomInfluxDbBatchOptionsCustomizerConfig {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
InfluxDbCustomizer influxDbBatchOptionsCustomizer() {
|
|
|
|
|
|
|
|
return (influxDb) -> {
|
|
|
|
|
|
|
|
BatchOptions batchOptions = BatchOptions.DEFAULTS.actions(20).flushDuration(20).jitterDuration(20);
|
|
|
|
|
|
|
|
influxDb.enableBatch(batchOptions);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|