23
23
import com .starrocks .catalog .PrimitiveType ;
24
24
import com .starrocks .catalog .ScalarType ;
25
25
import com .starrocks .catalog .Type ;
26
+ import com .starrocks .common .Config ;
26
27
import com .starrocks .connector .MetastoreType ;
27
28
import com .starrocks .connector .PartitionUtil ;
28
29
import com .starrocks .connector .exception .StarRocksConnectorException ;
@@ -47,7 +48,7 @@ public class CachingHiveMetastoreTest {
47
48
private HiveMetaClient client ;
48
49
private HiveMetastore metastore ;
49
50
private ExecutorService executor ;
50
- private long expireAfterWriteSec = 10 ;
51
+ private long expireAfterWriteSec = 30 ;
51
52
private long refreshAfterWriteSec = -1 ;
52
53
53
54
@ Before
@@ -169,6 +170,49 @@ public void testRefreshTableSync() {
169
170
Assert .assertEquals (1 , cachingHiveMetastore .tableNameLockMap .size ());
170
171
}
171
172
173
+ @ Test
174
+ public void testRefreshTableBackground () throws InterruptedException {
175
+ CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore (
176
+ metastore , executor , expireAfterWriteSec , refreshAfterWriteSec , 1000 , false );
177
+ Assert .assertFalse (cachingHiveMetastore .tableNameLockMap .containsKey (
178
+ HiveTableName .of ("db1" , "tbl1" )));
179
+ try {
180
+ // mock query table tbl1
181
+ List <String > partitionNames = cachingHiveMetastore .getPartitionKeysByValue ("db1" , "tbl1" ,
182
+ HivePartitionValue .ALL_PARTITION_VALUES );
183
+ cachingHiveMetastore .getPartitionsByNames ("db1" ,
184
+ "tbl1" , partitionNames );
185
+ // put table tbl1 in table cache
186
+ cachingHiveMetastore .refreshTable ("db1" , "tbl1" , true );
187
+ } catch (Exception e ) {
188
+ Assert .fail ();
189
+ }
190
+ Assert .assertTrue (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
191
+
192
+ try {
193
+ cachingHiveMetastore .refreshTableBackground ("db1" , "tbl1" , true );
194
+ } catch (Exception e ) {
195
+ Assert .fail ();
196
+ }
197
+ // not skip refresh table, table cache still exist
198
+ Assert .assertTrue (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
199
+ // sleep 1s, background refresh table will be skipped
200
+ Thread .sleep (1000 );
201
+ long oldValue = Config .background_refresh_metadata_time_secs_since_last_access_secs ;
202
+ // not refresh table, just skip refresh table
203
+ Config .background_refresh_metadata_time_secs_since_last_access_secs = 0 ;
204
+
205
+ try {
206
+ cachingHiveMetastore .refreshTableBackground ("db1" , "tbl1" , true );
207
+ } catch (Exception e ) {
208
+ Assert .fail ();
209
+ } finally {
210
+ Config .background_refresh_metadata_time_secs_since_last_access_secs = oldValue ;
211
+ }
212
+ // table cache will be removed because of skip refresh table
213
+ Assert .assertFalse (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
214
+ }
215
+
172
216
@ Test
173
217
public void testRefreshHiveView () {
174
218
CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore (
0 commit comments