Skip to content

Commit

Permalink
remote tenant name config
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Feb 28, 2024
1 parent e1a303f commit 636480c
Showing 1 changed file with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.testcontainers.oceanbase;

import org.apache.commons.lang3.StringUtils;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.utility.DockerImageName;

Expand All @@ -27,8 +26,6 @@ public class OceanBaseCEContainer extends JdbcDatabaseContainer<OceanBaseCEConta

private static final Integer RPC_PORT = 2882;

private static final String SYSTEM_TENANT_NAME = "sys";

private static final String DEFAULT_TEST_TENANT_NAME = "test";

private static final String DEFAULT_USERNAME = "root";
Expand All @@ -37,8 +34,6 @@ public class OceanBaseCEContainer extends JdbcDatabaseContainer<OceanBaseCEConta

private static final String DEFAULT_DATABASE_NAME = "test";

private String tenantName = DEFAULT_TEST_TENANT_NAME;

public OceanBaseCEContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}
Expand Down Expand Up @@ -73,7 +68,9 @@ public String getDatabaseName() {

@Override
public String getUsername() {
return DEFAULT_USERNAME + "@" + tenantName;
// In OceanBase, the jdbc username is related to the name of user, tenant and cluster, if a tenant name other than
// the default value 'test' is used, you should manually construct the jdbc username by yourself.
return DEFAULT_USERNAME + "@" + DEFAULT_TEST_TENANT_NAME;
}

@Override
Expand All @@ -85,28 +82,4 @@ public String getPassword() {
protected String getTestQueryString() {
return "SELECT 1";
}

/**
* Set the non-system tenant to be created for testing.
*
* @param tenantName the name of tenant to be created
* @return this
*/
public OceanBaseCEContainer withTenant(String tenantName) {
if (StringUtils.isEmpty(tenantName)) {
throw new IllegalArgumentException("Tenant name cannot be null or empty");
}
if (SYSTEM_TENANT_NAME.equals(tenantName)) {
throw new IllegalArgumentException("Tenant name cannot be " + SYSTEM_TENANT_NAME);
}
this.tenantName = tenantName;
return self();
}

@Override
protected void configure() {
if (!DEFAULT_TEST_TENANT_NAME.equals(tenantName)) {
withEnv("OB_TENANT_NAME", tenantName);
}
}
}

0 comments on commit 636480c

Please sign in to comment.