Merge pull request #4864 from vitlibar/test-format-schema-on-server

Add test checking using format schema via HTTP interface.
This commit is contained in:
alexey-milovidov 2019-04-01 11:01:08 +03:00 committed by GitHub
commit e3cee18b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import psycopg2
import requests import requests
import base64 import base64
import pymongo import pymongo
import urllib
import docker import docker
from docker.errors import ContainerError from docker.errors import ContainerError
@ -482,6 +483,10 @@ class ClickHouseInstance:
def get_query_request(self, *args, **kwargs): def get_query_request(self, *args, **kwargs):
return self.client.get_query_request(*args, **kwargs) return self.client.get_query_request(*args, **kwargs)
# Connects to the instance via HTTP interface, sends a query and returns the answer
def http_query(self, sql, data=None):
return urllib.urlopen("http://"+self.ip_address+":8123/?query="+urllib.quote(sql,safe=''), data).read()
def restart_clickhouse(self, stop_start_wait_sec=5): def restart_clickhouse(self, stop_start_wait_sec=5):
if not self.stay_alive: if not self.stay_alive:
raise Exception("clickhouse can be restarted only with stay_alive=True instance") raise Exception("clickhouse can be restarted only with stay_alive=True instance")

View File

@ -0,0 +1,6 @@
syntax = "proto3";
message KeyValuePair {
uint64 key = 1;
string value = 2;
}

View File

@ -0,0 +1,40 @@
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
instance = cluster.add_instance('instance',
clickhouse_path_dir='clickhouse_path')
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
instance.query('CREATE DATABASE test')
yield cluster
finally:
cluster.shutdown()
def create_simple_table():
instance.query("DROP TABLE IF EXISTS test.simple")
instance.query('''
CREATE TABLE test.simple (key UInt64, value String)
ENGINE = MergeTree ORDER BY tuple();
''')
def test_protobuf_format_input(started_cluster):
create_simple_table()
instance.http_query(
"INSERT INTO test.simple FORMAT Protobuf SETTINGS format_schema='simple:KeyValuePair'",
"\x07\x08\x01\x12\x03abc\x07\x08\x02\x12\x03def")
assert instance.query("SELECT * from test.simple") == "1\tabc\n2\tdef\n"
def test_protobuf_format_output(started_cluster):
create_simple_table()
instance.query("INSERT INTO test.simple VALUES (1, 'abc'), (2, 'def')");
assert instance.http_query("SELECT * FROM test.simple FORMAT Protobuf SETTINGS format_schema='simple:KeyValuePair'") == \
"\x07\x08\x01\x12\x03abc\x07\x08\x02\x12\x03def"