Skip to content

Commit

Permalink
Merge branch 'main' into issue-81
Browse files Browse the repository at this point in the history
  • Loading branch information
vagetablechicken authored Mar 31, 2022
2 parents 5c5c108 + e974846 commit 65d716f
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 153 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
sh steps/download_openmldb_spark.sh $SPARK_HOME
cd onebox
bash start_onebox.sh
sh start_onebox.sh standalone
- name: Build and Coverage
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
run: |
sh steps/ut_zookeeper.sh start
sh steps/download_openmldb_spark.sh $SPARK_HOME
cd onebox && sh start_onebox.sh && cd - || exit
cd onebox && sh start_onebox.sh && sh start_onebox.sh standalone && cd - || exit
- name: run java modules smoke test
working-directory: java
Expand Down
2 changes: 2 additions & 0 deletions docs/cn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
请访问 OpenMLDB 中文文档网站:[https://openmldb.ai/docs/zh](https://openmldb.ai/docs/zh)

9 changes: 0 additions & 9 deletions docs/cn/index.html

This file was deleted.

17 changes: 10 additions & 7 deletions java/openmldb-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -29,13 +39,6 @@
<version>${variant.native.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,20 @@

package com._4paradigm.openmldb.sdk;

import lombok.Data;


@Data
public class SdkOption {
// options for cluster mode
private String zkCluster;
private String zkPath;
// options for standalone mode
private String host;
private long port;

private long sessionTimeout = 10000;
private Boolean enableDebug = false;
private long requestTimeout = 60000;

public String getZkCluster() {
return zkCluster;
}

public void setZkCluster(String zkCluster) {
this.zkCluster = zkCluster;
}

public String getZkPath() {
return zkPath;
}

public void setZkPath(String zkPath) {
this.zkPath = zkPath;
}

public long getSessionTimeout() {
return sessionTimeout;
}

public void setSessionTimeout(long sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}

public Boolean getEnableDebug() {
return enableDebug;
}

public void setEnableDebug(Boolean enableDebug) {
this.enableDebug = enableDebug;
}

public long getRequestTimeout() {
return requestTimeout;
}

public void setRequestTimeout(long requestTimeout) {
this.requestTimeout = requestTimeout;
}
private boolean isClusterMode = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com._4paradigm.openmldb.SQLRequestRow;
import com._4paradigm.openmldb.SQLRouter;
import com._4paradigm.openmldb.SQLRouterOptions;
import com._4paradigm.openmldb.StandaloneOptions;
import com._4paradigm.openmldb.Status;
import com._4paradigm.openmldb.TableColumnDescPair;
import com._4paradigm.openmldb.TableColumnDescPairVector;
Expand Down Expand Up @@ -61,14 +62,25 @@ public class SqlClusterExecutor implements SqlExecutor {
public SqlClusterExecutor(SdkOption option, String libraryPath) throws SqlException {
initJavaSdkLibrary(libraryPath);

SQLRouterOptions sqlOpt = new SQLRouterOptions();
sqlOpt.setSession_timeout(option.getSessionTimeout());
sqlOpt.setZk_cluster(option.getZkCluster());
sqlOpt.setZk_path(option.getZkPath());
sqlOpt.setEnable_debug(option.getEnableDebug());
sqlOpt.setRequest_timeout(option.getRequestTimeout());
this.sqlRouter = sql_router_sdk.NewClusterSQLRouter(sqlOpt);
sqlOpt.delete();
if (option.isClusterMode()) {
SQLRouterOptions sqlOpt = new SQLRouterOptions();
sqlOpt.setSession_timeout(option.getSessionTimeout());
sqlOpt.setZk_cluster(option.getZkCluster());
sqlOpt.setZk_path(option.getZkPath());
sqlOpt.setEnable_debug(option.getEnableDebug());
sqlOpt.setRequest_timeout(option.getRequestTimeout());
this.sqlRouter = sql_router_sdk.NewClusterSQLRouter(sqlOpt);
sqlOpt.delete();
} else {
StandaloneOptions sqlOpt = new StandaloneOptions();
sqlOpt.setSession_timeout(option.getSessionTimeout());
sqlOpt.setEnable_debug(option.getEnableDebug());
sqlOpt.setRequest_timeout(option.getRequestTimeout());
sqlOpt.setHost(option.getHost());
sqlOpt.setPort(option.getPort());
this.sqlRouter = sql_router_sdk.NewStandaloneSQLRouter(sqlOpt);
sqlOpt.delete();
}
if (sqlRouter == null) {
throw new SqlException("fail to create sql executor");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com._4paradigm.openmldb.sdk.SqlExecutor;
import com._4paradigm.openmldb.sdk.impl.SqlClusterExecutor;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.collections.Maps;

Expand All @@ -42,25 +43,38 @@
public class SQLRouterSmokeTest {

private final Random random = new Random(System.currentTimeMillis());
public static SqlExecutor router;
public static SqlExecutor clusterExecutor;
public static SqlExecutor standaloneExecutor;

static {
try {
SdkOption option = new SdkOption();
option.setZkPath(TestConfig.ZK_PATH);
option.setZkCluster(TestConfig.ZK_CLUSTER);
option.setSessionTimeout(200000);
router = new SqlClusterExecutor(option);
java.sql.Statement state = router.getStatement();
clusterExecutor = new SqlClusterExecutor(option);
java.sql.Statement state = clusterExecutor.getStatement();
state.execute("SET @@execute_mode='online';");
state.close();
// create standalone router
SdkOption standaloneOption = new SdkOption();
standaloneOption.setHost(TestConfig.HOST);
standaloneOption.setPort(TestConfig.PORT);
standaloneOption.setClusterMode(false);
standaloneOption.setSessionTimeout(20000);
standaloneExecutor = new SqlClusterExecutor(standaloneOption);
} catch (Exception e) {
e.printStackTrace();
}
}

@Test
public void testSmoke() {
@DataProvider(name = "executor")
public Object[] executor() {
return new Object[] {clusterExecutor, standaloneExecutor};
}

@Test(dataProvider = "executor")
public void testSmoke(SqlExecutor router) {
try {
String dbname = "db" + random.nextInt(100000);
// create db
Expand Down Expand Up @@ -234,8 +248,8 @@ public void testSmoke() {
}
}

@Test
public void testParameterizedQueryFail() {
@Test(dataProvider = "executor")
public void testParameterizedQueryFail(SqlExecutor router) {
try {
String dbname = "db" + random.nextInt(100000);
// create db
Expand All @@ -261,8 +275,8 @@ public void testParameterizedQueryFail() {
}
}

@Test
public void testInsertMeta() {
@Test(dataProvider = "executor")
public void testInsertMeta(SqlExecutor router) {
String dbname = "db" + random.nextInt(100000);
// create db
router.dropDB(dbname);
Expand Down Expand Up @@ -302,8 +316,8 @@ public void testInsertMeta() {

}

@Test
public void testInsertPreparedState() {
@Test(dataProvider = "executor")
public void testInsertPreparedState(SqlExecutor router) {
try {
String dbname = "db" + random.nextInt(100000);
// create db
Expand Down Expand Up @@ -429,8 +443,8 @@ public void testInsertPreparedState() {
}
}

@Test
public void testInsertPreparedStateBatch() {
@Test(dataProvider = "executor")
public void testInsertPreparedStateBatch(SqlExecutor router) {
Object[][] batchData = new Object[][]{
{
"insert into tsql1010 values(?, ?, 'zhao', 1.0, null, 'z');",
Expand Down Expand Up @@ -563,8 +577,8 @@ public void testInsertPreparedStateBatch() {
}
}

@Test
public void testDDLParseMethods() throws SQLException {
@Test(dataProvider = "executor")
public void testDDLParseMethods(SqlExecutor router) throws SQLException {
Map<String, Map<String, Schema>> schemaMaps = new HashMap<>();
Schema sch = new Schema(Collections.singletonList(new Column("c1", Types.VARCHAR)));
Map<String, Schema> dbSchema = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package com._4paradigm.openmldb.jdbc;

public class TestConfig {
// config for cluster mode
public static String ZK_CLUSTER="127.0.0.1:6181";
public static String ZK_PATH="/onebox";


// config for standalone mode
public static String HOST="127.0.0.1";
public static long PORT=6527;
}
Loading

0 comments on commit 65d716f

Please sign in to comment.