use of org.influxdb.InfluxDB in project beam by apache.
the class InfluxDbIOTest method validateReadTest.
@Test
public void validateReadTest() {
String influxHost = "http://localhost";
String userName = "admin";
String password = "admin";
String influxDatabaseName = "testDataBase";
InfluxDB influxDb = Mockito.mock(InfluxDB.class);
PowerMockito.when(InfluxDBFactory.connect(anyString(), anyString(), anyString(), any(OkHttpClient.Builder.class))).thenReturn(influxDb);
PowerMockito.when(InfluxDBFactory.connect(anyString(), anyString(), anyString())).thenReturn(influxDb);
doReturn(getDatabase(influxDatabaseName)).when(influxDb).query(new Query("SHOW DATABASES"));
doReturn(getDatabase(influxDatabaseName)).when(influxDb).query(new Query("SHOW SHARDS"));
doReturn(mockResultForNumberAndSizeOfBlocks()).when(influxDb).query(new Query("EXPLAIN SELECT * FROM cpu", influxDatabaseName));
doReturn(mockResult("cpu", 20)).when(influxDb).query(new Query("SELECT * FROM cpu", influxDatabaseName));
PCollection<Long> data = pipeline.apply("Read data to InfluxDB", InfluxDbIO.read().withDataSourceConfiguration(DataSourceConfiguration.create(StaticValueProvider.of(influxHost), StaticValueProvider.of(userName), StaticValueProvider.of(password))).withDatabase(influxDatabaseName).withQuery("SELECT * FROM cpu")).apply(Count.globally());
PAssert.that(data).containsInAnyOrder(20L);
PipelineResult result = pipeline.run();
Assert.assertEquals(State.DONE, result.waitUntilFinish());
}
use of org.influxdb.InfluxDB in project beam by apache.
the class InfluxDbIO method getDBShardedInformation.
private static List<ShardInformation> getDBShardedInformation(String database, DataSourceConfiguration configuration, boolean disableCertificateValidation) {
String query = "SHOW SHARDS";
DBShardInformation dbInfo = new DBShardInformation();
try (InfluxDB connection = getConnection(configuration, disableCertificateValidation)) {
QueryResult queryResult = connection.query(new Query(query));
List<Result> results = queryResult.getResults();
for (Result result : results) {
for (Series series : result.getSeries()) {
dbInfo.loadShardInformation(database, series);
}
}
}
Collections.sort(dbInfo.getShardInformation(database), new ShardInformationByStartDate());
return dbInfo.getShardInformation(database);
}
use of org.influxdb.InfluxDB in project beam by apache.
the class InfluxDbIOIT method createRetentionPolicyInDB.
public void createRetentionPolicyInDB(String dbName, InfluxDBPipelineOptions options, String retentionPolicyName) {
try (InfluxDB connection = InfluxDBFactory.connect(options.getInfluxDBURL(), options.getInfluxDBUserName(), options.getInfluxDBPassword())) {
connection.query(new Query(String.format("CREATE DATABASE %s", dbName)));
connection.query(new Query(String.format("CREATE RETENTION POLICY %s ON %s DURATION 1d REPLICATION 1", retentionPolicyName, dbName)));
}
}
use of org.influxdb.InfluxDB in project spring-boot by spring-projects.
the class InfluxDbAutoConfigurationTests method influxDbWithCustomizer.
@Test
void influxDbWithCustomizer() {
this.contextRunner.withBean(InfluxDbCustomizer.class, () -> (influxDb) -> influxDb.setDatabase("test")).withPropertyValues("spring.influx.url=http://localhost").run((context) -> {
assertThat(context).hasSingleBean(InfluxDB.class);
InfluxDB influxDb = context.getBean(InfluxDB.class);
assertThat(influxDb).hasFieldOrPropertyWithValue("database", "test");
});
}
use of org.influxdb.InfluxDB in project spring-boot by spring-projects.
the class InfluxDbAutoConfigurationTests method getReadTimeoutProperty.
private int getReadTimeoutProperty(AssertableApplicationContext context) {
InfluxDB influxDb = context.getBean(InfluxDB.class);
Retrofit retrofit = (Retrofit) ReflectionTestUtils.getField(influxDb, "retrofit");
OkHttpClient callFactory = (OkHttpClient) retrofit.callFactory();
return callFactory.readTimeoutMillis();
}
Aggregations