@Test
  public void do_test()
      throws InterruptedException,
          TException,
          IoTDBConnectionException,
          IOException,
          StatementExecutionException {
    Thread.sleep(1000);
    // Write data before subscribing
    session_src.executeNonQueryStatement(
        "insert into "
            + device
            + "(time,s_0,s_1)values(1710288000000,313,'2024-03-13 08:00:00+08:00');"); // 2024-03-13
    // 08:00:00+08:00
    insert_data(1706659200000L, device); // 2024-01-31 08:00:00+08:00
    insert_data(1706659200000L, device2); // 2024-01-31 08:00:00+08:00
    // Subscribe
    consumer = create_pull_consumer("multi_tsfile_2topic", "1_consumer", false, null);
    System.out.println("###### Subscription Query Before:");
    subs.getSubscriptions().forEach((System.out::println));
    assertEquals(subs.getSubscriptions().size(), 0, "Before subscription show subscriptions");
    consumer.subscribe(topicName, topicName2);
    System.out.println("###### Subscribe and query:");
    subs.getSubscriptions().forEach((System.out::println));
    assertEquals(subs.getSubscriptions().size(), 2, "subscribe then show subscriptions");

    final AtomicInteger rowCount = new AtomicInteger();
    Thread thread1 =
        new Thread(
            () -> {
              List<String> devices = new ArrayList<>(2);
              devices.add(device);
              devices.add(device2);
              try {
                List<Integer> results = consume_tsfile(consumer, devices);
                System.out.println(results);
                rowCount.addAndGet(results.get(0));
                rowCount.addAndGet(results.get(1));
              } catch (InterruptedException e) {
                throw new RuntimeException(e);
              }
            });
    thread1.start();
    // Subscribe and then write data
    Thread thread =
        new Thread(
            () -> {
              long timestamp = System.currentTimeMillis();
              for (int i = 0; i < 20; i++) {
                try {
                  insert_data(timestamp, device);
                  insert_data(timestamp, device2);
                  timestamp += 30000;
                } catch (Exception e) {
                  throw new RuntimeException(e);
                }
              }
            });
    thread.start();
    thread.join();
    thread1.join();

    System.out.println(
        "src insert " + device + " :" + getCount(session_src, "select count(s_0) from " + device));
    System.out.println(
        "src insert "
            + device2
            + " :"
            + getCount(session_src, "select count(s_0) from " + device2));
    assertEquals(rowCount.get(), 200, "After first consumption");
    // Unsubscribe
    consumer.unsubscribe(topicName);
    System.out.println("###### After cancellation query:");
    subs.getSubscriptions(topicName).forEach((System.out::println));
    assertEquals(
        subs.getSubscriptions(topicName).size(), 0, "Unsubscribe 1 and then show subscriptions");

    // Unsubscribe and then write data
    insert_data(System.currentTimeMillis(), device2);
    int result = consume_tsfile(consumer, device2);
    session_src.executeNonQueryStatement(
        "insert into "
            + device
            + "(time,s_0,s_1)values(1703980800000,3.45,'2023-12-31 08:00:00+08:00');"); // 2023-12-31 08:00:00+08:00
    assertEquals(result, 5, "After the second consumption");

    // close
    consumer.close();
    try {
      consumer.subscribe(topicName, topicName2);
    } catch (Exception e) {
      System.out.println("subscribe again after close, expecting an exception");
    }
    assertEquals(subs.getSubscriptions(topicName).size(), 0, "show subscriptions after close");
    subs.getSubscriptions(topicName).forEach((System.out::println));
  }
1 consumer subscribes to 2 topics: historical data
integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pullconsumer/multi/IoTDBOneConsumerMultiTopicsTsfileIT.java