Java Code Examples for org.influxdb.dto.BatchPoints#database()

The following examples show how to use org.influxdb.dto.BatchPoints#database() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfluxDBPusher.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Push multiple points at once.
 * @param points list of {@link Point}s to report
 */
public void push(List<Point> points) {
  BatchPoints.Builder batchPointsBuilder = BatchPoints.database(database);
  for (Point point : points) {
    batchPointsBuilder.point(point);
  }
  influxDB.write(batchPointsBuilder.build());
}
 
Example 2
Source File: RetryCapableBatchWriterTest.java    From influxdb-java with MIT License 5 votes vote down vote up
BatchPoints getBP(int count) {
  BatchPoints.Builder b = BatchPoints.database("d1");
  for (int i = 0; i < count; i++) {
    b.point(Point.measurement("x1").addField("x", 1).build()).build();
  }
  return b.build();
}
 
Example 3
Source File: InfluxDBPusher.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
/**
 * Push a single Point
 * @param point the {@link Point} to report
 */
public void push(Point point) {
  BatchPoints.Builder batchPointsBuilder = BatchPoints.database(database);
  batchPointsBuilder.point(point);
  influxDB.write(batchPointsBuilder.build());
}
 
Example 4
Source File: RetryCapableBatchWriterTest.java    From influxdb-java with MIT License 4 votes vote down vote up
@Test
public void testRetryingKeepChronologicalOrder() {
  
  BatchPoints.Builder b = BatchPoints.database("d1");
  for (int i = 0; i < 200; i++) {
    b.point(Point.measurement("x1").time(1,TimeUnit.HOURS).
        addField("x", 1).
        tag("t", "v1").build()).build();
  }
  
  BatchPoints bp1 = b.build();
  
  b = BatchPoints.database("d1");
  
  b.point(Point.measurement("x1").time(1,TimeUnit.HOURS).
      addField("x", 2).
      tag("t", "v2").build()).build();
  
  for (int i = 0; i < 199; i++) {
    b.point(Point.measurement("x1").time(2,TimeUnit.HOURS).
        addField("x", 2).
        tag("t", "v2").build()).build();
  }
  BatchPoints bp2 = b.build();
  
  InfluxDB mockInfluxDB = mock(InfluxDB.class);
  BiConsumer<Iterable<Point>, Throwable> errorHandler = mock(BiConsumer.class);
  RetryCapableBatchWriter rw = new RetryCapableBatchWriter(mockInfluxDB, errorHandler,
      450, 150);
  doAnswer(new TestAnswer() {
    int i = 0;
    @Override
    protected void check(InvocationOnMock invocation) {
      if (i++ < 1) {
        throw InfluxDBException.buildExceptionForErrorState("cache-max-memory-size exceeded 104/1400"); 
      }
      return;
    }
  }).when(mockInfluxDB).write(any(BatchPoints.class));
  
  rw.write(Collections.singletonList(bp1));
  rw.write(Collections.singletonList(bp2));
  
  ArgumentCaptor<BatchPoints> captor4Write = ArgumentCaptor.forClass(BatchPoints.class);
  verify(mockInfluxDB, times(3)).write(captor4Write.capture());
  
  //bp1 written but failed because of recoverable cache-max-memory-size error
  Assertions.assertEquals(bp1, captor4Write.getAllValues().get(0));
  //bp1 rewritten on writing of bp2 
  Assertions.assertEquals(bp1, captor4Write.getAllValues().get(1));
  //bp2 written
  Assertions.assertEquals(bp2, captor4Write.getAllValues().get(2));
}
 
Example 5
Source File: Points.java    From camel-quarkus with Apache License 2.0 3 votes vote down vote up
public BatchPoints toBatchPoints() {
    BatchPoints.Builder batchPoints = BatchPoints.database(this.database);

    points.forEach(p -> batchPoints.point(p.toPoint()));

    return batchPoints.build();
}