jt2594838 commented on a change in pull request #372: 
[IOTDB-198]Reimplementation sync module
URL: https://github.com/apache/incubator-iotdb/pull/372#discussion_r325992475
 
 

 ##########
 File path: 
server/src/test/java/org/apache/iotdb/db/sync/receiver/load/FileLoaderTest.java
 ##########
 @@ -0,0 +1,434 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.sync.receiver.load;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Random;
+import java.util.Set;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.conf.directories.DirectoryManager;
+import org.apache.iotdb.db.engine.StorageEngine;
+import org.apache.iotdb.db.engine.storagegroup.StorageGroupProcessor;
+import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.exception.DiskSpaceInsufficientException;
+import org.apache.iotdb.db.exception.MetadataErrorException;
+import org.apache.iotdb.db.exception.StartupException;
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.db.sync.sender.conf.SyncConstant;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FileLoaderTest {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(FileLoaderTest.class);
+  private static final String SG_NAME = "root.sg";
+  private static IoTDB daemon;
+  private String dataDir;
+  private FileLoader fileLoader;
+
+  @Before
+  public void setUp()
+      throws IOException, InterruptedException, StartupException, 
DiskSpaceInsufficientException, MetadataErrorException {
+    EnvironmentUtils.closeStatMonitor();
+    daemon = IoTDB.getInstance();
+    daemon.active();
+    EnvironmentUtils.envSetUp();
+    dataDir = new 
File(DirectoryManager.getInstance().getNextFolderForSequenceFile())
+        .getParentFile().getAbsolutePath();
+    initMetadata();
+  }
+
+  private void initMetadata() throws MetadataErrorException {
+    MManager mmanager = MManager.getInstance();
+    mmanager.init();
+    mmanager.clear();
+    mmanager.setStorageLevelToMTree("root.sg0");
+    mmanager.setStorageLevelToMTree("root.sg1");
+    mmanager.setStorageLevelToMTree("root.sg2");
+  }
+
+  @After
+  public void tearDown() throws InterruptedException, IOException, 
StorageEngineException {
+    daemon.stop();
+    EnvironmentUtils.cleanEnv();
+  }
+
+  @Test
+  public void loadNewTsfiles() throws IOException, StorageEngineException {
+    fileLoader = FileLoader.createFileLoader(getReceiverFolderFile());
+    Map<String, List<File>> allFileList = new HashMap<>();
+    Map<String, Set<String>> correctSequenceLoadedFileMap = new HashMap<>();
+
+    // add some new tsfiles
+    Random r = new Random(0);
+    long time = System.currentTimeMillis();
+    for (int i = 0; i < 3; i++) {
+      for (int j = 0; j < 10; j++) {
+        allFileList.putIfAbsent(SG_NAME + i, new ArrayList<>());
+        correctSequenceLoadedFileMap.putIfAbsent(SG_NAME + i, new HashSet<>());
+        String rand = String.valueOf(r.nextInt(10000));
+        String fileName =
+            getSnapshotFolder() + File.separator + SG_NAME + i + 
File.separator + (time + i * 100
+                + j) + IoTDBConstant.FILE_NAME_SEPARATOR + rand
+                + IoTDBConstant.FILE_NAME_SEPARATOR + "0.tsfile";
+        File syncFile = new File(fileName);
+        File dataFile = new File(
+            
syncFile.getParentFile().getParentFile().getParentFile().getParentFile()
+                .getParentFile(), IoTDBConstant.SEQUENCE_FLODER_NAME
+            + File.separatorChar + syncFile.getParentFile().getName() + 
File.separatorChar
+            + syncFile.getName());
+        correctSequenceLoadedFileMap.get(SG_NAME + 
i).add(dataFile.getAbsolutePath());
+        allFileList.get(SG_NAME + i).add(syncFile);
+        if (!syncFile.getParentFile().exists()) {
+          syncFile.getParentFile().mkdirs();
+        }
+        if (!syncFile.exists() && !syncFile.createNewFile()) {
+          LOGGER.error("Can not create new file {}", syncFile.getPath());
+        }
+        if (!new File(syncFile.getAbsolutePath() + 
TsFileResource.RESOURCE_SUFFIX).exists()
+            && !new File(syncFile.getAbsolutePath() + 
TsFileResource.RESOURCE_SUFFIX)
+            .createNewFile()) {
+          LOGGER.error("Can not create new file {}", syncFile.getPath());
+        }
+        TsFileResource tsFileResource = new TsFileResource(syncFile);
+        tsFileResource.getStartTimeMap().put(String.valueOf(i), (long) j * 10);
+        tsFileResource.getEndTimeMap().put(String.valueOf(i), (long) j * 10 + 
5);
+        tsFileResource.serialize();
+      }
+    }
+
+    for (int i = 0; i < 3; i++) {
+      StorageGroupProcessor processor = 
StorageEngine.getInstance().getProcessor(SG_NAME + i);
+      assert processor.getSequenceFileList().isEmpty();
 
 Review comment:
   The native asserts will not take effect without using the "-ea" option. By 
the way, we do not use those asserts elsewhere.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to