MTree implements Serializable { static String combineMetadataInStrings(String[] metadataStrs) { JsonObject[] jsonObjects = new JsonObject[metadataStrs.length]; for (int i = 0; i < jsonObjects.length; i++) { jsonObjects[i] = GSON.fromJson(metadataStrs[i], JsonObject.class); } JsonObject root = jsonObjects[0]; for (int i = 1; i < jsonObjects.length; i++) { root = combineJsonObjects(root, jsonObjects[i]); } return jsonToString(root); } MTree(); private  MTree(MNode root); void serializeTo(String snapshotPath); @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning static MTree deserializeFrom(File mtreeSnapshot); @Override String toString(); static final Gson GSON; }
@Test public void testCombineMetadataInStrings() { MTree root = new MTree(); MTree root1 = new MTree(); MTree root2 = new MTree(); MTree root3 = new MTree(); try { CompressionType compressionType = TSFileDescriptor.getInstance().getConfig().getCompressor(); root.setStorageGroup(new PartialPath("root.a.d0")); root.createTimeseries(new PartialPath("root.a.d0.s0"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root.createTimeseries(new PartialPath("root.a.d0.s1"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root.setStorageGroup(new PartialPath("root.a.d1")); root.createTimeseries(new PartialPath("root.a.d1.s0"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root.createTimeseries(new PartialPath("root.a.d1.s1"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root.setStorageGroup(new PartialPath("root.a.b.d0")); root.createTimeseries(new PartialPath("root.a.b.d0.s0"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root1.setStorageGroup(new PartialPath("root.a.d0")); root1.createTimeseries(new PartialPath("root.a.d0.s0"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root1.createTimeseries(new PartialPath("root.a.d0.s1"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root2.setStorageGroup(new PartialPath("root.a.d1")); root2.createTimeseries(new PartialPath("root.a.d1.s0"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root2.createTimeseries(new PartialPath("root.a.d1.s1"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); root3.setStorageGroup(new PartialPath("root.a.b.d0")); root3.createTimeseries(new PartialPath("root.a.b.d0.s0"), TSDataType.valueOf("INT32"), TSEncoding.valueOf("RLE"), compressionType, Collections.emptyMap(), null); String[] metadatas = new String[3]; metadatas[0] = root1.toString(); metadatas[1] = root2.toString(); metadatas[2] = root3.toString(); assertEquals(MTree.combineMetadataInStrings(metadatas), root.toString()); } catch (MetadataException e) { e.printStackTrace(); fail(e.getMessage()); } }