-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2445bb1
commit 7d12580
Showing
5 changed files
with
196 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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>io.ceresdb</groupId> | ||
<artifactId>tests</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>ceresdb-integration-test</name> | ||
<url>https://github.com/CeresDB/ceresdb/</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<log4j.version>2.8.2</log4j.version> | ||
<ceresdb.version>1.0.1</ceresdb.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>${log4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<version>${log4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<version>${log4j.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.ceresdb</groupId> | ||
<artifactId>ceresdb-all</artifactId> | ||
<version>${ceresdb.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>io.ceresdb.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
103 changes: 103 additions & 0 deletions
103
integration_tests/sdk/java/src/main/java/io/ceresdb/App.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,103 @@ | ||
package io.ceresdb; | ||
|
||
import io.ceresdb.models.*; | ||
import io.ceresdb.options.CeresDBOptions; | ||
import org.junit.Assert; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static io.ceresdb.RouteMode.DIRECT; | ||
|
||
public class App { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | ||
|
||
private static String TABLE = "table_for_java_tests" + System.currentTimeMillis(); | ||
private static String HOST = "localhost"; | ||
private static int PORT = 8831; | ||
private static CeresDBClient CLIENT; | ||
|
||
static { | ||
final CeresDBOptions opts = CeresDBOptions.newBuilder(HOST, PORT, DIRECT) // CeresDB default grpc port 8831,use DIRECT RouteMode | ||
.database("public") // use database for client, can be overridden by the RequestContext in request | ||
// maximum retry times when write fails | ||
// (only some error codes will be retried, such as the routing table failure) | ||
.writeMaxRetries(1) | ||
// maximum retry times when read fails | ||
// (only some error codes will be retried, such as the routing table failure) | ||
.readMaxRetries(1).build(); | ||
|
||
CLIENT = new CeresDBClient(); | ||
if (!CLIENT.init(opts)) { | ||
throw new IllegalStateException("Fail to start CeresDBClient"); | ||
} | ||
} | ||
|
||
private static void query(long now, boolean addNewColumn) throws Throwable { | ||
final SqlQueryRequest queryRequest = SqlQueryRequest.newBuilder() | ||
.forTables(TABLE) // table name is optional. If not provided, SQL parser will parse the `ssql` to get the table name and do the routing automaticly | ||
.sql("select * from %s where timestamp = %d", TABLE, now) | ||
.build(); | ||
final CompletableFuture<Result<SqlQueryOk, Err>> qf = CLIENT.sqlQuery(queryRequest); | ||
final Result<SqlQueryOk, Err> queryResult = qf.get(); | ||
|
||
Assert.assertTrue(queryResult.isOk()); | ||
|
||
final SqlQueryOk queryOk = queryResult.getOk(); | ||
// TODO: add row equal assert | ||
LOGGER.warn("result {}", queryOk.getRowList()); | ||
Assert.assertEquals(2, queryOk.getRowCount()); | ||
} | ||
|
||
private static void write(long now, boolean addNewColumn) throws Throwable { | ||
List<Point> points = new LinkedList<>(); | ||
for (int i = 0; i < 2; i++) { | ||
Point.PointBuilder pointBuilder = Point.newPointBuilder(TABLE) | ||
.setTimestamp(now) | ||
.addTag("tag", String.format("tag-%d", i)) | ||
.addField("value", Value.withInt8(10 + i)); | ||
if (addNewColumn) { | ||
pointBuilder = pointBuilder | ||
.addTag("new-tag", String.format("new-tag-%d", i)); | ||
} | ||
|
||
points.add(pointBuilder.build()); | ||
} | ||
final CompletableFuture<Result<WriteOk, Err>> wf = CLIENT.write(new WriteRequest(points)); | ||
final Result<WriteOk, Err> writeResult = wf.get(); | ||
Assert.assertTrue(writeResult.isOk()); | ||
} | ||
|
||
private static void checkAutoCreateTable() throws Throwable { | ||
long now = System.currentTimeMillis(); | ||
write(now, false); | ||
query(now, false); | ||
} | ||
|
||
private static void checkAutoAddColumns() throws Throwable { | ||
long now = System.currentTimeMillis(); | ||
write(now, true); | ||
query(now, true); | ||
} | ||
|
||
private static void run() throws Throwable { | ||
checkAutoCreateTable(); | ||
checkAutoAddColumns(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
LOGGER.warn("Begin tests, table:{}", TABLE); | ||
try { | ||
run(); | ||
} catch (Throwable e) { | ||
LOGGER.error("Test failed", e); | ||
System.exit(1); | ||
} | ||
|
||
LOGGER.warn("Test finish."); | ||
System.exit(0); | ||
} | ||
} |
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="[%level] [%d{YYYY-MM-dd HH:mm:ss.SSS}] [%t] [%F:%L] - %m%n"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="warn"> | ||
<AppenderRef ref="Console"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |