Skip to content

Commit

Permalink
test: add Java test cases for oceanbase-ce (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe authored Jun 24, 2024
1 parent a5e9832 commit a7915e5
Show file tree
Hide file tree
Showing 7 changed files with 525 additions and 25 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/java-test-oceanbase-ce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: java test oceanbase-ce

on:
workflow_call:
inputs:
cache_key:
required: true
type: string
image_file:
required: true
type: string
mode:
required: true
type: string
cluster_name:
required: false
type: string
default: 'obcluster'
port:
required: true
type: string
sys_password:
required: false
type: string
default: ''
test_tenant:
required: false
type: string
default: 'test'
test_password:
required: false
type: string
default: ''
init_sql:
required: false
type: string
default: ''

jobs:
test-oceanbase-ce:
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.cache_key }}
path: /tmp

- name: Load Docker image
run: docker load -i /tmp/${{ inputs.image_file }}

- name: Start Docker container
uses: oceanbase/setup-oceanbase-ce@v1
with:
image_name: oceanbase-ce
container_name: oceanbase-ce
mode: ${{ inputs.mode }}
cluster_name: ${{ inputs.cluster_name }}
sql_port: ${{ inputs.port }}
sys_root_password: ${{ inputs.sys_password }}
tenant_name: ${{ inputs.test_tenant }}
tenant_root_password: ${{ inputs.test_password }}
init_sql: ${{ inputs.init_sql }}

- name: Set server IP
id: set_server_ip
run: |
if [ "${{ inputs.mode }}" == "slim" ]; then
echo "Use '127.0.0.1' as server_ip on slim mode."
echo "server_ip=127.0.0.1" >> $GITHUB_OUTPUT
else
echo "Getting IP from container..."
container_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' oceanbase-ce)
echo "Container IP is $container_ip. Setting server_ip to container IP."
echo "server_ip=$container_ip" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'zulu'

- name: Build test project
run: |
cd test
mvn install -DskipTests=true
- name: Test Docker container
env:
server_ip: ${{ steps.set_server_ip.outputs.server_ip }}
cluster_name: ${{ inputs.cluster_name }}
port: ${{ inputs.port }}
sys_password: ${{ inputs.sys_password }}
test_tenant: ${{ inputs.test_tenant }}
test_password: ${{ inputs.test_password }}
run: |
cd test
mvn verify -Dtest=OceanBaseCETest -DfailIfNoTests=false
57 changes: 32 additions & 25 deletions .github/workflows/test-oceanbase-ce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ name: test oceanbase-ce

on:
push:
paths:
- '.github/workflows/test-oceanbase-ce.yml'
- 'oceanbase-ce/**'
branches: [ main ]
pull_request:
paths:
- '.github/workflows/test-oceanbase-ce.yml'
- '.github/workflows/**-oceanbase-ce.yml'
- 'oceanbase-ce/**'
- 'test/**'

concurrency:
group: test-oceanbase-ce-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
Expand Down Expand Up @@ -48,26 +51,30 @@ jobs:
path: oceanbase-ce.tar

test-slim:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: oceanbase-ce
path: /tmp

- name: Load Docker image
run: docker load -i /tmp/oceanbase-ce.tar
uses: ./.github/workflows/java-test-oceanbase-ce.yml
with:
cache_key: oceanbase-ce
image_file: oceanbase-ce.tar
mode: slim
port: 1234
test_password: 123456
init_sql: "USE test;
CREATE TABLE user(id INT(10) PRIMARY KEY, name VARCHAR(20));
INSERT INTO user VALUES (1, 'tom'), (2, 'jerry');"

- name: Start Docker container
uses: oceanbase/setup-oceanbase-ce@v1
with:
image_name: oceanbase-ce
container_name: ob-slim
fastboot: false

- name: Test Docker container
run: |
docker exec ob-slim obclient -h127.0.0.1 -P2881 -uroot -e 'select version()'
docker exec ob-slim obclient -h127.0.0.1 -P2881 -uroot@test -e 'show databases'
test-mini:
needs: build
uses: ./.github/workflows/java-test-oceanbase-ce.yml
with:
cache_key: oceanbase-ce
image_file: oceanbase-ce.tar
cluster_name: github-action
mode: mini
port: 1234
sys_password: 1234567
test_tenant: mini
test_password: 7654321
init_sql: "USE test;
CREATE TABLE user(id INT(10) PRIMARY KEY, name VARCHAR(20));
INSERT INTO user VALUES (1, 'tom'), (2, 'jerry');"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.idea
.vscode
*.log
target
oceanbase-ce/Dockerfile.inner
110 changes: 110 additions & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<groupId>com.oceanbase</groupId>
<artifactId>docker-images-test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>

<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.4.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.23.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.27.1</version>
<configuration>
<java>
<googleJavaFormat>
<version>1.7</version>
<style>AOSP</style>
</googleJavaFormat>
<removeUnusedImports />
</java>
<pom>
<sortPom>
<encoding>UTF-8</encoding>
<nrOfIndentSpace>4</nrOfIndentSpace>
<keepBlankLines>true</keepBlankLines>
<indentBlankLines>false</indentBlankLines>
<indentSchemaLocation>false</indentSchemaLocation>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
<sortModules>false</sortModules>
<sortExecutions>false</sortExecutions>
<expandEmptyElements>false</expandEmptyElements>
<sortProperties>false</sortProperties>
</sortPom>
<replace>
<name>Leading blank line</name>
<search>project</search>
<replacement>project</replacement>
</replace>
</pom>
<upToDateChecking>
<enabled>true</enabled>
</upToDateChecking>
</configuration>
<executions>
<execution>
<id>spotless-check</id>
<goals>
<goal>check</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit a7915e5

Please sign in to comment.