1818
1919package org .apache .paimon .rest ;
2020
21+ import java .util .UUID ;
2122import org .apache .paimon .Snapshot ;
2223import org .apache .paimon .catalog .Catalog ;
2324import org .apache .paimon .catalog .CatalogContext ;
@@ -125,12 +126,7 @@ void testListPartitionsFromFile() throws Exception {
125126
126127 @ Test
127128 void testRefreshFileIO () throws Exception {
128- Options options = new Options ();
129- options .set (RESTCatalogOptions .URI , restCatalogServer .getUrl ());
130- options .set (RESTCatalogOptions .TOKEN , initToken );
131- options .set (RESTCatalogOptions .DATA_TOKEN_ENABLED , true );
132- options .set (RESTCatalogOptions .TOKEN_PROVIDER , AuthProviderEnum .BEAR .identifier ());
133- this .catalog = new RESTCatalog (CatalogContext .create (options ));
129+ this .catalog = initDataTokenCatalog ();
134130 List <Identifier > identifiers =
135131 Lists .newArrayList (
136132 Identifier .create ("test_db_a" , "test_table_a" ),
@@ -140,9 +136,33 @@ void testRefreshFileIO() throws Exception {
140136 createTable (identifier , Maps .newHashMap (), Lists .newArrayList ("col1" ));
141137 FileStoreTable fileStoreTable = (FileStoreTable ) catalog .getTable (identifier );
142138 assertEquals (true , fileStoreTable .fileIO ().exists (fileStoreTable .location ()));
139+
140+ RESTTokenFileIO fileIO = (RESTTokenFileIO ) fileStoreTable .fileIO ();
141+ RESTToken fileDataToken = fileIO .validToken ();
142+ RESTToken serverDataToken = restCatalogServer .dataTokenStore .get (identifier .getFullName ());
143+ assertEquals (serverDataToken , fileDataToken );
143144 }
144145 }
145146
147+ @ Test
148+ void testRefreshFileIOWhenExpired () throws Exception {
149+ this .catalog = initDataTokenCatalog ();
150+ Identifier identifier =
151+ Identifier .create ("test_data_token" , "table_for_testing_date_token" );
152+ RESTToken expiredDataToken = new RESTToken (ImmutableMap .of ("akId" , "akId" , "akSecret" , UUID .randomUUID ().toString ()), System .currentTimeMillis ());
153+ restCatalogServer .setDataToken (identifier , expiredDataToken );
154+ createTable (identifier , Maps .newHashMap (), Lists .newArrayList ("col1" ));
155+ FileStoreTable fileStoreTable = (FileStoreTable ) catalog .getTable (identifier );
156+ RESTTokenFileIO fileIO = (RESTTokenFileIO ) fileStoreTable .fileIO ();
157+ RESTToken fileDataToken = fileIO .validToken ();
158+ assertEquals (expiredDataToken , fileDataToken );
159+ RESTToken newDataToken = new RESTToken (ImmutableMap .of ("akId" , "akId" , "akSecret" , UUID .randomUUID ().toString ()), System .currentTimeMillis () + 100_000 );
160+ restCatalogServer .setDataToken (identifier , newDataToken );
161+ RESTToken nextFileDataToken = fileIO .validToken ();
162+ assertEquals (newDataToken , nextFileDataToken );
163+ assertEquals (true , nextFileDataToken .expireAtMillis () - fileDataToken .expireAtMillis () > 0 );
164+ }
165+
146166 @ Test
147167 void testSnapshotFromREST () throws Catalog .TableNotExistException {
148168 Options options = new Options ();
@@ -183,6 +203,12 @@ protected boolean supportsAlterDatabase() {
183203 return true ;
184204 }
185205
206+
207+ // TODO implement this
208+ @ Override
209+ @ Test
210+ public void testTableUUID () {}
211+
186212 private void createTable (
187213 Identifier identifier , Map <String , String > options , List <String > partitionKeys )
188214 throws Exception {
@@ -198,8 +224,12 @@ private void createTable(
198224 true );
199225 }
200226
201- // TODO implement this
202- @ Override
203- @ Test
204- public void testTableUUID () {}
227+ private Catalog initDataTokenCatalog () {
228+ Options options = new Options ();
229+ options .set (RESTCatalogOptions .URI , restCatalogServer .getUrl ());
230+ options .set (RESTCatalogOptions .TOKEN , initToken );
231+ options .set (RESTCatalogOptions .DATA_TOKEN_ENABLED , true );
232+ options .set (RESTCatalogOptions .TOKEN_PROVIDER , AuthProviderEnum .BEAR .identifier ());
233+ return new RESTCatalog (CatalogContext .create (options ));
234+ }
205235}
0 commit comments