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

    schemaRegion.createTimeSeries(
        SchemaRegionWritePlanFactory.getCreateTimeSeriesPlan(
            new MeasurementPath("root.sg.wf01.wt01.status"),
            TSDataType.BOOLEAN,
            TSEncoding.PLAIN,
            CompressionType.SNAPPY,
            null,
            null,
            null,
            null),
        -1);
    schemaRegion.createTimeSeries(
        SchemaRegionWritePlanFactory.getCreateTimeSeriesPlan(
            new MeasurementPath("root.sg.wf01.wt01.temperature"),
            TSDataType.FLOAT,
            TSEncoding.RLE,
            CompressionType.GZIP,
            null,
            new HashMap<String, String>() {
              {
                put("tag1", "t1");
                put("tag2", "t2");
              }
            },
            new HashMap<String, String>() {
              {
                put("attr1", "a1");
                put("attr2", "a2");
              }
            },
            "temp"),
        -1);
    PathPatternTree patternTree = new PathPatternTree();
    patternTree.appendPathPattern(new PartialPath("root.sg.wf01.wt01.*"));
    patternTree.constructTree();

    ClusterSchemaTree schemas =
        schemaRegion.fetchSeriesSchema(
            patternTree, Collections.emptyMap(), true, false, true, false);
    List<MeasurementPath> measurementPaths =
        schemas.searchMeasurementPaths(new PartialPath("root.sg.wf01.wt01.*")).left;
    Assert.assertEquals(2, measurementPaths.size());
    for (final MeasurementPath measurementPath : measurementPaths) {
      if (measurementPath.getFullPath().equals("root.sg.wf01.wt01.status")) {
        Assert.assertTrue(StringUtils.isEmpty(measurementPath.getMeasurementAlias()));
        Assert.assertEquals(0, measurementPath.getTagMap().size());
        Assert.assertEquals(TSDataType.BOOLEAN, measurementPath.getMeasurementSchema().getType());
        Assert.assertEquals(
            TSEncoding.PLAIN, measurementPath.getMeasurementSchema().getEncodingType());
        Assert.assertEquals(
            CompressionType.SNAPPY, measurementPath.getMeasurementSchema().getCompressor());
      } else if (measurementPath.getFullPath().equals("root.sg.wf01.wt01.temperature")) {
        // Only when user query with alias, the alias in path will be set
        Assert.assertEquals("", measurementPath.getMeasurementAlias());
        Assert.assertEquals(2, measurementPath.getTagMap().size());
        Assert.assertEquals(TSDataType.FLOAT, measurementPath.getMeasurementSchema().getType());
        Assert.assertEquals(
            TSEncoding.RLE, measurementPath.getMeasurementSchema().getEncodingType());
        Assert.assertEquals(
            CompressionType.GZIP, measurementPath.getMeasurementSchema().getCompressor());
      } else {
        Assert.fail("Unexpected MeasurementPath " + measurementPath);
      }
    }
    patternTree = new PathPatternTree();
    patternTree.appendPathPattern(new PartialPath("root.sg.wf01.wt01.temp"));
    patternTree.constructTree();
    schemas =
        schemaRegion.fetchSeriesSchema(
            patternTree, Collections.emptyMap(), false, false, true, false);
    measurementPaths =
        schemas.searchMeasurementPaths(new PartialPath("root.sg.wf01.wt01.temp")).left;
    Assert.assertEquals(1, measurementPaths.size());
    Assert.assertEquals("root.sg.wf01.wt01.temperature", measurementPaths.get(0).getFullPath());
    Assert.assertEquals("temp", measurementPaths.get(0).getMeasurementAlias());
    Assert.assertNull(measurementPaths.get(0).getTagMap());
    Assert.assertEquals(TSDataType.FLOAT, measurementPaths.get(0).getMeasurementSchema().getType());
    Assert.assertEquals(
        TSEncoding.RLE, measurementPaths.get(0).getMeasurementSchema().getEncodingType());
    Assert.assertEquals(
        CompressionType.GZIP, measurementPaths.get(0).getMeasurementSchema().getCompressor());

    // Test blacklist
    patternTree = new PathPatternTree();
    patternTree.appendPathPattern(new PartialPath("root.sg.wf01.wt01.**"));
    patternTree.constructTree();

    Assert.assertEquals(new Pair<>(2L, false), schemaRegion.constructSchemaBlackList(patternTree));

    Assert.assertTrue(
        schemaRegion
            .fetchSeriesSchema(patternTree, Collections.emptyMap(), false, false, true, false)
            .isEmpty());

    patternTree = new PathPatternTree();
    patternTree.appendPathPattern(new PartialPath("root.sg.wf01.wt01.temperature"));
    patternTree.constructTree();
    Assert.assertTrue(
        schemaRegion
            .fetchSeriesSchema(patternTree, Collections.emptyMap(), false, false, true, false)
            .isEmpty());

    patternTree = new PathPatternTree();
    patternTree.appendPathPattern(new PartialPath("root.sg.wf01.*.temperature"));
    patternTree.constructTree();
    Assert.assertTrue(
        schemaRegion
            .fetchSeriesSchema(patternTree, Collections.emptyMap(), false, false, true, false)
            .isEmpty());
  }
This class define test cases for {@link ISchemaRegion}. All test cases will be run in both Memory
and PBTree modes. In PBTree mode, there are three kinds of test environment: full memory, partial
memory and non memory.
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java