Search in sources :

Example 1 with Builder

use of org.influxdb.dto.BatchPoints.Builder 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InfluxDB (org.influxdb.InfluxDB)1 BatchPoints (org.influxdb.dto.BatchPoints)1 Builder (org.influxdb.dto.BatchPoints.Builder)1 Point (org.influxdb.dto.Point)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1