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

Added GitHub action for testing #1

Merged
merged 8 commits into from
Oct 17, 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
49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

services:
singlestore:
# check for new versions at https://github.com/singlestore-labs/singlestoredb-dev-image/pkgs/container/singlestoredb-dev/versions
image: ghcr.io/singlestore-labs/singlestoredb-dev:0.2.35
ports:
- "3306:3306"
env:
# if you want a free SingleStore license for your own use please visit https://www.singlestore.com/cloud-trial/
SINGLESTORE_LICENSE: ${{ secrets.SINGLESTORE_LICENSE }}
ROOT_PASSWORD: ${{ secrets.ROOT_PASSWORD }}

env:
ROOT_PASSWORD: ${{ secrets.ROOT_PASSWORD }}

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Copy common.proto file
uses: wei/wget@v1
with:
args: -O src/main/proto/common.proto https://raw.githubusercontent.com/fivetran/fivetran_sdk/production/common.proto
- name: Copy destination_sdk.proto file
uses: wei/wget@v1
with:
args: -O src/main/proto/connector_sdk.proto https://raw.githubusercontent.com/fivetran/fivetran_sdk/production/connector_sdk.proto
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: build
Empty file added src/main/proto/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.singlestore.fivetran.connector;

import com.google.common.collect.ImmutableMap;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;
import org.junit.jupiter.api.BeforeAll;

public class IntegrationTestBase {

static String host = "127.0.0.1";
static String port = "3306";
static String user = "root";
static String password = "1";
static String password = System.getenv("ROOT_PASSWORD");
static String database = "db";

static SingleStoreConfiguration getConfig(String table) {
Expand All @@ -19,10 +22,14 @@ static SingleStoreConfiguration getConfig(String table) {

@BeforeAll
public static void init() throws Exception {
SingleStoreConfiguration conf = getConfig("init");
SingleStoreConnection conn = new SingleStoreConnection(conf);
try (Statement stmt = conn.getConnection().createStatement()) {
String url = String.format("jdbc:singlestore://%s:%s", host, port);
Properties connectionProps = new Properties();
connectionProps.put("user", user);
connectionProps.put("password", password);
try (Connection conn = DriverManager.getConnection(url, connectionProps);
Statement stmt = conn.createStatement()) {
stmt.execute("SET GLOBAL enable_observe_queries=1");
stmt.execute(String.format("CREATE DATABASE IF NOT EXISTS %s", database));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void getSchema() throws Exception {
DataType.STRING,
DataType.STRING,
DataType.STRING,
DataType.STRING,
DataType.BINARY,
DataType.BINARY
);

Expand Down Expand Up @@ -892,59 +892,68 @@ public void observeVectorJson() throws Exception {
SingleStoreConfiguration conf = getConfig("observeVectorJson");
SingleStoreConnection conn = new SingleStoreConnection(conf);

try (Statement stmt = conn.getConnection().createStatement()) {
stmt.execute("SET GLOBAL vector_type_project_format = 'JSON'");
stmt.execute("DROP TABLE IF EXISTS observeVectorJson");
stmt.execute("CREATE TABLE observeVectorJson(a VECTOR(2, I32))");
stmt.execute("INSERT INTO observeVectorJson VALUES ('[1, 2]')");
}

SchemaList schemaList = conn.getSchema();
List<Schema> schemas = schemaList.getSchemasList();
assertEquals(1, schemas.size());

Schema schema = schemas.get(0);
assertEquals(database, schema.getName());

List<Table> tables = schema.getTablesList();
assertEquals(1, tables.size());

Table table = tables.get(0);
assertEquals("observeVectorJson", table.getName());

List<Column> columns = table.getColumnsList();
assertEquals(1, columns.size());
try {
try (Statement stmt = conn.getConnection().createStatement()) {
stmt.execute("DROP TABLE IF EXISTS observeVectorJson");
stmt.execute("CREATE TABLE observeVectorJson(a VECTOR(2, I32))");
stmt.execute("INSERT INTO observeVectorJson VALUES ('[1, 2]')");
}

Column column = columns.get(0);
assertEquals("a", column.getName());
assertEquals(DataType.JSON, column.getType());
final Exception[] observeException = new Exception[1];
SingleStoreConnection observeConn = new SingleStoreConnection(conf);
List<Record> records = new ArrayList<>();

final Exception[] observeException = new Exception[1];
SingleStoreConnection observeConn = new SingleStoreConnection(conf);
List<Record> records = new ArrayList<>();

Thread t = new Thread(() -> {
try {
observeConn.observe(new State(8), (operation, partition, offset, row) -> {
if (operation.equals("Delete") || operation.equals("Update") || operation.equals(
"Insert")) {
records.add(new Record(operation, row));
}
});
} catch (Exception e) {
observeException[0] = e;
try (Statement stmt = observeConn.getConnection().createStatement()) {
stmt.execute("SET vector_type_project_format = 'JSON'");
}
});
t.start();
Thread.sleep(1000);
((com.singlestore.jdbc.Connection) observeConn.getConnection()).cancelCurrentQuery();
Thread.sleep(1000);
t.interrupt();

assertTrue(observeException[0].getMessage().contains("Query execution was interrupted"));

assertEquals(1, records.size());
// TODO: at the moment, OBSERVE returns wrong values when `vector_type_project_format` is JSON
// assertEquals("[1,2]", records.get(0).row.get("a").getJson());
SchemaList schemaList = observeConn.getSchema();
List<Schema> schemas = schemaList.getSchemasList();
assertEquals(1, schemas.size());

Schema schema = schemas.get(0);
assertEquals(database, schema.getName());

List<Table> tables = schema.getTablesList();
assertEquals(1, tables.size());

Table table = tables.get(0);
assertEquals("observeVectorJson", table.getName());

List<Column> columns = table.getColumnsList();
assertEquals(1, columns.size());

Column column = columns.get(0);
assertEquals("a", column.getName());
assertEquals(DataType.JSON, column.getType());

Thread t = new Thread(() -> {
try {
observeConn.observe(new State(8), (operation, partition, offset, row) -> {
if (operation.equals("Delete") || operation.equals("Update") || operation.equals(
"Insert")) {
records.add(new Record(operation, row));
}
});
} catch (Exception e) {
observeException[0] = e;
}
});
t.start();
Thread.sleep(1000);
((com.singlestore.jdbc.Connection) observeConn.getConnection()).cancelCurrentQuery();
Thread.sleep(1000);
t.interrupt();

assertTrue(observeException[0].getMessage().contains("Query execution was interrupted"));

assertEquals(1, records.size());
// TODO: at the moment, OBSERVE returns wrong values when `vector_type_project_format` is JSON
// assertEquals("[1,2]", records.get(0).row.get("a").getJson());
} finally {
try (Statement stmt = conn.getConnection().createStatement()) {
stmt.execute("SET vector_type_project_format = 'BINARY'");
}
}
}
}
Loading