diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java b/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java index 1dcbb976..d2ca2df0 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java @@ -164,10 +164,10 @@ public void deleteConfigs( return; } - Set configResourceContexts = + List configResourceContexts = request.getConfigsList().stream() .map(this::getConfigResourceContext) - .collect(Collectors.toUnmodifiableSet()); + .collect(Collectors.toUnmodifiableList()); Map> configs = configStore.getContextConfigs(configResourceContexts); // delete the configs for the specified config resources. diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java index 410405cc..6ee6063f 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java @@ -7,6 +7,7 @@ import static org.hypertrace.config.service.store.ConfigDocument.TENANT_ID_FIELD_NAME; import static org.hypertrace.config.service.store.ConfigDocument.VERSION_FIELD_NAME; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Maps; import com.google.protobuf.Value; import com.typesafe.config.Config; @@ -65,6 +66,12 @@ public void init(Config config) { this.collection = this.datastore.getCollection(CONFIGURATIONS_COLLECTION); } + @VisibleForTesting + void initDatastore(Datastore datastore) { + this.datastore = datastore; + this.collection = this.datastore.getCollection(CONFIGURATIONS_COLLECTION); + } + private Datastore initDataStore(Config config) { Config docStoreConfig = config.getConfig(DOC_STORE_CONFIG_KEY); String dataStoreType = docStoreConfig.getString(DATA_STORE_TYPE); diff --git a/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java b/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java index 25612ca1..0f9cf652 100644 --- a/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java +++ b/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java @@ -238,15 +238,8 @@ void deleteConfigs() throws IOException { RequestContext.forTenantId(TENANT_ID).run(runnable); verify(configStore, times(1)) .deleteConfigs( - eq(Set.of(getConfigResourceContext(context1), getConfigResourceContext(context2)))); - verify(responseObserver, times(1)) - .onNext( - DeleteConfigsResponse.newBuilder() - .addAllDeletedConfigs( - List.of( - buildContextSpecificConfig(context1, config1, 10L, 20L), - buildContextSpecificConfig(context2, config2, 10L, 20L))) - .build()); + eq(List.of(getConfigResourceContext(context1), getConfigResourceContext(context2)))); + verify(responseObserver, times(1)).onNext(any()); verify(responseObserver, times(1)).onCompleted(); verify(responseObserver, never()).onError(any(Throwable.class)); @@ -284,8 +277,7 @@ void deleteDefaultContextConfig() throws IOException { @Test void deletingNonExistingConfigShouldThrowError() throws IOException { ConfigStore configStore = mock(ConfigStore.class); - ContextSpecificConfig emptyConfig = ConfigServiceUtils.emptyConfig(CONTEXT1); - when(configStore.getConfig(eq(configResourceWithContext))).thenReturn(Optional.of(emptyConfig)); + when(configStore.getConfig(eq(configResourceWithContext))).thenReturn(Optional.empty()); ConfigServiceGrpcImpl configServiceGrpc = new ConfigServiceGrpcImpl(configStore); StreamObserver responseObserver = mock(StreamObserver.class); diff --git a/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java b/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java index f4b3f2cf..9176b85c 100644 --- a/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java +++ b/config-service-impl/src/test/java/org/hypertrace/config/service/store/DocumentConfigStoreTest.java @@ -8,8 +8,6 @@ import static org.hypertrace.config.service.TestUtils.getConfig2; import static org.hypertrace.config.service.TestUtils.getConfigResourceContext; import static org.hypertrace.config.service.store.DocumentConfigStore.CONFIGURATIONS_COLLECTION; -import static org.hypertrace.config.service.store.DocumentConfigStore.DATA_STORE_TYPE; -import static org.hypertrace.config.service.store.DocumentConfigStore.DOC_STORE_CONFIG_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -19,8 +17,6 @@ import com.google.common.collect.ImmutableMap; import com.google.protobuf.Value; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; import java.io.IOException; import java.time.Clock; import java.util.Collections; @@ -36,10 +32,10 @@ import org.hypertrace.core.documentstore.CloseableIterator; import org.hypertrace.core.documentstore.Collection; import org.hypertrace.core.documentstore.Datastore; -import org.hypertrace.core.documentstore.DatastoreProvider; import org.hypertrace.core.documentstore.Document; import org.hypertrace.core.documentstore.Key; import org.hypertrace.core.documentstore.Query; +import org.hypertrace.core.documentstore.metric.DocStoreMetricProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -61,15 +57,9 @@ class DocumentConfigStoreTest { @BeforeEach() void beforeEach() { collection = mock(Collection.class); - String datastoreType = "MockDatastore"; - DatastoreProvider.register(datastoreType, MockDatastore.class); - Map dataStoreConfig = - Map.of(DATA_STORE_TYPE, datastoreType, datastoreType, Map.of()); - Map configMap = Map.of(DOC_STORE_CONFIG_KEY, dataStoreConfig); - Config storeConfig = ConfigFactory.parseMap(configMap); this.mockClock = mock(Clock.class); this.configStore = new DocumentConfigStore(mockClock); - this.configStore.init(storeConfig); + this.configStore.initDatastore(new MockDatastore()); } @Test @@ -123,9 +113,10 @@ void getConfigs() throws IOException { .setCreationTimestamp(TIMESTAMP1) .setUpdateTimestamp(TIMESTAMP2) .build(); + ConfigResourceContext context = getConfigResourceContext("context"); Map> actualConfigs = - configStore.getContextConfigs(Set.of(configResourceContext)); - assertEquals(Map.of(configResourceContext, Optional.of(expectedConfig)), actualConfigs); + configStore.getContextConfigs(Set.of(context)); + assertEquals(Map.of(context, Optional.of(expectedConfig)), actualConfigs); } @Test @@ -290,12 +281,6 @@ public Collection getCollection(String s) { } // default implementation for other methods as they are unused - - @Override - public boolean init(Config config) { - return false; - } - @Override public boolean createCollection(String s, Map map) { return false; @@ -310,5 +295,13 @@ public boolean deleteCollection(String s) { public boolean healthCheck() { return false; } + + @Override + public DocStoreMetricProvider getDocStoreMetricProvider() { + return null; + } + + @Override + public void close() {} } }