Search in sources :

Example 11 with InfluxDB

use of org.influxdb.InfluxDB in project spring-boot by spring-projects.

the class InfluxDbHealthIndicatorTests method influxDbIsUp.

@Test
void influxDbIsUp() {
    Pong pong = mock(Pong.class);
    given(pong.getVersion()).willReturn("0.9");
    InfluxDB influxDb = mock(InfluxDB.class);
    given(influxDb.ping()).willReturn(pong);
    InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDb);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("version")).isEqualTo("0.9");
    then(influxDb).should().ping();
}
Also used : Health(org.springframework.boot.actuate.health.Health) InfluxDB(org.influxdb.InfluxDB) Pong(org.influxdb.dto.Pong) Test(org.junit.jupiter.api.Test)

Example 12 with InfluxDB

use of org.influxdb.InfluxDB in project spring-boot by spring-projects.

the class InfluxDbHealthIndicatorTests method influxDbIsDown.

@Test
void influxDbIsDown() {
    InfluxDB influxDb = mock(InfluxDB.class);
    given(influxDb.ping()).willThrow(new InfluxDBException(new IOException("Connection failed")));
    InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDb);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection failed");
    then(influxDb).should().ping();
}
Also used : InfluxDBException(org.influxdb.InfluxDBException) Health(org.springframework.boot.actuate.health.Health) InfluxDB(org.influxdb.InfluxDB) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 13 with InfluxDB

use of org.influxdb.InfluxDB in project cloudstack by apache.

the class StatsCollectorTest method configureAndTestCreateInfluxDbConnection.

private void configureAndTestCreateInfluxDbConnection(boolean databaseExists) {
    statsCollector.externalStatsHost = HOST_ADDRESS;
    statsCollector.externalStatsPort = INFLUXDB_DEFAULT_PORT;
    InfluxDB influxDbConnection = Mockito.mock(InfluxDB.class);
    Mockito.when(influxDbConnection.databaseExists(DEFAULT_DATABASE_NAME)).thenReturn(databaseExists);
    PowerMockito.mockStatic(InfluxDBFactory.class);
    PowerMockito.when(InfluxDBFactory.connect(URL)).thenReturn(influxDbConnection);
    InfluxDB returnedConnection = statsCollector.createInfluxDbConnection();
    Assert.assertEquals(influxDbConnection, returnedConnection);
}
Also used : InfluxDB(org.influxdb.InfluxDB)

Example 14 with InfluxDB

use of org.influxdb.InfluxDB in project cloudstack by apache.

the class StatsCollectorTest method writeBatchesTest.

@Test
public void writeBatchesTest() {
    InfluxDB influxDbConnection = Mockito.mock(InfluxDB.class);
    Mockito.doNothing().when(influxDbConnection).write(Mockito.any(Point.class));
    Builder builder = Mockito.mock(Builder.class);
    BatchPoints batchPoints = Mockito.mock(BatchPoints.class);
    PowerMockito.mockStatic(BatchPoints.class);
    PowerMockito.when(BatchPoints.database(DEFAULT_DATABASE_NAME)).thenReturn(builder);
    Mockito.when(builder.build()).thenReturn(batchPoints);
    Map<String, String> tagsToAdd = new HashMap<>();
    tagsToAdd.put("hostId", "1");
    Map<String, Object> fieldsToAdd = new HashMap<>();
    fieldsToAdd.put("total_memory_kbs", 10000000);
    Point point = Point.measurement("measure").tag(tagsToAdd).time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).fields(fieldsToAdd).build();
    List<Point> points = new ArrayList<>();
    points.add(point);
    Mockito.when(batchPoints.point(point)).thenReturn(batchPoints);
    statsCollector.writeBatches(influxDbConnection, DEFAULT_DATABASE_NAME, points);
    Mockito.verify(influxDbConnection).write(batchPoints);
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InfluxDB(org.influxdb.InfluxDB) Builder(org.influxdb.dto.BatchPoints.Builder) ArrayList(java.util.ArrayList) Point(org.influxdb.dto.Point) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with InfluxDB

use of org.influxdb.InfluxDB in project wildfly-camel by wildfly-extras.

the class InfluxDBIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    cubeController.create(CONTAINER_INFLUX_DB);
    cubeController.start(CONTAINER_INFLUX_DB);
    InfluxDB influxDB = InfluxDBFactory.connect("http://" + TestUtils.getDockerHost() + ":8086", "admin", "admin");
    influxDB.createDatabase(INFLUX_DB_NAME);
    context.bind(INFLUX_DB_BIND_NAME, influxDB);
}
Also used : InfluxDB(org.influxdb.InfluxDB) Before(org.junit.Before)

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