This is an automated email from the ASF dual-hosted git repository. ejttianyu pushed a commit to branch dev_merge in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 4647eb3048b5d7632765a557fb9b8a4e4fdae3b7 Author: EJTTianyu <[email protected]> AuthorDate: Wed May 13 19:30:51 2020 +0800 add merge session test --- cli/pom.xml | 5 + cli/src/main/java/org/apache/iotdb/cli/Cli.java | 5 + .../java/org/apache/iotdb/cli/SessionTest.java | 136 +++++++++++++++++++++ 3 files changed, 146 insertions(+) diff --git a/cli/pom.xml b/cli/pom.xml index b5f5e31..4aa1f80 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -56,6 +56,11 @@ <groupId>jline</groupId> <artifactId>jline</artifactId> </dependency> + <dependency> + <groupId>org.apache.iotdb</groupId> + <artifactId>iotdb-session</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> <build> <plugins> diff --git a/cli/src/main/java/org/apache/iotdb/cli/Cli.java b/cli/src/main/java/org/apache/iotdb/cli/Cli.java index dc0e967..44ac98e 100644 --- a/cli/src/main/java/org/apache/iotdb/cli/Cli.java +++ b/cli/src/main/java/org/apache/iotdb/cli/Cli.java @@ -53,6 +53,11 @@ public class Cli extends AbstractCli { hf.setWidth(MAX_HELP_CONSOLE_WIDTH); commandLine = null; + if (args[0].equals("sessionInsert")) { + SessionTest.sessionInsert(); + return; + } + String[] newArgs; String[] newArgs2; diff --git a/cli/src/main/java/org/apache/iotdb/cli/SessionTest.java b/cli/src/main/java/org/apache/iotdb/cli/SessionTest.java new file mode 100644 index 0000000..0de62dd --- /dev/null +++ b/cli/src/main/java/org/apache/iotdb/cli/SessionTest.java @@ -0,0 +1,136 @@ +/* + * 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 org.apache.iotdb.cli; + +import java.util.ArrayList; +import java.util.List; +import org.apache.iotdb.rpc.IoTDBConnectionException; +import org.apache.iotdb.rpc.StatementExecutionException; +import org.apache.iotdb.session.pool.SessionDataSetWrapper; +import org.apache.iotdb.session.pool.SessionPool; + +public class SessionTest { + + public static void sessionInsert() { + + for (int i = 0; i < 6; i++) { + Thread thread = new Thread(new Write(i)); + thread.start(); + } + +// try { +// Thread.sleep(5000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// new Thread(() -> { +// try { +// for (int i = 0; i < 6; i++) { +// query(i); +// } +// } catch (IoTDBConnectionException e) { +// e.printStackTrace(); +// } catch (StatementExecutionException e) { +// e.printStackTrace(); +// } +// }).start(); + + } + + private static class Write implements Runnable { + + private int device; + + public Write(int i) { + this.device = i; + } + + @Override + public void run() { + SessionPool session = new SessionPool("127.0.0.1", 6667, "root", "root", 5); + + long time = 0; + while (true) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + long start = System.currentTimeMillis(); + time += 5000; + String deviceId = "root.sg.d1"; + List<String> measurements = new ArrayList<>(); + for (int i = 0; i < 50000; i++) { + measurements.add("s" + (i + device * 50000)); + } + + List<String> values = new ArrayList<>(); + for (int i = 0; i < 50000; i++) { + values.add("1"); + } + + try { + session.insertRecord(deviceId, time, measurements, values); + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + System.out.println( + Thread.currentThread().getName() + " write: " + (System.currentTimeMillis() - start) + + " time " + time); + } + } + } + + private static void query(int device) + throws IoTDBConnectionException, StatementExecutionException { + SessionDataSetWrapper dataSet; + SessionPool session = new SessionPool("127.0.0.1", 6667, "root", "root", 5); + + while (true) { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + long start = System.currentTimeMillis(); + + StringBuilder builder = new StringBuilder("select last "); + for (int c = 0; c < 49999; c++) { + builder.append("s").append(c).append(","); + } + + builder.append("s49999 "); + builder.append("from root.sg1.d" + device); + + dataSet = session.executeQueryStatement(builder.toString()); + int a = 0; + while (dataSet.hasNext()) { + a++; + dataSet.next(); + } + System.out.print(Thread.currentThread().getName() + " read " + a + " "); + System.out.println(System.currentTimeMillis() - start); + session.closeResultSet(dataSet); + } + + } +} \ No newline at end of file
