Skip to content

Commit

Permalink
test: add jdbc it case (#39)
Browse files Browse the repository at this point in the history
* add jdbc it case

* update ci

* update github action job name
  • Loading branch information
whhe authored Oct 11, 2023
1 parent d8dad7b commit 2d80a74
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 118 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build Main

on:
push:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'zulu'
cache: 'maven'
- name: Maven Install
run: mvn clean install -DskipTests=true

test-jdbc:
name: Test (flink-connector-oceanbase)
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'zulu'
cache: 'maven'
- name: Maven Test
run: mvn verify -pl :flink-connector-oceanbase
36 changes: 36 additions & 0 deletions .github/workflows/build_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build PR

on:
pull_request:
paths-ignore:
- 'docs/**'
- '**.md'
- '.*'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'zulu'
cache: 'maven'
- name: Maven Install
run: mvn clean install -DskipTests=true

test-jdbc:
name: Test (flink-connector-oceanbase)
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'zulu'
cache: 'maven'
- name: Maven Test
run: mvn verify -pl :flink-connector-oceanbase
20 changes: 0 additions & 20 deletions .github/workflows/maven_build_main.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/maven_build_pr.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

English | [简体中文](README_CN.md)

[![Build Status](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/maven_build_main.yml/badge.svg?branch=main)](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/maven_build_main.yml)
[![Build Status](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/build_main.yml/badge.svg?branch=main)](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/build_main.yml)
[![Release](https://img.shields.io/github/release/oceanbase/flink-connector-oceanbase.svg)](https://github.com/oceanbase/flink-connector-oceanbase/releases)
[![License](https://img.shields.io/badge/license-Mulan%20PSL%20v2-green.svg)](LICENSE)

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English](README.md) | 简体中文

[![Build Status](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/maven_build_main.yml/badge.svg?branch=main)](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/maven_build_main.yml)
[![Build Status](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/build_main.yml/badge.svg?branch=main)](https://github.com/oceanbase/flink-connector-oceanbase/actions/workflows/build_main.yml)
[![Release](https://img.shields.io/github/release/oceanbase/flink-connector-oceanbase.svg)](https://github.com/oceanbase/flink-connector-oceanbase/releases)
[![License](https://img.shields.io/badge/license-Mulan%20PSL%20v2-green.svg)](LICENSE)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.oceanbase.connector.flink;

import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import java.time.Duration;

public class OceanBaseContainer extends JdbcDatabaseContainer<OceanBaseContainer> {

public static final String DOCKER_IMAGE_NAME = "oceanbase/oceanbase-ce";

private static final DockerImageName DEFAULT_IMAGE_NAME =
DockerImageName.parse(DOCKER_IMAGE_NAME);

private static final Integer SQL_PORT = 2881;
private static final Integer RPC_PORT = 2882;

private static final String DEFAULT_USERNAME = "root";
private static final String DEFAULT_PASSWORD = "";
private static final String DEFAULT_TENANT_NAME = "test";
private static final String DEFAULT_DATABASE_NAME = "test";

private String tenantName = DEFAULT_TENANT_NAME;

public OceanBaseContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public OceanBaseContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);

this.waitStrategy =
Wait.forLogMessage(".*boot success!.*", 1)
.withStartupTimeout(Duration.ofMinutes(5));

addExposedPorts(SQL_PORT, RPC_PORT);
}

@Override
public String getDriverClassName() {
return "com.oceanbase.jdbc.Driver";
}

public Integer getSqlPort() {
return getActualPort(SQL_PORT);
}

public Integer getActualPort(int port) {
return "host".equals(getNetworkMode()) ? port : getMappedPort(port);
}

@Override
public String getJdbcUrl() {
return getJdbcUrl(DEFAULT_DATABASE_NAME);
}

public String getJdbcUrl(String databaseName) {
String additionalUrlParams = constructUrlParameters("?", "&");
return "jdbc:oceanbase://"
+ getHost()
+ ":"
+ getSqlPort()
+ "/"
+ databaseName
+ additionalUrlParams;
}

public OceanBaseContainer withTenant(String tenantName) {
this.tenantName = tenantName;
return this;
}

public String getTenantName() {
return tenantName;
}

@Override
public String getDatabaseName() {
return DEFAULT_DATABASE_NAME;
}

@Override
public String getUsername() {
return DEFAULT_USERNAME + "@" + tenantName;
}

@Override
public String getPassword() {
return DEFAULT_PASSWORD;
}

@Override
protected String getTestQueryString() {
return "SELECT 1";
}

@Override
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
}

@Override
protected void configure() {
withEnv("MODE", "slim");
withEnv("OB_TENANT_NAME", tenantName);
}
}
Loading

0 comments on commit 2d80a74

Please sign in to comment.