-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add Java test cases for oceanbase-ce
- Loading branch information
Showing
7 changed files
with
459 additions
and
26 deletions.
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,89 @@ | ||
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 | ||
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: '' | ||
server_ip: | ||
required: false | ||
type: string | ||
default: '127.0.0.1' | ||
rs_list: | ||
required: false | ||
type: string | ||
default: '127.0.0.1:2882:2881' | ||
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 | ||
mode: ${{ inputs.mode }} | ||
sql_port: ${{ inputs.port }} | ||
sys_root_password: ${{ inputs.sys_password }} | ||
tenant_name: ${{ inputs.test_tenant }} | ||
init_sql: ${{ inputs.init_sql }} | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '8' | ||
distribution: 'zulu' | ||
|
||
- name: Test Docker container | ||
env: | ||
cluster_name: 'github-action' | ||
host: '127.0.0.1' | ||
port: ${{ inputs.port }} | ||
sys_username: 'root' | ||
sys_password: ${{ inputs.sys_password }} | ||
test_tenant: ${{ inputs.test_tenant }} | ||
test_username: 'root@${{ inputs.test_tenant }}' | ||
test_password: ${{ inputs.test_password }} | ||
server_ip: ${{ inputs.server_ip }} | ||
rs_list: ${{ inputs.rs_list }} | ||
run: | | ||
cd test | ||
mvn verify -Dtest=OceanBaseCETest -DfailIfNoTests=false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.idea | ||
.vscode | ||
*.log | ||
target | ||
oceanbase-ce/Dockerfile.inner |
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,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> |
115 changes: 115 additions & 0 deletions
115
test/src/test/java/com/oceanbase/test/OceanBaseCETest.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,115 @@ | ||
/* | ||
* Copyright 2024 OceanBase. | ||
* | ||
* 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 com.oceanbase.test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Driver; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class OceanBaseCETest { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(OceanBaseCETest.class); | ||
|
||
static Stream<Arguments> testOceanBaseCEArgs() { | ||
String host = Utils.getNonEmptyEnv("host"); | ||
String port = Utils.getNonEmptyEnv("port"); | ||
String sysUsername = Utils.getNonEmptyEnv("sys_username"); | ||
String sysPassword = System.getenv("sys_password"); | ||
String testTenant = Utils.getEnvOrDefault("test_tenant", "test"); | ||
String testUsername = Utils.getNonEmptyEnv("test_username"); | ||
String testPassword = System.getenv("test_password"); | ||
|
||
return Stream.of( | ||
Arguments.of(true, host, port, "sys", sysUsername, sysPassword), | ||
Arguments.of(false, host, port, "sys", sysUsername, sysPassword), | ||
Arguments.of(true, host, port, testTenant, testUsername, testPassword), | ||
Arguments.of(false, host, port, testTenant, testUsername, testPassword)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("testOceanBaseCEArgs") | ||
public void testOceanBaseCE( | ||
boolean useLegacyDriver, | ||
String host, | ||
String port, | ||
String tenantName, | ||
String username, | ||
String password) { | ||
|
||
LOG.info( | ||
"Testing with args: [useLegacyDriver: {}, host: {}, port: {}, username: {}, password: {}]", | ||
useLegacyDriver, | ||
host, | ||
port, | ||
username, | ||
password); | ||
|
||
String jdbcUrl = String.format("jdbc:mysql://%s:%s/test?useSSL=false", host, port); | ||
|
||
Properties props = new Properties(); | ||
props.setProperty("user", username); | ||
if (password != null) { | ||
props.put("password", password); | ||
} | ||
|
||
Driver driver = Utils.getDriver(useLegacyDriver); | ||
try (Connection conn = driver.connect(jdbcUrl, props)) { | ||
LOG.info("Connected to OceanBase CE successfully"); | ||
|
||
LOG.info("Version comment: {}", Utils.getVersionComment(conn)); | ||
|
||
String tenant = Utils.getTenantName(conn); | ||
LOG.info("Tenant name: {}", tenant); | ||
Assertions.assertEquals(tenantName, tenant); | ||
|
||
checkClusterName(conn); | ||
checkRSList(conn); | ||
|
||
if ("sys".equals(tenantName)) { | ||
checkServerIP(conn); | ||
} | ||
} catch (SQLException e) { | ||
Assertions.fail(e); | ||
} | ||
} | ||
|
||
private void checkClusterName(Connection conn) { | ||
String clusterName = Utils.getClusterName(conn); | ||
LOG.info("Cluster name: {}", clusterName); | ||
Assertions.assertEquals(Utils.getEnvOrDefault("cluster_name", "obcluster"), clusterName); | ||
} | ||
|
||
private void checkServerIP(Connection conn) { | ||
String serverIP = Utils.getServerIP(conn); | ||
LOG.info("Server IP: {}", serverIP); | ||
Assertions.assertEquals(Utils.getEnvOrDefault("server_ip", "127.0.0.1"), serverIP); | ||
} | ||
|
||
private void checkRSList(Connection conn) { | ||
String rsList = Utils.getRSList(conn); | ||
LOG.info("RS List: {}", rsList); | ||
Assertions.assertEquals(Utils.getEnvOrDefault("rs_list", "127.0.0.1:2882:2881"), rsList); | ||
} | ||
} |
Oops, something went wrong.