2525import org .apache .iotdb .commons .schema .table .column .TagColumnSchema ;
2626import org .apache .iotdb .db .conf .IoTDBConfig ;
2727import org .apache .iotdb .db .conf .IoTDBDescriptor ;
28+ import org .apache .iotdb .commons .utils .FileUtils ;
2829import org .apache .iotdb .db .exception .DiskSpaceInsufficientException ;
2930import org .apache .iotdb .db .exception .StorageEngineException ;
3031import org .apache .iotdb .db .schemaengine .table .DataNodeTableCache ;
@@ -78,6 +79,7 @@ public class ObjectTypeCompactionTest extends AbstractCompactionTest {
7879
7980 private String threadName ;
8081 private File objectDir ;
82+ private File regionDir ;
8183
8284 private final IoTDBConfig config = IoTDBDescriptor .getInstance ().getConfig ();
8385
@@ -93,6 +95,8 @@ public void setUp()
9395 super .setUp ();
9496 try {
9597 objectDir = new File (TierManager .getInstance ().getNextFolderForObjectFile ());
98+ regionDir = new File (objectDir , "0" );
99+ regionDir .mkdirs ();
96100 } catch (DiskSpaceInsufficientException e ) {
97101 throw new RuntimeException (e );
98102 }
@@ -107,7 +111,7 @@ public void tearDown() throws IOException, StorageEngineException {
107111 File [] files = objectDir .listFiles ();
108112 if (files != null ) {
109113 for (File file : files ) {
110- Files . delete (file . toPath () );
114+ FileUtils . deleteFileOrDirectory (file );
111115 }
112116 }
113117 config .setRestrictObjectLimit (false );
@@ -126,9 +130,9 @@ public void createTable(String tableName, long ttl) {
126130 @ Test
127131 public void testSeqCompactionWithTTL () throws IOException , WriteProcessException {
128132 Pair <TsFileResource , File > pair1 =
129- generateTsFileAndObject (true , System .currentTimeMillis () - 10000 );
133+ generateTsFileAndObject (true , System .currentTimeMillis () - 10000 , 0 );
130134 Pair <TsFileResource , File > pair2 =
131- generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 );
135+ generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 , 100 );
132136 tsFileManager .add (pair1 .getLeft (), true );
133137 tsFileManager .add (pair2 .getLeft (), true );
134138 InnerSpaceCompactionTask task =
@@ -147,9 +151,9 @@ public void testSeqCompactionWithTTL() throws IOException, WriteProcessException
147151 @ Test
148152 public void testUnseqCompactionWithTTL () throws IOException , WriteProcessException {
149153 Pair <TsFileResource , File > pair1 =
150- generateTsFileAndObject (false , System .currentTimeMillis () + 100000 );
154+ generateTsFileAndObject (false , System .currentTimeMillis () + 100000 , 1 );
151155 Pair <TsFileResource , File > pair2 =
152- generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 );
156+ generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 , 0 );
153157 tsFileManager .add (pair1 .getLeft (), false );
154158 tsFileManager .add (pair2 .getLeft (), false );
155159 InnerSpaceCompactionTask task =
@@ -168,9 +172,9 @@ public void testUnseqCompactionWithTTL() throws IOException, WriteProcessExcepti
168172 @ Test
169173 public void testUnseqCompactionWithReadPointWithTTL () throws IOException , WriteProcessException {
170174 Pair <TsFileResource , File > pair1 =
171- generateTsFileAndObject (false , System .currentTimeMillis () + 100000 );
175+ generateTsFileAndObject (false , System .currentTimeMillis () + 100000 , 0 );
172176 Pair <TsFileResource , File > pair2 =
173- generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 );
177+ generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 , 0 );
174178 tsFileManager .add (pair1 .getLeft (), false );
175179 tsFileManager .add (pair2 .getLeft (), false );
176180 InnerSpaceCompactionTask task =
@@ -189,9 +193,9 @@ public void testUnseqCompactionWithReadPointWithTTL() throws IOException, WriteP
189193 @ Test
190194 public void testCrossCompactionWithTTL () throws IOException , WriteProcessException {
191195 Pair <TsFileResource , File > pair1 =
192- generateTsFileAndObject (true , System .currentTimeMillis () + 100000 );
196+ generateTsFileAndObject (true , System .currentTimeMillis () + 100000 , 1 );
193197 Pair <TsFileResource , File > pair2 =
194- generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 );
198+ generateTsFileAndObject (false , System .currentTimeMillis () - 1000000 , 2 );
195199 tsFileManager .add (pair1 .getLeft (), true );
196200 tsFileManager .add (pair2 .getLeft (), false );
197201 CrossSpaceCompactionTask task =
@@ -211,9 +215,9 @@ public void testCrossCompactionWithTTL() throws IOException, WriteProcessExcepti
211215 @ Test
212216 public void testSettleCompaction () throws IOException , WriteProcessException {
213217 Pair <TsFileResource , File > pair1 =
214- generateTsFileAndObject (true , System .currentTimeMillis () - 10000 );
218+ generateTsFileAndObject (true , System .currentTimeMillis () - 10000 , 3 );
215219 Pair <TsFileResource , File > pair2 =
216- generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 );
220+ generateTsFileAndObject (true , System .currentTimeMillis () + 1000000 , 0 );
217221 tsFileManager .add (pair1 .getLeft (), true );
218222 tsFileManager .add (pair2 .getLeft (), true );
219223 SettleCompactionTask task =
@@ -230,19 +234,19 @@ public void testSettleCompaction() throws IOException, WriteProcessException {
230234 Assert .assertTrue (pair2 .getRight ().exists ());
231235 }
232236
233- private Pair <TsFileResource , File > generateTsFileAndObject (boolean seq , long timestamp )
237+ private Pair <TsFileResource , File > generateTsFileAndObject (boolean seq , long timestamp , int regionIdInTsFile )
234238 throws IOException , WriteProcessException {
235239 TsFileResource resource = createEmptyFileAndResource (seq );
236- Path testFile1 = Files .createTempFile (objectDir .toPath (), "test_" , ".bin" );
240+ Path testFile1 = Files .createTempFile (regionDir .toPath (), "test_" , ".bin" );
237241 byte [] content = new byte [100 ];
238242 for (int i = 0 ; i < 100 ; i ++) {
239243 content [i ] = (byte ) i ;
240244 }
241245 Files .write (testFile1 , content );
242- String relativePath = testFile1 .toFile ().getName ();
243- ByteBuffer buffer = ByteBuffer .allocate (Long .BYTES + relativePath .length ());
246+ String relativePathInTsFile = regionIdInTsFile + File . separator + testFile1 .toFile ().getName ();
247+ ByteBuffer buffer = ByteBuffer .allocate (Long .BYTES + relativePathInTsFile .length ());
244248 buffer .putLong (100L );
245- buffer .put (BytesUtils .stringToBytes (relativePath ));
249+ buffer .put (BytesUtils .stringToBytes (relativePathInTsFile ));
246250 buffer .flip ();
247251 IDeviceID deviceID = new StringArrayDeviceID ("t1" , "d1" );
248252 try (TsFileIOWriter writer = new TsFileIOWriter (resource .getTsFile ())) {
0 commit comments