36
36
import org .apache .rocketmq .common .ThreadFactoryImpl ;
37
37
import org .apache .rocketmq .logging .org .slf4j .Logger ;
38
38
import org .apache .rocketmq .logging .org .slf4j .LoggerFactory ;
39
+ import org .apache .rocketmq .store .logfile .DefaultMappedFile ;
40
+ import org .apache .rocketmq .tieredstore .TieredStoreTestUtil ;
39
41
import org .apache .rocketmq .tieredstore .common .AppendResult ;
40
42
import org .apache .rocketmq .tieredstore .common .TieredMessageStoreConfig ;
41
43
import org .apache .rocketmq .tieredstore .common .TieredStoreExecutor ;
@@ -67,10 +69,11 @@ public class IndexStoreServiceTest {
67
69
@ Before
68
70
public void init () throws IOException , ClassNotFoundException , NoSuchMethodException {
69
71
TieredStoreExecutor .init ();
70
- filePath = Paths . get ( System . getProperty ( "user.home" ) , "store_test" ,
71
- UUID . randomUUID (). toString (). replace ( "-" , "" ). substring ( 0 , 8 ) ).toString ();
72
+ filePath = UUID . randomUUID (). toString (). replace ( "-" , "" ). substring ( 0 , 8 );
73
+ String directory = Paths . get ( System . getProperty ( "user.home" ) , "store_test" , filePath ).toString ();
72
74
storeConfig = new TieredMessageStoreConfig ();
73
- storeConfig .setStorePathRootDir (filePath );
75
+ storeConfig .setStorePathRootDir (directory );
76
+ storeConfig .setTieredStoreFilePath (directory );
74
77
storeConfig .setTieredStoreIndexFileMaxHashSlotNum (5 );
75
78
storeConfig .setTieredStoreIndexFileMaxIndexNum (20 );
76
79
storeConfig .setTieredBackendServiceProvider ("org.apache.rocketmq.tieredstore.provider.posix.PosixFileSegment" );
@@ -83,6 +86,9 @@ public void shutdown() {
83
86
indexService .shutdown ();
84
87
indexService .destroy ();
85
88
}
89
+ TieredStoreTestUtil .destroyMetadataStore ();
90
+ TieredStoreTestUtil .destroyTempDir (storeConfig .getStorePathRootDir ());
91
+ TieredStoreTestUtil .destroyTempDir (storeConfig .getTieredStoreFilePath ());
86
92
TieredStoreExecutor .shutdown ();
87
93
}
88
94
@@ -99,26 +105,23 @@ public void basicServiceTest() throws InterruptedException {
99
105
}
100
106
101
107
@ Test
102
- public void doConvertOldFormatTest () {
108
+ public void doConvertOldFormatTest () throws IOException {
103
109
indexService = new IndexStoreService (fileAllocator , filePath );
104
110
long timestamp = indexService .getTimeStoreTable ().firstKey ();
105
111
Assert .assertEquals (AppendResult .SUCCESS , indexService .putKey (
106
112
TOPIC_NAME , TOPIC_ID , QUEUE_ID , KEY_SET , MESSAGE_OFFSET , MESSAGE_SIZE , timestamp ));
107
113
indexService .shutdown ();
108
114
109
115
File file = new File (Paths .get (filePath , IndexStoreService .FILE_DIRECTORY_NAME , String .valueOf (timestamp )).toString ());
110
- log .info (filePath );
111
- log .info (file .getPath ());
112
- Assert .assertTrue (file .exists ());
113
-
114
- Assert .assertTrue (file .renameTo (new File (file .getParent (), "0000" )));
115
- file = new File (Paths .get (file .getParent (), "0000" ).toString ());
116
- Assert .assertTrue (file .exists ());
116
+ DefaultMappedFile mappedFile = new DefaultMappedFile (file .getName (), (int ) file .length ());
117
+ mappedFile .renameTo (String .valueOf (new File (file .getParent (), "0000" )));
118
+ mappedFile .shutdown (10 * 1000 );
117
119
118
120
indexService = new IndexStoreService (fileAllocator , filePath );
119
121
ConcurrentSkipListMap <Long , IndexFile > timeStoreTable = indexService .getTimeStoreTable ();
120
122
Assert .assertEquals (1 , timeStoreTable .size ());
121
123
Assert .assertEquals (Long .valueOf (timestamp ), timeStoreTable .firstKey ());
124
+ mappedFile .destroy (10 * 1000 );
122
125
}
123
126
124
127
@ Test
0 commit comments