Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 committed Jan 17, 2024
2 parents dcacd31 + 7cf95e6 commit 3a0edd2
Show file tree
Hide file tree
Showing 32 changed files with 463 additions and 171 deletions.
40 changes: 20 additions & 20 deletions integration_tests/client-library/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@


def check_go():
print("--- go client test")
subprocess.run(["docker", "compose", "exec", "go-lang", "bash", "-c", "cd /go-client && ./run.sh"], check=True)


def check_python():
print("--- python client test")
subprocess.run(["docker", "compose", "exec", "python", "bash", "-c",
"cd /python-client && pip3 install -r requirements.txt && pytest"], check=True)


def check_java():
print("--- java client test")
subprocess.run(["docker", "compose", "exec", "java", "bash", "-c", "apt-get update && apt-get install -y maven"],
check=True)
subprocess.run(["docker", "compose", "exec", "java", "bash", "-c", "cd /java-client && mvn clean test"], check=True)


def check_nodejs():
subprocess.run(
["docker", "compose", "exec", "nodejs", "bash", "-c", "cd /nodejs-client && npm install && npm test"],
check=True)


subprocess.run(["docker", "compose", "up", "-d"], check=True)
sleep(10)

failed_cases = []

try:
check_go()
except Exception as e:
print(e)
failed_cases.append("go client failed")

try:
check_python()
except Exception as e:
print(e)
failed_cases.append("python client failed")

try:
check_java()
except Exception as e:
print(e)
failed_cases.append("java client failed")
for client in ['go', 'python', 'java', 'nodejs']:
print(f"--- {client} client test")
try:
if client == 'go':
check_go()
elif client == 'python':
check_python()
elif client == 'java':
check_java()
elif client == 'nodejs':
check_nodejs()
except Exception as e:
print(e)
failed_cases.append(f"{client} client failed")

if len(failed_cases) != 0:
print(f"--- client check failed for case\n{failed_cases}")
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/client-library/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ services:
command: tail -f /dev/null
volumes:
- ./java:/java-client
nodejs:
image: node:21.6.0-bullseye-slim
command: tail -f /dev/null
volumes:
- ./nodejs:/nodejs-client

volumes:
risingwave-standalone:
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/client-library/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
29 changes: 29 additions & 0 deletions integration_tests/client-library/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pg from 'pg';

export function rw_client() {
let types = pg.types
types.setTypeParser(types.builtins.TIMESTAMP, parseTimestamp)
types.setTypeParser(types.builtins.DATE, parseDate)
types.setTypeParser(types.builtins.INT8, parseBigint)

return new pg.Client({
host: 'risingwave-standalone',
port: 4566,
database: 'dev',
user: 'root',
password: '',
types: types,
})
}

function parseDate(val) {
return val === null ? null : val
}

function parseTimestamp(val) {
return val === null ? null : val
}

function parseBigint(val) {
return val === null ? null : BigInt(val)
}
20 changes: 20 additions & 0 deletions integration_tests/client-library/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "rw-nodejs-client-test",
"version": "1.0.0",
"description": "rw nodejs client test",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"mocha": "^10.2.0",
"chai": "^5.0.0"
},
"dependencies": {
"pg": "^8.11.3",
"postgres-interval": "^4.0.1"
},
"type": "module"
}
44 changes: 44 additions & 0 deletions integration_tests/client-library/nodejs/test/crud_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {checkInsertedData, createTable, deleteDataByName, dropTable, insertData, updateSalaryData} from './util.js'

export async function test_crud(client) {
await createTable(client)

let name = "John Doe"
let age = 30
let salary = BigInt(50000)
let tripIDs = ['12345', '67890']
let fareData = {
initial_charge: 3.0,
subsequent_charge: 1.5,
surcharge: 0.5,
tolls: 2.0,
}
let deci = 3.14159
let birthdate = "1993-05-15"
let starttime = "18:20:00"
let timest = "1993-05-15 00:00:00"
let timestz = new Date()
let timegap = "5 hours"
await insertData(client, name, age, salary, tripIDs, birthdate, deci, fareData, starttime, timest, timestz, timegap)
await checkInsertedData(client, name, age, salary, tripIDs, birthdate, deci, fareData, starttime, timest, timestz, timegap)

// Insert data with null values
let nullName = "Null Person"
let nullAge = 0
let nullSalary = BigInt(0)
let nullTripIDs = []
let nullFareData = {}
let nullBirthDate = "0001-01-01"
let nullStarttime = "00:00:00"
let nullTimest = "0001-01-01 00:00:00"
let nullTimestz = new Date(0)
let nullTimegap = "0"
let nullDeci = 0.0
await insertData(client, nullName, nullAge, nullSalary, nullTripIDs, nullBirthDate, nullDeci, nullFareData, nullStarttime, nullTimest, nullTimestz, nullTimegap)

await checkInsertedData(client, nullName, nullAge, nullSalary, nullTripIDs, nullBirthDate, nullDeci, nullFareData, nullStarttime, nullTimest, nullTimestz, nullTimegap)

await updateSalaryData(client, name, BigInt(60000))
await deleteDataByName(client, name)
await dropTable(client)
}
18 changes: 18 additions & 0 deletions integration_tests/client-library/nodejs/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { rw_client } from '../index.js'
import { test_crud } from "./crud_test.js";

let client = rw_client()

beforeEach(async function () {
await client.connect()
})

afterEach(async function () {
await client.end()
})

describe('nodejs client test', function () {
it('crud test', async function () {
await test_crud(client)
})
});
108 changes: 108 additions & 0 deletions integration_tests/client-library/nodejs/test/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import * as chai from "chai";

const assert = chai.assert

export async function createTable(client) {
let createTableQuery = `
CREATE TABLE sample_table_nodejs
(
name VARCHAR,
age INTEGER,
salary BIGINT,
trip_id VARCHAR[],
birthdate DATE,
deci DOUBLE PRECISION,
fare STRUCT < initial_charge DOUBLE PRECISION,
subsequent_charge DOUBLE PRECISION,
surcharge DOUBLE PRECISION,
tolls DOUBLE PRECISION >,
starttime TIME,
timest TIMESTAMP,
timestz TIMESTAMPTZ,
timegap INTERVAL
)
`;
await client.query(createTableQuery)
console.log("Table created successfully.")
}

export async function dropTable(client) {
let query = "drop table sample_table_nodejs;"
await client.query(query)
console.log("Table dropped successfully.")
}

export async function insertData(client, name, age, salary, tripIDs, birthdate, deci, fareData, starttime, timest, timestz, timegap) {
let insertDateQuery = {
text: `
INSERT INTO sample_table_nodejs (name, age, salary, trip_id, birthdate, deci, fare, starttime, timest,
timestz, timegap)
VALUES ($1, $2, $3, $4, $5, $6, ROW($7, $8, $9, $10), $11, $12, $13, $14);
`,
values: [name, age, salary, tripIDs, birthdate, deci, fareData.initial_charge, fareData.subsequent_charge, fareData.surcharge, fareData.tolls, starttime, timest, timestz, timegap]
}
await client.query(insertDateQuery)
console.log("Data inserted successfully.")
}

export async function checkInsertedData(client, name, age, salary, tripIDs, birthdate, deci, fareData, starttime, timest, timestz, timegap) {
await client.query("FLUSH;")

let query = "SELECT name, age, salary, trip_id, birthdate, deci, fare, starttime, timest, timestz, timegap FROM sample_table_nodejs WHERE name=$1"
let res = await client.query(query, [name])
let row = res.rows[0]

let retrievedName = row.name
assert.deepStrictEqual(retrievedName, name)

let retrievedAge = row.age
assert.deepStrictEqual(retrievedAge, age)

let retrievedSalary = row.salary
assert.deepStrictEqual(retrievedSalary, salary)

let retrievedTripIDs = row.trip_id
assert.deepStrictEqual(retrievedTripIDs, tripIDs)

let retrievedBirthdate = row.birthdate
assert.deepStrictEqual(retrievedBirthdate, birthdate)

let retrievedDeci = row.deci
assert.deepStrictEqual(retrievedDeci, deci)

let retrievedFareData = row.fare

let retrievedStarttime = row.starttime
assert.deepStrictEqual(retrievedStarttime, starttime)

let retrievedTimest = row.timest
assert.deepStrictEqual(retrievedTimest, timest)

let retrievedTimestz = row.timestz
assert.deepStrictEqual(retrievedTimestz, timestz)

let retrievedTimegap = row.timegap.toPostgres()
assert.deepStrictEqual(retrievedTimegap, timegap)

console.log("Data checked successfully.")
}

export async function updateSalaryData(client, name, salary) {
let query = `
UPDATE sample_table_nodejs
SET salary=$1
WHERE name = $2;
`
await client.query(query, [salary, name])
console.log("Data updated successfully.")
}

export async function deleteDataByName(client, name) {
let query = `
DELETE
FROM sample_table_nodejs
WHERE name = $1;
`
await client.query(query, [name])
console.log("Data deleted successfully.")
}
Loading

0 comments on commit 3a0edd2

Please sign in to comment.