Skip to content

Commit

Permalink
fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-bansal committed Oct 12, 2023
1 parent c7628de commit d6daf46
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ public void deleteConfigs(
return;
}

Set<ConfigResourceContext> configResourceContexts =
List<ConfigResourceContext> configResourceContexts =
request.getConfigsList().stream()
.map(this::getConfigResourceContext)
.collect(Collectors.toUnmodifiableSet());
.collect(Collectors.toUnmodifiableList());
Map<ConfigResourceContext, Optional<ContextSpecificConfig>> configs =
configStore.getContextConfigs(configResourceContexts);
// delete the configs for the specified config resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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<DeleteConfigResponse> responseObserver = mock(StreamObserver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -61,15 +57,9 @@ class DocumentConfigStoreTest {
@BeforeEach()
void beforeEach() {
collection = mock(Collection.class);
String datastoreType = "MockDatastore";
DatastoreProvider.register(datastoreType, MockDatastore.class);
Map<String, Object> dataStoreConfig =
Map.of(DATA_STORE_TYPE, datastoreType, datastoreType, Map.of());
Map<String, Object> 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
Expand Down Expand Up @@ -123,9 +113,10 @@ void getConfigs() throws IOException {
.setCreationTimestamp(TIMESTAMP1)
.setUpdateTimestamp(TIMESTAMP2)
.build();
ConfigResourceContext context = getConfigResourceContext("context");
Map<ConfigResourceContext, Optional<ContextSpecificConfig>> 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
Expand Down Expand Up @@ -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<String, String> map) {
return false;
Expand All @@ -310,5 +295,13 @@ public boolean deleteCollection(String s) {
public boolean healthCheck() {
return false;
}

@Override
public DocStoreMetricProvider getDocStoreMetricProvider() {
return null;
}

@Override
public void close() {}
}
}

0 comments on commit d6daf46

Please sign in to comment.