Search in sources :

Example 6 with InfluxDB

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());
}
Also used : Query(org.influxdb.dto.Query) InfluxDB(org.influxdb.InfluxDB) PipelineResult(org.apache.beam.sdk.PipelineResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with InfluxDB

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);
}
Also used : Series(org.influxdb.dto.QueryResult.Series) QueryResult(org.influxdb.dto.QueryResult) Query(org.influxdb.dto.Query) InfluxDB(org.influxdb.InfluxDB) QueryResult(org.influxdb.dto.QueryResult) Result(org.influxdb.dto.QueryResult.Result)

Example 8 with InfluxDB

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)));
    }
}
Also used : Query(org.influxdb.dto.Query) InfluxDB(org.influxdb.InfluxDB)

Example 9 with InfluxDB

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");
    });
}
Also used : InfluxDB(org.influxdb.InfluxDB) Test(org.junit.jupiter.api.Test)

Example 10 with InfluxDB

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();
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) InfluxDB(org.influxdb.InfluxDB)

Aggregations

InfluxDB (org.influxdb.InfluxDB)26 Test (org.junit.Test)7 Query (org.influxdb.dto.Query)5 BatchPoints (org.influxdb.dto.BatchPoints)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Builder (org.influxdb.dto.Point.Builder)3 Test (org.junit.jupiter.api.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 PipelineResult (org.apache.beam.sdk.PipelineResult)2 QueryResult (org.influxdb.dto.QueryResult)2 Series (org.influxdb.dto.QueryResult.Series)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Health (org.springframework.boot.actuate.health.Health)2 Bean (org.springframework.context.annotation.Bean)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1