From 24b358de65235c0317442315191cf9ac693f7919 Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Tue, 9 Aug 2022 17:57:17 +0800 Subject: [PATCH 1/9] chore:add gitignore for idea config --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0a53632..f6f86ec 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ target .classpath .project .settings + +# IDEA files +*.iml \ No newline at end of file From a0d797fd71f5ff2384569250f69cf8e6625e74c5 Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Tue, 9 Aug 2022 19:18:20 +0800 Subject: [PATCH 2/9] test:add readme test --- .../src/test/java/com/ceresdb/ReadmeTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java diff --git a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java new file mode 100644 index 0000000..1a044c6 --- /dev/null +++ b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java @@ -0,0 +1,77 @@ +package com.ceresdb; + +import com.ceresdb.models.*; +import com.ceresdb.options.CeresDBxOptions; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +/** + * @author kesheng + * @date 2022/8/9 5:52 下午 + */ +public class ReadmeTest { + + @Ignore + @Test + public void readmeTest() throws ExecutionException, InterruptedException { + // CeresDBx options + final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // CeresDB 默认配置端口号为 8831,不需要修改 + .tenant("test", "sub_test", "test_token") // 租户信息 + .writeMaxRetries(1) // 写入失败重试次数上限(只有部分错误 code 才会重试,比如路由表失效) + .readMaxRetries(1) // 查询失败重试次数上限(只有部分错误 code 才会重试,比如路由表失效) + .build(); + + final CeresDBxClient client = new CeresDBxClient(); + if (!client.init(opts)) { + throw new IllegalStateException("Fail to start CeresDBxClient"); + } + + final long t0 = System.currentTimeMillis(); + final long t1 = t0 + 1000; + final long t2 = t1 + 1000; + final Rows data = Series.newBuilder("machine_metric") + .tag("city", "Singapore") + .tag("ip", "127.0.0.1") + .toRowsBuilder() + // 下面针对 cpu、mem 两列,一次写入了三行数据(3 个时间戳),CeresDB 鼓励这种实践,SDK 可以通过高效的压缩来减少网络传输,并且对 server 端写入非常友好 + .field(t0, "cpu", FieldValue.withDouble(0.23)) // 第 1 行第 1 列 + .field(t0, "mem", FieldValue.withDouble(0.55)) // 第 1 行第 2 列 + .field(t1, "cpu", FieldValue.withDouble(0.25)) // 第 2 行第 1 列 + .field(t1, "mem", FieldValue.withDouble(0.56)) // 第 2 行第 2 列 + .field(t2, "cpu", FieldValue.withDouble(0.21)) // 第 3 行第 1 列 + .field(t2, "mem", FieldValue.withDouble(0.52)) // 第 3 行第 2 列 + .build(); + + final CompletableFuture> wf = client.write(data); + // 这里用 `future.get` 只是方便演示,推荐借助 CompletableFuture 强大的 API 实现异步编程 + final Result wr = wf.get(); + + Assert.assertTrue(wr.isOk()); + Assert.assertEquals(3, wr.getOk().getSuccess()); + // `Result` 类参考了 Rust 语言,提供了丰富的 mapXXX、andThen 类 function 方便对结果值进行转换,提高编程效率,欢迎参考 API 文档使用 + Assert.assertEquals(3, wr.mapOr(0, WriteOk::getSuccess).intValue()); + Assert.assertEquals(0, wr.getOk().getFailed()); + Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed).intValue()); + + final QueryRequest queryRequest = QueryRequest.newBuilder() + .forMetrics("machine_metric") // 表名可选填,不填的话 SQL Parser 会自动解析 ql 涉及到的表名并完成自动路由 + .ql("select timestamp, cpu, mem from machine_metric") // + .build(); + final CompletableFuture> qf = client.query(queryRequest); + // 这里用 `future.get` 只是方便演示,推荐借助 CompletableFuture 强大的 API 实现异步编程 + final Result qr = qf.get(); + + Assert.assertTrue(qr.isOk()); + + final QueryOk queryOk = qr.getOk(); + + final List records = queryOk.mapToRecord().collect(Collectors.toList()); + } + +} From 6d84f410e003046be6225449bac43a22ed8be15c Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Tue, 9 Aug 2022 19:19:05 +0800 Subject: [PATCH 3/9] docs:update readme --- README.md | 8 ++++---- README_CN.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0583a34..08d0df9 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ SqlResult result = client.management().executeSql("CREATE TABLE MY_FIRST_TABL(" ## Data ingestion example ```java // CeresDBx options -final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8081) // +final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // .tenant("test", "sub_test", "test_token") // tenant info // maximum retry times when write fails // (only some error codes will be retried, such as the routing table failure) @@ -149,7 +149,7 @@ final long t1 = t0 + 1000; final long t2 = t1 + 1000; final Rows data = Series.newBuilder("machine_metric") .tag("city", "Singapore") - .tag("ip", "127.0.01") + .tag("ip", "127.0.0.1") .toRowsBuilder() // codes below organizes 3 lines data (3 timestamps) for the `cpu` and `mem` column, this will just transport once through network. CeresDB encourage practices like this, because the SDK could use efficient compression algorithm to reduce network overhead and also be friedly to the sever side. .field(t0, "cpu", FieldValue.withDouble(0.23)) // first row, first column @@ -167,9 +167,9 @@ final Result wr = wf.get(); Assert.assertTrue(wr.isOk()); Assert.assertEquals(3, wr.getOk().getSuccess()); // `Result` class referenced the Rust language practice, provides rich functions (such as mapXXX, andThen) transforming the result value to improve programming efficiency. You can refer to the API docs for detail usage. -Assert.assertEquals(3, wr.mapOr(0, WriteOk::getSuccess())); +Assert.assertEquals(3, wr.mapOr(0, WriteOk::getSuccess).intValue()); Assert.assertEquals(0, wr.getOk().getFailed()); -Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed)); +Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed).intValue()); final QueryRequest queryRequest = QueryRequest.newBuilder() .forMetrics("machine_metric") // table name is optional. If not provided, SQL parser will parse the `ql` to get the table name and do the routing automaticly diff --git a/README_CN.md b/README_CN.md index 9513411..9579474 100644 --- a/README_CN.md +++ b/README_CN.md @@ -126,7 +126,7 @@ SqlResult result = client.management().executeSql("CREATE TABLE MY_FIRST_TABL(" ## 写入 Example ```java // CeresDBx options -final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8081) // +final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // .tenant("test", "sub_test", "test_token") // 租户信息 .writeMaxRetries(1) // 写入失败重试次数上限(只有部分错误 code 才会重试,比如路由表失效) .readMaxRetries(1) // 查询失败重试次数上限(只有部分错误 code 才会重试,比如路由表失效) @@ -142,7 +142,7 @@ final long t1 = t0 + 1000; final long t2 = t1 + 1000; final Rows data = Series.newBuilder("machine_metric") .tag("city", "Singapore") - .tag("ip", "127.0.01") + .tag("ip", "127.0.0.1") .toRowsBuilder() // 下面针对 cpu、mem 两列,一次写入了三行数据(3 个时间戳),CeresDB 鼓励这种实践,SDK 可以通过高效的压缩来减少网络传输,并且对 server 端写入非常友好 .field(t0, "cpu", FieldValue.withDouble(0.23)) // 第 1 行第 1 列 @@ -160,9 +160,9 @@ final Result wr = wf.get(); Assert.assertTrue(wr.isOk()); Assert.assertEquals(3, wr.getOk().getSuccess()); // `Result` 类参考了 Rust 语言,提供了丰富的 mapXXX、andThen 类 function 方便对结果值进行转换,提高编程效率,欢迎参考 API 文档使用 -Assert.assertEquals(3, wr.mapOr(0, WriteOk::getSuccess())); +Assert.assertEquals(3, wr.mapOr(0, WriteOk::getSuccess).intValue()); Assert.assertEquals(0, wr.getOk().getFailed()); -Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed)); +Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed).intValue()); final QueryRequest queryRequest = QueryRequest.newBuilder() .forMetrics("machine_metric") // 表名可选填,不填的话 SQL Parser 会自动解析 ql 涉及到的表名并完成自动路由 From 14cf430727839e4f96996df890f1fb05492772df Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Tue, 9 Aug 2022 19:44:17 +0800 Subject: [PATCH 4/9] style:fix formatter problem --- ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java index 1a044c6..a856d6c 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java @@ -35,9 +35,7 @@ public void readmeTest() throws ExecutionException, InterruptedException { final long t0 = System.currentTimeMillis(); final long t1 = t0 + 1000; final long t2 = t1 + 1000; - final Rows data = Series.newBuilder("machine_metric") - .tag("city", "Singapore") - .tag("ip", "127.0.0.1") + final Rows data = Series.newBuilder("machine_metric").tag("city", "Singapore").tag("ip", "127.0.0.1") .toRowsBuilder() // 下面针对 cpu、mem 两列,一次写入了三行数据(3 个时间戳),CeresDB 鼓励这种实践,SDK 可以通过高效的压缩来减少网络传输,并且对 server 端写入非常友好 .field(t0, "cpu", FieldValue.withDouble(0.23)) // 第 1 行第 1 列 From 22c52ccd73ef380694d9ff217810b8f63de188f3 Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Wed, 10 Aug 2022 14:58:09 +0800 Subject: [PATCH 5/9] test: change code comments to english --- .../src/test/java/com/ceresdb/ReadmeTest.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java index a856d6c..86ea39a 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java @@ -20,12 +20,14 @@ public class ReadmeTest { @Ignore @Test public void readmeTest() throws ExecutionException, InterruptedException { - // CeresDBx options - final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // CeresDB 默认配置端口号为 8831,不需要修改 - .tenant("test", "sub_test", "test_token") // 租户信息 - .writeMaxRetries(1) // 写入失败重试次数上限(只有部分错误 code 才会重试,比如路由表失效) - .readMaxRetries(1) // 查询失败重试次数上限(只有部分错误 code 才会重试,比如路由表失效) - .build(); + final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // ceresdb default grpc port 8831 + .tenant("test", "sub_test", "test_token") // tenant info + // maximum retry times when write fails + // (only some error codes will be retried, such as the routing table failure) + .writeMaxRetries(1) + // maximum retry times when read fails + // (only some error codes will be retried, such as the routing table failure) + .readMaxRetries(1).build(); final CeresDBxClient client = new CeresDBxClient(); if (!client.init(opts)) { @@ -37,32 +39,32 @@ public void readmeTest() throws ExecutionException, InterruptedException { final long t2 = t1 + 1000; final Rows data = Series.newBuilder("machine_metric").tag("city", "Singapore").tag("ip", "127.0.0.1") .toRowsBuilder() - // 下面针对 cpu、mem 两列,一次写入了三行数据(3 个时间戳),CeresDB 鼓励这种实践,SDK 可以通过高效的压缩来减少网络传输,并且对 server 端写入非常友好 - .field(t0, "cpu", FieldValue.withDouble(0.23)) // 第 1 行第 1 列 - .field(t0, "mem", FieldValue.withDouble(0.55)) // 第 1 行第 2 列 - .field(t1, "cpu", FieldValue.withDouble(0.25)) // 第 2 行第 1 列 - .field(t1, "mem", FieldValue.withDouble(0.56)) // 第 2 行第 2 列 - .field(t2, "cpu", FieldValue.withDouble(0.21)) // 第 3 行第 1 列 - .field(t2, "mem", FieldValue.withDouble(0.52)) // 第 3 行第 2 列 + // codes below organizes 3 lines data (3 timestamps) for the `cpu` and `mem` column, this will just transport once through network. CeresDB encourage practices like this, because the SDK could use efficient compression algorithm to reduce network overhead and also be friedly to the sever side. + .field(t0, "cpu", FieldValue.withDouble(0.23)) // first row, first column + .field(t0, "mem", FieldValue.withDouble(0.55)) // first row, second column + .field(t1, "cpu", FieldValue.withDouble(0.25)) // second row, first column + .field(t1, "mem", FieldValue.withDouble(0.56)) // second row, second column + .field(t2, "cpu", FieldValue.withDouble(0.21)) // third row, first column + .field(t2, "mem", FieldValue.withDouble(0.52)) // third row, second column .build(); final CompletableFuture> wf = client.write(data); - // 这里用 `future.get` 只是方便演示,推荐借助 CompletableFuture 强大的 API 实现异步编程 + // here the `future.get` is just for demonstration, a better async programming practice would be using the CompletableFuture API final Result wr = wf.get(); Assert.assertTrue(wr.isOk()); Assert.assertEquals(3, wr.getOk().getSuccess()); - // `Result` 类参考了 Rust 语言,提供了丰富的 mapXXX、andThen 类 function 方便对结果值进行转换,提高编程效率,欢迎参考 API 文档使用 + // `Result` class referenced the Rust language practice, provides rich functions (such as mapXXX, andThen) transforming the result value to improve programming efficiency. You can refer to the API docs for detail usage. Assert.assertEquals(3, wr.mapOr(0, WriteOk::getSuccess).intValue()); Assert.assertEquals(0, wr.getOk().getFailed()); Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed).intValue()); - final QueryRequest queryRequest = QueryRequest.newBuilder() - .forMetrics("machine_metric") // 表名可选填,不填的话 SQL Parser 会自动解析 ql 涉及到的表名并完成自动路由 + final QueryRequest queryRequest = QueryRequest.newBuilder().forMetrics( + "machine_metric") // table name is optional. If not provided, SQL parser will parse the `ql` to get the table name and do the routing automaticly .ql("select timestamp, cpu, mem from machine_metric") // .build(); final CompletableFuture> qf = client.query(queryRequest); - // 这里用 `future.get` 只是方便演示,推荐借助 CompletableFuture 强大的 API 实现异步编程 + // here the `future.get` is just for demonstration, a better async programming practice would be using the CompletableFuture API final Result qr = qf.get(); Assert.assertTrue(qr.isOk()); From 43432d413baa675b88f65608295494427f6f4825 Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Wed, 10 Aug 2022 15:36:09 +0800 Subject: [PATCH 6/9] style: fix formatter problem --- ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java index 86ea39a..76ef8b7 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java @@ -17,9 +17,7 @@ */ public class ReadmeTest { - @Ignore - @Test - public void readmeTest() throws ExecutionException, InterruptedException { + @Ignore @Test public void readmeTest() throws ExecutionException, InterruptedException { final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // ceresdb default grpc port 8831 .tenant("test", "sub_test", "test_token") // tenant info // maximum retry times when write fails From 7c8b5d948a8760a5b74fadf133208cc4c9b5b310 Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Thu, 11 Aug 2022 10:41:06 +0800 Subject: [PATCH 7/9] doc: fix some typo problem --- README.md | 2 +- ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 08d0df9..be243e6 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ final Rows data = Series.newBuilder("machine_metric") .tag("city", "Singapore") .tag("ip", "127.0.0.1") .toRowsBuilder() - // codes below organizes 3 lines data (3 timestamps) for the `cpu` and `mem` column, this will just transport once through network. CeresDB encourage practices like this, because the SDK could use efficient compression algorithm to reduce network overhead and also be friedly to the sever side. + // codes below organizes 3 lines data (3 timestamps) for the `cpu` and `mem` column, this will just transport once through network. CeresDB encourage practices like this, because the SDK could use efficient compression algorithm to reduce network traffic and also be friendly to the sever side. .field(t0, "cpu", FieldValue.withDouble(0.23)) // first row, first column .field(t0, "mem", FieldValue.withDouble(0.55)) // first row, second column .field(t1, "cpu", FieldValue.withDouble(0.25)) // second row, first column diff --git a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java index 76ef8b7..2185bab 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java @@ -13,7 +13,6 @@ /** * @author kesheng - * @date 2022/8/9 5:52 下午 */ public class ReadmeTest { @@ -37,7 +36,7 @@ public class ReadmeTest { final long t2 = t1 + 1000; final Rows data = Series.newBuilder("machine_metric").tag("city", "Singapore").tag("ip", "127.0.0.1") .toRowsBuilder() - // codes below organizes 3 lines data (3 timestamps) for the `cpu` and `mem` column, this will just transport once through network. CeresDB encourage practices like this, because the SDK could use efficient compression algorithm to reduce network overhead and also be friedly to the sever side. + // codes below organizes 3 lines data (3 timestamps) for the `cpu` and `mem` column, this will just transport once through network. CeresDB encourage practices like this, because the SDK could use efficient compression algorithm to reduce network traffic and also be friendly to the sever side. .field(t0, "cpu", FieldValue.withDouble(0.23)) // first row, first column .field(t0, "mem", FieldValue.withDouble(0.55)) // first row, second column .field(t1, "cpu", FieldValue.withDouble(0.25)) // second row, first column From 44c2fd5da2493e42efd37bfa7df8708dc6f505cb Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Thu, 11 Aug 2022 17:06:09 +0800 Subject: [PATCH 8/9] style: fix formatter problem --- .../test/java/com/ceresdb/CeresDBTest.java | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java b/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java index a154286..731cee6 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java @@ -67,8 +67,7 @@ public class CeresDBTest { private CeresDBxOptions opts; private CeresDBxClient client; - @Before - public void before() { + @Before public void before() { final RpcOptions rpcOpts = RpcOptions.newDefault(); rpcOpts.setBlockOnLimit(false); rpcOpts.setInitialLimit(32); @@ -122,8 +121,7 @@ private static String result(final boolean result) { return result ? "success" : "failed"; } - @After - public void after() { + @After public void after() { final SqlResult descResult = this.client.management().executeSql("DROP TABLE %s", TEST_TABLE_NAME); LOG.info("DROP TABLE: {}.", descResult); MetricsUtil.reportImmediately(); @@ -134,9 +132,7 @@ public CeresDBxOptions getOpts() { return opts; } - @Ignore - @Test - public void comprehensiveTest() throws ExecutionException, InterruptedException { + @Ignore @Test public void comprehensiveTest() throws ExecutionException, InterruptedException { final Calendar time = Calendar.getInstance(); final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); final String timeString = format.format(time.getTime()); @@ -165,7 +161,7 @@ public void comprehensiveTest() throws ExecutionException, InterruptedException ok.mapToRecord().forEach(rd -> { LOG.info("Field descriptor: {}", rd.getFieldDescriptors()); LOG.info("Data: ts={}, c1={}, c2={}, c3={}, c4={}, c5={}, c6={}, c7={}, c8={}, c9={}," + // - "c10={}, c11={}, c12={}, c13={}, c14={}, c15={}, c16={}", rd.getTimestamp("ts"), // + "c10={}, c11={}, c12={}, c13={}, c14={}, c15={}, c16={}", rd.getTimestamp("ts"), // rd.getString("c1"), // rd.getInt64("c2"), // rd.getDouble("c3"), // @@ -185,12 +181,12 @@ public void comprehensiveTest() throws ExecutionException, InterruptedException final Management management = this.client.management(); - final SqlResult alterResult1 = management.executeSql("ALTER TABLE %s ADD COLUMN (c18 UINT64, c19 STRING TAG)", - TEST_TABLE_NAME); + final SqlResult alterResult1 = management + .executeSql("ALTER TABLE %s ADD COLUMN (c18 UINT64, c19 STRING TAG)", TEST_TABLE_NAME); LOG.info("ALTER TABLE 1: {}.", alterResult1); - final SqlResult alterResult2 = management.executeSql("ALTER TABLE %s ADD COLUMN c20 STRING TAG", - TEST_TABLE_NAME); + final SqlResult alterResult2 = management + .executeSql("ALTER TABLE %s ADD COLUMN c20 STRING TAG", TEST_TABLE_NAME); LOG.info("ALTER TABLE 2: {}.", alterResult2); final SqlResult descResult = management.executeSql("DESCRIBE %s", TEST_TABLE_NAME); @@ -246,22 +242,17 @@ private Collection makeRows(final Calendar time, final int count) { return rows; } - @Ignore - @Test - public void holdConnectionTest() throws ExecutionException, InterruptedException { + @Ignore @Test public void holdConnectionTest() throws ExecutionException, InterruptedException { comprehensiveTest(); for (int i = 0; i < 1000; i++) { Thread.sleep(1000); } } - @SuppressWarnings("all") - @Ignore - @Test - public void loopToWriteTest() throws Exception { + @SuppressWarnings("all") @Ignore @Test public void loopToWriteTest() throws Exception { final int concurrence = 32; final List>> fs = new ArrayList<>(); - for (;;) { + for (; ; ) { try { for (int i = 0; i < concurrence; i++) { fs.add(writeAsync(Calendar.getInstance(), 32)); @@ -278,9 +269,7 @@ public void loopToWriteTest() throws Exception { } } - @Ignore - @Test - public void streamWriteTest() { + @Ignore @Test public void streamWriteTest() { final StreamWriteBuf writeBuf = this.client.streamWrite(TEST_TABLE_NAME); final CompletableFuture future = writeBuf.write(makeRows(Calendar.getInstance(), 2)) // .write(makeRows(Calendar.getInstance(), 3)) // @@ -293,9 +282,7 @@ public void streamWriteTest() { Assert.assertEquals(35, future.join().getSuccess()); } - @Ignore - @Test - public void streamQueryTest() { + @Ignore @Test public void streamQueryTest() { final Calendar time = Calendar.getInstance(); final StreamWriteBuf writeBuf = this.client.streamWrite(TEST_TABLE_NAME); for (int i = 0; i < 1000; i++) { From 69afce1a3212797ca9e23a564cf13f0a7180f122 Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Fri, 12 Aug 2022 11:06:52 +0800 Subject: [PATCH 9/9] style: fix formatter problem --- .../test/java/com/ceresdb/CeresDBTest.java | 39 ++++++++++++------- .../src/test/java/com/ceresdb/ReadmeTest.java | 23 +++++++++-- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java b/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java index 731cee6..a154286 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/CeresDBTest.java @@ -67,7 +67,8 @@ public class CeresDBTest { private CeresDBxOptions opts; private CeresDBxClient client; - @Before public void before() { + @Before + public void before() { final RpcOptions rpcOpts = RpcOptions.newDefault(); rpcOpts.setBlockOnLimit(false); rpcOpts.setInitialLimit(32); @@ -121,7 +122,8 @@ private static String result(final boolean result) { return result ? "success" : "failed"; } - @After public void after() { + @After + public void after() { final SqlResult descResult = this.client.management().executeSql("DROP TABLE %s", TEST_TABLE_NAME); LOG.info("DROP TABLE: {}.", descResult); MetricsUtil.reportImmediately(); @@ -132,7 +134,9 @@ public CeresDBxOptions getOpts() { return opts; } - @Ignore @Test public void comprehensiveTest() throws ExecutionException, InterruptedException { + @Ignore + @Test + public void comprehensiveTest() throws ExecutionException, InterruptedException { final Calendar time = Calendar.getInstance(); final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); final String timeString = format.format(time.getTime()); @@ -161,7 +165,7 @@ public CeresDBxOptions getOpts() { ok.mapToRecord().forEach(rd -> { LOG.info("Field descriptor: {}", rd.getFieldDescriptors()); LOG.info("Data: ts={}, c1={}, c2={}, c3={}, c4={}, c5={}, c6={}, c7={}, c8={}, c9={}," + // - "c10={}, c11={}, c12={}, c13={}, c14={}, c15={}, c16={}", rd.getTimestamp("ts"), // + "c10={}, c11={}, c12={}, c13={}, c14={}, c15={}, c16={}", rd.getTimestamp("ts"), // rd.getString("c1"), // rd.getInt64("c2"), // rd.getDouble("c3"), // @@ -181,12 +185,12 @@ public CeresDBxOptions getOpts() { final Management management = this.client.management(); - final SqlResult alterResult1 = management - .executeSql("ALTER TABLE %s ADD COLUMN (c18 UINT64, c19 STRING TAG)", TEST_TABLE_NAME); + final SqlResult alterResult1 = management.executeSql("ALTER TABLE %s ADD COLUMN (c18 UINT64, c19 STRING TAG)", + TEST_TABLE_NAME); LOG.info("ALTER TABLE 1: {}.", alterResult1); - final SqlResult alterResult2 = management - .executeSql("ALTER TABLE %s ADD COLUMN c20 STRING TAG", TEST_TABLE_NAME); + final SqlResult alterResult2 = management.executeSql("ALTER TABLE %s ADD COLUMN c20 STRING TAG", + TEST_TABLE_NAME); LOG.info("ALTER TABLE 2: {}.", alterResult2); final SqlResult descResult = management.executeSql("DESCRIBE %s", TEST_TABLE_NAME); @@ -242,17 +246,22 @@ private Collection makeRows(final Calendar time, final int count) { return rows; } - @Ignore @Test public void holdConnectionTest() throws ExecutionException, InterruptedException { + @Ignore + @Test + public void holdConnectionTest() throws ExecutionException, InterruptedException { comprehensiveTest(); for (int i = 0; i < 1000; i++) { Thread.sleep(1000); } } - @SuppressWarnings("all") @Ignore @Test public void loopToWriteTest() throws Exception { + @SuppressWarnings("all") + @Ignore + @Test + public void loopToWriteTest() throws Exception { final int concurrence = 32; final List>> fs = new ArrayList<>(); - for (; ; ) { + for (;;) { try { for (int i = 0; i < concurrence; i++) { fs.add(writeAsync(Calendar.getInstance(), 32)); @@ -269,7 +278,9 @@ private Collection makeRows(final Calendar time, final int count) { } } - @Ignore @Test public void streamWriteTest() { + @Ignore + @Test + public void streamWriteTest() { final StreamWriteBuf writeBuf = this.client.streamWrite(TEST_TABLE_NAME); final CompletableFuture future = writeBuf.write(makeRows(Calendar.getInstance(), 2)) // .write(makeRows(Calendar.getInstance(), 3)) // @@ -282,7 +293,9 @@ private Collection makeRows(final Calendar time, final int count) { Assert.assertEquals(35, future.join().getSuccess()); } - @Ignore @Test public void streamQueryTest() { + @Ignore + @Test + public void streamQueryTest() { final Calendar time = Calendar.getInstance(); final StreamWriteBuf writeBuf = this.client.streamWrite(TEST_TABLE_NAME); for (int i = 0; i < 1000; i++) { diff --git a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java index 2185bab..9ee8e73 100644 --- a/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java +++ b/ceresdb-example/src/test/java/com/ceresdb/ReadmeTest.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.ceresdb; import com.ceresdb.models.*; @@ -16,7 +32,9 @@ */ public class ReadmeTest { - @Ignore @Test public void readmeTest() throws ExecutionException, InterruptedException { + @Ignore + @Test + public void readmeTest() throws ExecutionException, InterruptedException { final CeresDBxOptions opts = CeresDBxOptions.newBuilder("127.0.0.1", 8831) // ceresdb default grpc port 8831 .tenant("test", "sub_test", "test_token") // tenant info // maximum retry times when write fails @@ -56,8 +74,7 @@ public class ReadmeTest { Assert.assertEquals(0, wr.getOk().getFailed()); Assert.assertEquals(0, wr.mapOr(-1, WriteOk::getFailed).intValue()); - final QueryRequest queryRequest = QueryRequest.newBuilder().forMetrics( - "machine_metric") // table name is optional. If not provided, SQL parser will parse the `ql` to get the table name and do the routing automaticly + final QueryRequest queryRequest = QueryRequest.newBuilder().forMetrics("machine_metric") // table name is optional. If not provided, SQL parser will parse the `ql` to get the table name and do the routing automaticly .ql("select timestamp, cpu, mem from machine_metric") // .build(); final CompletableFuture> qf = client.query(queryRequest);