Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
flaming-archer committed Nov 2, 2023
1 parent 602f261 commit 7611c7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import lombok.extern.log4j.Log4j2;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
Expand Down Expand Up @@ -410,7 +411,8 @@ public List<String> getAllDatabases() {
return new ArrayList<>(mappingsByDatabaseName.keySet());
}

public List<String> getPrimaryAllDatabases() {
@VisibleForTesting
List<String> getPrimaryAllDatabases() {
BiFunction<String, DatabaseMapping, Boolean> filter = getFilter();

Map<DatabaseMapping, String> mappingsForPattern = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.hotels.bdp.waggledance.mapping.model.QueryMapping;
import com.hotels.bdp.waggledance.mapping.service.MetaStoreMappingFactory;
import com.hotels.bdp.waggledance.mapping.service.PanopticOperationHandler;
import com.hotels.bdp.waggledance.mapping.service.impl.StaticDatabaseMappingService.StaticDatabaseMappingPanopticOperationHandler;
import com.hotels.bdp.waggledance.server.NoPrimaryMetastoreException;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -458,6 +459,25 @@ public void panopticOperationsHandlerGetAllDatabases() {
assertThat(handler.getAllDatabases(), is(allDatabases));
}

@Test
public void panopticOperationsHandlerGetPrimaryAllDatabases() throws Exception {
String pattern = "*";
List<String> allPrimaryDatabases =
Lists.newArrayList("primary_db1", "primary_db2", "primary_db3");
when(primaryDatabaseClient.get_databases(pattern)).thenReturn(allPrimaryDatabases);
when(primaryDatabaseClient.get_all_databases()).thenReturn(allPrimaryDatabases);

primaryMetastore.setMappedDatabases(Lists.newArrayList("primary_db1"));

service = new StaticDatabaseMappingService(metaStoreMappingFactory,
Arrays.asList(primaryMetastore, federatedMetastore), queryMapping);


StaticDatabaseMappingPanopticOperationHandler handler =
(StaticDatabaseMappingPanopticOperationHandler) service.getPanopticOperationHandler();
assertThat(handler.getPrimaryAllDatabases(), is(Lists.newArrayList("primary_db1")));
}

@Test
public void panopticOperationsHandlerGetAllDatabasesWithEmptyMappedDatabases() {
federatedMetastore.setMappedDatabases(Collections.emptyList());
Expand Down

0 comments on commit 7611c7d

Please sign in to comment.