From c05b84a1c6854598e749e3bfcfa8056579986e0b Mon Sep 17 00:00:00 2001 From: andrea bertagnolli Date: Wed, 6 Nov 2024 12:34:03 +0100 Subject: [PATCH] ci: fix compilation (#241) --- .../bigquery/DataPlaneBigQueryExtension.java | 2 +- .../pipeline/BigQueryDataSinkFactory.java | 11 +---- .../pipeline/BigQueryDataSourceFactory.java | 18 +------- .../pipeline/BigQueryDataSinkFactoryTest.java | 46 +++---------------- .../BigQueryDataSourceFactoryTest.java | 46 +++---------------- .../gcp/storage/GcsDataSinkFactory.java | 5 -- .../gcp/storage/GcsDataSourceFactory.java | 6 --- .../gcp/storage/GcsDataSinkFactoryTest.java | 30 +----------- .../gcp/storage/GcsDataSourceFactoryTest.java | 27 ++--------- 9 files changed, 22 insertions(+), 169 deletions(-) diff --git a/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/DataPlaneBigQueryExtension.java b/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/DataPlaneBigQueryExtension.java index 37ce7c50..d300de28 100644 --- a/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/DataPlaneBigQueryExtension.java +++ b/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/DataPlaneBigQueryExtension.java @@ -81,7 +81,7 @@ public void initialize(ServiceExtensionContext context) { var executorService = executorInstrumentation.instrument( Executors.newFixedThreadPool(bigQueryConfiguration.threadPoolSize()), "BigQuery Source"); - var sourceFactory = new BigQueryDataSourceFactory(bigQueryConfiguration, monitor, paramsProvider, typeManager, executorService, iamService); + var sourceFactory = new BigQueryDataSourceFactory(bigQueryConfiguration, monitor, paramsProvider, executorService, iamService); pipelineService.registerFactory(sourceFactory); var sinkFactory = new BigQueryDataSinkFactory(bigQueryConfiguration, executorContainer.getExecutorService(), monitor, vault, typeManager, paramsProvider, iamService); diff --git a/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactory.java b/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactory.java index 55cc0508..0a51eed2 100644 --- a/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactory.java +++ b/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactory.java @@ -53,7 +53,7 @@ public class BigQueryDataSinkFactory implements DataSinkFactory { private final TypeManager typeManager; private final BigQueryRequestParamsProvider requestParamsProvider; private final BigQuerySinkDataAddressValidator sinkDataAddressValidator = new BigQuerySinkDataAddressValidator(); - private IamService iamService; + private final IamService iamService; public BigQueryDataSinkFactory( BigQueryConfiguration configuration, @@ -72,11 +72,6 @@ public BigQueryDataSinkFactory( this.iamService = iamService; } - @Override - public boolean canHandle(DataFlowStartMessage message) { - return BIGQUERY_DATA.equals(message.getDestinationDataAddress().getType()); - } - @Override public @NotNull Result validateRequest(DataFlowStartMessage message) { // canHandle has been already invoked to have this factory selected. @@ -95,10 +90,6 @@ public String supportedType() { @Override public DataSink createSink(DataFlowStartMessage message) { - if (!canHandle(message)) { - throw new GcpException("BigQuery Data Sink cannot create sink for request type " + message.getSourceDataAddress().getType()); - } - monitor.info("BigQuery Data Sink Factory " + message.getId()); var params = requestParamsProvider.provideSinkParams(message); var target = params.getTarget(); diff --git a/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactory.java b/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactory.java index 07f13cc5..5ff07a31 100644 --- a/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactory.java +++ b/extensions/data-plane/data-plane-google-bigquery/src/main/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactory.java @@ -19,13 +19,10 @@ import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSource; import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSourceFactory; import org.eclipse.edc.gcp.bigquery.BigQueryConfiguration; -import org.eclipse.edc.gcp.bigquery.service.BigQueryServiceSchema; import org.eclipse.edc.gcp.bigquery.validation.BigQuerySourceDataAddressValidator; -import org.eclipse.edc.gcp.common.GcpException; import org.eclipse.edc.gcp.iam.IamService; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.result.Result; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; import org.jetbrains.annotations.NotNull; @@ -41,28 +38,21 @@ public class BigQueryDataSourceFactory implements DataSourceFactory { private final BigQueryConfiguration configuration; private final BigQueryRequestParamsProvider requestParamsProvider; private final Monitor monitor; - private final TypeManager typeManager; private final ExecutorService executorService; private final BigQuerySourceDataAddressValidator sourceDataAddressValidator = new BigQuerySourceDataAddressValidator(); - private IamService iamService; + private final IamService iamService; public BigQueryDataSourceFactory(BigQueryConfiguration configuration, Monitor monitor, BigQueryRequestParamsProvider requestParamsProvider, - TypeManager typeManager, ExecutorService executorService, + ExecutorService executorService, IamService iamService) { this.configuration = configuration; this.monitor = monitor; this.requestParamsProvider = requestParamsProvider; - this.typeManager = typeManager; this.executorService = executorService; this.iamService = iamService; } - @Override - public boolean canHandle(DataFlowStartMessage message) { - return BigQueryServiceSchema.BIGQUERY_DATA.equals(message.getSourceDataAddress().getType()); - } - @Override public @NotNull Result validateRequest(DataFlowStartMessage message) { // canHandle has been already invoked to have this factory selected. @@ -81,10 +71,6 @@ public String supportedType() { @Override public DataSource createSource(DataFlowStartMessage message) { - if (!canHandle(message)) { - throw new GcpException("BigQuery Data Source cannot create source for request type " + message.getSourceDataAddress().getType()); - } - var params = requestParamsProvider.provideSourceParams(message); var target = params.getTarget(); diff --git a/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactoryTest.java b/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactoryTest.java index 3c340c0c..0bebffb7 100644 --- a/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactoryTest.java +++ b/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSinkFactoryTest.java @@ -17,7 +17,6 @@ import org.eclipse.edc.connector.dataplane.gcp.bigquery.params.BigQueryRequestParamsProvider; import org.eclipse.edc.gcp.bigquery.BigQueryConfiguration; import org.eclipse.edc.gcp.bigquery.service.BigQueryServiceSchema; -import org.eclipse.edc.gcp.common.GcpException; import org.eclipse.edc.gcp.iam.IamService; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.security.Vault; @@ -30,58 +29,30 @@ import java.util.concurrent.ExecutorService; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; public class BigQueryDataSinkFactoryTest { private static final String TEST_PROJECT = "test-project"; private static final String TEST_DATASET = "test-dataset"; private static final String TEST_TABLE = "test-table"; - private static final String TEST_OTHER_TYPE = "AnotherDataAddressType"; private static final String TEST_REQUEST_ID = "request-id"; private static final String TEST_PROCESS_ID = "process-id"; private static final String TEST_CUSTOMER_NAME = "customer-name"; private static final String TEST_SINK_SERVICE_ACCOUNT_NAME = "sinkAccount"; - private BigQueryConfiguration bigQueryConfiguration = new BigQueryConfiguration(null, null, "testEndpoint", 0); - private TypeManager typeManager = mock(); - private Monitor monitor = mock(); - private ExecutorService executorService = mock(); - private Vault vault = mock(); - private IamService iamService = mock(); + private final BigQueryConfiguration bigQueryConfiguration = new BigQueryConfiguration(null, null, "testEndpoint", 0); + private final TypeManager typeManager = mock(); + private final Monitor monitor = mock(); + private final ExecutorService executorService = mock(); + private final Vault vault = mock(); + private final IamService iamService = mock(); @BeforeEach void setup() { - reset(monitor); - reset(typeManager); - reset(executorService); - reset(vault); - reset(iamService); - when(monitor.withPrefix(any(String.class))).thenReturn(monitor); } - @Test - void testCanHandle() { - var provider = new BigQueryRequestParamsProvider(); - var factory = new BigQueryDataSinkFactory(bigQueryConfiguration, executorService, monitor, vault, typeManager, provider, iamService); - - var bqDataFlowRequest = getDataFlowRequest(BigQueryServiceSchema.BIGQUERY_DATA); - - assertThat(factory.canHandle(bqDataFlowRequest)).isTrue(); - - var otherDataFlowRequest = getDataFlowRequest(TEST_OTHER_TYPE); - - assertThat(factory.canHandle(otherDataFlowRequest)).isFalse(); - } - - @Test - void testValidateRequest() { - // TODO add tests if validateRequest body is implemented with specific tests. - } - @Test void testCreateSink() { var provider = new BigQueryRequestParamsProvider(); @@ -91,11 +62,6 @@ void testCreateSink() { var bqSink = factory.createSink(bqDataFlowRequest); assertThat(bqSink).isNotNull(); - - var otherDataFlowRequest = getDataFlowRequest(TEST_OTHER_TYPE); - - Throwable exception = assertThrows(GcpException.class, () -> factory.createSink(otherDataFlowRequest)); - assertThat(exception.getMessage()).isEqualTo("BigQuery Data Sink cannot create sink for request type " + TEST_OTHER_TYPE); } private DataFlowStartMessage getDataFlowRequest(String type) { diff --git a/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactoryTest.java b/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactoryTest.java index da1ea2a4..6e38308c 100644 --- a/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactoryTest.java +++ b/extensions/data-plane/data-plane-google-bigquery/src/test/java/org/eclipse/edc/connector/dataplane/gcp/bigquery/pipeline/BigQueryDataSourceFactoryTest.java @@ -18,10 +18,8 @@ import org.eclipse.edc.gcp.bigquery.BigQueryConfiguration; import org.eclipse.edc.gcp.bigquery.service.BigQueryServiceSchema; import org.eclipse.edc.gcp.common.GcpConfiguration; -import org.eclipse.edc.gcp.common.GcpException; import org.eclipse.edc.gcp.iam.IamService; import org.eclipse.edc.spi.monitor.Monitor; -import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; import org.junit.jupiter.api.BeforeEach; @@ -31,8 +29,6 @@ import java.util.concurrent.Executors; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -42,58 +38,30 @@ public class BigQueryDataSourceFactoryTest { private static final String TEST_DATASET = "test-dataset"; private static final String TEST_TABLE = "test-table"; private static final String TEST_QUERY = "select * from " + TEST_TABLE + ";"; - private static final String TEST_OTHER_TYPE = "AnotherDataAddressType"; private static final String TEST_REQUEST_ID = "request-id"; private static final String TEST_PROCESS_ID = "process-id"; private static final String TEST_CUSTOMER_NAME = "customer-name"; private static final String TEST_SINK_SERVICE_ACCOUNT_NAME = "sinkAccount"; private final ExecutorService executionPool = Executors.newFixedThreadPool(2); - private GcpConfiguration gcpConfiguration = new GcpConfiguration(TEST_PROJECT, TEST_SINK_SERVICE_ACCOUNT_NAME, null, null); - private BigQueryConfiguration configuration = new BigQueryConfiguration(gcpConfiguration, "testEndpoint", null, 0); - private TypeManager typeManager = mock(); - private Monitor monitor = mock(); - private IamService iamService = mock(); + private final GcpConfiguration gcpConfiguration = new GcpConfiguration(TEST_PROJECT, TEST_SINK_SERVICE_ACCOUNT_NAME, null, null); + private final BigQueryConfiguration configuration = new BigQueryConfiguration(gcpConfiguration, "testEndpoint", null, 0); + private final Monitor monitor = mock(); + private final IamService iamService = mock(); @BeforeEach void setup() { when(monitor.withPrefix(any(String.class))).thenReturn(monitor); } - @Test - void testCanHandle() { - var provider = new BigQueryRequestParamsProvider(); - var factory = new BigQueryDataSourceFactory(configuration, monitor, provider, typeManager, executionPool, iamService); - - var bqDataFlowRequest = getDataFlowRequest(BigQueryServiceSchema.BIGQUERY_DATA); - - assertThat(factory.canHandle(bqDataFlowRequest)).isTrue(); - - var otherDataFlowRequest = getDataFlowRequest(TEST_OTHER_TYPE); - - assertThat(factory.canHandle(otherDataFlowRequest)).isFalse(); - } - - @Test - void testValidateRequest() { - // TODO add tests if validateRequest body is implemented with specific tests. - } - @Test void testCreateSource() { var provider = new BigQueryRequestParamsProvider(); - var factory = new BigQueryDataSourceFactory(configuration, monitor, provider, typeManager, executionPool, iamService); - + var factory = new BigQueryDataSourceFactory(configuration, monitor, provider, executionPool, iamService); var bqDataFlowRequest = getDataFlowRequest(BigQueryServiceSchema.BIGQUERY_DATA); - try (var bqSource = factory.createSource(bqDataFlowRequest)) { - assertThat(bqSource).isNotNull(); - } catch (Exception e) { - fail(e.getMessage()); - } + var bqSource = factory.createSource(bqDataFlowRequest); - var otherDataFlowRequest = getDataFlowRequest(TEST_OTHER_TYPE); - var exception = assertThrows(GcpException.class, () -> factory.createSource(otherDataFlowRequest)); - assertThat(exception.getMessage()).isEqualTo("BigQuery Data Source cannot create source for request type " + TEST_OTHER_TYPE); + assertThat(bqSource).isNotNull(); } private DataFlowStartMessage getDataFlowRequest(String type) { diff --git a/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactory.java b/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactory.java index 8615e919..46518cef 100644 --- a/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactory.java +++ b/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactory.java @@ -58,11 +58,6 @@ public String supportedType() { return GcsStoreSchema.TYPE; } - @Override - public boolean canHandle(DataFlowStartMessage request) { - return GcsStoreSchema.TYPE.equals(request.getDestinationDataAddress().getType()); - } - @Override public @NotNull Result validateRequest(DataFlowStartMessage request) { var destination = request.getDestinationDataAddress(); diff --git a/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactory.java b/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactory.java index 735d9911..45019677 100644 --- a/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactory.java +++ b/extensions/data-plane/data-plane-google-storage/src/main/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactory.java @@ -36,17 +36,11 @@ public GcsDataSourceFactory(Monitor monitor) { this.monitor = monitor; } - @Override public String supportedType() { return GcsStoreSchema.TYPE; } - @Override - public boolean canHandle(DataFlowStartMessage request) { - return GcsStoreSchema.TYPE.equals(request.getSourceDataAddress().getType()); - } - @Override public @NotNull Result validateRequest(DataFlowStartMessage request) { var source = request.getSourceDataAddress(); diff --git a/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactoryTest.java b/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactoryTest.java index 4b013a32..beb9c941 100644 --- a/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactoryTest.java +++ b/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSinkFactoryTest.java @@ -20,7 +20,6 @@ import org.eclipse.edc.gcp.storage.GcsStoreSchema; import org.eclipse.edc.json.JacksonTypeManager; import org.eclipse.edc.spi.EdcException; -import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.security.Vault; import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.spi.types.domain.DataAddress; @@ -33,7 +32,6 @@ import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.UUID; -import java.util.concurrent.ExecutorService; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -47,37 +45,13 @@ class GcsDataSinkFactoryTest { private Vault vault = mock(); private IamService iamService = mock(); private GcsDataSinkFactory factory = new GcsDataSinkFactory( - mock(ExecutorService.class), - mock(Monitor.class), + mock(), + mock(), vault, typeManager, iamService ); - @Test - void canHandle_returnsTrueWhenExpectedType() { - var destination = DataAddress.Builder - .newInstance() - .type(GcsStoreSchema.TYPE) - .build(); - - var result = factory.canHandle(createRequest(destination)); - - assertThat(result).isTrue(); - } - - @Test - void canHandle_returnsFalseWhenUnexpectedType() { - var destination = DataAddress.Builder - .newInstance() - .type("Not Google Storage") - .build(); - - var result = factory.canHandle(createRequest(destination)); - - assertThat(result).isFalse(); - } - @Test void validate_ShouldSucceedIfPropertiesAreValid() { var destination = DataAddress.Builder diff --git a/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactoryTest.java b/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactoryTest.java index cb4babb5..a198500a 100644 --- a/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactoryTest.java +++ b/extensions/data-plane/data-plane-google-storage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceFactoryTest.java @@ -31,29 +31,8 @@ class GcsDataSourceFactoryTest { - Monitor monitor = mock(Monitor.class); - - private final GcsDataSourceFactory factory = - new GcsDataSourceFactory(monitor); - - @Test - void canHandle_returnsTrueWhenExpectedType() { - var dataAddress = createDataAddress(GcsStoreSchema.TYPE) - .build(); - var result = factory.canHandle(TestFunctions.createRequest(dataAddress)); - - assertThat(result).isTrue(); - } - - @Test - void canHandle_returnsFalseWhenUnexpectedType() { - var dataAddress = createDataAddress("Not Google Storage") - .build(); - - var result = factory.canHandle(TestFunctions.createRequest(dataAddress)); - - assertThat(result).isFalse(); - } + private final Monitor monitor = mock(Monitor.class); + private final GcsDataSourceFactory factory = new GcsDataSourceFactory(monitor); @Test void validate_ShouldSucceedIfPropertiesAreValid() { @@ -95,4 +74,4 @@ public Stream provideArguments(ExtensionContext context) { ); } } -} \ No newline at end of file +}