You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2021/10/09 07:31:28 UTC
[iotdb] branch master updated: [IOTDB-1798] Compatibility of Apache
IoTDB with InfluxDB - `flush` / `ping` / `version` (#4091)
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new ed159df [IOTDB-1798] Compatibility of Apache IoTDB with InfluxDB - `flush` / `ping` / `version` (#4091)
ed159df is described below
commit ed159dfa4b6cbb8ee9b7e2121b20ef5ec6b1f60a
Author: Xieqijun <44...@users.noreply.github.com>
AuthorDate: Sat Oct 9 15:31:03 2021 +0800
[IOTDB-1798] Compatibility of Apache IoTDB with InfluxDB - `flush` / `ping` / `version` (#4091)
---
.../org/apache/iotdb/influxdb/IoTDBInfluxDB.java | 30 +++++++++++++++++++---
.../influxdb/integration/IoTDBInfluxDBIT.java | 23 +++++++++++++++++
2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/IoTDBInfluxDB.java b/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/IoTDBInfluxDB.java
index a7f030e..98cb94a 100644
--- a/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/IoTDBInfluxDB.java
+++ b/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/IoTDBInfluxDB.java
@@ -20,7 +20,11 @@
package org.apache.iotdb.influxdb;
import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.Session;
+import org.apache.iotdb.session.SessionDataSet;
+import org.apache.iotdb.tsfile.read.common.Field;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
import org.influxdb.BatchOptions;
import org.influxdb.InfluxDB;
@@ -241,7 +245,11 @@ public class IoTDBInfluxDB implements InfluxDB {
@Override
public void flush() {
- throw new UnsupportedOperationException(METHOD_NOT_SUPPORTED);
+ try {
+ session.executeNonQueryStatement("flush");
+ } catch (IoTDBConnectionException | StatementExecutionException e) {
+ throw new InfluxDBException(e);
+ }
}
@Override
@@ -377,11 +385,27 @@ public class IoTDBInfluxDB implements InfluxDB {
@Override
public Pong ping() {
- throw new UnsupportedOperationException(METHOD_NOT_SUPPORTED);
+ final long started = System.currentTimeMillis();
+ String version = version();
+ Pong pong = new Pong();
+ pong.setVersion(version);
+ pong.setResponseTime(System.currentTimeMillis() - started);
+ return pong;
}
@Override
public String version() {
- throw new UnsupportedOperationException(METHOD_NOT_SUPPORTED);
+ try {
+ SessionDataSet sessionDataSet = session.executeQueryStatement("show version");
+ String version = null;
+ while (sessionDataSet.hasNext()) {
+ RowRecord record = sessionDataSet.next();
+ List<Field> fields = record.getFields();
+ version = fields.get(0).getStringValue();
+ }
+ return version;
+ } catch (StatementExecutionException | IoTDBConnectionException e) {
+ throw new InfluxDBException(e.getMessage());
+ }
}
}
diff --git a/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java b/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
index f49cbd8..5b028d0 100644
--- a/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
+++ b/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
@@ -23,17 +23,22 @@ import org.apache.iotdb.session.Session;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBException;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
public class IoTDBInfluxDBIT {
private String host;
private Integer port;
private String username;
private String password;
+ private InfluxDB influxDB;
@Rule
public GenericContainer IotDB =
@@ -45,6 +50,12 @@ public class IoTDBInfluxDBIT {
port = IotDB.getMappedPort(6667);
username = "root";
password = "root";
+ influxDB = IoTDBInfluxDBFactory.connect(host, port, username, password);
+ }
+
+ @After
+ public void tearDown() {
+ influxDB.close();
}
@Test
@@ -99,4 +110,16 @@ public class IoTDBInfluxDBIT {
public void testConnectAuthFailed() {
InfluxDB influxDB = IoTDBInfluxDBFactory.connect(host, port, "1", "1");
}
+
+ @Test
+ public void testVersion() {
+ String version = influxDB.version();
+ assertNotNull(version);
+ assertTrue(version.length() > 0);
+ }
+
+ @Test
+ public void testPing() {
+ assertTrue(influxDB.ping().getResponseTime() > 0);
+ }
}