2323import org .apache .iotdb .commons .schema .table .TsTable ;
2424import org .apache .iotdb .commons .schema .table .column .FieldColumnSchema ;
2525import org .apache .iotdb .commons .schema .table .column .TagColumnSchema ;
26+ import org .apache .iotdb .commons .utils .FileUtils ;
2627import org .apache .iotdb .db .exception .DiskSpaceInsufficientException ;
2728import org .apache .iotdb .db .exception .StorageEngineException ;
2829import org .apache .iotdb .db .schemaengine .table .DataNodeTableCache ;
@@ -76,6 +77,7 @@ public class ObjectTypeCompactionTest extends AbstractCompactionTest {
7677
7778 private String threadName ;
7879 private File objectDir ;
80+ private File regionDir ;
7981
8082 @ Before
8183 @ Override
@@ -88,6 +90,8 @@ public void setUp()
8890 super .setUp ();
8991 try {
9092 objectDir = new File (TierManager .getInstance ().getNextFolderForObjectFile ());
93+ regionDir = new File (objectDir , "0" );
94+ regionDir .mkdirs ();
9195 } catch (DiskSpaceInsufficientException e ) {
9296 throw new RuntimeException (e );
9397 }
@@ -102,7 +106,7 @@ public void tearDown() throws IOException, StorageEngineException {
102106 File [] files = objectDir .listFiles ();
103107 if (files != null ) {
104108 for (File file : files ) {
105- Files . delete (file . toPath () );
109+ FileUtils . deleteFileOrDirectory (file );
106110 }
107111 }
108112 }
@@ -120,9 +124,9 @@ public void createTable(String tableName, long ttl) {
120124 @ Test
121125 public void testSeqCompactionWithTTL () throws IOException , WriteProcessException {
122126 Pair <TsFileResource , File > pair1 =
123- generateTsFileAndObject (true , System .currentTimeMillis () - 10000 );
127+ generateTsFileAndObject (true , System .currentTimeMillis () - 10000 , 0 );
124128 Pair <TsFileResource , File > pair2 =
125- generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 );
129+ generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 , 100 );
126130 tsFileManager .add (pair1 .getLeft (), true );
127131 tsFileManager .add (pair2 .getLeft (), true );
128132 InnerSpaceCompactionTask task =
@@ -141,9 +145,9 @@ public void testSeqCompactionWithTTL() throws IOException, WriteProcessException
141145 @ Test
142146 public void testUnseqCompactionWithTTL () throws IOException , WriteProcessException {
143147 Pair <TsFileResource , File > pair1 =
144- generateTsFileAndObject (false , System .currentTimeMillis () + 100000 );
148+ generateTsFileAndObject (false , System .currentTimeMillis () + 100000 , 1 );
145149 Pair <TsFileResource , File > pair2 =
146- generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 );
150+ generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 , 0 );
147151 tsFileManager .add (pair1 .getLeft (), false );
148152 tsFileManager .add (pair2 .getLeft (), false );
149153 InnerSpaceCompactionTask task =
@@ -162,9 +166,9 @@ public void testUnseqCompactionWithTTL() throws IOException, WriteProcessExcepti
162166 @ Test
163167 public void testUnseqCompactionWithReadPointWithTTL () throws IOException , WriteProcessException {
164168 Pair <TsFileResource , File > pair1 =
165- generateTsFileAndObject (false , System .currentTimeMillis () + 100000 );
169+ generateTsFileAndObject (false , System .currentTimeMillis () + 100000 , 0 );
166170 Pair <TsFileResource , File > pair2 =
167- generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 );
171+ generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 , 0 );
168172 tsFileManager .add (pair1 .getLeft (), false );
169173 tsFileManager .add (pair2 .getLeft (), false );
170174 InnerSpaceCompactionTask task =
@@ -183,9 +187,9 @@ public void testUnseqCompactionWithReadPointWithTTL() throws IOException, WriteP
183187 @ Test
184188 public void testCrossCompactionWithTTL () throws IOException , WriteProcessException {
185189 Pair <TsFileResource , File > pair1 =
186- generateTsFileAndObject (true , System .currentTimeMillis () + 100000 );
190+ generateTsFileAndObject (true , System .currentTimeMillis () + 100000 , 1 );
187191 Pair <TsFileResource , File > pair2 =
188- generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 );
192+ generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 , 2 );
189193 tsFileManager .add (pair1 .getLeft (), true );
190194 tsFileManager .add (pair2 .getLeft (), false );
191195 CrossSpaceCompactionTask task =
@@ -205,9 +209,9 @@ public void testCrossCompactionWithTTL() throws IOException, WriteProcessExcepti
205209 @ Test
206210 public void testSettleCompaction () throws IOException , WriteProcessException {
207211 Pair <TsFileResource , File > pair1 =
208- generateTsFileAndObject (true , System .currentTimeMillis () - 10000 );
212+ generateTsFileAndObject (true , System .currentTimeMillis () - 10000 , 3 );
209213 Pair <TsFileResource , File > pair2 =
210- generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 );
214+ generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 , 0 );
211215 tsFileManager .add (pair1 .getLeft (), true );
212216 tsFileManager .add (pair2 .getLeft (), true );
213217 SettleCompactionTask task =
@@ -224,19 +228,19 @@ public void testSettleCompaction() throws IOException, WriteProcessException {
224228 Assert .assertTrue (pair2 .getRight ().exists ());
225229 }
226230
227- private Pair <TsFileResource , File > generateTsFileAndObject (boolean seq , long timestamp )
231+ private Pair <TsFileResource , File > generateTsFileAndObject (boolean seq , long timestamp , int regionIdInTsFile )
228232 throws IOException , WriteProcessException {
229233 TsFileResource resource = createEmptyFileAndResource (seq );
230- Path testFile1 = Files .createTempFile (objectDir .toPath (), "test_" , ".bin" );
234+ Path testFile1 = Files .createTempFile (regionDir .toPath (), "test_" , ".bin" );
231235 byte [] content = new byte [100 ];
232236 for (int i = 0 ; i < 100 ; i ++) {
233237 content [i ] = (byte ) i ;
234238 }
235239 Files .write (testFile1 , content );
236- String relativePath = testFile1 .toFile ().getName ();
237- ByteBuffer buffer = ByteBuffer .allocate (Long .BYTES + relativePath .length ());
240+ String relativePathInTsFile = regionIdInTsFile + File . separator + testFile1 .toFile ().getName ();
241+ ByteBuffer buffer = ByteBuffer .allocate (Long .BYTES + relativePathInTsFile .length ());
238242 buffer .putLong (100L );
239- buffer .put (BytesUtils .stringToBytes (relativePath ));
243+ buffer .put (BytesUtils .stringToBytes (relativePathInTsFile ));
240244 buffer .flip ();
241245 IDeviceID deviceID = new StringArrayDeviceID ("t1" , "d1" );
242246 try (TsFileIOWriter writer = new TsFileIOWriter (resource .getTsFile ())) {
0 commit comments