diff --git a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingService.java b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingService.java index 60ae89d2a..ac8e2cf7a 100644 --- a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingService.java +++ b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingService.java @@ -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; @@ -410,7 +411,8 @@ public List getAllDatabases() { return new ArrayList<>(mappingsByDatabaseName.keySet()); } - public List getPrimaryAllDatabases() { + @VisibleForTesting + List getPrimaryAllDatabases() { BiFunction filter = getFilter(); Map mappingsForPattern = new LinkedHashMap<>(); diff --git a/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingServiceTest.java b/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingServiceTest.java index f1f7b9603..505934342 100644 --- a/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingServiceTest.java +++ b/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/mapping/service/impl/StaticDatabaseMappingServiceTest.java @@ -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) @@ -458,6 +459,25 @@ public void panopticOperationsHandlerGetAllDatabases() { assertThat(handler.getAllDatabases(), is(allDatabases)); } + @Test + public void panopticOperationsHandlerGetPrimaryAllDatabases() throws Exception { + String pattern = "*"; + List 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());