Skip to content
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

test: use latest LTS docker image & set cluster name #70

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,62 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertTrue;

public class OBKVHBaseConnectorITCase extends OceanBaseMySQLTestBase {

public static final String CLUSTER_NAME = "obcluster";
public static final String CONFIG_URL =
"http:https://127.0.0.1:8080/services?Action=ObRootServiceInfo&ObCluster=" + CLUSTER_NAME;

@Override
protected String getTestTable() {
return "htable";
}

@Override
protected String getUrl() {
return CONFIG_URL;
}

@Override
protected String getUsername() {
return OB_SERVER.getUsername() + "#" + CLUSTER_NAME;
private static final Logger LOG = LoggerFactory.getLogger(OBKVHBaseConnectorITCase.class);

@ClassRule public static final GenericContainer<?> CONTAINER = container("sql/init.sql");

private static final String TEST_TABLE = "htable";

protected String getConfigUrl() {
try (Connection connection =
DriverManager.getConnection(
getJdbcUrl(CONTAINER), SYS_USERNAME, SYS_PASSWORD);
Statement statement = connection.createStatement()) {
ResultSet rs = statement.executeQuery("SHOW PARAMETERS LIKE 'obconfig_url'");
String configUrl = rs.next() ? rs.getString("VALUE") : null;
if (configUrl == null || configUrl.isEmpty()) {
throw new RuntimeException("obconfig_url not found");
}
LOG.info("Got obconfig_url: {}", configUrl);
return configUrl;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

@Override
protected Map<String, String> getOptions() {
Map<String, String> options = super.getOptions();
options.put("sys.username", OB_SERVER.getSysUsername());
options.put("sys.password", OB_SERVER.getSysPassword());
Map<String, String> options = new HashMap<>();
options.put("url", getConfigUrl());
options.put("sys.username", SYS_USERNAME);
options.put("sys.password", SYS_PASSWORD);
options.put("username", TEST_USERNAME + "#" + CLUSTER_NAME);
options.put("password", TEST_PASSWORD);
options.put("schema-name", TEST_DATABASE);
options.put("table-name", TEST_TABLE);
return options;
}

Expand All @@ -95,6 +114,9 @@ public void before() throws Exception {

@After
public void after() throws Exception {
if (client == null) {
return;
}
client.delete(
Arrays.asList(
deleteFamily("1", "family1"),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import org.apache.flink.util.TestLogger;

import org.junit.ClassRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.MountableFile;

import java.util.HashMap;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -37,44 +39,49 @@ public abstract class OceanBaseMySQLTestBase extends TestLogger {

private static final Logger LOG = LoggerFactory.getLogger(OceanBaseMySQLTestBase.class);

public static final String IMAGE_TAG = "4.2.1_bp2";

@ClassRule
public static final OceanBaseContainer OB_SERVER =
new OceanBaseContainer(OceanBaseContainer.DOCKER_IMAGE_NAME + ":" + IMAGE_TAG)
.withNetworkMode("host")
.withSysPassword("123456")
.withCopyFileToContainer(
MountableFile.forClasspathResource("sql/init.sql"),
"/root/boot/init.d/init.sql")
.withLogConsumer(new Slf4jLogConsumer(LOG));

protected String getUrl() {
return OB_SERVER.getJdbcUrl();
}

protected abstract String getTestTable();

protected String getUsername() {
return OB_SERVER.getUsername();
protected static final Network NETWORK = Network.newNetwork();

public static final int SQL_PORT = 2881;
public static final int RPC_PORT = 2882;
public static final int CONFIG_SERVER_PORT = 8080;

public static final String CLUSTER_NAME = "github-action";
public static final String SYS_USERNAME = "root";
public static final String SYS_PASSWORD = "123456";
public static final String TEST_TENANT = "flink";
public static final String TEST_USERNAME = "root@" + TEST_TENANT;
public static final String TEST_PASSWORD = "654321";
public static final String TEST_DATABASE = "test";

@SuppressWarnings("resource")
protected static GenericContainer<?> container(String initSqlFile) {
GenericContainer<?> container =
new GenericContainer<>("oceanbase/oceanbase-ce")
.withNetwork(NETWORK)
.withExposedPorts(SQL_PORT, RPC_PORT, CONFIG_SERVER_PORT)
.withEnv("MODE", "mini")
.withEnv("OB_CLUSTER_NAME", CLUSTER_NAME)
.withEnv("OB_SYS_PASSWORD", SYS_PASSWORD)
.withEnv("OB_TENANT_NAME", TEST_TENANT)
.withEnv("OB_TENANT_PASSWORD", TEST_PASSWORD)
.waitingFor(Wait.forLogMessage(".*boot success!.*", 1))
.withStartupTimeout(Duration.ofMinutes(4))
.withLogConsumer(new Slf4jLogConsumer(LOG));
if (initSqlFile != null) {
container.withCopyFileToContainer(
MountableFile.forClasspathResource(initSqlFile), "/root/boot/init.d/init.sql");
}
return container;
}

protected String getPassword() {
return OB_SERVER.getPassword();
}
protected abstract Map<String, String> getOptions();

protected String getDatabaseName() {
return OB_SERVER.getDatabaseName();
protected String getJdbcUrl(GenericContainer<?> container) {
return getJdbcUrl(container.getHost(), container.getMappedPort(SQL_PORT));
}

protected Map<String, String> getOptions() {
Map<String, String> options = new HashMap<>();
options.put("url", getUrl());
options.put("username", getUsername());
options.put("password", getPassword());
options.put("schema-name", getDatabaseName());
options.put("table-name", getTestTable());
return options;
protected String getJdbcUrl(String host, int port) {
return "jdbc:mysql:https://" + host + ":" + port + "/" + TEST_DATABASE + "?useSSL=false";
}

protected String getOptionsString() {
Expand Down
Loading
Loading