@Test
public void testSetStorageGroup() throws IllegalPathException {

  // set storage group first
  MTree root = new MTree();
  try {
    root.setStorageGroup(new PartialPath("root.laptop.d1"));
    assertTrue(root.isPathExist(new PartialPath("root.laptop.d1")));
    assertTrue(root.checkStorageGroupByPath(new PartialPath("root.laptop.d1")));
    assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1")).getFullPath());
    assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s1")));
    assertTrue(root.checkStorageGroupByPath(new PartialPath("root.laptop.d1.s1")));
    assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1.s1")).getFullPath());
  } catch (MetadataException e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
  try {
    root.setStorageGroup(new PartialPath("root.laptop.d2"));
  } catch (MetadataException e) {
    fail(e.getMessage());
  }
  try {
    root.setStorageGroup(new PartialPath("root.laptop"));
  } catch (MetadataException e) {
    Assert.assertEquals(
        "root.laptop has already been set to storage group",
        e.getMessage());
  }
  // check timeseries
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s0")));
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s1")));
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d2.s0")));
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d2.s1")));
  try {
    assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1.s0")).getFullPath());
    root.createTimeseries(new PartialPath("root.laptop.d1.s0"), TSDataType.INT32, TSEncoding.RLE,
        TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null);
    assertEquals("root.laptop.d1", root.getStorageGroupPath(new PartialPath("root.laptop.d1.s1")).getFullPath());
    root.createTimeseries(new PartialPath("root.laptop.d1.s1"), TSDataType.INT32, TSEncoding.RLE,
        TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null);
    assertEquals("root.laptop.d2", root.getStorageGroupPath(new PartialPath("root.laptop.d2.s0")).getFullPath());
    root.createTimeseries(new PartialPath("root.laptop.d2.s0"), TSDataType.INT32, TSEncoding.RLE,
        TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null);
    assertEquals("root.laptop.d2", root.getStorageGroupPath(new PartialPath("root.laptop.d2.s1")).getFullPath());
    root.createTimeseries(new PartialPath("root.laptop.d2.s1"), TSDataType.INT32, TSEncoding.RLE,
        TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null);
  } catch (MetadataException e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
  try {
    root.deleteTimeseriesAndReturnEmptyStorageGroup(new PartialPath("root.laptop.d1.s0"));
  } catch (MetadataException e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s0")));
  try {
    root.deleteStorageGroup(new PartialPath("root.laptop.d1"));
  } catch (MetadataException e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d1.s1")));
  assertFalse(root.isPathExist(new PartialPath("root.laptop.d1")));
  assertTrue(root.isPathExist(new PartialPath("root.laptop")));
  assertTrue(root.isPathExist(new PartialPath("root.laptop.d2")));
  assertTrue(root.isPathExist(new PartialPath("root.laptop.d2.s0")));
}