@Test
  public void testGetMatchedDevices() throws Exception {
    final ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);

    SchemaRegionTestUtil.createSimpleTimeSeriesByList(
        schemaRegion,
        Arrays.asList(
            "root.laptop.d0",
            "root.laptop.d1.s1",
            "root.laptop.d1.s2.t1",
            "root.laptop.d1.s3",
            "root.laptop.d2.s1",
            "root.laptop.d2.s2"));

    // CASE 01. Query a timeseries, result should be empty set.
    Assert.assertEquals(
        Collections.emptyList(),
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.laptop.d0")));

    // CASE 02. Query an existing device.
    Assert.assertEquals(
        Collections.singletonList(new ShowDevicesResult("root.laptop.d1", false, -1)),
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.laptop.d1")));
    Assert.assertEquals(
        Collections.singletonList(new ShowDevicesResult("root.laptop.d2", false, -1)),
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.laptop.d2")));

    // CASE 03. Query an existing device, which has a sub device
    Assert.assertEquals(
        Collections.singletonList(new ShowDevicesResult("root.laptop", false, -1)),
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.laptop")));

    // CASE 04. Query devices using '*'
    Assert.assertEquals(
        Collections.singletonList(new ShowDevicesResult("root.laptop", false, -1)),
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.*")));

    // CASE 05. Query all devices using 'root.**'
    List<IDeviceSchemaInfo> expectedList =
        Arrays.asList(
            new ShowDevicesResult("root.laptop", false, -1),
            new ShowDevicesResult("root.laptop.d1", false, -1),
            new ShowDevicesResult("root.laptop.d2", false, -1),
            new ShowDevicesResult("root.laptop.d1.s2", false, -1));
    List<IDeviceSchemaInfo> actualResult =
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.**"));
    // Compare hash sets because the order does not matter.
    HashSet<IDeviceSchemaInfo> expectedHashset = new HashSet<>(expectedList);
    HashSet<IDeviceSchemaInfo> actualHashset = new HashSet<>(actualResult);
    Assert.assertEquals(expectedHashset, actualHashset);

    // CASE 06. show devices root.**.d*
    expectedList =
        Arrays.asList(
            new ShowDevicesResult("root.laptop.d1", false, -1),
            new ShowDevicesResult("root.laptop.d2", false, -1));
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(schemaRegion, new PartialPath("root.**.d*"));
    // Compare hash sets because the order does not matter.
    expectedHashset = new HashSet<>(expectedList);
    actualHashset = new HashSet<>(actualResult);
    Assert.assertEquals(expectedHashset, actualHashset);

    // CASE 07. show devices root.** limit 3 offset 0
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(
            schemaRegion, new PartialPath("root.**"), 3, 0, false);
    Assert.assertEquals(3, actualResult.size());
    // CASE 08. show devices root.** limit 3 offset 1
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(
            schemaRegion, new PartialPath("root.**"), 3, 1, false);
    Assert.assertEquals(3, actualResult.size());
    // CASE 09. show devices root.** limit 3 offset 2
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(
            schemaRegion, new PartialPath("root.**"), 3, 2, false);
    Assert.assertEquals(2, actualResult.size());
    // CASE 10. show devices root.** limit 3 offset 99
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(
            schemaRegion, new PartialPath("root.**"), 3, 99, false);
    Assert.assertEquals(0, actualResult.size());
    // CASE 11. show devices root.** where device contains 'laptop'
    expectedList =
        Arrays.asList(
            new ShowDevicesResult("root.laptop", false, -1),
            new ShowDevicesResult("root.laptop.d1", false, -1),
            new ShowDevicesResult("root.laptop.d1.s2", false, -1),
            new ShowDevicesResult("root.laptop.d2", false, -1));
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(
            schemaRegion,
            new PartialPath("root.**"),
            0,
            0,
            false,
            SchemaFilterFactory.createPathContainsFilter("laptop"));
    expectedHashset = new HashSet<>(expectedList);
    actualHashset = new HashSet<>(actualResult);
    Assert.assertEquals(expectedHashset, actualHashset);
    // CASE 11. show devices root.** where device contains 'laptop.d' limit 2 offset 0
    expectedList =
        Arrays.asList(
            new ShowDevicesResult("root.laptop.d1", false, -1),
            new ShowDevicesResult("root.laptop.d1.s2", false, -1));
    actualResult =
        SchemaRegionTestUtil.getMatchedDevices(
            schemaRegion,
            new PartialPath("root.**"),
            2,
            0,
            false,
            SchemaFilterFactory.createPathContainsFilter("laptop.d"));
    expectedHashset = new HashSet<>(expectedList);
    actualHashset = new HashSet<>(actualResult);
    Assert.assertEquals(expectedHashset, actualHashset);
  }
Test {@link ISchemaRegion#constructSchemaBlackList}, {@link
ISchemaRegion#rollbackSchemaBlackList}, {@link ISchemaRegion#fetchSchemaBlackList} and{@link
ISchemaRegion#deleteTimeseriesInBlackList}
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java