Skip to content

Commit

Permalink
refactor: extract sql-lib and sql-testfixtures modules (#4653)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Dec 3, 2024
1 parent 0dc4cdb commit ebd43aa
Show file tree
Hide file tree
Showing 82 changed files with 139 additions and 85 deletions.
29 changes: 29 additions & 0 deletions core/common/lib/sql-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Cofinity-X
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Cofinity-X - initial API and implementation
*
*/

plugins {
`java-library`
}

dependencies {
api(project(":spi:common:core-spi"))
api(project(":spi:common:transaction-datasource-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":core:common:lib:util-lib"))

testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
}


Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

package org.eclipse.edc.sql;

import static org.eclipse.edc.sql.SqlCoreExtension.DEFAULT_EDC_SQL_FETCH_SIZE;

/**
* Configuration class for {@link SqlQueryExecutor}
*/
public record SqlQueryExecutorConfiguration(int fetchSize) {

public static final String DEFAULT_EDC_SQL_FETCH_SIZE = "5000";

public static SqlQueryExecutorConfiguration ofDefaults() {
return new SqlQueryExecutorConfiguration(Integer.parseInt(DEFAULT_EDC_SQL_FETCH_SIZE));
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/common/sql/sql-bootstrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
api(project(":spi:common:core-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core")) // SqlQueryExecutor
implementation(project(":core:common:lib:sql-lib"))
//
testImplementation(project(":core:common:junit"))
testImplementation(libs.assertj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

package org.eclipse.edc.sql.bootstrapper;

import org.eclipse.edc.boot.system.injection.ObjectFactory;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapperExtension.SCHEMA_AUTOCREATE_PROPERTY;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand All @@ -46,20 +47,20 @@ void setUp(ServiceExtensionContext context) {
}

@Test
void prepare_autocreateDisabled(SqlSchemaBootstrapperExtension extension, ServiceExtensionContext context) {
var config = mock(Config.class);
when(config.getBoolean(eq("edc.sql.schema.autocreate"), anyBoolean())).thenReturn(false);
when(context.getConfig()).thenReturn(config);
void shouldNotCreateSchema_whenSettingIsDisabled(ObjectFactory objectFactory, ServiceExtensionContext context) {
var extension = objectFactory.constructInstance(SqlSchemaBootstrapperExtension.class);
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of(SCHEMA_AUTOCREATE_PROPERTY, "false")));

extension.initialize(context);
extension.prepare();

verifyNoInteractions(transactionContext);
}

@Test
void prepare(SqlSchemaBootstrapperExtension extension, ServiceExtensionContext context) {
var config = mock(Config.class);
when(config.getBoolean(eq(SCHEMA_AUTOCREATE_PROPERTY), anyBoolean())).thenReturn(true);
when(context.getConfig()).thenReturn(config);
void shouldCreateSchema_whenSettingIsEnabled(ServiceExtensionContext context, ObjectFactory objectFactory) {
when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of(SCHEMA_AUTOCREATE_PROPERTY, "true")));
var extension = objectFactory.constructInstance(SqlSchemaBootstrapperExtension.class);
when(transactionContext.execute(isA(TransactionContext.ResultTransactionBlock.class)))
.thenReturn(Result.success("foobar"));

Expand All @@ -69,4 +70,4 @@ void prepare(SqlSchemaBootstrapperExtension extension, ServiceExtensionContext c
verify(transactionContext).execute(isA(TransactionContext.ResultTransactionBlock.class));
}

}
}
14 changes: 3 additions & 11 deletions extensions/common/sql/sql-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ plugins {
dependencies {
api(project(":spi:common:core-spi"))
api(project(":spi:common:transaction-spi"))
api(project(":spi:common:transaction-datasource-spi"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":core:common:lib:util-lib"))
implementation(project(":spi:common:transaction-datasource-spi"))


testImplementation(project(":core:common:junit"))
testFixturesImplementation(project(":spi:common:transaction-datasource-spi"))
testFixturesImplementation(project(":core:common:junit"))
testFixturesImplementation(libs.junit.jupiter.api)
testFixturesImplementation(libs.mockito.core)
testFixturesImplementation(libs.postgres)

testFixturesImplementation(libs.testcontainers.junit)
testFixturesImplementation(libs.testcontainers.postgres)

testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
}


Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import org.eclipse.edc.transaction.spi.NoopTransactionContext;
import org.eclipse.edc.transaction.spi.TransactionContext;

import static org.eclipse.edc.sql.SqlQueryExecutorConfiguration.DEFAULT_EDC_SQL_FETCH_SIZE;

@Extension(value = SqlCoreExtension.NAME)
public class SqlCoreExtension implements ServiceExtension {

public static final String NAME = "SQL Core";

public static final String DEFAULT_EDC_SQL_FETCH_SIZE = "5000";
@Setting(description = "Fetch size value used in SQL queries", defaultValue = DEFAULT_EDC_SQL_FETCH_SIZE, key = "edc.sql.fetch.size")
private int fetchSize;

Expand Down
7 changes: 3 additions & 4 deletions extensions/common/sql/sql-lease/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ dependencies {
api(project(":spi:common:core-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":extensions:common:transaction:transaction-local"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-lease")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(libs.postgres)
testImplementation(libs.assertj)

testFixturesImplementation(project(":extensions:common:sql:sql-core"))
testFixturesImplementation(project(":core:common:lib:sql-lib")) // TODO: these fixtures could finish in sql-testfixtures module
}


Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ plugins {

dependencies {
api(project(":spi:common:transaction-datasource-spi"))
api(project(":extensions:common:sql:sql-core"))

implementation(project(":core:common:lib:sql-lib"))

implementation(libs.apache.commons.pool)

Expand Down
35 changes: 35 additions & 0 deletions extensions/common/sql/sql-test-fixtures/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Cofinity-X
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Cofinity-X - Initial build file
*
*/

plugins {
`java-library`
`java-test-fixtures`
}

dependencies {
testFixturesImplementation(project(":spi:common:core-spi"))
testFixturesImplementation(project(":spi:common:transaction-datasource-spi"))
testFixturesImplementation(project(":spi:common:transaction-spi"))
testFixturesImplementation(project(":core:common:junit"))
testFixturesImplementation(project(":core:common:lib:sql-lib"))
testFixturesImplementation(project(":extensions:common:sql:sql-lease"))

testFixturesImplementation(libs.junit.jupiter.api)
testFixturesImplementation(libs.mockito.core)
testFixturesImplementation(libs.postgres)
testFixturesImplementation(libs.testcontainers.junit)
testFixturesImplementation(libs.testcontainers.postgres)
}


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.sql.lease.testfixtures;
package org.eclipse.edc.sql.testfixtures;

import org.eclipse.edc.sql.SqlQueryExecutor;
import org.eclipse.edc.sql.lease.LeaseStatements;
Expand Down
6 changes: 3 additions & 3 deletions extensions/common/store/sql/edr-index-sql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ dependencies {
api(project(":spi:common:core-spi"))
api(project(":spi:common:transaction-spi"))

implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))
implementation(project(":spi:common:edr-store-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(testFixtures(project(":spi:common:edr-store-spi")))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ dependencies {
api(project(":spi:common:jwt-spi"))
api(project(":spi:common:transaction-spi"))

implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))
implementation(project(":spi:common:transaction-datasource-spi"))
testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(testFixtures(project(":spi:common:jwt-spi")))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ dependencies {
api(project(":spi:common:core-spi"))
api(project(":spi:common:transaction-spi"))

implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))
implementation(project(":spi:common:identity-trust-sts-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(testFixtures(project(":spi:common:identity-trust-sts-spi")))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {

testImplementation(project(":tests:junit-base"));

testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
}


Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
api(project(":spi:control-plane:asset-spi"))

implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))
implementation(project(":core:common:lib:util-lib"))

Expand All @@ -32,7 +32,7 @@ dependencies {
testImplementation(project(":spi:common:policy-model"))
testImplementation(libs.assertj)
testImplementation(testFixtures(project(":spi:control-plane:asset-spi")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(libs.postgres)

testImplementation(libs.testcontainers.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ dependencies {
api(project(":spi:control-plane:contract-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":spi:common:policy-model"))
testImplementation(libs.assertj)
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(testFixtures(project(":spi:control-plane:contract-spi")))
testImplementation(libs.postgres)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ dependencies {
api(project(":spi:control-plane:contract-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-lease"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))


testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-lease")))
testImplementation(libs.assertj)
testImplementation(testFixtures(project(":spi:control-plane:contract-spi")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
testImplementation(libs.postgres)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.edc.junit.testfixtures.TestUtils;
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.sql.testfixtures.LeaseUtil;
import org.eclipse.edc.sql.testfixtures.PostgresqlStoreSetupExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
testImplementation(project(":core:control-plane:control-plane-catalog"))
testImplementation(project(":core:control-plane:control-plane-contract"))
testImplementation(project(":core:control-plane:control-plane-core"))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
}


Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ dependencies {
api(project(":spi:control-plane:contract-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))


testImplementation(project(":core:common:junit"))
testImplementation(libs.postgres)
testImplementation(testFixtures(project(":spi:control-plane:policy-spi")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))
}


Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
api(project(":spi:control-plane:transfer-spi"))
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))
implementation(project(":extensions:common:sql:sql-core"))
implementation(project(":core:common:lib:sql-lib"))
implementation(project(":extensions:common:sql:sql-lease"))
implementation(project(":extensions:common:sql:sql-bootstrapper"))

Expand All @@ -32,8 +32,7 @@ dependencies {
testImplementation(libs.awaitility)
testImplementation(libs.postgres)
testImplementation(testFixtures(project(":spi:control-plane:transfer-spi")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-lease")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
testImplementation(testFixtures(project(":extensions:common:sql:sql-test-fixtures")))

}

Expand Down
Loading

0 comments on commit ebd43aa

Please sign in to comment.