Skip to content
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

fix(test): adapt tests to new Runtime model in EDC #204

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 45 additions & 67 deletions DEPENDENCIES

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dependencies {

testImplementation(libs.edc.sql.core)
testImplementation(libs.edc.sql.dataplane.instancestore)
testImplementation(libs.edc.junit)
testImplementation(testFixtures(libs.edc.sql.lease))
testImplementation(testFixtures(libs.edc.sql.core))
testImplementation(testFixtures(libs.edc.dpf.selector.spi))
testImplementation(testFixtures(project(":extensions:common:azure:azure-test")))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@
import org.eclipse.edc.json.JacksonTypeManager;
import org.eclipse.edc.policy.model.PolicyRegistrationTypes;
import org.eclipse.edc.sql.QueryExecutor;
import org.eclipse.edc.sql.lease.testfixtures.LeaseUtil;
import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;

import java.sql.SQLException;
import java.time.Clock;
import java.time.Duration;
import javax.sql.DataSource;

import static org.eclipse.edc.azure.testfixtures.CosmosPostgresTestExtension.DEFAULT_DATASOURCE_NAME;
import static org.eclipse.edc.junit.testfixtures.TestUtils.getResourceFileContentAsString;

@ParallelPostgresCosmosTest
@ExtendWith(CosmosPostgresTestExtension.class)
public class CosmosDataPlaneInstanceStoreTest extends DataPlaneInstanceStoreTestBase {
private static final DataPlaneInstanceStatements STATEMENTS = new PostgresDataPlaneInstanceStatements();
SqlDataPlaneInstanceStore store;
private final DataPlaneInstanceStatements statements = new PostgresDataPlaneInstanceStatements();
private SqlDataPlaneInstanceStore store;
private LeaseUtil leaseUtil;

@BeforeAll
static void createDatabase(CosmosPostgresTestExtension.SqlHelper helper) {
Expand All @@ -52,13 +60,22 @@ static void dropDatabase(CosmosPostgresTestExtension.SqlHelper helper) {
}

@BeforeEach
void setUp(DataSourceRegistry reg, TransactionContext transactionContext, QueryExecutor queryExecutor, CosmosPostgresTestExtension.SqlHelper helper) {
void setUp(DataSourceRegistry reg, DataSource dataSource, TransactionContext transactionContext, QueryExecutor queryExecutor, CosmosPostgresTestExtension.SqlHelper helper) {

var clock = Clock.systemUTC();

var typeManager = new JacksonTypeManager();
typeManager.registerTypes(DataPlaneInstance.class);
typeManager.registerTypes(PolicyRegistrationTypes.TYPES.toArray(Class<?>[]::new));
leaseUtil = new LeaseUtil(transactionContext, () -> {
try {
return dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}, statements, clock);

store = new SqlDataPlaneInstanceStore(reg, DEFAULT_DATASOURCE_NAME, transactionContext, STATEMENTS, typeManager.getMapper(), queryExecutor);
store = new SqlDataPlaneInstanceStore(reg, DEFAULT_DATASOURCE_NAME, transactionContext, STATEMENTS, typeManager.getMapper(), queryExecutor, clock, CONNECTOR_NAME);
helper.truncateTable(STATEMENTS.getDataPlaneInstanceTable());
}

Expand All @@ -68,5 +85,18 @@ protected DataPlaneInstanceStore getStore() {
return store;
}

@Override
protected void leaseEntity(String entityId, String owner, Duration duration) {
leaseUtil.leaseEntity(entityId, owner, duration);
}

@Override
protected boolean isLeasedBy(String entityId, String owner) {
return leaseUtil.isLeased(entityId, owner);
}

@Override
protected Duration getTestTimeout() {
return Duration.ofSeconds(2);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
CREATE TABLE IF NOT EXISTS edc_lease
(
leased_by VARCHAR NOT NULL,
leased_at BIGINT,
lease_duration INTEGER NOT NULL,
lease_id VARCHAR NOT NULL
CONSTRAINT lease_pk
PRIMARY KEY
);


CREATE TABLE IF NOT EXISTS edc_data_plane_instance
(
id VARCHAR NOT NULL PRIMARY KEY,
data JSON
id VARCHAR NOT NULL PRIMARY KEY,
data JSON,
lease_id VARCHAR
CONSTRAINT data_plane_instance_lease_id_fk
REFERENCES edc_lease
ON DELETE SET NULL
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.edc.connector.dataplane.spi.store.DataPlaneStore;
import org.eclipse.edc.json.JacksonTypeManager;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.junit.extensions.EmbeddedRuntime;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.spi.types.domain.DataAddress;
Expand Down Expand Up @@ -98,7 +99,7 @@ static void afterAll() {

@Test
void transfer_success(
EdcExtension edc,
EmbeddedRuntime edc,
AzureResourceManager azure,
DataPlaneManager dataPlaneManager,
DataPlaneStore store) {
Expand Down Expand Up @@ -184,7 +185,7 @@ private static class Account {
private final BlobServiceClient client;
private final String containerName = "test-container-" + UUID.randomUUID();

Account(AzureResourceManager azure, EdcExtension edc, String setting) {
Account(AzureResourceManager azure, EmbeddedRuntime edc, String setting) {
String accountId = Objects.requireNonNull(edc.getContext().getConfig().getString(setting), setting);
var account = azure.storageAccounts().getById(accountId);
name = account.name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void transferBlob_success(String assetName, String[] blobsToTransfer) {
providerClient.createContractDefinition(assetId, UUID.randomUUID().toString(), policyId, policyId);

// Write Key to vault
consumer.getContext().getService(Vault.class).storeSecret(format("%s-key1", CONSUMER_STORAGE_ACCOUNT_NAME), CONSUMER_STORAGE_ACCOUNT_KEY);
provider.getContext().getService(Vault.class).storeSecret(format("%s-key1", PROVIDER_STORAGE_ACCOUNT_NAME), PROVIDER_STORAGE_ACCOUNT_KEY);
consumer.getService(Vault.class).storeSecret(format("%s-key1", CONSUMER_STORAGE_ACCOUNT_NAME), CONSUMER_STORAGE_ACCOUNT_KEY);
provider.getService(Vault.class).storeSecret(format("%s-key1", PROVIDER_STORAGE_ACCOUNT_NAME), PROVIDER_STORAGE_ACCOUNT_KEY);

var transferProcessId = consumerClient.requestAssetAndTransferToBlob(providerClient, assetId, CONSUMER_STORAGE_ACCOUNT_NAME);
await().pollInterval(POLL_INTERVAL).atMost(TIMEOUT).untilAsserted(() -> {
Expand Down
Loading