HTHou commented on code in PR #13550:
URL: https://github.com/apache/iotdb/pull/13550#discussion_r1776324075


##########
iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionCacheLeaderTest.java:
##########
@@ -931,6 +1025,161 @@ public void testInsertTabletsWithSessionBroken() throws 
StatementExecutionExcept
     }
   }
 
+  @Test
+  public void testInsertRelationalTabletWithSessionBroken() throws 
StatementExecutionException {
+    // without leader cache
+    session = new MockSession("127.0.0.1", 55560, false, "table");
+    try {
+      session.open();
+    } catch (IoTDBConnectionException e) {
+      Assert.fail(e.getMessage());
+    }
+    assertNull(session.tableModelDeviceIdToEndpoint);
+    assertNull(session.endPointToSessionConnection);
+
+    // set the session connection as broken
+    ((MockSession) 
session).getLastConstructedSessionConnection().setConnectionBroken(true);
+
+    String tableName = "table1";
+    List<IMeasurementSchema> schemaList = new ArrayList<>();
+    List<ColumnType> columnTypeList = new ArrayList<>();
+    schemaList.add(new MeasurementSchema("id", TSDataType.STRING));
+    schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
+    schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
+    columnTypeList.add(ColumnType.ID);
+    columnTypeList.add(ColumnType.MEASUREMENT);
+    columnTypeList.add(ColumnType.MEASUREMENT);
+    Tablet tablet = new Tablet(tableName, schemaList, columnTypeList, 50);
+    long timestamp = System.currentTimeMillis();
+    for (long row = 0; row < 100; row++) {
+      int rowIndex = tablet.rowSize++;
+      tablet.addTimestamp(rowIndex, timestamp);
+      tablet.addValue(schemaList.get(0).getMeasurementId(), rowIndex, "id" + 
(rowIndex % 4));
+      for (int s = 1; s < 3; s++) {
+        long value = new Random().nextLong();
+        tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value);
+      }
+
+      if (tablet.rowSize == tablet.getMaxRowNumber()) {
+        try {
+          session.insertRelationalTablet(tablet);
+        } catch (IoTDBConnectionException e) {
+          assertEquals(
+              "the session connection = TEndPoint(ip:127.0.0.1, port:55560) is 
broken",
+              e.getMessage());
+        }
+        tablet.reset();
+      }
+      timestamp++;
+    }
+
+    if (tablet.rowSize != 0) {
+      try {
+        session.insertRelationalTablet(tablet);
+      } catch (IoTDBConnectionException e) {
+        assertEquals(
+            "the session connection = TEndPoint(ip:127.0.0.1, port:55560) is 
broken",
+            e.getMessage());
+      }
+      tablet.reset();
+    }
+
+    assertNull(session.tableModelDeviceIdToEndpoint);
+    assertNull(session.endPointToSessionConnection);
+    try {
+      session.close();
+    } catch (IoTDBConnectionException e) {
+      Assert.fail(e.getMessage());
+    }
+
+    // with leader cache
+    // rest the session connection
+    session = new MockSession("127.0.0.1", 55560, true, "table");
+    try {
+      session.open();
+    } catch (IoTDBConnectionException e) {
+      Assert.fail(e.getMessage());
+    }
+    assertEquals(0, session.tableModelDeviceIdToEndpoint.size());
+    assertEquals(1, session.endPointToSessionConnection.size());
+
+    for (long row = 0; row < 100; row++) {
+      int rowIndex = tablet.rowSize++;
+      tablet.addTimestamp(rowIndex, timestamp);
+      tablet.addValue(schemaList.get(0).getMeasurementId(), rowIndex, "id" + 
(rowIndex % 4));
+      for (int s = 1; s < 3; s++) {
+        long value = new Random().nextLong();
+        tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value);
+      }
+
+      if (tablet.rowSize == tablet.getMaxRowNumber()) {
+        try {
+          session.insertRelationalTablet(tablet);
+        } catch (IoTDBConnectionException e) {
+          assertEquals(
+              "the session connection = TEndPoint(ip:127.0.0.1, port:55560) is 
broken",
+              e.getMessage());
+        }
+        tablet.reset();
+      }
+      timestamp++;
+    }
+
+    // set the session connection as broken
+    ((MockSession) 
session).getLastConstructedSessionConnection().setConnectionBroken(true);
+    // set connection as broken, due to we enable the cache leader, when we 
called
+    // ((MockSession) session).getLastConstructedSessionConnection(), the 
session's endpoint has
+    // been changed to EndPoint(ip:127.0.0.1, port:55562)
+    Assert.assertEquals(
+        "MockSessionConnection{ endPoint=TEndPoint(ip:127.0.0.1, port:55562)}",
+        ((MockSession) 
session).getLastConstructedSessionConnection().toString());
+
+    for (long row = 0; row < 100; row++) {
+      int rowIndex = tablet.rowSize++;
+      tablet.addTimestamp(rowIndex, timestamp);
+      tablet.addValue(schemaList.get(0).getMeasurementId(), rowIndex, "id" + 
(rowIndex % 4));
+      for (int s = 1; s < 3; s++) {
+        long value = new Random().nextLong();
+        tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, value);
+      }
+
+      if (tablet.rowSize == tablet.getMaxRowNumber()) {
+        try {
+          session.insertRelationalTablet(tablet);
+        } catch (IoTDBConnectionException e) {
+          assertEquals(
+              "the session connection = TEndPoint(ip:127.0.0.1, port:55560) is 
broken",
+              e.getMessage());
+        }

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to