mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
docker: create a database "test" for ClickHouse
Keep using the default one for the migration tests, but for the small tests, use the "test" one.
This commit is contained in:
@@ -67,6 +67,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
|
|
||||||
conn, err := ch.Dial(ctx, ch.Options{
|
conn, err := ch.Dial(ctx, ch.Options{
|
||||||
Address: server,
|
Address: server,
|
||||||
|
Database: "test",
|
||||||
DialTimeout: 100 * time.Millisecond,
|
DialTimeout: 100 * time.Millisecond,
|
||||||
Settings: []ch.Setting{
|
Settings: []ch.Setting{
|
||||||
{Key: "allow_suspicious_low_cardinality_types", Value: "1"},
|
{Key: "allow_suspicious_low_cardinality_types", Value: "1"},
|
||||||
@@ -78,7 +79,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
|
|
||||||
// Create the table
|
// Create the table
|
||||||
q := fmt.Sprintf(
|
q := fmt.Sprintf(
|
||||||
`CREATE OR REPLACE TABLE test_table_insert (%s) ENGINE = Memory`,
|
`CREATE OR REPLACE TABLE test_schema_insert (%s) ENGINE = Memory`,
|
||||||
c.ClickHouseCreateTable(schema.ClickHouseSkipAliasedColumns, schema.ClickHouseSkipGeneratedColumns),
|
c.ClickHouseCreateTable(schema.ClickHouseSkipAliasedColumns, schema.ClickHouseSkipGeneratedColumns),
|
||||||
)
|
)
|
||||||
t.Logf("Query: %s", q)
|
t.Logf("Query: %s", q)
|
||||||
@@ -91,7 +92,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
// Insert
|
// Insert
|
||||||
input := bf.ClickHouseProtoInput()
|
input := bf.ClickHouseProtoInput()
|
||||||
if err := conn.Do(ctx, ch.Query{
|
if err := conn.Do(ctx, ch.Query{
|
||||||
Body: input.Into("test_table_insert"),
|
Body: input.Into("test_schema_insert"),
|
||||||
Input: input,
|
Input: input,
|
||||||
OnInput: func(ctx context.Context) error {
|
OnInput: func(ctx context.Context) error {
|
||||||
bf.Clear()
|
bf.Clear()
|
||||||
@@ -105,14 +106,17 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
// Check the result (with the full-featured client)
|
// Check the result (with the full-featured client)
|
||||||
{
|
{
|
||||||
conn, err := clickhouse.Open(&clickhouse.Options{
|
conn, err := clickhouse.Open(&clickhouse.Options{
|
||||||
Addr: []string{server},
|
Addr: []string{server},
|
||||||
|
Auth: clickhouse.Auth{
|
||||||
|
Database: "test",
|
||||||
|
},
|
||||||
DialTimeout: 100 * time.Millisecond,
|
DialTimeout: 100 * time.Millisecond,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("clickhouse.Open() error:\n%+v", err)
|
t.Fatalf("clickhouse.Open() error:\n%+v", err)
|
||||||
}
|
}
|
||||||
// Use formatRow to get JSON representation
|
// Use formatRow to get JSON representation
|
||||||
rows, err := conn.Query(ctx, "SELECT formatRow('JSONEachRow', *) FROM test_table_insert ORDER BY TimeReceived")
|
rows, err := conn.Query(ctx, "SELECT formatRow('JSONEachRow', *) FROM test_schema_insert ORDER BY TimeReceived")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("clickhouse.Query() error:\n%+v", err)
|
t.Fatalf("clickhouse.Query() error:\n%+v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
1
docker/clickhouse/test-db.sql
Normal file
1
docker/clickhouse/test-db.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CREATE DATABASE IF NOT EXISTS test;
|
||||||
@@ -124,11 +124,13 @@ services:
|
|||||||
- zookeeper
|
- zookeeper
|
||||||
environment:
|
environment:
|
||||||
- CLICKHOUSE_SKIP_USER_SETUP=1
|
- CLICKHOUSE_SKIP_USER_SETUP=1
|
||||||
|
- CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1
|
||||||
cap_add:
|
cap_add:
|
||||||
- SYS_NICE
|
- SYS_NICE
|
||||||
volumes:
|
volumes:
|
||||||
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
|
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
|
||||||
- ./clickhouse/cluster-1.xml:/etc/clickhouse-server/config.d/cluster-1.xml
|
- ./clickhouse/cluster-1.xml:/etc/clickhouse-server/config.d/cluster-1.xml
|
||||||
|
- ./clickhouse/test-db.sql:/docker-entrypoint-initdb.d/test-db.sql
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:8123:8123/tcp
|
- 127.0.0.1:8123:8123/tcp
|
||||||
- 127.0.0.1:9000:9000/tcp
|
- 127.0.0.1:9000:9000/tcp
|
||||||
|
|||||||
@@ -118,9 +118,6 @@ func isOldTable(schema *schema.Component, table string) bool {
|
|||||||
if strings.Contains(table, schema.ClickHouseHash()) {
|
if strings.Contains(table, schema.ClickHouseHash()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(table, "test_") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
oldSuffixes := []string{
|
oldSuffixes := []string{
|
||||||
"_raw",
|
"_raw",
|
||||||
"_raw_consumer",
|
"_raw_consumer",
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
|
|
||||||
conn, err := ch.Dial(ctx, ch.Options{
|
conn, err := ch.Dial(ctx, ch.Options{
|
||||||
Address: server,
|
Address: server,
|
||||||
|
Database: "test",
|
||||||
DialTimeout: 100 * time.Millisecond,
|
DialTimeout: 100 * time.Millisecond,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -29,7 +30,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := conn.Do(ctx, ch.Query{
|
if err := conn.Do(ctx, ch.Query{
|
||||||
Body: `CREATE OR REPLACE TABLE test_table_insert
|
Body: `CREATE OR REPLACE TABLE test_example_insert
|
||||||
(
|
(
|
||||||
ts DateTime64(9),
|
ts DateTime64(9),
|
||||||
severity_text Enum8('INFO'=1, 'DEBUG'=2),
|
severity_text Enum8('INFO'=1, 'DEBUG'=2),
|
||||||
@@ -81,7 +82,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
|
|
||||||
// Insert single data block.
|
// Insert single data block.
|
||||||
if err := conn.Do(ctx, ch.Query{
|
if err := conn.Do(ctx, ch.Query{
|
||||||
Body: "INSERT INTO test_table_insert VALUES",
|
Body: "INSERT INTO test_example_insert VALUES",
|
||||||
Input: input,
|
Input: input,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatalf("Do() error:\n%+v", err)
|
t.Fatalf("Do() error:\n%+v", err)
|
||||||
@@ -92,7 +93,7 @@ func TestInsertMemory(t *testing.T) {
|
|||||||
// Stream data to ClickHouse server in multiple data blocks.
|
// Stream data to ClickHouse server in multiple data blocks.
|
||||||
var blocks int
|
var blocks int
|
||||||
if err := conn.Do(ctx, ch.Query{
|
if err := conn.Do(ctx, ch.Query{
|
||||||
Body: input.Into("test_table_insert"), // helper that generates INSERT INTO query with all columns
|
Body: input.Into("test_example_insert"), // helper that generates INSERT INTO query with all columns
|
||||||
Input: input,
|
Input: input,
|
||||||
|
|
||||||
// OnInput is called to prepare Input data before encoding and sending
|
// OnInput is called to prepare Input data before encoding and sending
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ func TestInsert(t *testing.T) {
|
|||||||
// Create components
|
// Create components
|
||||||
dbConf := clickhousedb.DefaultConfiguration()
|
dbConf := clickhousedb.DefaultConfiguration()
|
||||||
dbConf.Servers = []string{server}
|
dbConf.Servers = []string{server}
|
||||||
|
dbConf.Database = "test"
|
||||||
dbConf.DialTimeout = 100 * time.Millisecond
|
dbConf.DialTimeout = 100 * time.Millisecond
|
||||||
chdb, err := clickhousedb.New(r, dbConf, clickhousedb.Dependencies{
|
chdb, err := clickhousedb.New(r, dbConf, clickhousedb.Dependencies{
|
||||||
Daemon: daemon.NewMock(t),
|
Daemon: daemon.NewMock(t),
|
||||||
|
|||||||
Reference in New Issue
Block a user