@Test
  public void do_test()
      throws InterruptedException,
          TException,
          IoTDBConnectionException,
          IOException,
          StatementExecutionException {
    final AtomicInteger onReceive = new AtomicInteger(0);
    List<AtomicInteger> rowCounts = new ArrayList<>(2);
    rowCounts.add(new AtomicInteger(0));
    rowCounts.add(new AtomicInteger(0));

    List<Path> paths = new ArrayList<>(2);
    paths.add(new Path(device, "s_0", true));
    paths.add(new Path(device2, "s_0", true));

    String sql =
        "select count(s_0) from "
            + device
            + " where time >= 2024-01-01T00:00:00+08:00 and time <= 2024-03-31T00:00:00+08:00";

    // Write data before subscribing
    insert_data(1704038396000L, device); // 2023-12-31 23:59:56+08:00
    insert_data(1704038396000L, device2); // 2023-12-31 23:59:56+08:00
    session_src.executeNonQueryStatement("flush");
    consumer =
        new SubscriptionTreePushConsumer.Builder()
            .host(SRC_HOST)
            .port(SRC_PORT)
            .consumerId("time_range_accurate_device_tsfile_push")
            .consumerGroupId("loose_range_path")
            .ackStrategy(AckStrategy.AFTER_CONSUME)
            .fileSaveDir("target/push-subscription")
            .consumeListener(
                message -> {
                  try {
                    onReceive.addAndGet(1);
                    TsFileReader reader = message.getTsFileHandler().openReader();
                    for (int i = 0; i < 2; i++) {
                      QueryDataSet dataset =
                          reader.query(
                              QueryExpression.create(
                                  Collections.singletonList(paths.get(i)), null));
                      while (dataset.hasNext()) {
                        rowCounts.get(i).addAndGet(1);
                        RowRecord next = dataset.next();
                        System.out.println(next.getTimestamp() + "," + next.getFields());
                      }
                    }

                  } catch (IOException e) {
                    throw new RuntimeException(e);
                  }
                  return ConsumeResult.SUCCESS;
                })
            .buildPushConsumer();
    consumer.open();
    // Subscribe
    consumer.subscribe(topicName);
    subs.getSubscriptions().forEach(System.out::println);
    assertEquals(subs.getSubscriptions().size(), 1, "show subscriptions after subscription");
    System.out.println(FORMAT.format(new Date()) + " src :" + getCount(session_src, sql));

    AWAIT.untilAsserted(
        () -> {
          assertGte(onReceive.get(), 1);
          assertGte(rowCounts.get(0).get(), 3, "Write data before subscription" + device);
          assertGte(rowCounts.get(0).get(), 3, "Write data before subscription" + device2);
        });

    insert_data(System.currentTimeMillis(), device); // now, not in range
    insert_data(System.currentTimeMillis(), device2); // now, not in range
    session_src.executeNonQueryStatement("flush");
    System.out.println(FORMAT.format(new Date()) + " src :" + getCount(session_src, sql));

    AWAIT.untilAsserted(
        () -> {
          assertGte(onReceive.get(), 1);
          assertGte(rowCounts.get(0).get(), 3, "Write out-of-range data" + device);
          assertGte(rowCounts.get(0).get(), 3, "Write out-of-range data" + device2);
        });

    insert_data(1707782400000L, device); // 2024-02-13 08:00:00+08:00
    insert_data(1707782400000L, device2); // 2024-02-13 08:00:00+08:00
    session_src.executeNonQueryStatement("flush");
    System.out.println(FORMAT.format(new Date()) + " src :" + getCount(session_src, sql));

    AWAIT.untilAsserted(
        () -> {
          assertGte(onReceive.get(), 2);
          assertGte(rowCounts.get(0).get(), 8, "write data" + device);
          assertGte(rowCounts.get(0).get(), 8, "write data " + device2);
        });

    insert_data(1711814398000L, device); // 2024-03-30 23:59:58+08:00
    insert_data(1711814398000L, device2); // 2024-03-30 23:59:58+08:00
    session_src.executeNonQueryStatement("flush");
    System.out.println(FORMAT.format(new Date()) + " src :" + getCount(session_src, sql));

    AWAIT.untilAsserted(
        () -> {
          assertGte(onReceive.get(), 3);
          assertGte(rowCounts.get(0).get(), 10, "Write data: end boundary at " + device);
          assertGte(rowCounts.get(0).get(), 10, "Write data: end boundary at " + device2);
        });

    insert_data(1711900798000L, device); // 2024-03-31 23:59:58+08:00
    insert_data(1711900798000L, device2); // 2024-03-31 23:59:58+08:00
    System.out.println(FORMAT.format(new Date()) + " src :" + getCount(session_src, sql));

    AWAIT.untilAsserted(
        () -> {
          assertGte(onReceive.get(), 3);
          assertGte(rowCounts.get(0).get(), 10, "Write data: > end " + device);
          assertGte(rowCounts.get(0).get(), 10, "Write data: > end " + device2);
        });
  }
loose range: path
pattern: device
push consumer
integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/loose_range/IoTDBPathLooseDeviceTsfilePushConsumerIT.java