From 0d81c6e8cc6716c72ef23514a89361f4d13f1553 Mon Sep 17 00:00:00 2001 From: Malik Diarra Date: Mon, 14 Feb 2022 18:58:12 -0800 Subject: [PATCH] Add additional unit tests --- .../config/persistence/ConfigRepository.java | 2 +- ...baseConfigPersistenceE2EReadWriteTest.java | 43 ++++++++++--------- .../airbyte/config/persistence/MockData.java | 40 +++++++++++++++++ 3 files changed, 63 insertions(+), 22 deletions(-) diff --git a/airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java b/airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java index 263e40ce52f79..e8cbe0417bc95 100644 --- a/airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java +++ b/airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java @@ -556,7 +556,7 @@ public void updateConnectionState(final UUID connectionId, final State state) th throw new IllegalStateException(e); } } - + public Optional getSourceCatalog(final UUID sourceId, final String configurationHash, final String connectorVersion) diff --git a/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/DatabaseConfigPersistenceE2EReadWriteTest.java b/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/DatabaseConfigPersistenceE2EReadWriteTest.java index 5714f6d5a3d7e..aaf6ae7673762 100644 --- a/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/DatabaseConfigPersistenceE2EReadWriteTest.java +++ b/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/DatabaseConfigPersistenceE2EReadWriteTest.java @@ -10,7 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.spy; -import io.airbyte.commons.json.Jsons; import io.airbyte.config.ActorCatalog; import io.airbyte.config.ActorCatalogFetchEvent; import io.airbyte.config.ConfigSchema; @@ -31,7 +30,6 @@ import io.airbyte.validation.json.JsonValidationException; import java.io.IOException; import java.util.List; -import java.util.UUID; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -265,27 +263,30 @@ private void standardWorkspace() throws JsonValidationException, IOException, Co } public void standardActorCatalog() throws JsonValidationException, IOException, ConfigNotFoundException { - final SourceConnection source = MockData.sourceConnections().get(0); - final ActorCatalog actorCatalog = new ActorCatalog() - .withId(UUID.randomUUID()) - .withCatalog(Jsons.deserialize("{}")) - .withCatalogHash("TESTHASH"); - final ActorCatalogFetchEvent actorCatalogFetchEvent = new ActorCatalogFetchEvent() - .withId(UUID.randomUUID()) - .withActorCatalogId(actorCatalog.getId()) - .withActorId(source.getSourceId()) - .withConfigHash("CONFIG_HASH") - .withConnectorVersion("1.0.0"); - configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), actorCatalog); - final ActorCatalog retrievedActorCatalog = configPersistence.getConfig( - ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), ActorCatalog.class); - assertEquals(actorCatalog, retrievedActorCatalog); + for (final ActorCatalog actorCatalog : MockData.actorCatalogs()) { + configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), actorCatalog); + final ActorCatalog retrievedActorCatalog = configPersistence.getConfig( + ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), ActorCatalog.class); + assertEquals(actorCatalog, retrievedActorCatalog); + } ; + final List actorCatalogs = configPersistence + .listConfigs(ConfigSchema.ACTOR_CATALOG, ActorCatalog.class); + assertEquals(MockData.actorCatalogs().size(), actorCatalogs.size()); + assertThat(MockData.actorCatalogs()).hasSameElementsAs(actorCatalogs); - configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, actorCatalogFetchEvent.getId().toString(), actorCatalogFetchEvent); - final ActorCatalogFetchEvent retrievedActorCatalogFetchEvent = configPersistence.getConfig( - ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, actorCatalogFetchEvent.getId().toString(), ActorCatalogFetchEvent.class); - assertEquals(actorCatalogFetchEvent, retrievedActorCatalogFetchEvent); + for (final ActorCatalogFetchEvent actorCatalogFetchEvent : MockData.actorCatalogFetchEvents()) { + configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, + actorCatalogFetchEvent.getId().toString(), actorCatalogFetchEvent); + final ActorCatalogFetchEvent retrievedActorCatalogFetchEvent = configPersistence.getConfig( + ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, actorCatalogFetchEvent.getId().toString(), + ActorCatalogFetchEvent.class); + assertEquals(actorCatalogFetchEvent, retrievedActorCatalogFetchEvent); + } + final List actorCatalogFetchEvents = configPersistence + .listConfigs(ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, ActorCatalogFetchEvent.class); + assertEquals(MockData.actorCatalogFetchEvents().size(), actorCatalogFetchEvents.size()); + assertThat(MockData.actorCatalogFetchEvents()).hasSameElementsAs(actorCatalogFetchEvents); } } diff --git a/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/MockData.java b/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/MockData.java index 33d8fb2533099..c7aba39916029 100644 --- a/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/MockData.java +++ b/airbyte-config/persistence/src/test/java/io/airbyte/config/persistence/MockData.java @@ -6,6 +6,8 @@ import com.google.common.collect.Lists; import io.airbyte.commons.json.Jsons; +import io.airbyte.config.ActorCatalog; +import io.airbyte.config.ActorCatalogFetchEvent; import io.airbyte.config.DestinationConnection; import io.airbyte.config.DestinationOAuthParameter; import io.airbyte.config.JobSyncConfig.NamespaceDefinitionType; @@ -68,6 +70,12 @@ public class MockData { private static final UUID SOURCE_OAUTH_PARAMETER_ID_2 = UUID.randomUUID(); private static final UUID DESTINATION_OAUTH_PARAMETER_ID_1 = UUID.randomUUID(); private static final UUID DESTINATION_OAUTH_PARAMETER_ID_2 = UUID.randomUUID(); + private static final UUID ACTOR_CATALOG_ID_1 = UUID.randomUUID(); + private static final UUID ACTOR_CATALOG_ID_2 = UUID.randomUUID(); + private static final UUID ACTOR_CATALOG_ID_3 = UUID.randomUUID(); + private static final UUID ACTOR_CATALOG_FETCH_EVENT_ID_1 = UUID.randomUUID(); + private static final UUID ACTOR_CATALOG_FETCH_EVENT_ID_2 = UUID.randomUUID(); + private static final Instant NOW = Instant.parse("2021-12-15T20:30:40.00Z"); public static StandardWorkspace standardWorkspace() { @@ -341,6 +349,38 @@ public static List standardSyncStates() { return Arrays.asList(standardSyncState1, standardSyncState2, standardSyncState3, standardSyncState4); } + public static List actorCatalogs() { + final ActorCatalog actorCatalog1 = new ActorCatalog() + .withId(ACTOR_CATALOG_ID_1) + .withCatalog(Jsons.deserialize("{}")) + .withCatalogHash("TESTHASH"); + final ActorCatalog actorCatalog2 = new ActorCatalog() + .withId(ACTOR_CATALOG_ID_2) + .withCatalog(Jsons.deserialize("{}")) + .withCatalogHash("12345"); + final ActorCatalog actorCatalog3 = new ActorCatalog() + .withId(ACTOR_CATALOG_ID_3) + .withCatalog(Jsons.deserialize("{}")) + .withCatalogHash("SomeOtherHash"); + return Arrays.asList(actorCatalog1, actorCatalog2, actorCatalog3); + } + + public static List actorCatalogFetchEvents() { + final ActorCatalogFetchEvent actorCatalogFetchEvent1 = new ActorCatalogFetchEvent() + .withId(ACTOR_CATALOG_FETCH_EVENT_ID_1) + .withActorCatalogId(ACTOR_CATALOG_ID_1) + .withActorId(SOURCE_ID_1) + .withConfigHash("CONFIG_HASH") + .withConnectorVersion("1.0.0"); + final ActorCatalogFetchEvent actorCatalogFetchEvent2 = new ActorCatalogFetchEvent() + .withId(ACTOR_CATALOG_FETCH_EVENT_ID_2) + .withActorCatalogId(ACTOR_CATALOG_ID_2) + .withActorId(SOURCE_ID_2) + .withConfigHash("1394") + .withConnectorVersion("1.2.0"); + return Arrays.asList(actorCatalogFetchEvent1); + } + public static Instant now() { return NOW; }