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

feat: add java integration tests #786

Merged
merged 1 commit into from
Mar 29, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ jobs:
working-directory: integration_tests/sdk/go
run: |
go run main.go
- name: Run Java SDK tests
working-directory: integration_tests
run: |
make run-java
- name: Upload Logs
if: always()
uses: actions/upload-artifact@v3
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ kill-old-process:

run: clean build kill-old-process
RUST_BACKTRACE=1 $(CERESDB_TEST_BINARY)

run-java:
java -version
cd sdk/java && MAVEN_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED" mvn clean compile exec:java
72 changes: 72 additions & 0 deletions integration_tests/sdk/java/pom.xml
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 integration_tests/sdk/java/src/main/java/io/ceresdb/App.java
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);
}
}
13 changes: 13 additions & 0 deletions integration_tests/sdk/java/src/main/resources/log4j2.xml
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>