Skip to content

Commit 93b9ead

Browse files
committed
remove deprecated retention policy method usage
1 parent 763defd commit 93b9ead

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ String dbName = "aTimeSeries";
2929
influxDB.query(new Query("CREATE DATABASE " + dbName));
3030
influxDB.setDatabase(dbName);
3131
String rpName = "aRetentionPolicy";
32-
influxDB.createRetentionPolicy(rpName, dbName, "30d", "30m", 2, true);
32+
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 SHARD DURATION 30m DEFAULT"));
3333
influxDB.setRetentionPolicy(rpName);
3434

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

5050
Query query = new Query("SELECT idle FROM cpu", dbName);
5151
influxDB.query(query);
52-
influxDB.dropRetentionPolicy(rpName, dbName);
52+
influxDB.query(new Query("DROP RETENTION POLICY " + rpName + " ON " + dbName));
5353
influxDB.query(new Query("DROP DATABASE " + dbName));
5454
influxDB.close();
5555
```
@@ -88,7 +88,7 @@ InfluxDB influxDB = InfluxDBFactory.connect("http://172.17.0.2:8086", "root", "r
8888
String dbName = "aTimeSeries";
8989
influxDB.query(new Query("CREATE DATABASE " + dbName));
9090
String rpName = "aRetentionPolicy";
91-
influxDB.createRetentionPolicy(rpName, dbName, "30d", "30m", 2, true);
91+
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 SHARD DURATION 30m DEFAULT"));
9292

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

128128
BatchPoints batchPoints = BatchPoints
129129
.database(dbName)
@@ -147,7 +147,7 @@ batchPoints.point(point2);
147147
influxDB.write(batchPoints);
148148
Query query = new Query("SELECT idle FROM cpu", dbName);
149149
influxDB.query(query);
150-
influxDB.dropRetentionPolicy(rpName, dbName);
150+
influxDB.query(new Query("DROP RETENTION POLICY " + rpName + " ON " + dbName));
151151
influxDB.query(new Query("DROP DATABASE " + dbName));
152152
```
153153

src/test/java/org/influxdb/InfluxDBTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,9 @@ public void testCreateDropRetentionPolicies() {
11141114
String dbName = "rpTest_" + System.currentTimeMillis();
11151115
this.influxDB.query(new Query("CREATE DATABASE " + dbName));
11161116

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

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

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

11331133
result = this.influxDB.query(query);
11341134
Assertions.assertNull(result.getError());

src/test/java/org/influxdb/impl/BatchProcessorTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.influxdb.TestUtils;
2929
import org.influxdb.dto.BatchPoints;
3030
import org.influxdb.dto.Point;
31+
import org.influxdb.dto.Query;
3132
import org.junit.jupiter.api.Assertions;
3233
import org.junit.jupiter.api.Test;
3334
import org.junit.platform.runner.JUnitPlatform;
@@ -178,15 +179,15 @@ public void precision() throws Exception {
178179
try (InfluxDB influxDB = TestUtils.connectToInfluxDB()) {
179180
try {
180181
influxDB.createDatabase(dbName);
181-
influxDB.createRetentionPolicy(rpName, dbName, "30h", 2, true);
182+
influxDB.query(new Query("CREATE RETENTION POLICY " + rpName + " ON " + dbName + " DURATION 30h REPLICATION 2 DEFAULT"));
182183

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

185186
BatchProcessor batchProcessor = getPrivateField(influxDB, "batchProcessor");
186187
BatchWriter originalBatchWriter = getPrivateField(batchProcessor, "batchWriter");
187188
batchWriter = Mockito.spy(originalBatchWriter);
188189
setPrivateField(batchProcessor, "batchWriter", batchWriter);
189-
190+
190191
Point point1 = Point.measurement("cpu")
191192
.time(System.currentTimeMillis() /1000, TimeUnit.SECONDS)
192193
.addField("idle", 90L)
@@ -200,11 +201,11 @@ public void precision() throws Exception {
200201
influxDB.deleteDatabase(dbName);
201202
}
202203
}
203-
204+
204205
ArgumentCaptor<Collection<BatchPoints>> argument = ArgumentCaptor.forClass(Collection.class);
205206

206207
verify(batchWriter, atLeastOnce()).write(argument.capture());
207-
208+
208209
for (Collection<BatchPoints> list : argument.getAllValues()) {
209210
for (BatchPoints p : list) {
210211
assertTrue(p.toString().contains("precision=SECONDS"));
@@ -219,7 +220,7 @@ static <T> T getPrivateField(final Object obj, final String name) throws Excepti
219220
field.setAccessible(true);
220221
return (T) field.get(obj);
221222
}
222-
223+
223224
static void setPrivateField(final Object obj, final String name, final Object value) throws Exception {
224225
Field field = obj.getClass().getDeclaredField(name);
225226
field.setAccessible(true);

0 commit comments

Comments
 (0)