This is an automated email from the ASF dual-hosted git repository.
caogaofei 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 8980844590a Add UT for session module (#11158)
8980844590a is described below
commit 8980844590aa6775910031de94f45b789d1ed90f
Author: Summer <[email protected]>
AuthorDate: Tue Sep 26 14:42:15 2023 +0800
Add UT for session module (#11158)
---
.../main/java/org/apache/iotdb/tool/ImportCsv.java | 2 +-
.../iotdb/session/SessionConnectionTest.java | 388 ++++++
.../java/org/apache/iotdb/session/SessionTest.java | 1175 ++++++++++++++++++
.../session/pool/SessionPoolExceptionTest.java | 266 ++++
.../apache/iotdb/session/pool/SessionPoolTest.java | 1264 +++++++++++++++++++-
.../iotdb/session/util/SessionUtilsTest.java | 176 +++
6 files changed, 3268 insertions(+), 3 deletions(-)
diff --git
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
index 8d8b3b7a964..f6ea5138645 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
@@ -478,7 +478,7 @@ public class ImportCsv extends AbstractCsvTool {
records.forEach(
recordObj -> {
- if (Boolean.TRUE.equals(!hasStarted.get())) {
+ if (Boolean.FALSE.equals(hasStarted.get())) {
hasStarted.set(true);
} else if (pointSize.get() >= batchPointSize) {
writeAndEmptyDataSet(deviceIds, times, typesList, valuesList,
measurementsList, 3);
diff --git
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionConnectionTest.java
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionConnectionTest.java
new file mode 100644
index 00000000000..e5eecb5545e
--- /dev/null
+++
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionConnectionTest.java
@@ -0,0 +1,388 @@
+/*
+ * 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.session;
+
+import org.apache.iotdb.common.rpc.thrift.TAggregationType;
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.rpc.BatchExecutionException;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.RedirectException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.service.rpc.thrift.IClientRPCService;
+import
org.apache.iotdb.service.rpc.thrift.TCreateTimeseriesUsingSchemaTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSAppendSchemaTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSBackupConfigurationResp;
+import org.apache.iotdb.service.rpc.thrift.TSConnectionInfoResp;
+import org.apache.iotdb.service.rpc.thrift.TSCreateAlignedTimeseriesReq;
+import org.apache.iotdb.service.rpc.thrift.TSCreateMultiTimeseriesReq;
+import org.apache.iotdb.service.rpc.thrift.TSCreateSchemaTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSCreateTimeseriesReq;
+import org.apache.iotdb.service.rpc.thrift.TSDeleteDataReq;
+import org.apache.iotdb.service.rpc.thrift.TSDropSchemaTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp;
+import org.apache.iotdb.service.rpc.thrift.TSInsertRecordReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertRecordsOfOneDeviceReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertRecordsReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordsOfOneDeviceReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertStringRecordsReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertTabletReq;
+import org.apache.iotdb.service.rpc.thrift.TSInsertTabletsReq;
+import org.apache.iotdb.service.rpc.thrift.TSPruneSchemaTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSQueryTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSQueryTemplateResp;
+import org.apache.iotdb.service.rpc.thrift.TSSetSchemaTemplateReq;
+import org.apache.iotdb.service.rpc.thrift.TSUnsetSchemaTemplateReq;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.transport.TTransport;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.powermock.reflect.Whitebox;
+
+import java.time.ZoneId;
+import java.util.Arrays;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+
+public class SessionConnectionTest {
+
+ @Mock private SessionConnection sessionConnection;
+ @Mock private TTransport transport;
+ @Mock private IClientRPCService.Iface client;
+
+ @Mock private Session session;
+
+ @Before
+ public void setUp() throws IoTDBConnectionException,
StatementExecutionException, TException {
+ MockitoAnnotations.initMocks(this);
+ sessionConnection = new SessionConnection();
+ Whitebox.setInternalState(sessionConnection, "transport", transport);
+ Whitebox.setInternalState(sessionConnection, "client", client);
+ session = new Session(Arrays.asList("127.0.0.1:12"), "root", "root");
+ Whitebox.setInternalState(sessionConnection, "session", session);
+ Mockito.when(transport.isOpen()).thenReturn(true);
+ TSStatus tsStatus = new
TSStatus(TSStatusCode.REDIRECTION_RECOMMEND.getStatusCode());
+ TSStatus tsStatusSuccess = new
TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
+ tsStatus.setSubStatus(
+ Arrays.asList(new
TSStatus(TSStatusCode.REDIRECTION_RECOMMEND.getStatusCode())));
+ Mockito.when(client.setStorageGroup(anyLong(),
anyString())).thenReturn(tsStatus);
+ TSExecuteStatementResp execResp = new TSExecuteStatementResp(tsStatus);
+ execResp.setColumns(Arrays.asList());
+ execResp.setDataTypeList(Arrays.asList());
+ execResp.setQueryId(1l);
+ execResp.setQueryResult(Arrays.asList());
+ execResp.setIgnoreTimeStamp(false);
+ execResp.setMoreData(false);
+ Mockito.when(client.executeQueryStatementV2(any())).thenReturn(execResp);
+
Mockito.when(client.executeFastLastDataQueryForOneDeviceV2(any())).thenReturn(execResp);
+ Mockito.when(client.executeLastDataQueryV2(any())).thenReturn(execResp);
+ Mockito.when(client.deleteStorageGroups(anyLong(),
any())).thenReturn(tsStatus);
+ Mockito.when(client.createTimeseries(any())).thenReturn(tsStatus);
+ Mockito.when(client.createAlignedTimeseries(any())).thenReturn(tsStatus);
+ Mockito.when(client.createMultiTimeseries(any())).thenReturn(tsStatus);
+ Mockito.when(client.executeUpdateStatementV2(any())).thenReturn(execResp);
+ Mockito.when(client.closeOperation(any())).thenReturn(tsStatus);
+ Mockito.when(client.executeAggregationQueryV2(any())).thenReturn(execResp);
+ Mockito.when(client.executeRawDataQueryV2(any())).thenReturn(execResp);
+ Mockito.when(client.insertRecord(any())).thenReturn(tsStatus);
+ Mockito.when(client.testInsertRecord(any())).thenReturn(tsStatus);
+ Mockito.when(client.insertRecords(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.testInsertRecords(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.insertStringRecord(any())).thenReturn(tsStatus);
+ Mockito.when(client.testInsertStringRecord(any())).thenReturn(tsStatus);
+
Mockito.when(client.insertStringRecords(any())).thenReturn(tsStatusSuccess);
+
Mockito.when(client.testInsertStringRecords(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.insertRecordsOfOneDevice(any())).thenReturn(tsStatus);
+
Mockito.when(client.insertStringRecordsOfOneDevice(any())).thenReturn(tsStatus);
+ Mockito.when(client.deleteTimeseries(anyLong(),
any())).thenReturn(tsStatus);
+ Mockito.when(client.insertTablet(any())).thenReturn(tsStatus);
+ Mockito.when(client.testInsertTablet(any())).thenReturn(tsStatus);
+ Mockito.when(client.insertTablets(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.testInsertTablets(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.deleteData(any())).thenReturn(tsStatusSuccess);
+
Mockito.when(client.createSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+
Mockito.when(client.appendSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+
Mockito.when(client.pruneSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.querySchemaTemplate(any()))
+ .thenReturn(new TSQueryTemplateResp(tsStatusSuccess, 1));
+ Mockito.when(client.setSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+
Mockito.when(client.unsetSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.dropSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+
Mockito.when(client.createTimeseriesUsingSchemaTemplate(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.getBackupConfiguration())
+ .thenReturn(new TSBackupConfigurationResp(tsStatusSuccess));
+ Mockito.when(client.fetchAllConnectionsInfo()).thenReturn(new
TSConnectionInfoResp());
+ Mockito.when(client.setTimeZone(any())).thenReturn(tsStatusSuccess);
+ Mockito.when(client.closeSession(any())).thenReturn(tsStatusSuccess);
+ }
+
+ @After
+ public void close() throws IoTDBConnectionException {
+ sessionConnection.close();
+ }
+
+ @Test(expected = NumberFormatException.class)
+ public void testBuildSessionConnection() throws IoTDBConnectionException {
+ session = new Session("local", 12, "root", "root");
+ SessionConnection sessionConnection1 = new SessionConnection(session,
ZoneId.systemDefault());
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testBuildSessionConnection2() throws IoTDBConnectionException {
+ session = new Session("local", 12, "root", "root");
+ SessionConnection sessionConnection1 =
+ new SessionConnection(session, new TEndPoint("localhost", 1234),
ZoneId.systemDefault());
+ }
+
+ @Test
+ public void testSetStorageGroup() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionConnection.setTimeZone(ZoneId.systemDefault().getId());
+ sessionConnection.setStorageGroup("root.test1");
+ }
+
+ @Test
+ public void testDeleteStorageGroups()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.deleteStorageGroups(Arrays.asList("root.test1"));
+ }
+
+ @Test
+ public void testCreateTimeseries() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionConnection.createTimeseries(new TSCreateTimeseriesReq());
+ }
+
+ @Test(expected = BatchExecutionException.class)
+ public void testCreateTimeseriesRedirect()
+ throws IoTDBConnectionException, StatementExecutionException, TException
{
+ TSStatus tsStatus = new
TSStatus(TSStatusCode.MULTIPLE_ERROR.getStatusCode());
+ tsStatus.setSubStatus(Arrays.asList(new TSStatus()));
+ Mockito.when(client.createTimeseries(any())).thenReturn(tsStatus);
+ sessionConnection.createTimeseries(new TSCreateTimeseriesReq());
+ }
+
+ @Test(expected = StatementExecutionException.class)
+ public void testCreateTimeseriesException()
+ throws IoTDBConnectionException, StatementExecutionException, TException
{
+ TSStatus tsStatus = new
TSStatus(TSStatusCode.INCOMPATIBLE_VERSION.getStatusCode());
+ tsStatus.setSubStatus(Arrays.asList(new TSStatus()));
+ Mockito.when(client.createTimeseries(any())).thenReturn(tsStatus);
+ sessionConnection.createTimeseries(new TSCreateTimeseriesReq());
+ }
+
+ @Test
+ public void testCreateAlignedTimeseries()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.createAlignedTimeseries(new
TSCreateAlignedTimeseriesReq());
+ }
+
+ @Test
+ public void testCreateMultiTimeseries()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.createMultiTimeseries(new TSCreateMultiTimeseriesReq());
+ }
+
+ @Test
+ public void testCheckTimeseriesExists()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.checkTimeseriesExists("root.test1.dev1.s1", 500l);
+ }
+
+ @Test
+ public void testExecuteQueryStatement()
+ throws IoTDBConnectionException, StatementExecutionException,
RedirectException {
+ sessionConnection.executeQueryStatement("show version", 500l);
+ }
+
+ @Test
+ public void testExecuteNonQueryStatement()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.executeNonQueryStatement(
+ "create timeseries root.stock.Legacy.0700HK.L1_BuyNo WITH
datatype=BOOLEAN, encoding=PLAIN;");
+ }
+
+ @Test
+ public void testExecuteRawDataQuery()
+ throws IoTDBConnectionException, StatementExecutionException,
RedirectException {
+ sessionConnection.executeRawDataQuery(
+ Arrays.asList("root.test1"),
+ System.currentTimeMillis() - 1000 * 60 * 24,
+ System.currentTimeMillis(),
+ 500l);
+ }
+
+ @Test
+ public void testExecuteLastDataQueryForOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.executeLastDataQueryForOneDevice(
+ "db1", "dev1", Arrays.asList("s1", "s2"), true, 500l);
+ }
+
+ @Test
+ public void testExecuteLastDataQuery()
+ throws IoTDBConnectionException, StatementExecutionException,
RedirectException {
+ sessionConnection.executeLastDataQuery(Arrays.asList("s1", "s2"), 5000,
500l);
+ }
+
+ @Test
+ public void testExecuteAggregationQuery()
+ throws IoTDBConnectionException, StatementExecutionException,
RedirectException {
+ sessionConnection.executeAggregationQuery(
+ Arrays.asList("s1", "s2"),
+ Arrays.asList(TAggregationType.LAST_VALUE,
TAggregationType.MAX_VALUE));
+ sessionConnection.executeAggregationQuery(
+ Arrays.asList("s1", "s2"),
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE),
+ System.currentTimeMillis() - 1000 * 60 * 24,
+ System.currentTimeMillis());
+ sessionConnection.executeAggregationQuery(
+ Arrays.asList("s1", "s2"),
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE),
+ System.currentTimeMillis() - 1000 * 60 * 24,
+ System.currentTimeMillis(),
+ 500l);
+ sessionConnection.executeAggregationQuery(
+ Arrays.asList("s1", "s2"),
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE),
+ System.currentTimeMillis() - 1000 * 60 * 24,
+ System.currentTimeMillis(),
+ 500l,
+ 500l);
+ }
+
+ @Test
+ public void testExecuteAggregationQueryWithTime()
+ throws IoTDBConnectionException, StatementExecutionException,
RedirectException {
+ sessionConnection.executeAggregationQuery(
+ Arrays.asList("s1", "s2"),
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE),
+ System.currentTimeMillis() - 1000 * 60 * 24,
+ System.currentTimeMillis());
+ }
+
+ @Test
+ public void testTimeZone() {
+ String zoneId = ZoneId.systemDefault().getId();
+ sessionConnection.setTimeZoneOfSession(ZoneId.systemDefault().getId());
+ Assert.assertEquals(zoneId, sessionConnection.getTimeZone());
+ }
+
+ @Test
+ public void testInsertRecord()
+ throws IoTDBConnectionException, StatementExecutionException,
RedirectException {
+ sessionConnection.insertRecord(new TSInsertRecordReq());
+ sessionConnection.insertRecord(new TSInsertStringRecordReq());
+ sessionConnection.testInsertRecord(new TSInsertStringRecordReq());
+ sessionConnection.testInsertRecord(new TSInsertRecordReq());
+ sessionConnection.insertRecords(new TSInsertRecordsReq());
+ sessionConnection.insertRecords(new TSInsertStringRecordsReq());
+ sessionConnection.testInsertRecords(new TSInsertRecordsReq());
+ sessionConnection.testInsertRecords(new TSInsertStringRecordsReq());
+ sessionConnection.insertRecordsOfOneDevice(new
TSInsertRecordsOfOneDeviceReq());
+ sessionConnection.insertStringRecordsOfOneDevice(new
TSInsertStringRecordsOfOneDeviceReq());
+ sessionConnection.insertTablet(new TSInsertTabletReq());
+ sessionConnection.testInsertTablet(new TSInsertTabletReq());
+ sessionConnection.insertTablets(new TSInsertTabletsReq());
+ sessionConnection.testInsertTablets(new TSInsertTabletsReq());
+ sessionConnection.deleteTimeseries(Arrays.asList("root.sg1.d1.s1"));
+ }
+
+ @Test
+ public void testDeleteData() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionConnection.deleteData(new TSDeleteDataReq());
+ }
+
+ @Test
+ public void testCreateSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.createSchemaTemplate(new TSCreateSchemaTemplateReq());
+ }
+
+ @Test
+ public void testAppendSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.appendSchemaTemplate(new TSAppendSchemaTemplateReq());
+ }
+
+ @Test
+ public void testPruneSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.pruneSchemaTemplate(new TSPruneSchemaTemplateReq());
+ }
+
+ @Test
+ public void testQuerySchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.querySchemaTemplate(new TSQueryTemplateReq());
+ }
+
+ @Test
+ public void testSetSchemaTemplate() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionConnection.setSchemaTemplate(new TSSetSchemaTemplateReq());
+ }
+
+ @Test
+ public void testUnsetSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.unsetSchemaTemplate(new TSUnsetSchemaTemplateReq());
+ }
+
+ @Test
+ public void testDropSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.dropSchemaTemplate(new TSDropSchemaTemplateReq());
+ }
+
+ @Test
+ public void testCreateTimeseriesUsingSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.createTimeseriesUsingSchemaTemplate(
+ new TCreateTimeseriesUsingSchemaTemplateReq());
+ }
+
+ @Test
+ public void testGetBackupConfiguration()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionConnection.getBackupConfiguration();
+ }
+
+ @Test
+ public void testFetchAllConnections() throws IoTDBConnectionException {
+ sessionConnection.fetchAllConnections();
+ }
+
+ @Test
+ public void testToString() {
+ sessionConnection.setEnableRedirect(true);
+ Assert.assertEquals(true, sessionConnection.isEnableRedirect());
+ sessionConnection.setEndPoint(new TEndPoint("localhost", 1234));
+ Assert.assertEquals("localhost", sessionConnection.getEndPoint().getIp());
+ sessionConnection.toString();
+ }
+}
diff --git
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
new file mode 100644
index 00000000000..3dbfc02feca
--- /dev/null
+++
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
@@ -0,0 +1,1175 @@
+/*
+ * 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.session;
+
+import org.apache.iotdb.common.rpc.thrift.TAggregationType;
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.isession.ISession;
+import org.apache.iotdb.isession.SessionConfig;
+import org.apache.iotdb.isession.util.Version;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.service.rpc.thrift.TSQueryTemplateResp;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.utils.BitMap;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.powermock.reflect.Whitebox;
+
+import java.io.IOException;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+
+public class SessionTest {
+
+ @Mock private ISession session;
+
+ @Mock private SessionConnection sessionConnection;
+
+ @Before
+ public void setUp() throws IoTDBConnectionException,
StatementExecutionException {
+ MockitoAnnotations.initMocks(this);
+ session = new Session("host", 11, "user", "pwd");
+ Whitebox.setInternalState(session, "defaultSessionConnection",
sessionConnection);
+ TSQueryTemplateResp resp = new TSQueryTemplateResp();
+ resp.setMeasurements(Arrays.asList("root.sg1.d1.s1"));
+
Mockito.when(sessionConnection.querySchemaTemplate(any())).thenReturn(resp);
+ HashMap<String, TEndPoint> deviceIdToEndpoint = new HashMap<>();
+ deviceIdToEndpoint.put("device1", new TEndPoint());
+ deviceIdToEndpoint.put("device2", new TEndPoint());
+ Whitebox.setInternalState(session, "deviceIdToEndpoint",
deviceIdToEndpoint);
+ HashMap<TEndPoint, SessionConnection> endPointToSessionConnection = new
HashMap<>();
+ endPointToSessionConnection.put(new TEndPoint(), sessionConnection);
+ Whitebox.setInternalState(session, "endPointToSessionConnection",
endPointToSessionConnection);
+ }
+
+ @After
+ public void tearDown() throws IoTDBConnectionException {
+ // Close the session pool after each test
+ if (null != session) {
+ session.close();
+ }
+ }
+
+ @Test
+ public void testBuildSession() {
+ Session session1 =
+ new Session.Builder()
+ .nodeUrls(Arrays.asList("host:port"))
+ .username("username")
+ .password("pwd")
+ .build();
+ session1 =
+ new Session.Builder()
+ .host("host")
+ .port(12)
+ .username("username")
+ .password("pwd")
+ .fetchSize(1000)
+ .zoneId(ZoneId.systemDefault())
+ .enableRedirection(true)
+ .thriftMaxFrameSize(SessionConfig.DEFAULT_MAX_FRAME_SIZE)
+
.thriftDefaultBufferSize(SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY)
+ .version(Version.V_0_13)
+ .timeOut(500l)
+ .build();
+ }
+
+ @Test
+ public void testTimeZone() throws IoTDBConnectionException,
StatementExecutionException {
+ String timeZone = session.getTimeZone();
+ timeZone = "UTC";
+ session.setTimeZone(timeZone);
+ session.setTimeZoneOfSession(timeZone);
+ assertEquals(timeZone, ((Session) session).zoneId.toString());
+ }
+
+ @Test
+ public void testSetStorageGroup() throws IoTDBConnectionException,
StatementExecutionException {
+ session.setStorageGroup("root.sg1");
+ }
+
+ @Test
+ public void testDeleteStorageGroup()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.deleteStorageGroup("root.sg1");
+ }
+
+ @Test
+ public void testDeleteStorageGroups()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.deleteStorageGroups(Arrays.asList("root.sg1"));
+ }
+
+ @Test
+ public void testCreateDatabase() throws IoTDBConnectionException,
StatementExecutionException {
+ session.createDatabase("root.sg1");
+ }
+
+ @Test
+ public void testDeleteDatabase() throws IoTDBConnectionException,
StatementExecutionException {
+ session.deleteDatabase("root.sg1");
+ }
+
+ @Test
+ public void testDeleteDatabases() throws IoTDBConnectionException,
StatementExecutionException {
+ session.deleteDatabases(Arrays.asList("root.sg1"));
+ }
+
+ @Test
+ public void testCreateTimeseries() throws IoTDBConnectionException,
StatementExecutionException {
+ String path = "root.device3.humidity";
+ TSDataType dataType = TSDataType.BOOLEAN;
+ TSEncoding encoding = TSEncoding.RLE;
+ CompressionType compressor = CompressionType.SNAPPY;
+ session.createTimeseries(path, dataType, encoding, compressor);
+ }
+
+ @Test
+ public void testCreateMultiTimeseries()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.device3.humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.BOOLEAN);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.RLE);
+ List<CompressionType> compressors = Arrays.asList(CompressionType.SNAPPY);
+ Map<String, String> props = new HashMap<>();
+ List<Map<String, String>> propList = Arrays.asList(props);
+ Map<String, String> tags = new HashMap<>();
+ tags.put("tag1", "vt1");
+ List<Map<String, String>> tagsList = Arrays.asList(tags);
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("att1", "av1");
+ List<Map<String, String>> attributesList = Arrays.asList(attributes);
+ List<String> measurementAliasList = Arrays.asList("atmosphere");
+ session.createMultiTimeseries(
+ paths,
+ dataTypes,
+ encodings,
+ compressors,
+ propList,
+ tagsList,
+ attributesList,
+ measurementAliasList);
+ }
+
+ @Test
+ public void testCheckTimeseriesExists()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.checkTimeseriesExists("root.sg1.d1.s1");
+ }
+
+ @Test
+ public void testSetAndGetQueryTimeout() {
+ long timeoutInMs = 5000l;
+ session.setQueryTimeout(timeoutInMs);
+ long queryTimeout = session.getQueryTimeout();
+ Assert.assertEquals(timeoutInMs, queryTimeout);
+ }
+
+ @Test
+ public void testInsertRecord() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> measurements = Arrays.asList("s1", "s2");
+ List<TSDataType> types = Arrays.asList(TSDataType.TEXT, TSDataType.FLOAT);
+ session.insertRecord("root.sg1.d1", 1691999031779l, measurements, types,
"测试", 22.3f);
+ }
+
+ @Test
+ public void testDeleteTimeseries() throws IoTDBConnectionException,
StatementExecutionException {
+ session.deleteTimeseries("root.sg1.d1.s1");
+ }
+
+ @Test
+ public void testDeleteTimeseriesList()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.deleteTimeseries(Arrays.asList("root.sg1.d1.s1"));
+ }
+
+ @Test
+ public void testInsertAlignedRecord()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> measurements = Arrays.asList("s1", "s2");
+ List<TSDataType> types = Arrays.asList(TSDataType.TEXT, TSDataType.FLOAT);
+ List<Object> values = Arrays.asList("测试", 22.3f);
+ session.insertAlignedRecord("root.sg1.d1", 1691999031779l, measurements,
types, values);
+ List<Object> values0 = Arrays.asList(null, 22.3f);
+ session.insertAlignedRecord("root.sg1.d1", 1691999031779l, measurements,
types, values0);
+ List<String> values1 = Arrays.asList("测试", "22.3f");
+ session.insertAlignedRecord("root.sg1.d1", 1691999031779l, measurements,
values1);
+ List<String> values2 = Arrays.asList("测试");
+ session.insertAlignedRecord("root.sg1.d1", 1691999031779l, measurements,
values2);
+ }
+
+ @Test
+ public void testExecuteQueryStatement()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.executeQueryStatement("show version");
+ }
+
+ @Test
+ public void testExecuteQueryStatementWithTimeout()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.executeQueryStatement("show version", 500l);
+ }
+
+ @Test
+ public void testExecuteNonQueryStatement()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.executeNonQueryStatement(
+ "create timeseries root.温度检测.天气.a002 WITH DATATYPE=text,
ENCODING=PLAIN,DEADBAND=SDT,COMPDEV=2;");
+ }
+
+ @Test
+ public void testExecuteRawDataQuery()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ session.executeRawDataQuery(paths, 2l, 10l, 500l);
+ }
+
+ @Test
+ public void testExecuteLastDataQuery()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ session.executeLastDataQuery(paths, 10l);
+ }
+
+ @Test
+ public void testExecuteLastDataQueryTimeout()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ session.executeLastDataQuery(paths, 10l, 500l);
+ }
+
+ @Test
+ public void testExecuteLastDataQueryWithPaths()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ session.executeLastDataQuery(paths);
+ }
+
+ @Test
+ public void testExecuteAggregationQuery()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE);
+ session.executeAggregationQuery(paths, aggregations);
+ }
+
+ @Test
+ public void testExecuteAggregationQueryWithStartTimeEndTime()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE);
+ session.executeAggregationQuery(paths, aggregations, 2l, 10l);
+ }
+
+ @Test
+ public void testExecuteAggregationQueryWithInterval()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE);
+ session.executeAggregationQuery(paths, aggregations, 2l, 10000l, 5000);
+ }
+
+ @Test
+ public void testExecuteAggregationQueryWithIntervalSlidingStep()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.sg1.d1.s1", "root.sg1.d1.s2");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.LAST_VALUE, TAggregationType.MAX_VALUE);
+ session.executeAggregationQuery(paths, aggregations, 2l, 100000l, 5000,
5000);
+ }
+
+ @Test
+ public void testCreateTimeseriesWithTag()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String path = "root.device3.humidity";
+ TSDataType dataType = TSDataType.BOOLEAN;
+ TSEncoding encoding = TSEncoding.RLE;
+ CompressionType compressor = CompressionType.SNAPPY;
+ Map<String, String> props = new HashMap<>();
+ Map<String, String> tags = new HashMap<>();
+ tags.put("tag1", "vt1");
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("att1", "av1");
+ String measurementAlias = " atmosphere";
+ session.createTimeseries(
+ path, dataType, encoding, compressor, props, tags, attributes,
measurementAlias);
+ }
+
+ @Test
+ public void testCreateAlignedTimeseries()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> measurements = Arrays.asList("temperature", "humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.FLOAT);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.PLAIN,
TSEncoding.PLAIN);
+ List<CompressionType> compressors =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ List<String> measurementAlias = Arrays.asList("atmosphere", "centigrade");
+ session.createAlignedTimeseries(
+ "root.device3", measurements, dataTypes, encodings, compressors,
measurementAlias);
+ }
+
+ @Test
+ public void testCreateAlignedTimeseriesWithTags()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> measurements = Arrays.asList("temperature", "humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.FLOAT);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.PLAIN,
TSEncoding.PLAIN);
+ List<CompressionType> compressors =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ Map<String, String> tags = new HashMap<>();
+ tags.put("tag1", "vt1");
+ List<Map<String, String>> tagsList = Arrays.asList(tags);
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("att1", "av1");
+ List<Map<String, String>> attributesList = Arrays.asList(attributes);
+ List<String> measurementAlias = Arrays.asList("atmosphere", "centigrade");
+ session.createAlignedTimeseries(
+ "root.device3",
+ measurements,
+ dataTypes,
+ encodings,
+ compressors,
+ measurementAlias,
+ tagsList,
+ attributesList);
+ }
+
+ @Test
+ public void testInsertRecordsDirectionException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", true);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L, 3L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertRecords(deviceIds, timeList, measurementsList, valuesList);
+ }
+
+ @Test
+ public void testInsertRecordsNoDirectionException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", false);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L, 3L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertRecords(deviceIds, timeList, measurementsList, valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecordsException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertRecords(deviceIds, timeList, measurementsList, valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecords2Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertRecords(deviceIds, timeList, measurementsList, typesList,
valuesListObj);
+ }
+
+ @Test
+ public void testInsertAlignedRecords()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", false);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L, 6L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
valuesList);
+ }
+
+ @Test
+ public void testInsertAlignedRecordsEnableRedirection()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", true);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L, 6L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertAlignedRecordsException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertAlignedRecordsExceptionEnableRedirection()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertAlignedRecords2Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
typesList, valuesListObj);
+ }
+
+ @Test
+ public void testInsertAlignedRecordsWithTypeException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", true);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L, 7L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
typesList, valuesListObj);
+ }
+
+ @Test
+ public void testInsertAlignedRecordsWithType2Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", false);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L, 7L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
typesList, valuesListObj);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecords5Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesListObj);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecords6Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecords7Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertAlignedRecords(deviceIds, timeList, measurementsList,
typesList, valuesListObj);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecords8Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesListObj);
+ }
+
+ @Test
+ public void testInsertRecordsRawException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L, 3L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertStringRecordsOfOneDevice("device1", timeList,
measurementsList, valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertRecords9Exception()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertStringRecordsOfOneDevice("device1", timeList,
measurementsList, valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertStringRecordsOfOneDeviceSortedException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertStringRecordsOfOneDevice("device1", timeList,
measurementsList, valuesList, true);
+ }
+
+ @Test
+ public void testInsertAlignedRecordsOfOneDeviceRawException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L, 3L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertAlignedRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesListObj);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertAlignedRecordsOfOneDeviceSortedException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.insertAlignedRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesListObj,
false);
+ }
+
+ @Test
+ public void testInsertAlignedStringRecordsOfOneDeviceRaw()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L, 3L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedStringRecordsOfOneDevice(
+ "device1", timeList, measurementsList, valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertAlignedStringRecordsOfOneDeviceException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedStringRecordsOfOneDevice(
+ "device1", timeList, measurementsList, valuesList);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInsertAlignedStringRecordsOfOneDeviceSortedException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.insertAlignedStringRecordsOfOneDevice(
+ "device1", timeList, measurementsList, valuesList, true);
+ }
+
+ @Test
+ public void testTestInsertRecordsException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ session.testInsertRecords(deviceIds, timeList, measurementsList,
valuesList);
+ }
+
+ @Test
+ public void testTestInsertRecordsObjectException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<Object>> valuesListObj =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ session.testInsertRecords(deviceIds, timeList, measurementsList,
typesList, valuesListObj);
+ }
+
+ @Test
+ public void testTestInsertRecordException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.testInsertRecord(
+ "device1", 1L, Arrays.asList("temperature", "humidity"),
Arrays.asList("220.0", "1.5"));
+ }
+
+ @Test
+ public void testTestInsertRecordWithDataTypeException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.testInsertRecord(
+ "device1",
+ 1L,
+ Arrays.asList("temperature", "humidity"),
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(220.0f, 1.5f));
+ }
+
+ @Test
+ public void testDeleteDataException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.deleteData("root.sg1.d1.s1", System.currentTimeMillis());
+ }
+
+ @Test
+ public void testDeleteDataListException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.deleteData(Arrays.asList("root.sg1.d1.s1"),
System.currentTimeMillis());
+ }
+
+ @Test
+ public void testDeleteDataListWithStartTimeAndEndTimeException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.deleteData(
+ Arrays.asList("root.sg1.d1.s1"),
+ System.currentTimeMillis() - 1000 * 60 * 20,
+ System.currentTimeMillis());
+ }
+
+ @Test
+ public void testSetSchemaTemplateException()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.setSchemaTemplate("template1", "prefixPath");
+ }
+
+ @Test
+ public void testInsertTablet() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertTablet(tablet);
+ }
+
+ @Test
+ public void testInsertTabletOutOfOrder()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {5l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertTablet(tablet);
+ }
+
+ @Test
+ public void testInsertAlignedTablet()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.INT32);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ int[][] values = new int[][] {{12, 22}, {14, 34}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertAlignedTablet(tablet);
+ }
+
+ @Test
+ public void testInsertAlignedTablet2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.INT32);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ int[][] values = new int[][] {{12, 22}, {14, 34}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertAlignedTablet(tablet);
+ }
+
+ @Test
+ public void testInsertTabletsSorted()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.INT32);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {2l, 1l};
+ int[][] values = new int[][] {{34, 42}, {40, 42}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertTablets(map);
+ session.insertTablets(map, true);
+ session.insertAlignedTablets(map);
+ session.insertAlignedTablets(map, true);
+ session.testInsertTablet(tablet);
+ session.testInsertTablet(tablet, true);
+ session.testInsertTablets(map);
+ session.testInsertTablets(map, true);
+ }
+
+ @Test
+ public void testInsertAlignedTablets()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.FLOAT);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {2l, 1l};
+ float[][] values = new float[][] {{1.1f, 1.0f}, {1.2f, 1.0f}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertAlignedTablets(map);
+ }
+
+ @Test
+ public void testInsertAlignedTabletsSorted()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.DOUBLE);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {2l, 1l};
+ double[][] values = new double[][] {{22.2, 22.0}, {21.5, 23.0}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertAlignedTablets(map, false);
+ }
+
+ @Test
+ public void testInsertAlignedTabletsSortedEnableRedirection()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Whitebox.setInternalState(session, "enableRedirection", false);
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.TEXT);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {2l, 3l};
+ Binary[][] values =
+ new Binary[][] {
+ {new Binary("test"), new Binary("test2")}, {new Binary("test"), new
Binary("test1")}
+ };
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.insertAlignedTablets(map, false);
+ session.setEnableRedirection(true);
+ Assert.assertEquals(true, session.isEnableRedirection());
+ session.setEnableQueryRedirection(true);
+ Assert.assertEquals(true, session.isEnableQueryRedirection());
+ }
+
+ @Test
+ public void testTestInsertTablet() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.testInsertTablet(tablet);
+ }
+
+ @Test
+ public void testTestInsertTabletSorted()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.testInsertTablet(tablet, true);
+ }
+
+ @Test
+ public void testTestInsertTablets() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.testInsertTablets(map);
+ }
+
+ @Test
+ public void testTestInsertTabletsSorted()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ session.testInsertTablets(map, true);
+ }
+
+ @Test
+ public void testCreateSchemaTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ List<String> measurement = Arrays.asList("root.ut1.temperature",
"root.ut1.humidity");
+ session.createSchemaTemplate(
+ "template4",
+ measurement,
+ Arrays.asList(TSDataType.FLOAT, TSDataType.INT32),
+ Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN),
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY),
+ true);
+ }
+
+ @Test(expected = StatementExecutionException.class)
+ public void testCreateSchemaTemplate2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> schemaNames = Arrays.asList("schema1");
+ List<List<String>> measurements =
+ Arrays.asList(Arrays.asList("root.ut1.temperature",
"root.ut1.humidity"));
+ List<List<TSDataType>> dataTypes =
+ Arrays.asList(Arrays.asList(TSDataType.FLOAT, TSDataType.INT32));
+ List<List<TSEncoding>> encodings =
+ Arrays.asList(Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN));
+ List<CompressionType> compressionTypes =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ session.createSchemaTemplate(
+ "template3", schemaNames, measurements, dataTypes, encodings,
compressionTypes);
+ }
+
+ @Test
+ public void testAddAlignedMeasurementsInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.addAlignedMeasurementsInTemplate(
+ "template1",
+ Arrays.asList("root.sg1.d1.s1"),
+ Arrays.asList(TSDataType.INT64),
+ Arrays.asList(TSEncoding.PLAIN),
+ Arrays.asList(CompressionType.SNAPPY));
+ }
+
+ @Test
+ public void testAddAlignedMeasurementInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.addAlignedMeasurementInTemplate(
+ "template1", "root.sg1.d1.s1", TSDataType.INT64, TSEncoding.PLAIN,
CompressionType.SNAPPY);
+ }
+
+ @Test
+ public void testAddUnalignedMeasurementsInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.addUnalignedMeasurementsInTemplate(
+ "template1",
+ Arrays.asList("root.sg1.d1.s1"),
+ Arrays.asList(TSDataType.INT64),
+ Arrays.asList(TSEncoding.PLAIN),
+ Arrays.asList(CompressionType.SNAPPY));
+ }
+
+ @Test
+ public void testAddUnalignedMeasurementInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.addUnalignedMeasurementInTemplate(
+ "template1", "root.sg1.d1.s1", TSDataType.INT64, TSEncoding.PLAIN,
CompressionType.SNAPPY);
+ }
+
+ @Test
+ public void testDeleteNodeInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.deleteNodeInTemplate("template1", "root.sg1.d1.s1");
+ }
+
+ @Test
+ public void testCountMeasurementsInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.countMeasurementsInTemplate("template1");
+ }
+
+ @Test
+ public void testIsMeasurementInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.isMeasurementInTemplate("template1", "root.sg1.d1.s1");
+ }
+
+ @Test
+ public void testIsPathExistInTemplate()
+ throws IoTDBConnectionException, IOException,
StatementExecutionException {
+ session.isPathExistInTemplate("template1", "root.sg1.d1.s1");
+ }
+
+ @Test
+ public void testShowMeasurementsInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.showMeasurementsInTemplate("template1");
+ }
+
+ @Test
+ public void testShowMeasurementsInTemplatePattern()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.showMeasurementsInTemplate("template1", "root.sg1.**");
+ }
+
+ @Test
+ public void testShowAllTemplates() throws IoTDBConnectionException,
StatementExecutionException {
+ session.showAllTemplates();
+ }
+
+ @Test
+ public void testShowPathsTemplateSetOn()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.showPathsTemplateSetOn("template1");
+ }
+
+ @Test
+ public void testShowPathsTemplateUsingOn()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.showPathsTemplateUsingOn("template1");
+ }
+
+ @Test
+ public void testUnsetSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.unsetSchemaTemplate("root.sg1.d1.**", "template1");
+ }
+
+ @Test
+ public void testDropSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.dropSchemaTemplate("template1");
+ }
+
+ @Test
+ public void testCreateTimeseriesUsingSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.createTimeseriesUsingSchemaTemplate(Arrays.asList("root.sg1.d1",
"root.sg1.d2"));
+ }
+
+ @Test
+ public void testFetchAllConnections() throws IoTDBConnectionException {
+ session.fetchAllConnections();
+ }
+
+ @Test
+ public void testGetBackupConfiguration()
+ throws IoTDBConnectionException, StatementExecutionException {
+ session.getBackupConfiguration();
+ }
+}
diff --git
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolExceptionTest.java
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolExceptionTest.java
new file mode 100644
index 00000000000..e9ea2882b1c
--- /dev/null
+++
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolExceptionTest.java
@@ -0,0 +1,266 @@
+/*
+ * 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.session.pool;
+
+import org.apache.iotdb.isession.ISession;
+import org.apache.iotdb.isession.pool.ISessionPool;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.Session;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.utils.BitMap;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.powermock.reflect.Whitebox;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentLinkedDeque;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class SessionPoolExceptionTest {
+
+ @Mock private ISessionPool sessionPool;
+
+ @Mock private Session session;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ sessionPool = new SessionPool(Arrays.asList("host:11"), "user",
"password", 10);
+ ConcurrentLinkedDeque<ISession> queue = new ConcurrentLinkedDeque<>();
+ queue.add(session);
+ Whitebox.setInternalState(sessionPool, "queue", queue);
+ }
+
+ @After
+ public void tearDown() {
+ // Close the session pool after each test
+ if (null != sessionPool) {
+ sessionPool.close();
+ }
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertRecords() throws Exception {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertRecords(anyList(), anyList(), anyList(), anyList(), anyList());
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertRecords(deviceIds, timeList, measurementsList,
typesList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertTablet() throws IoTDBConnectionException,
StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertTablet(any(Tablet.class), anyBoolean());
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ sessionPool.insertTablet(tablet);
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertTablets() throws IoTDBConnectionException,
StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertTablets(anyMap(), anyBoolean());
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device2", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ sessionPool.insertTablets(map);
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertAlignedRecords()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertAlignedRecords(anyList(), anyList(), anyList(), anyList(),
anyList());
+ List<String> deviceIds = Arrays.asList("alignedDevice3", "alignedDevice4");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertAlignedRecords(deviceIds, timeList, measurementsList,
typesList, valuesList);
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertAlignedTablets()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertAlignedTablets(anyMap(), anyBoolean());
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("alignedDevice2", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ sessionPool.insertAlignedTablets(map);
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertRecordsOfOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertRecordsOfOneDevice(
+ anyString(), anyList(), anyList(), anyList(), anyList(),
anyBoolean());
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesList);
+ }
+
+ @Test(expected = IoTDBConnectionException.class)
+ public void testInsertStringRecordsOfOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertStringRecordsOfOneDevice(anyString(), anyList(), anyList(),
anyList(), anyBoolean());
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", "50.0f"), Arrays.asList("220.0",
"1.5"));
+ sessionPool.insertStringRecordsOfOneDevice("device1", timeList,
measurementsList, valuesList);
+ }
+
+ @Test
+ public void testInsertRecordsOfOneDeviceWithNoSort()
+ throws IoTDBConnectionException, StatementExecutionException {
+ Mockito.doThrow(new IoTDBConnectionException(""))
+ .when(session)
+ .insertRecordsOfOneDevice(anyString(), anyList(), anyList(),
anyList(), anyList());
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesList);
+ }
+
+ @Test
+ public void testInsertRecords2() throws Exception {
+ ConcurrentLinkedDeque<ISession> queue = new ConcurrentLinkedDeque<>();
+ queue.add(session);
+ Whitebox.setInternalState(sessionPool, "queue", queue);
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ try {
+ sessionPool.insertRecords(deviceIds, timeList, measurementsList,
typesList, valuesList);
+ } catch (IoTDBConnectionException e) {
+ assertTrue(e instanceof IoTDBConnectionException);
+ }
+ }
+}
diff --git
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
index 225c5f8000a..7636b4025cc 100644
---
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
+++
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java
@@ -19,11 +19,13 @@
package org.apache.iotdb.session.pool;
+import org.apache.iotdb.common.rpc.thrift.TAggregationType;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.isession.ISession;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.isession.pool.ISessionPool;
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
+import org.apache.iotdb.isession.template.Template;
import org.apache.iotdb.isession.util.Version;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.RpcUtils;
@@ -37,10 +39,16 @@ import
org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp;
import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq;
import org.apache.iotdb.service.rpc.thrift.TSFetchResultsResp;
import org.apache.iotdb.session.Session;
+import org.apache.iotdb.session.template.InternalNode;
+import org.apache.iotdb.session.template.MeasurementNode;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
import org.apache.iotdb.tsfile.read.common.block.column.TsBlockSerde;
+import org.apache.iotdb.tsfile.utils.BitMap;
import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.apache.thrift.TException;
import org.junit.After;
@@ -56,6 +64,7 @@ import org.powermock.reflect.Whitebox;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
@@ -68,6 +77,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -119,6 +129,41 @@ public class SessionPoolTest {
assertEquals(Version.V_1_0, pool.getVersion());
}
+ @Test
+ public void testBuilder2() {
+ SessionPool pool =
+ new SessionPool.Builder()
+ .nodeUrls(Arrays.asList("127.0.0.1:1234"))
+ .maxSize(10)
+ .user("abc")
+ .password("123")
+ .fetchSize(1)
+ .waitToGetSessionTimeoutInMs(2)
+ .enableRedirection(true)
+ .enableCompression(true)
+ .zoneId(ZoneOffset.UTC)
+ .connectionTimeoutInMs(3)
+ .version(Version.V_1_0)
+ .thriftDefaultBufferSize(1024)
+ .thriftMaxFrameSize(67108864)
+ .build();
+
+ assertEquals("abc", pool.getUser());
+ assertEquals("123", pool.getPassword());
+ assertEquals(10, pool.getMaxSize());
+ assertEquals(1, pool.getFetchSize());
+ assertEquals(2, pool.getWaitToGetSessionTimeoutInMs());
+ assertTrue(pool.isEnableRedirection());
+ assertTrue(pool.isEnableCompression());
+ assertEquals(3, pool.getConnectionTimeoutInMs());
+ assertEquals(ZoneOffset.UTC, pool.getZoneId());
+ assertEquals(Version.V_1_0, pool.getVersion());
+ pool.setQueryTimeout(12345);
+ assertEquals(12345, pool.getQueryTimeout());
+ pool.setVersion(Version.V_0_13);
+ assertEquals(Version.V_0_13, pool.getVersion());
+ }
+
@Before
public void setUp() throws IoTDBConnectionException,
StatementExecutionException, TException {
// Initialize the session pool before each test
@@ -138,7 +183,7 @@ public class SessionPoolTest {
TSStatus closeResp = successStatus;
Mockito.when(client.closeOperation(any(TSCloseOperationReq.class))).thenReturn(closeResp);
- sessionPool = new SessionPool("host", 11, "user", "password", 10);
+ sessionPool = new SessionPool("host", 11, "user", "password", 5);
ConcurrentLinkedDeque<ISession> queue = new ConcurrentLinkedDeque<>();
queue.add(session);
@@ -149,7 +194,1221 @@ public class SessionPoolTest {
@After
public void tearDown() {
// Close the session pool after each test
- sessionPool.close();
+ if (null != sessionPool) {
+ sessionPool.close();
+ }
+ }
+
+ @Test
+ public void testInsertTablet() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ sessionPool.insertTablet(tablet);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testFetchSize() {
+ sessionPool.setFetchSize(1000);
+ Assert.assertEquals(1000, sessionPool.getFetchSize());
+ }
+
+ @Test
+ public void testSetEnableRedirection() {
+ sessionPool.setEnableRedirection(false);
+ Assert.assertEquals(false, sessionPool.isEnableRedirection());
+ }
+
+ @Test
+ public void testEnableQueryRedirection() {
+ sessionPool.setEnableQueryRedirection(true);
+ Assert.assertEquals(true, sessionPool.isEnableQueryRedirection());
+ }
+
+ @Test
+ public void testTimeZone() throws IoTDBConnectionException,
StatementExecutionException {
+ String zoneId = ZoneId.systemDefault().getId();
+ sessionPool.setTimeZone(ZoneId.systemDefault().getId());
+ Assert.assertEquals(zoneId, sessionPool.getZoneId().toString());
+ }
+
+ @Test
+ public void testTestInsertTablet1() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ sessionPool.testInsertTablet(tablet);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertTablet2() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ sessionPool.testInsertTablet(tablet, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertTablets() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ sessionPool.testInsertTablets(map);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertTablets2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ boolean[][] values = new boolean[][] {{true, false}, {true, false}};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ sessionPool.testInsertTablets(map, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertRecords() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("11", "12"), Arrays.asList("10", "11"));
+ sessionPool.testInsertRecords(deviceIds, timeList, measurementsList,
valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertRecords2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(11.20, "ssq1"), Arrays.asList(11.21,
"ssq2"));
+ sessionPool.testInsertRecords(deviceIds, timeList, measurementsList,
typesList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertRecord() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionPool.testInsertRecord(
+ "device1", 1L, Arrays.asList("temperature", "humidity"),
Arrays.asList("11", "12"));
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testTestInsertRecord2() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionPool.testInsertRecord(
+ "device1",
+ 1L,
+ Arrays.asList("temperature", "humidity"),
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList("11", "12"));
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedTablet()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("alignedDevice1", schemas, timestamp, values,
partBitMap, 2);
+ sessionPool.insertAlignedTablet(tablet);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertTablets() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device2", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ sessionPool.insertTablets(map);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedTablets()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("alignedDevice2", schemas, timestamp, values,
partBitMap, 2);
+ Map<String, Tablet> map = new HashMap<>();
+ map.put("one", tablet);
+ sessionPool.insertAlignedTablets(map);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedRecords()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("alignedDevice3", "alignedDevice4");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertAlignedRecords(deviceIds, timeList, measurementsList,
typesList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertRecordsOfOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertRecordsOfOneDeviceWithSort()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesList, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertOneRecordsOfOneDevice2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertOneDeviceRecords(
+ "device1", timeList, measurementsList, typesList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertOneRecordsOfOneDevice3()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertOneDeviceRecords(
+ "device1", timeList, measurementsList, typesList, valuesList, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedRecordsOfOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertAlignedRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedRecordsOfOneDevice2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<TSDataType>> typesList =
+ Arrays.asList(
+ Arrays.asList(TSDataType.FLOAT, TSDataType.FLOAT),
+ Arrays.asList(TSDataType.DOUBLE, TSDataType.DOUBLE));
+ List<List<Object>> valuesList =
+ Arrays.asList(Arrays.asList(25.0f, 50.0f), Arrays.asList(220.0, 1.5));
+ sessionPool.insertAlignedRecordsOfOneDevice(
+ "device1", timeList, measurementsList, typesList, valuesList, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertStringRecordsOfOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", "50.0f"), Arrays.asList("220.0",
"1.5"));
+ sessionPool.insertStringRecordsOfOneDevice("device1", timeList,
measurementsList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertStringRecordsOfOneDevice2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", "50.0f"), Arrays.asList("220.0",
"1.5"));
+ sessionPool.insertStringRecordsOfOneDevice(
+ "device1", timeList, measurementsList, valuesList, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedStringRecordsOfOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", "50.0f"), Arrays.asList("220.0",
"1.5"));
+ sessionPool.insertAlignedStringRecordsOfOneDevice(
+ "device1", timeList, measurementsList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedStringRecordsOfOneDevice2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", "50.0f"), Arrays.asList("220.0",
"1.5"));
+ sessionPool.insertAlignedStringRecordsOfOneDevice(
+ "device1", timeList, measurementsList, valuesList, true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertRecords2() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", " 50.0f"), Arrays.asList("220.0",
"1.5"));
+ sessionPool.insertRecords(deviceIds, timeList, measurementsList,
valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedRecords2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> deviceIds = Arrays.asList("device1", "device2");
+ List<Long> timeList = Arrays.asList(1L, 2L);
+ List<List<String>> measurementsList =
+ Arrays.asList(
+ Arrays.asList("temperature", "humidity"), Arrays.asList("voltage",
"current"));
+ List<List<String>> valuesList =
+ Arrays.asList(Arrays.asList("25.0f", " 50.0f"), Arrays.asList("220.0",
"1.5"));
+
+ sessionPool.insertAlignedRecords(deviceIds, timeList, measurementsList,
valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertRecord() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> measurementsList = Arrays.asList("temperature", "humidity");
+ List<TSDataType> typesList = Arrays.asList(TSDataType.DOUBLE,
TSDataType.DOUBLE);
+ sessionPool.insertRecord("device1", 3L, measurementsList, typesList,
"25.0", "50.0");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertRecord2() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> measurementsList = Arrays.asList("temperature", "humidity");
+ List<TSDataType> typesList = Arrays.asList(TSDataType.FLOAT,
TSDataType.FLOAT);
+ List<Object> valuesList = Arrays.asList("25.0f", " 50.0f");
+ sessionPool.insertRecord("device1", 4L, measurementsList, typesList,
valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertRecord3() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> measurementsList = Arrays.asList("temperature", "humidity");
+ List<String> valuesList = Arrays.asList("25.0f", " 50.0f");
+ sessionPool.insertRecord("device1", 4L, measurementsList, valuesList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testGetTimestampPrecision()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.getTimestampPrecision();
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedRecord()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String multiSeriesId = "alignedDevice1";
+ long time = 5L;
+ List<String> multiMeasurementComponents = Arrays.asList("temperature",
"humidity");
+ List<TSDataType> types = Arrays.asList(TSDataType.BOOLEAN,
TSDataType.INT32);
+ List<Object> values = Arrays.asList(true, 11);
+ sessionPool.insertAlignedRecord(multiSeriesId, time,
multiMeasurementComponents, types, values);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testInsertAlignedRecord2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String multiSeriesId = "alignedDevice1";
+ long time = 5L;
+ List<String> multiMeasurementComponents = Arrays.asList("temperature",
"humidity");
+ List<String> values = Arrays.asList("12ws", "11ws");
+ sessionPool.insertAlignedRecord(multiSeriesId, time,
multiMeasurementComponents, values);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteTimeseries() throws IoTDBConnectionException,
StatementExecutionException {
+ String path = "root.device1.temperature";
+ sessionPool.deleteTimeseries(path);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteTimeseriesList()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.device1.temperature",
"root.device1.humidity");
+ sessionPool.deleteTimeseries(paths);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteData() throws IoTDBConnectionException,
StatementExecutionException {
+ String path = "root.device1.temperature";
+ long time = 2L;
+ sessionPool.deleteData(path, time);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteData2() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> paths = Arrays.asList("root.device1.temperature",
"root.device1.humidity");
+ long time = 3L;
+ sessionPool.deleteData(paths, time);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteData3() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> paths = Arrays.asList("root.device1.temperature",
"root.device1.humidity");
+ sessionPool.deleteData(
+ paths, System.currentTimeMillis() - 1000 * 60,
System.currentTimeMillis());
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testSetStorageGroup() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionPool.setStorageGroup("root.device1");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteStorageGroup()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.deleteStorageGroup("root.device1");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteStorageGroups()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> sgs = Arrays.asList("root.device2", "root.device3");
+ sessionPool.deleteStorageGroups(sgs);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateDatabase() throws IoTDBConnectionException,
StatementExecutionException {
+ String database = "root.device1.temperature";
+ sessionPool.createDatabase(database);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteDatabase() throws IoTDBConnectionException,
StatementExecutionException {
+ String path = "root.device2.humidity";
+ sessionPool.deleteDatabase(path);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteDatabase2() throws IoTDBConnectionException,
StatementExecutionException {
+ List<String> paths = Arrays.asList("root.device2.temperature",
"root.device2.humidity");
+ sessionPool.deleteDatabases(paths);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateTimeseries() throws IoTDBConnectionException,
StatementExecutionException {
+ String path = "root.device3.temperature";
+ TSDataType dataType = TSDataType.BOOLEAN;
+ TSEncoding encoding = TSEncoding.RLE;
+ CompressionType compressor = CompressionType.SNAPPY;
+ sessionPool.createTimeseries(path, dataType, encoding, compressor);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateTimeseries2() throws IoTDBConnectionException,
StatementExecutionException {
+ String path = "root.device3.humidity";
+ TSDataType dataType = TSDataType.BOOLEAN;
+ TSEncoding encoding = TSEncoding.RLE;
+ CompressionType compressor = CompressionType.SNAPPY;
+ Map<String, String> props = new HashMap<>();
+ Map<String, String> tags = new HashMap<>();
+ tags.put("tag1", "vt1");
+ Map<String, String> attributes = new HashMap<>();
+ attributes.put("att1", "av1");
+ String measurementAlias = " atmosphere";
+ sessionPool.createTimeseries(
+ path, dataType, encoding, compressor, props, tags, attributes,
measurementAlias);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateAlignedTimeseries()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String deviceId = "device4";
+ List<String> measurements = Arrays.asList("temperature", "humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.INT32);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.RLE, TSEncoding.RLE);
+ List<CompressionType> compressors =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ List<String> measurementAlias = Arrays.asList("centigrade degree",
"atmosphere");
+ sessionPool.createAlignedTimeseries(
+ deviceId, measurements, dataTypes, encodings, compressors,
measurementAlias);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateAlignedTimeseries2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String deviceId = "device4";
+ List<String> measurements = Arrays.asList("temperature", "humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.INT32);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.RLE, TSEncoding.RLE);
+ List<CompressionType> compressors =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ List<String> measurementAlias = Arrays.asList("centigrade degree",
"atmosphere");
+ Map<String, String> tagMap = new HashMap<>();
+ tagMap.put("tag1", "v1");
+ Map<String, String> tagMap2 = new HashMap<>();
+ tagMap2.put("tag2", "v2");
+ Map<String, String> attrMap = new HashMap<>();
+ attrMap.put("attr1", "vt1");
+ Map<String, String> attrMap2 = new HashMap<>();
+ attrMap2.put("attr2", "vt2");
+ List<Map<String, String>> tags = Arrays.asList(tagMap, tagMap2);
+ List<Map<String, String>> attrs = Arrays.asList(attrMap, attrMap2);
+ sessionPool.createAlignedTimeseries(
+ deviceId, measurements, dataTypes, encodings, compressors,
measurementAlias, tags, attrs);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateMultiTimeseries()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.device5.temperature",
"root.device5.humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.INT32);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.RLE, TSEncoding.RLE);
+ List<CompressionType> compressors =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ List<Map<String, String>> propsList = new ArrayList<>();
+ List<Map<String, String>> tagsList = Arrays.asList();
+ List<Map<String, String>> attributesList = Arrays.asList();
+ List<String> measurementAliasList = Arrays.asList("centigrade degree",
"atmosphere");
+ sessionPool.createMultiTimeseries(
+ paths,
+ dataTypes,
+ encodings,
+ compressors,
+ propsList,
+ tagsList,
+ attributesList,
+ measurementAliasList);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCheckTimeseriesExists()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String path = "root.device5.temperature";
+ sessionPool.checkTimeseriesExists(path);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ Template templateShareTime = new Template("template1", true);
+ MeasurementNode measurementNode =
+ new MeasurementNode(
+ "root.ut0.sensor1",
+ Enum.valueOf(TSDataType.class, "INT32"),
+ Enum.valueOf(TSEncoding.class, "PLAIN"),
+ Enum.valueOf(CompressionType.class, "SNAPPY"));
+ templateShareTime.addToTemplate(measurementNode);
+ sessionPool.createSchemaTemplate(templateShareTime);
+ Template template = new Template("template2", false);
+ measurementNode =
+ new MeasurementNode(
+ "root.ut0.sensor2",
+ Enum.valueOf(TSDataType.class, "FLOAT"),
+ Enum.valueOf(TSEncoding.class, "PLAIN"),
+ Enum.valueOf(CompressionType.class, "SNAPPY"));
+ template.addToTemplate(measurementNode);
+ sessionPool.createSchemaTemplate(template);
+
+ template = new Template("template1");
+ InternalNode iNodeVector = new InternalNode("vector", true);
+ MeasurementNode mNodeS1 =
+ new MeasurementNode("s1", TSDataType.INT64, TSEncoding.RLE,
CompressionType.SNAPPY);
+ MeasurementNode mNodeS2 =
+ new MeasurementNode("s2", TSDataType.INT32, TSEncoding.RLE,
CompressionType.SNAPPY);
+ iNodeVector.addChild(mNodeS1);
+ iNodeVector.addChild(mNodeS2);
+ template.addToTemplate(iNodeVector);
+ sessionPool.createSchemaTemplate(template);
+ assertEquals(2, iNodeVector.getChildren().size());
+ assertEquals(false, iNodeVector.getChildren().get("s1").isShareTime());
+ iNodeVector.deleteChild(iNodeVector);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateSchemaTemplate2()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ List<String> measurements = Arrays.asList("root.ut.temperature",
"root.ut.humidity");
+ List<String> measurements1 = Arrays.asList("root.ut1.temperature",
"root.ut1.humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.INT32);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.PLAIN,
TSEncoding.PLAIN);
+ List<CompressionType> compressionTypes =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ sessionPool.createSchemaTemplate(
+ "template3", measurements, dataTypes, encodings, compressionTypes,
false);
+ sessionPool.createSchemaTemplate(
+ "template4", measurements1, dataTypes, encodings, compressionTypes,
true);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateSchemaTemplate3()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ List<String> schemaNames = Arrays.asList("schema1");
+ List<List<String>> measurements =
+ Arrays.asList(Arrays.asList("root.ut1.temperature",
"root.ut1.humidity"));
+ List<List<TSDataType>> dataTypes =
+ Arrays.asList(Arrays.asList(TSDataType.FLOAT, TSDataType.INT32));
+ List<List<TSEncoding>> encodings =
+ Arrays.asList(Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN));
+ List<CompressionType> compressionTypes =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ sessionPool.createSchemaTemplate(
+ "template3", schemaNames, measurements, dataTypes, encodings,
compressionTypes);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testAddAlignedMeasurementsInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ List<String> measurements = Arrays.asList("root.ut2.temperature",
"root.ut2.humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.INT32);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.PLAIN,
TSEncoding.PLAIN);
+ List<CompressionType> compressionTypes =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ sessionPool.addAlignedMeasurementsInTemplate(
+ "template3", measurements, dataTypes, encodings, compressionTypes);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testAddAlignedMeasurementInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ sessionPool.addAlignedMeasurementInTemplate(
+ "template4",
+ "root.ut3.temperature",
+ TSDataType.FLOAT,
+ TSEncoding.PLAIN,
+ CompressionType.SNAPPY);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testAddUnalignedMeasurementsInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ List<String> measurements = Arrays.asList("root.ut4.temperature",
"root.ut4.humidity");
+ List<TSDataType> dataTypes = Arrays.asList(TSDataType.FLOAT,
TSDataType.INT32);
+ List<TSEncoding> encodings = Arrays.asList(TSEncoding.PLAIN,
TSEncoding.PLAIN);
+ List<CompressionType> compressionTypes =
+ Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY);
+ sessionPool.addUnalignedMeasurementsInTemplate(
+ "template5", measurements, dataTypes, encodings, compressionTypes);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testAddUnalignedMeasurementInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ sessionPool.addUnalignedMeasurementInTemplate(
+ "template5",
+ "root.ut5.temperature",
+ TSDataType.TEXT,
+ TSEncoding.PLAIN,
+ CompressionType.SNAPPY);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDeleteNodeInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException,
IOException {
+ sessionPool.deleteNodeInTemplate("template1", "root.ut0.sensor1");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCountMeasurementsInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.countMeasurementsInTemplate("template2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testIsMeasurementInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.isMeasurementInTemplate("template2", "root.ut0.sensor2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testIsPathExistInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.isPathExistInTemplate("template2", "root.ut0.sensor2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testShowMeasurementsInTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.showMeasurementsInTemplate("template2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testShowMeasurementsInTemplate2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.showMeasurementsInTemplate("template2", "root.ut0.**");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testShowAllTemplates() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionPool.showAllTemplates();
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testShowPathsTemplateSetOn()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.showPathsTemplateSetOn("template2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testShowPathsTemplateUsingOn()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.showPathsTemplateUsingOn("template2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testSortTablet() throws IoTDBConnectionException,
StatementExecutionException {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device", schemas, timestamp, values,
partBitMap, 2);
+ sessionPool.sortTablet(tablet);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testSetSchemaTemplate() throws IoTDBConnectionException,
StatementExecutionException {
+ sessionPool.setSchemaTemplate("template2", "root.ut0.sensor2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testUnSetSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.unsetSchemaTemplate("root.ut0.sensor2", "template2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testDropSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.dropSchemaTemplate("template2");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testCreateTimeseriesUsingSchemaTemplate()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> devicePaths = Arrays.asList("root.ut3", "root.ut4");
+ sessionPool.createTimeseriesUsingSchemaTemplate(devicePaths);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteQueryStatement2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ String sql = "show version";
+ SessionDataSetWrapper sessionDataSetWrapper = null;
+ SessionDataSet sessionDataSet =
+ new SessionDataSet(
+ sql,
+ execResp.getColumns(),
+ execResp.getDataTypeList(),
+ null,
+ queryId,
+ statementId,
+ client,
+ 0,
+ execResp.queryResult,
+ true,
+ 10,
+ true,
+ 10);
+ Mockito.when(session.executeQueryStatement(any(String.class), eq(50)))
+ .thenReturn(sessionDataSet);
+ sessionDataSetWrapper = sessionPool.executeQueryStatement(sql, 50);
+ sessionDataSetWrapper.setSessionDataSet(sessionDataSet);
+ sessionPool.closeResultSet(sessionDataSetWrapper);
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteQueryStatement3()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.executeQueryStatement("show version");
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteNonQueryStatement()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.executeNonQueryStatement(
+ "create timeseries root.test.g_0.d_7815.s_7818 WITH datatype=boolean,
encoding=PLAIN");
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteRawDataQuery()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.test.g_0.d_7815.s_7818");
+ sessionPool.executeRawDataQuery(
+ paths, System.currentTimeMillis() - 1000 * 60 * 24l,
System.currentTimeMillis(), 50);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteLastDataQuery()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.test.g_0.d_7815.s_7818");
+ sessionPool.executeLastDataQuery(paths, System.currentTimeMillis() - 1000
* 60 * 24l);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteLastDataQuery2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.test.g_0.d_7815.s_7818");
+ sessionPool.executeLastDataQuery(paths);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteLastDataQuery3()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("root.test.g_0.d_7815.s_7818");
+ sessionPool.executeLastDataQuery(paths, System.currentTimeMillis() - 1000
* 60 * 24l, 50);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteLastDataQueryForOneDevice()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("s_7817", "s_7818");
+ sessionPool.executeLastDataQueryForOneDevice(
+ "root.test.g_0", "root.test.g_0.d_7818", paths, true);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteAggregationQuery()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("s_7817", "s_7818");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.MAX_VALUE, TAggregationType.LAST_VALUE);
+ sessionPool.executeAggregationQuery(paths, aggregations);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteAggregationQuery2()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("s_7817", "s_7818");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.MAX_VALUE, TAggregationType.LAST_VALUE);
+ sessionPool.executeAggregationQuery(
+ paths,
+ aggregations,
+ System.currentTimeMillis() - 1000 * 60 * 24l,
+ System.currentTimeMillis(),
+ 500);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testExecuteAggregationQuery3()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("s_7817", "s_7818");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.MAX_VALUE, TAggregationType.LAST_VALUE);
+ sessionPool.executeAggregationQuery(
+ paths,
+ aggregations,
+ System.currentTimeMillis() - 1000 * 60 * 24l,
+ System.currentTimeMillis());
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testEexecuteAggregationQuery4()
+ throws IoTDBConnectionException, StatementExecutionException {
+ List<String> paths = Arrays.asList("s_7817", "s_7818");
+ List<TAggregationType> aggregations =
+ Arrays.asList(TAggregationType.MAX_VALUE, TAggregationType.LAST_VALUE);
+ sessionPool.executeAggregationQuery(
+ paths,
+ aggregations,
+ System.currentTimeMillis() - 1000 * 60 * 24l,
+ System.currentTimeMillis(),
+ 500,
+ 500 * 1000);
+ assertEquals(
+ 0,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testFetchAllConnections() throws IoTDBConnectionException {
+ sessionPool.fetchAllConnections();
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
+ }
+
+ @Test
+ public void testGetBackupConfiguration()
+ throws IoTDBConnectionException, StatementExecutionException {
+ sessionPool.getBackupConfiguration();
+ assertEquals(
+ 1,
+ ((ConcurrentLinkedDeque<ISession>)
Whitebox.getInternalState(sessionPool, "queue")).size());
}
@Test(expected = StatementExecutionException.class)
@@ -256,6 +1515,7 @@ public class SessionPoolTest {
}
result.append("\n");
}
+ sessionDataSetWrapper.close();
String exResult =
"root.vehicle.d0.s2,root.vehicle.d0.s1,root.vehicle.d0.s0,root.vehicle.d0.s2\n"
+ "FLOAT,INT64,INT32,FLOAT\n"
diff --git
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/util/SessionUtilsTest.java
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/util/SessionUtilsTest.java
new file mode 100644
index 00000000000..bc678a42c38
--- /dev/null
+++
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/util/SessionUtilsTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.session.util;
+
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.utils.BitMap;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SessionUtilsTest {
+
+ @Test
+ public void testGetTimeBuffer() {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ long[] timestamp = new long[] {1l, 2l};
+ Object[] values = new Object[] {true, false};
+ BitMap[] partBitMap = new BitMap[2];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ ByteBuffer timeBuffer = SessionUtils.getTimeBuffer(tablet);
+ Assert.assertNotNull(timeBuffer);
+ }
+
+ @Test
+ public void testGetValueBuffer() {
+ List<MeasurementSchema> schemas = new ArrayList<>();
+ MeasurementSchema schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.INT32);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.INT64);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.FLOAT);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.DOUBLE);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.TEXT);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+ schema = new MeasurementSchema();
+ schema.setMeasurementId("pressure");
+ schema.setType(TSDataType.BOOLEAN);
+ schema.setCompressor(CompressionType.SNAPPY.serialize());
+ schema.setEncoding(TSEncoding.PLAIN.serialize());
+ schemas.add(schema);
+
+ long[] timestamp = new long[] {1l};
+ Object[] values = new Object[6];
+ values[0] = new int[] {1, 2};
+ values[1] = new long[] {1l, 2l};
+ values[2] = new float[] {1.1f, 1.2f};
+ values[3] = new double[] {0.707, 0.708};
+ values[4] =
+ new Binary[] {new Binary(new byte[] {(byte) 8}), new Binary(new byte[]
{(byte) 16})};
+ values[5] = new boolean[] {true, false};
+ BitMap[] partBitMap = new BitMap[6];
+ Tablet tablet = new Tablet("device1", schemas, timestamp, values,
partBitMap, 2);
+ ByteBuffer timeBuffer = SessionUtils.getValueBuffer(tablet);
+ Assert.assertNotNull(timeBuffer);
+ }
+
+ @Test
+ public void testGetValueBuffer2() throws IoTDBConnectionException {
+ List<Object> valueList = Arrays.asList(12, 13l, 1.2f, 0.707, "test",
false);
+ List<TSDataType> typeList =
+ Arrays.asList(
+ TSDataType.INT32,
+ TSDataType.INT64,
+ TSDataType.FLOAT,
+ TSDataType.DOUBLE,
+ TSDataType.TEXT,
+ TSDataType.BOOLEAN);
+ ByteBuffer timeBuffer = SessionUtils.getValueBuffer(typeList, valueList);
+ Assert.assertNotNull(timeBuffer);
+
+ valueList = new ArrayList<>();
+ valueList.add(null);
+ typeList = Arrays.asList(TSDataType.INT32);
+ timeBuffer = SessionUtils.getValueBuffer(typeList, valueList);
+ Assert.assertNotNull(timeBuffer);
+
+ valueList = Arrays.asList(false);
+ typeList = Arrays.asList(TSDataType.UNKNOWN);
+ try {
+ timeBuffer = SessionUtils.getValueBuffer(typeList, valueList);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof IoTDBConnectionException);
+ }
+ }
+
+ @Test
+ public void testParseSeedNodeUrls() {
+ List<String> nodeUrls = Arrays.asList("127.0.0.1:1234");
+ List<TEndPoint> tEndPoints = SessionUtils.parseSeedNodeUrls(nodeUrls);
+ Assert.assertEquals(tEndPoints.size(), 1);
+
+ try {
+ tEndPoints = SessionUtils.parseSeedNodeUrls(null);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NumberFormatException);
+ }
+
+ nodeUrls = Arrays.asList("127.0.0.1:1234:0");
+ try {
+ tEndPoints = SessionUtils.parseSeedNodeUrls(nodeUrls);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NumberFormatException);
+ }
+
+ nodeUrls = Arrays.asList("127.0.0.1:test");
+ try {
+ tEndPoints = SessionUtils.parseSeedNodeUrls(nodeUrls);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NumberFormatException);
+ }
+ }
+
+ @Test
+ public void testParseSeedNodeUrlsException() {
+ List<String> nodeUrls = Arrays.asList("127.0.0.1:1234");
+ List<TEndPoint> tEndPoints = SessionUtils.parseSeedNodeUrls(nodeUrls);
+ Assert.assertEquals(tEndPoints.size(), 1);
+ }
+}