21
21
import com .starrocks .catalog .HiveTable ;
22
22
import com .starrocks .catalog .PrimitiveType ;
23
23
import com .starrocks .catalog .ScalarType ;
24
+ import com .starrocks .common .Config ;
24
25
import com .starrocks .connector .PartitionUtil ;
25
26
import com .starrocks .connector .exception .StarRocksConnectorException ;
26
27
import mockit .Expectations ;
@@ -43,7 +44,7 @@ public class CachingHiveMetastoreTest {
43
44
private HiveMetaClient client ;
44
45
private HiveMetastore metastore ;
45
46
private ExecutorService executor ;
46
- private long expireAfterWriteSec = 10 ;
47
+ private long expireAfterWriteSec = 30 ;
47
48
private long refreshAfterWriteSec = -1 ;
48
49
49
50
@ Before
@@ -158,6 +159,48 @@ public void testRefreshTableSync() {
158
159
Assert .assertEquals (1 , cachingHiveMetastore .tableNameLockMap .size ());
159
160
}
160
161
162
+ @ Test
163
+ public void testRefreshTableBackground () throws InterruptedException {
164
+ CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore (
165
+ metastore , executor , expireAfterWriteSec , refreshAfterWriteSec , 1000 , false );
166
+ Assert .assertFalse (cachingHiveMetastore .tableNameLockMap .containsKey (
167
+ HiveTableName .of ("db1" , "tbl1" )));
168
+ try {
169
+ // mock query table tbl1
170
+ List <String > partitionNames = cachingHiveMetastore .getPartitionKeys ("db1" , "tbl1" );
171
+ cachingHiveMetastore .getPartitionsByNames ("db1" ,
172
+ "tbl1" , partitionNames );
173
+ // put table tbl1 in table cache
174
+ cachingHiveMetastore .refreshTable ("db1" , "tbl1" , true );
175
+ } catch (Exception e ) {
176
+ Assert .fail ();
177
+ }
178
+ Assert .assertTrue (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
179
+
180
+ try {
181
+ cachingHiveMetastore .refreshTableBackground ("db1" , "tbl1" , true );
182
+ } catch (Exception e ) {
183
+ Assert .fail ();
184
+ }
185
+ // not skip refresh table, table cache still exist
186
+ Assert .assertTrue (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
187
+ // sleep 1s, background refresh table will be skipped
188
+ Thread .sleep (1000 );
189
+ long oldValue = Config .background_refresh_metadata_time_secs_since_last_access_secs ;
190
+ // not refresh table, just skip refresh table
191
+ Config .background_refresh_metadata_time_secs_since_last_access_secs = 0 ;
192
+
193
+ try {
194
+ cachingHiveMetastore .refreshTableBackground ("db1" , "tbl1" , true );
195
+ } catch (Exception e ) {
196
+ Assert .fail ();
197
+ } finally {
198
+ Config .background_refresh_metadata_time_secs_since_last_access_secs = oldValue ;
199
+ }
200
+ // table cache will be removed because of skip refresh table
201
+ Assert .assertFalse (cachingHiveMetastore .isTablePresent (HiveTableName .of ("db1" , "tbl1" )));
202
+ }
203
+
161
204
@ Test
162
205
public void testGetPartitionKeys () {
163
206
CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore (
0 commit comments