Skip to content

Commit

Permalink
Tests for ClickHouse
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Rabaut authored and briandennis committed Dec 19, 2018
1 parent a90f483 commit 2651208
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export const SAMPLE_DBS = {
keyFilename: '/home/plotly/falcon/google-credentials.json'
},
[DIALECTS.CLICKHOUSE]: {
dialect: 'clickhouse',
username: 'default',
password: 'connecttoplotly',
host: 'clickhouse.test.plotly.host',
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"docker:mssql:start": "docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux:latest",
"docker:oracle:build": "docker build test/docker/oracle -t falcon-test-oracle --no-cache",
"docker:oracle:start": "docker run --rm -ti -p 1521:1521 falcon-test-oracle",
"docker:clickhouse:build": "docker build test/docker/clickhouse -t falcon-test-clickhouse --no-cache",
"docker:clickhouse:start": "docker run --rm -ti -p 8123:8123 -p 9000:9000 falcon-test-clickhouse",
"rebuild:modules:electron": "cross-env FSEVENTS_BUILD_FROM_SOURCE=true node scripts/rebuild-modules.js --electron",
"rebuild:modules:node": "cross-env FSEVENTS_BUILD_FROM_SOURCE=true node scripts/rebuild-modules.js",
"fix:module:ibmdb": "node scripts/fix-module-ibmdb.js",
Expand All @@ -45,6 +47,7 @@
"test-unit-oauth2": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/routes.oauth2.spec.js",
"test-unit-oracle": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.oracle.spec.js",
"test-unit-oracle:node": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.oracle.spec.js",
"test-unit-clickhouse": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/datastores.clickhouse.spec.js",
"test-unit-plotly": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/plotly-api.spec.js",
"test-unit-queries": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/routes.queries.spec.js",
"test-unit-routes": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 electron-mocha --full-trace --timeout 90000 --compilers js:babel-register test/backend/routes.spec.js",
Expand Down
51 changes: 51 additions & 0 deletions test/backend/datastores.clickhouse.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { assert } from 'chai';

import { DIALECTS } from '../../app/constants/constants.js';
import {
connect,
query,
schemas,
tables
} from '../../backend/persistent/datastores/Datastores.js';

const connection = {
dialect: DIALECTS.CLICKHOUSE,
host: 'localhost',
port: 8123,
username: 'default',
database: 'plotly'
};

describe('ClickHouse', function() {
it('connect succeeds', function() {
return connect(connection);
});

it('tables returns list of tables', function() {
return tables(connection).then(result => assert.include(result, 'consumption'))
});

it('schemas returns schemas for all tables', function() {
return schemas(connection).then(({ rows, columnnames }) => {
assert.deepInclude(rows, ['consumption', 'alcohol', 'Float32']);
assert.deepInclude(rows, ['consumption', 'location', 'String']);
assert.deepEqual(columnnames, ['tablename', 'column_name', 'data_type']);
});
});

it('query returns rows and column names', function() {
return query(
'SELECT * FROM consumption LIMIT 5',
connection
).then(({ rows, columnnames }) => {
assert.deepEqual(rows, [
['Belarus', 17.5],
['Moldova', 16.8],
['Lithuania', 15.4],
['Russia', 15.1],
['Romania', 14.4]
]);
assert.deepEqual(columnnames, ['location', 'alcohol']);
});
});
})
17 changes: 17 additions & 0 deletions test/docker/clickhouse/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM yandex/clickhouse-server:18.14

ADD https://raw.githubusercontent.com/plotly/datasets/master/2010_alcohol_consumption_by_country.csv /2010_alcohol_consumption_by_country.csv

RUN sed -i -e "1d" /2010_alcohol_consumption_by_country.csv

RUN chmod 777 /2010_alcohol_consumption_by_country.csv

RUN apt-get -y update && apt-get -y install curl clickhouse-client

COPY setup.sh /

RUN chmod +x /setup.sh

EXPOSE 9000 8123

CMD /setup.sh
3 changes: 3 additions & 0 deletions test/docker/clickhouse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Dockerfile in this folder builds a Docker image that starts a ClickHouse server and sets up a test database.

Will fill this out more tomorrow...
22 changes: 22 additions & 0 deletions test/docker/clickhouse/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

clickhouse-server --config-file=/etc/clickhouse-server/config.xml &

# Wait for ClickHouse server to be ready
until $(curl --output /dev/null --silent --head --fail http://localhost:8123); do
echo -e -n '.'
sleep 2.5
done

clickhouse-client --query="CREATE DATABASE plotly";

clickhouse-client --database=plotly --query="CREATE TABLE consumption (location String, alcohol Float32) ENGINE = Memory";

cat /2010_alcohol_consumption_by_country.csv | clickhouse-client --database=plotly --query="INSERT INTO consumption FORMAT CSV";

# Keep ClickHouse server alive
while true
do
sleep 30
done

0 comments on commit 2651208

Please sign in to comment.