@Test
  public void testFetchSchemaWithTemplate() throws Exception {
    ISchemaRegion schemaRegion = getSchemaRegion("root.sg", 0);
    SchemaRegionTestUtil.createSimpleTimeSeriesByList(
        schemaRegion, Arrays.asList("root.sg.wf01.wt01.status", "root.sg.wf01.wt01.temperature"));
    int templateId = 1;
    Template template =
        new Template(
            "t1",
            Arrays.asList("s1", "s2"),
            Arrays.asList(TSDataType.DOUBLE, TSDataType.INT32),
            Arrays.asList(TSEncoding.RLE, TSEncoding.RLE),
            Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY));
    template.setId(templateId);
    ClusterTemplateManager.getInstance().putTemplate(template);
    schemaRegion.activateSchemaTemplate(
        SchemaRegionWritePlanFactory.getActivateTemplateInClusterPlan(
            new PartialPath("root.sg.wf02"), 2, templateId),
        template);
    Map<Integer, Template> templateMap = Collections.singletonMap(templateId, template);
    List<String> expectedTimeseries =
        Arrays.asList(
            "root.sg.wf01.wt01.status",
            "root.sg.wf01.wt01.temperature",
            "root.sg.wf02.s1",
            "root.sg.wf02.s2");

    // check fetch schema
    ClusterSchemaTree schemaTree =
        schemaRegion.fetchSeriesSchema(ALL_MATCH_SCOPE, templateMap, true, false, true, false);
    schemaTree.setTemplateMap(templateMap);
    List<MeasurementPath> schemas = schemaTree.searchMeasurementPaths(ALL_MATCH_PATTERN).left;
    Assert.assertEquals(expectedTimeseries.size(), schemas.size());
    schemas.sort(Comparator.comparing(PartialPath::getFullPath));
    for (int i = 0; i < schemas.size(); i++) {
      Assert.assertEquals(expectedTimeseries.get(i), schemas.get(i).getFullPath());
    }

    // check show timeseries
    List<ITimeSeriesSchemaInfo> result =
        SchemaRegionTestUtil.showTimeseries(schemaRegion, new PartialPath("root.**"), templateMap);
    result.sort(Comparator.comparing(ISchemaInfo::getFullPath));
    for (int i = 0; i < result.size(); i++) {
      Assert.assertEquals(expectedTimeseries.get(i), result.get(i).getFullPath());
    }
  }
Test {@link ISchemaRegion#constructSchemaBlackListWithTemplate}, {@link
ISchemaRegion#rollbackSchemaBlackListWithTemplate} and {@link
ISchemaRegion#deactivateTemplateInBlackList}
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTemplateTest.java