Skip to content

Commit

Permalink
Merge pull request #593 from influxdata/removedeprecatedretention
Browse files Browse the repository at this point in the history
remove deprecated retention policy method usage
  • Loading branch information
majst01 committed Apr 23, 2019
2 parents 763defd + 93b9ead commit 8ae777f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ String dbName = "aTimeSeries";
influxDB.query(new Query("CREATE DATABASE " + dbName));
influxDB.setDatabase(dbName);
String rpName = "aRetentionPolicy";
influxDB.createRetentionPolicy(rpName, dbName, "30d", "30m", 2, true);
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 SHARD DURATION 30m DEFAULT"));
influxDB.setRetentionPolicy(rpName);

influxDB.enableBatch(BatchOptions.DEFAULTS);
Expand All @@ -49,7 +49,7 @@ influxDB.write(Point.measurement("disk")

Query query = new Query("SELECT idle FROM cpu", dbName);
influxDB.query(query);
influxDB.dropRetentionPolicy(rpName, dbName);
influxDB.query(new Query("DROP RETENTION POLICY " + rpName + " ON " + dbName));
influxDB.query(new Query("DROP DATABASE " + dbName));
influxDB.close();
```
Expand Down Expand Up @@ -88,7 +88,7 @@ InfluxDB influxDB = InfluxDBFactory.connect("http://172.17.0.2:8086", "root", "r
String dbName = "aTimeSeries";
influxDB.query(new Query("CREATE DATABASE " + dbName));
String rpName = "aRetentionPolicy";
influxDB.createRetentionPolicy(rpName, dbName, "30d", "30m", 2, true);
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 SHARD DURATION 30m DEFAULT"));

// Flush every 2000 Points, at least every 100ms
influxDB.enableBatch(BatchOptions.DEFAULTS.actions(2000).flushDuration(100));
Expand All @@ -109,7 +109,7 @@ influxDB.write(dbName, rpName, point1);
influxDB.write(dbName, rpName, point2);
Query query = new Query("SELECT idle FROM cpu", dbName);
influxDB.query(query);
influxDB.dropRetentionPolicy(rpName, dbName);
influxDB.query(new Query("DROP RETENTION POLICY " + rpName + " ON " + dbName));
influxDB.query(new Query("DROP DATABASE " + dbName));
influxDB.close();
```
Expand All @@ -123,7 +123,7 @@ InfluxDB influxDB = InfluxDBFactory.connect("http://172.17.0.2:8086", "root", "r
String dbName = "aTimeSeries";
influxDB.query(new Query("CREATE DATABASE " + dbName));
String rpName = "aRetentionPolicy";
influxDB.createRetentionPolicy(rpName, dbName, "30d", "30m", 2, true);
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 DEFAULT"));

BatchPoints batchPoints = BatchPoints
.database(dbName)
Expand All @@ -147,7 +147,7 @@ batchPoints.point(point2);
influxDB.write(batchPoints);
Query query = new Query("SELECT idle FROM cpu", dbName);
influxDB.query(query);
influxDB.dropRetentionPolicy(rpName, dbName);
influxDB.query(new Query("DROP RETENTION POLICY " + rpName + " ON " + dbName));
influxDB.query(new Query("DROP DATABASE " + dbName));
```

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/influxdb/InfluxDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,9 @@ public void testCreateDropRetentionPolicies() {
String dbName = "rpTest_" + System.currentTimeMillis();
this.influxDB.query(new Query("CREATE DATABASE " + dbName));

this.influxDB.createRetentionPolicy("testRP1", dbName, "30h", 2, false);
this.influxDB.createRetentionPolicy("testRP2", dbName, "10d", "20m", 2, false);
this.influxDB.createRetentionPolicy("testRP3", dbName, "2d4w", "20m", 2);
this.influxDB.query(new Query("CREATE RETENTION POLICY testRP1 ON " + dbName + " DURATION 30h REPLICATION 2"));
this.influxDB.query(new Query("CREATE RETENTION POLICY testRP2 ON " + dbName + " DURATION 10d REPLICATION 2 SHARD DURATION 20m"));
this.influxDB.query(new Query("CREATE RETENTION POLICY testRP3 ON " + dbName + " DURATION 2d4w REPLICATION 2 SHARD DURATION 20m DEFAULT"));

Query query = new Query("SHOW RETENTION POLICIES", dbName);
QueryResult result = this.influxDB.query(query);
Expand All @@ -1126,9 +1126,9 @@ public void testCreateDropRetentionPolicies() {
Assertions.assertTrue(retentionPolicies.get(2).contains("testRP2"));
Assertions.assertTrue(retentionPolicies.get(3).contains("testRP3"));

this.influxDB.dropRetentionPolicy("testRP1", dbName);
this.influxDB.dropRetentionPolicy("testRP2", dbName);
this.influxDB.dropRetentionPolicy("testRP3", dbName);
this.influxDB.query(new Query("DROP RETENTION POLICY testRP1 ON " + dbName));
this.influxDB.query(new Query("DROP RETENTION POLICY testRP2 ON " + dbName));
this.influxDB.query(new Query("DROP RETENTION POLICY testRP3 ON " + dbName));

result = this.influxDB.query(query);
Assertions.assertNull(result.getError());
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/influxdb/impl/BatchProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.influxdb.TestUtils;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.Query;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand Down Expand Up @@ -178,15 +179,15 @@ public void precision() throws Exception {
try (InfluxDB influxDB = TestUtils.connectToInfluxDB()) {
try {
influxDB.createDatabase(dbName);
influxDB.createRetentionPolicy(rpName, dbName, "30h", 2, true);
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 DEFAULT"));

influxDB.enableBatch(BatchOptions.DEFAULTS.actions(2000).precision(TimeUnit.SECONDS).flushDuration(100));

BatchProcessor batchProcessor = getPrivateField(influxDB, "batchProcessor");
BatchWriter originalBatchWriter = getPrivateField(batchProcessor, "batchWriter");
batchWriter = Mockito.spy(originalBatchWriter);
setPrivateField(batchProcessor, "batchWriter", batchWriter);

Point point1 = Point.measurement("cpu")
.time(System.currentTimeMillis() /1000, TimeUnit.SECONDS)
.addField("idle", 90L)
Expand All @@ -200,11 +201,11 @@ public void precision() throws Exception {
influxDB.deleteDatabase(dbName);
}
}

ArgumentCaptor<Collection<BatchPoints>> argument = ArgumentCaptor.forClass(Collection.class);

verify(batchWriter, atLeastOnce()).write(argument.capture());

for (Collection<BatchPoints> list : argument.getAllValues()) {
for (BatchPoints p : list) {
assertTrue(p.toString().contains("precision=SECONDS"));
Expand All @@ -219,7 +220,7 @@ static <T> T getPrivateField(final Object obj, final String name) throws Excepti
field.setAccessible(true);
return (T) field.get(obj);
}

static void setPrivateField(final Object obj, final String name, final Object value) throws Exception {
Field field = obj.getClass().getDeclaredField(name);
field.setAccessible(true);
Expand Down

0 comments on commit 8ae777f

Please sign in to comment.