-
Notifications
You must be signed in to change notification settings - Fork 58
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
Integation tests for PgSQL connector #67
Open
willyborankin
wants to merge
8
commits into
master
Choose a base branch
from
integration_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
988b577
Release version 6.3.1
actions-user 4f49aea
Bump version to 6.4.0-SNAPSHOT
actions-user 0c46aea
Add Github Actions workflow for making releases
ivanyu 25a95ce
Merge pull request #75 from aiven/ivanyu/release-workflow
willyborankin 600eaf8
Merge pull request #74 from aiven/release-6.3.1
ivanyu 816a254
Setup jdk version in workflow
willyborankin 7c9b414
Merge pull request #76 from aiven/workflow-setup-jdk-version
2c2960e
Integation tests for PgSQL connector
willyborankin 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Create release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
commit_hash: | ||
description: "Hash of 'Release version x.y.z' commit" | ||
required: true | ||
|
||
jobs: | ||
build: | ||
name: Create Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Java SDK | ||
uses: actions/[email protected] | ||
with: | ||
java-version: 11 | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.inputs.commit_hash }} | ||
|
||
- name: Check commit title and extract version | ||
run: | | ||
export commit_title=$(git log --pretty=format:%s -1 ${{ github.event.inputs.commit_hash }}) | ||
echo "Commit title: $commit_title" | ||
if [[ $commit_title =~ ^Release\ version\ [0-9]*\.[0-9]*\.[0-9]*$ ]]; then | ||
echo "Valid commit title" | ||
else | ||
echo "Invalid commit title" | ||
exit 1 | ||
fi | ||
export version=$(echo ${commit_title} | sed s/^Release\ version\ //g) | ||
echo "Will use version ${version}" | ||
echo "version=${version}" >> $GITHUB_ENV | ||
|
||
- name: Build | ||
run: | | ||
./gradlew distTar distZip | ||
|
||
export tar_file=$(ls ./build/distributions/ | grep tar) | ||
export zip_file=$(ls ./build/distributions/ | grep zip) | ||
echo tar_file=${tar_file} >> $GITHUB_ENV | ||
echo zip_file=${zip_file} >> $GITHUB_ENV | ||
|
||
echo tar_path=`realpath ./build/distributions/${tar_file}` >> $GITHUB_ENV | ||
echo zip_path=`realpath ./build/distributions/${zip_file}` >> $GITHUB_ENV | ||
|
||
- name: Create release draft | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: "v${{ env.version }}" | ||
release_name: "v${{ env.version }}" | ||
body: | | ||
*Fill in* | ||
draft: true | ||
prerelease: false | ||
|
||
- name: Upload tar | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ${{ env.tar_path }} | ||
asset_name: ${{ env.tar_file }} | ||
asset_content_type: application/tar | ||
|
||
- name: Upload zip | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ${{ env.zip_path }} | ||
asset_name: ${{ env.zip_file }} | ||
asset_content_type: application/zip |
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
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
143 changes: 143 additions & 0 deletions
143
src/integration-test/java/io/aiven/connect/jdbc/AbstractIT.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,143 @@ | ||
/* | ||
* Copyright 2020 Aiven Oy | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package io.aiven.connect.jdbc; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.concurrent.Future; | ||
|
||
import org.apache.kafka.clients.admin.AdminClient; | ||
import org.apache.kafka.clients.admin.AdminClientConfig; | ||
import org.apache.kafka.clients.admin.NewTopic; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerConfig; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.clients.producer.RecordMetadata; | ||
|
||
import cloud.localstack.docker.LocalstackDockerExtension; | ||
import cloud.localstack.docker.annotation.LocalstackDockerProperties; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.KafkaContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@ExtendWith(LocalstackDockerExtension.class) | ||
@LocalstackDockerProperties(services = {"jdbc"}) | ||
@Testcontainers | ||
public abstract class AbstractIT { | ||
|
||
static final Logger LOGGER = LoggerFactory.getLogger(AbstractIT.class); | ||
|
||
protected static final String TEST_TOPIC_NAME = "test_pg_topic"; | ||
|
||
protected static KafkaProducer<String, GenericRecord> producer; | ||
|
||
@Container | ||
protected KafkaContainer kafkaContainer = | ||
new KafkaContainer() | ||
.withEnv("KAFKA_AUTO_CREATE_TOPICS_ENABLE", "false"); | ||
|
||
@Container | ||
protected SchemaRegistryContainer schemaRegistryContainer = | ||
new SchemaRegistryContainer(kafkaContainer); | ||
|
||
protected JdbcConnectService jdbcConnectService; | ||
|
||
@BeforeEach | ||
void startKafka() throws Exception { | ||
LOGGER.info("Configure Kafka connect plugins"); | ||
final var pluginDir = setupPluginDir(); | ||
setupKafka(); | ||
setupKafkaConnect(pluginDir); | ||
createProducer(); | ||
} | ||
|
||
protected AdminClient adminClient() { | ||
final Properties adminClientConfig = new Properties(); | ||
adminClientConfig.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers()); | ||
return AdminClient.create(adminClientConfig); | ||
} | ||
|
||
private static Path setupPluginDir() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically could be run in some |
||
final var testDir = Files.createTempDirectory("aiven-kafka-connect-jdbc-test-"); | ||
final var distFile = Paths.get(System.getProperty("integration-test.distribution.file.path")); | ||
assert Files.exists(distFile); | ||
|
||
final var pluginDir = Paths.get(testDir.toString(), "plugins/aiven-kafka-connect-jdbc/"); | ||
Files.createDirectories(pluginDir); | ||
|
||
final String cmd = String.format("tar -xf %s --strip-components=1 -C %s", | ||
distFile.toString(), pluginDir.toString()); | ||
final Process p = Runtime.getRuntime().exec(cmd); | ||
assert p.waitFor() == 0; | ||
return pluginDir; | ||
} | ||
|
||
private void setupKafka() throws Exception { | ||
LOGGER.info("Setup Kafka"); | ||
try (final var adminClient = adminClient()) { | ||
LOGGER.info("Create topic {}", TEST_TOPIC_NAME); | ||
final NewTopic newTopic = new NewTopic(TEST_TOPIC_NAME, 4, (short) 1); | ||
adminClient.createTopics(List.of(newTopic)).all().get(); | ||
} | ||
} | ||
|
||
private void setupKafkaConnect(final Path pluginDir) throws Exception { | ||
LOGGER.info("Start Kafka Connect"); | ||
jdbcConnectService = | ||
new JdbcConnectService(kafkaContainer.getBootstrapServers(), pluginDir); | ||
jdbcConnectService.start(); | ||
} | ||
|
||
private void createProducer() { | ||
LOGGER.info("Create kafka producer"); | ||
final Map<String, Object> producerProps = new HashMap<>(); | ||
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers()); | ||
producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, | ||
"io.confluent.kafka.serializers.KafkaAvroSerializer"); | ||
producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, | ||
"io.confluent.kafka.serializers.KafkaAvroSerializer"); | ||
producerProps.put("schema.registry.url", schemaRegistryContainer.getSchemaRegistryUrl()); | ||
producer = new KafkaProducer<>(producerProps); | ||
} | ||
|
||
@AfterEach | ||
void stopKafka() throws Exception { | ||
jdbcConnectService.stop(); | ||
} | ||
|
||
protected Future<RecordMetadata> sendMessageAsync(final int partition, | ||
final String key, | ||
final GenericRecord value) { | ||
final var msg = new ProducerRecord<>( | ||
TEST_TOPIC_NAME, partition, | ||
key == null ? null : key, | ||
value == null ? null : value); | ||
return producer.send(msg); | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
I'm not sure it's a good idea to put the burden of choosing this value (or even knowing the value must be chosen) on whoever is going to run the tests. For example, I frankly have no idea what I should insert here without some research. We just need one good enough value set as a constant in tests somewhere.