-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add count connection functions #10568
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...istence/src/test/java/io/airbyte/config/persistence/ConfigRepositoryE2EReadWriteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.config.persistence; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.spy; | ||
|
||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.config.DestinationConnection; | ||
import io.airbyte.config.SourceConnection; | ||
import io.airbyte.config.StandardDestinationDefinition; | ||
import io.airbyte.config.StandardSourceDefinition; | ||
import io.airbyte.config.StandardSourceDefinition.SourceType; | ||
import io.airbyte.config.StandardWorkspace; | ||
import io.airbyte.config.persistence.split_secrets.MemorySecretPersistence; | ||
import io.airbyte.config.persistence.split_secrets.NoOpSecretsHydrator; | ||
import io.airbyte.db.Database; | ||
import io.airbyte.db.instance.configs.ConfigsDatabaseInstance; | ||
import io.airbyte.db.instance.configs.ConfigsDatabaseMigrator; | ||
import io.airbyte.db.instance.development.DevDatabaseMigrator; | ||
import io.airbyte.db.instance.development.MigrationDevHelper; | ||
import io.airbyte.protocol.models.ConnectorSpecification; | ||
import io.airbyte.validation.json.JsonValidationException; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
public class ConfigRepositoryE2EReadWriteTest { | ||
|
||
private final StandardWorkspace workspace = new StandardWorkspace() | ||
.withWorkspaceId(UUID.randomUUID()) | ||
.withName("Default workspace") | ||
.withSlug("default-workspace") | ||
.withInitialSetupComplete(true); | ||
private static PostgreSQLContainer<?> container; | ||
private Database database; | ||
private ConfigRepository configRepository; | ||
private DatabaseConfigPersistence configPersistence; | ||
|
||
@BeforeAll | ||
public static void dbSetup() { | ||
container = new PostgreSQLContainer<>("postgres:13-alpine") | ||
.withDatabaseName("airbyte") | ||
.withUsername("docker") | ||
.withPassword("docker"); | ||
container.start(); | ||
} | ||
|
||
@BeforeEach | ||
void setup() throws IOException, JsonValidationException { | ||
final var secretPersistence = new MemorySecretPersistence(); | ||
database = new ConfigsDatabaseInstance(container.getUsername(), container.getPassword(), container.getJdbcUrl()).getAndInitialize(); | ||
configPersistence = spy(new DatabaseConfigPersistence(database)); | ||
configRepository = | ||
spy(new ConfigRepository(configPersistence, new NoOpSecretsHydrator(), Optional.of(secretPersistence), Optional.of(secretPersistence), | ||
database)); | ||
final ConfigsDatabaseMigrator configsDatabaseMigrator = | ||
new ConfigsDatabaseMigrator(database, DatabaseConfigPersistenceLoadDataTest.class.getName()); | ||
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator); | ||
MigrationDevHelper.runLastMigration(devDatabaseMigrator); | ||
configRepository.writeStandardWorkspace(workspace); | ||
} | ||
|
||
@AfterAll | ||
public static void dbDown() { | ||
container.close(); | ||
} | ||
|
||
@Test | ||
void testWorkspaceCountConnections() throws IOException, JsonValidationException { | ||
|
||
assertEquals(0, configRepository.countConnectionsForWorkspace(workspace.getWorkspaceId())); | ||
assertEquals(0, configRepository.countDestinationsForWorkspace(workspace.getWorkspaceId())); | ||
assertEquals(0, configRepository.countSourcesForWorkspace(workspace.getWorkspaceId())); | ||
|
||
final StandardSourceDefinition sourceDefinition = new StandardSourceDefinition() | ||
.withSourceDefinitionId(UUID.randomUUID()) | ||
.withSourceType(SourceType.DATABASE) | ||
.withDockerRepository("docker-repo") | ||
.withDockerImageTag("1.2.0") | ||
.withName("sourceDefinition"); | ||
configRepository.writeStandardSourceDefinition(sourceDefinition); | ||
|
||
final StandardDestinationDefinition destinationDefinition = new StandardDestinationDefinition() | ||
.withDestinationDefinitionId(UUID.randomUUID()) | ||
.withDockerRepository("docker-repo") | ||
.withDockerImageTag("1.4.0") | ||
.withName("destinationDefinition"); | ||
configRepository.writeStandardDestinationDefinition(destinationDefinition); | ||
|
||
final int sourceCount = 3; | ||
for (int i = 0; i < sourceCount; i++) { | ||
final SourceConnection source = new SourceConnection() | ||
.withSourceDefinitionId(sourceDefinition.getSourceDefinitionId()) | ||
.withSourceId(UUID.randomUUID()) | ||
.withName("SomeConnector") | ||
.withWorkspaceId(workspace.getWorkspaceId()) | ||
.withConfiguration(Jsons.deserialize("{}")); | ||
final ConnectorSpecification specification = new ConnectorSpecification() | ||
.withConnectionSpecification(Jsons.deserialize("{}")); | ||
configRepository.writeSourceConnection(source, specification); | ||
} | ||
|
||
final int destinationCount = 4; | ||
for (int i = 0; i < destinationCount; i++) { | ||
final DestinationConnection destination = new DestinationConnection() | ||
.withDestinationDefinitionId(destinationDefinition.getDestinationDefinitionId()) | ||
.withDestinationId(UUID.randomUUID()) | ||
.withName("SomeConnector") | ||
.withWorkspaceId(workspace.getWorkspaceId()) | ||
.withConfiguration(Jsons.deserialize("{}")); | ||
final ConnectorSpecification specification = new ConnectorSpecification() | ||
.withConnectionSpecification(Jsons.deserialize("{}")); | ||
configRepository.writeDestinationConnection(destination, specification); | ||
} | ||
|
||
assertEquals(3, configRepository.listSourceConnection().size()); | ||
assertEquals(4, configRepository.listDestinationConnection().size()); | ||
assertEquals(destinationCount + sourceCount, configRepository.countConnectionsForWorkspace(workspace.getWorkspaceId())); | ||
assertEquals(destinationCount, configRepository.countDestinationsForWorkspace(workspace.getWorkspaceId())); | ||
assertEquals(sourceCount, configRepository.countSourcesForWorkspace(workspace.getWorkspaceId())); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand, this would count the total amount of sources and destinations, but not the amount of connections (which should be stored in the
connection
table)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, it seems I misunderstood the needs expressed in that review: 89720b1.
So I guess you need a count of sources, destinations and connections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take another look