Skip to content

Commit

Permalink
Run Azure tests grouped on the CI thus saving some time
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Apr 14, 2021
1 parent ad462d8 commit ec33fa3
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
== Azure Event Hubs Service integration tests
== Azure isolated integration tests

By default the integration tests run only against the real remote Azure API.
=== Azurite

By default the integration tests are run against the Azurite test container,
or skipped, if the given service is not supported by Azurite.

Unsupported by Azurite:

* `azure-eventhubs`

=== Real Azure API

Prerequisites:

* A https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&tabs=azure-portal[general-purpose v2 Azure storage account] and
https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal[create a container]
* View the https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal#view-account-access-keys[account keys] and set the following environment variables:
* An https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create[Azure Event Hub]
* An https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-get-connection-string[Event Hubs connection string]

Expand All @@ -26,7 +36,7 @@ Here are the environment variables you need to set:
export AZURE_STORAGE_ACCOUNT_NAME=<your-azure-storage-account-name>
export AZURE_STORAGE_ACCOUNT_KEY=<your-azure-storage-account-key>
# the container has to exist before you run the test
export AZURE_BLOB_CONTAINER_NAME=<your-container-name>
export AZURE_EVENT_HUBS_BLOB_CONTAINER_NAME=<your-container-name>
export AZURE_EVENT_HUBS_CONNECTION_STRING="Endpoint=sb://<your-namespace>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<your-key>;EntityPath=<your-hub-name>"
----

Expand All @@ -37,3 +47,6 @@ To clean up, run
$ ./azure-resources.sh delete
----

You may want to `export CAMEL_QUARKUS_START_MOCK_BACKEND=false` to avoid starting he the local Azurite container and make sure that you test against the real remote Azure API.


Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<artifactId>camel-quarkus-integration-tests-azure</artifactId>
<version>1.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -51,17 +52,8 @@ public class AzureEventhubsResource {
@Inject
CamelContext context;

@ConfigProperty(name = "azure.storage.account-name")
String azureStorageAccountName;

@ConfigProperty(name = "azure.storage.account-key")
String azureStorageAccountKey;

@ConfigProperty(name = "azure.event.hubs.connection.string")
String connectionString;

@ConfigProperty(name = "azure.blob.container.name")
String azureBlobContainerName;
Optional<String> connectionString;

private volatile String message;
private int counter = 0;
Expand All @@ -73,7 +65,7 @@ public class AzureEventhubsResource {
@Scheduled(every = "1s")
void schedule() {
if (message != null) {
final String endpointUri = "azure-eventhubs:?connectionString=RAW(" + connectionString + ")";
final String endpointUri = "azure-eventhubs:?connectionString=RAW(" + connectionString.get() + ")";
producerTemplate.sendBody(endpointUri, message + (counter++));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.quarkus.component.azure.eventhubs.it;

import java.util.Optional;

import javax.enterprise.context.ApplicationScoped;

import com.azure.core.amqp.AmqpTransportType;
Expand All @@ -32,20 +34,22 @@ public class AzureEventhubsRoutes extends RouteBuilder {
String azureStorageAccountKey;

@ConfigProperty(name = "azure.event.hubs.connection.string")
String connectionString;
Optional<String> connectionString;

@ConfigProperty(name = "azure.blob.container.name")
@ConfigProperty(name = "azure.event.hubs.blob.container.name")
String azureBlobContainerName;

@Override
public void configure() throws Exception {
from("azure-eventhubs:?connectionString=RAW(" + connectionString
+ ")&blobAccountName=RAW(" + azureStorageAccountName
+ ")&blobAccessKey=RAW(" + azureStorageAccountKey
+ ")&blobContainerName=RAW(" + azureBlobContainerName + ")&amqpTransportType="
+ AmqpTransportType.AMQP)
.to("mock:azure-consumed");

if (connectionString.isPresent()) {
System.out.println("=== azureBlobContainerName = " + azureBlobContainerName);
from("azure-eventhubs:?connectionString=RAW(" + connectionString.get()
+ ")&blobAccountName=RAW(" + azureStorageAccountName
+ ")&blobAccessKey=RAW(" + azureStorageAccountKey
+ ")&blobContainerName=RAW(" + azureBlobContainerName + ")&amqpTransportType="
+ AmqpTransportType.AMQP)
.to("mock:azure-consumed");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


suffix="$(az ad signed-in-user show --query displayName -o tsv | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]' | cut -c-12)"
suffix="${suffix}1"
suffix="${suffix}4"
export AZURE_STORAGE_ACCOUNT_NAME=cqacc${suffix}
export AZURE_BLOB_CONTAINER_NAME=cq-container-${suffix}

Expand Down Expand Up @@ -54,7 +54,7 @@ function createResources() {

echo 'export AZURE_STORAGE_ACCOUNT_NAME="'${AZURE_STORAGE_ACCOUNT_NAME}'"'
echo 'export AZURE_STORAGE_ACCOUNT_KEY="'${AZURE_STORAGE_ACCOUNT_KEY}'"'
echo 'export AZURE_BLOB_CONTAINER_NAME="'${AZURE_BLOB_CONTAINER_NAME}'"'
echo 'export AZURE_EVENT_HUBS_BLOB_CONTAINER_NAME="'${AZURE_BLOB_CONTAINER_NAME}'"'
echo 'export AZURE_EVENT_HUBS_CONNECTION_STRING="'$AZURE_EVENT_HUBS_CONNECTION_STRING';EntityPath='${EH_NAME}'"'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<artifactId>camel-quarkus-integration-tests-azure</artifactId>
<version>1.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-integration-test-azure-storage-blob</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<artifactId>camel-quarkus-integration-tests-azure</artifactId>
<version>1.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-integration-test-azure-storage-queue</artifactId>
Expand Down
45 changes: 45 additions & 0 deletions integration-test-groups/azure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-test-groups</artifactId>
<version>1.9.0-SNAPSHOT</version>
</parent>

<artifactId>camel-quarkus-integration-tests-azure</artifactId>
<packaging>pom</packaging>

<name>Camel Quarkus :: Azure Integration Tests</name>

<properties>
<quarkus.banner.enabled>false</quarkus.banner.enabled>
</properties>

<modules>
<!-- extensions a..z; do not remove this comment, it is important when sorting via mvn process-resources -Pformat -->
<module>azure-eventhubs</module>
<module>azure-storage-blob</module>
<module>azure-storage-queue</module>
</modules>

</project>
7 changes: 4 additions & 3 deletions integration-test-groups/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus</artifactId>
<artifactId>camel-quarkus-build-parent-it</artifactId>
<version>1.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<relativePath>../poms/build-parent-it/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-integration-test-groups</artifactId>
Expand All @@ -33,8 +33,9 @@
<name>Camel Quarkus :: Integration Test Groups</name>

<modules>
<!-- extensions a..z; do not remove this comment, it is important when sorting via mvn process-resources -Pformat -->
<!-- test groups a..z; do not remove this comment, it is important when sorting via mvn process-resources -Pformat -->
<module>aws2</module>
<module>azure</module>
</modules>

</project>
20 changes: 20 additions & 0 deletions integration-tests/azure-grouped/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
== Azure grouped integration tests

This module allows executing all tests from `integration-test-groups/azure/*` grouped together.

While grouping brings the benefit of faster native compilation
(compared to the sum of compilation times of all modules under `integration-test-groups/azure/*`)
it is methodologically not as clean as running those tests in isolation.
Hence, this module is intended to be run instead of the tests under `integration-test-groups/azure/*`
if, in the given situation, the speed matters more than isolation.

=== How the grouping works

* The grouped module dynamically pulls all sources from the individual AWS test modules to its
* `target/[test-]classes` directories.
* `application.properties` files and service descriptors are concatenated using a Groovy script.
* The dependencies in the grouped `pom.xml` can be updated via `mvn process-resources -Pformat -N`.

=== Mock backend vs. real service

Please refer to link:../../integration-tests-azure/README.adoc[integration-test-groups/azure/README.adoc] for more details.

0 comments on commit ec33fa3

Please sign in to comment.