* Adding more LIVE VIEW tests

This commit is contained in:
Vitaliy Zakaznikov 2019-06-05 18:27:36 -04:00
parent 7d69496fbb
commit a946d09f1b
17 changed files with 248 additions and 4 deletions

View File

@ -0,0 +1,46 @@
#!/usr/bin/env python
import imp
import os
import sys
import signal
CURDIR = os.path.dirname(os.path.realpath(__file__))
uexpect = imp.load_source('uexpect', os.path.join(CURDIR, 'uexpect.py'))
def client(name=''):
client = uexpect.spawn(os.environ.get('CLICKHOUSE_CLIENT'))
client.eol('\r')
# Note: uncomment this line for debugging
#client.logger(sys.stdout, prefix=name)
client.timeout(2)
return client
prompt = ':\) '
end_of_block = r'.*\xe2\x94\x82\r\n.*\xe2\x94\x98\r\n'
client1 = client('client1>')
client2 = client('client2>')
client1.expect(prompt)
client2.expect(prompt)
client1.send('DROP TABLE IF EXISTS test.lv')
client1.expect(prompt)
client1.send(' DROP TABLE IF EXISTS test.mt')
client1.expect(prompt)
client1.send('CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()')
client1.expect(prompt)
client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt')
client1.expect(prompt)
client1.send('WATCH test.lv EVENTS')
client2.send('INSERT INTO test.mt VALUES (1),(2),(3)')
client1.expect('2.*4cd0592103888d4682de9a32a23602e3' + end_of_block)
client2.send('INSERT INTO test.mt VALUES (4),(5),(6)')
client1.expect('3.*2186dbea325ee4c56b67e9b792e993a3' + end_of_block)
# send Ctrl-C
os.kill(client1.process.pid,signal.SIGINT)
client1.expect(prompt)
client1.send('DROP TABLE test.lv')
client1.expect(prompt)
client1.send('DROP TABLE test.mt')
client1.expect(prompt)

View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
import imp
import os
import sys
import signal
CURDIR = os.path.dirname(os.path.realpath(__file__))
uexpect = imp.load_source('uexpect', os.path.join(CURDIR, 'uexpect.py'))
def client(name=''):
client = uexpect.spawn(os.environ.get('CLICKHOUSE_CLIENT'))
client.eol('\r')
# Note: uncomment this line for debugging
#client.logger(sys.stdout, prefix=name)
client.timeout(2)
return client
prompt = ':\) '
end_of_block = r'.*\xe2\x94\x82\r\n.*\xe2\x94\x98\r\n'
client1 = client('client1>')
client2 = client('client2>')
client1.expect(prompt)
client2.expect(prompt)
client1.send('DROP TABLE IF EXISTS test.lv')
client1.expect(prompt)
client1.send(' DROP TABLE IF EXISTS test.mt')
client1.expect(prompt)
client1.send('CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()')
client1.expect(prompt)
client1.send('CREATE TEMPORARY LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt')
client1.expect(prompt)
client1.send('WATCH test.lv EVENTS')
client2.send('INSERT INTO test.mt VALUES (1),(2),(3)')
client1.expect('2.*4cd0592103888d4682de9a32a23602e3' + end_of_block)
client1.expect('Progress: 2.00 rows.*\)')
# wait for heartbeat
client1.expect('Progress: 2.00 rows.*\)', timeout=15)
# send Ctrl-C
os.kill(client1.process.pid,signal.SIGINT)
client1.expect(prompt)
client1.send('DROP TABLE test.lv')
client1.expect(prompt)
client1.send('DROP TABLE test.mt')
client1.expect(prompt)

View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
import imp
import os
import sys
import signal
CURDIR = os.path.dirname(os.path.realpath(__file__))
uexpect = imp.load_source('uexpect', os.path.join(CURDIR, 'uexpect.py'))
def client(name=''):
client = uexpect.spawn(os.environ.get('CLICKHOUSE_CLIENT'))
client.eol('\r')
# Note: uncomment this line for debugging
#client.logger(sys.stdout, prefix=name)
client.timeout(2)
return client
prompt = ':\) '
end_of_block = r'.*\xe2\x94\x82\r\n.*\xe2\x94\x98\r\n'
client1 = client('client1>')
client2 = client('client2>')
client1.expect(prompt)
client2.expect(prompt)
client1.send('DROP TABLE IF EXISTS test.lv')
client1.expect(prompt)
client1.send(' DROP TABLE IF EXISTS test.mt')
client1.expect(prompt)
client1.send('CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()')
client1.expect(prompt)
client1.send('CREATE TEMPORARY LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt')
client1.expect(prompt)
client1.send('WATCH test.lv')
client2.send('INSERT INTO test.mt VALUES (1),(2),(3)')
client1.expect(r'6.*2' + end_of_block)
client1.expect('Progress: 2.00 rows.*\)')
# wait for heartbeat
client1.expect('Progress: 2.00 rows.*\)', timeout=15)
# send Ctrl-C
os.kill(client1.process.pid,signal.SIGINT)
client1.expect(prompt)
client1.send('DROP TABLE test.lv')
client1.expect(prompt)
client1.send('DROP TABLE test.mt')
client1.expect(prompt)

View File

@ -0,0 +1,51 @@
#!/usr/bin/env python
import imp
import os
import sys
import signal
CURDIR = os.path.dirname(os.path.realpath(__file__))
uexpect = imp.load_source('uexpect', os.path.join(CURDIR, 'uexpect.py'))
def client(name='', command=None):
if command is None:
client = uexpect.spawn(os.environ.get('CLICKHOUSE_CLIENT'))
else:
client = uexpect.spawn(command)
client.eol('\r')
# Note: uncomment this line for debugging
#client.logger(sys.stdout, prefix=name)
client.timeout(2)
return client
prompt = ':\) '
end_of_block = r'.*\xe2\x94\x82\r\n.*\xe2\x94\x98\r\n'
client1 = client('client1>')
client1.expect(prompt)
client1.send('DROP TABLE IF EXISTS test.lv')
client1.expect(prompt)
client1.send(' DROP TABLE IF EXISTS test.mt')
client1.expect(prompt)
client1.send('CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()')
client1.expect(prompt)
client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt')
client1.expect(prompt)
client2 = client('client2>', ['bash', '--noediting'])
client2.expect('\$ ')
client2.send('wget -O- -q "http://localhost:8123/?query=WATCH test.lv EVENTS"')
client2.expect('.*1\tc9d39b11cce79112219a73aaa319b475\r\n')
client1.send('INSERT INTO test.mt VALUES (1),(2),(3)')
client1.expect(prompt)
client2.expect('.*2\t.*\r\n')
## send Ctrl-C
os.kill(client2.process.pid,signal.SIGINT)
client1.send('DROP TABLE test.lv')
client1.expect(prompt)
client1.send('DROP TABLE test.mt')
client1.expect(prompt)

View File

@ -0,0 +1,51 @@
#!/usr/bin/env python
import imp
import os
import sys
import signal
CURDIR = os.path.dirname(os.path.realpath(__file__))
uexpect = imp.load_source('uexpect', os.path.join(CURDIR, 'uexpect.py'))
def client(name='', command=None):
if command is None:
client = uexpect.spawn(os.environ.get('CLICKHOUSE_CLIENT'))
else:
client = uexpect.spawn(command)
client.eol('\r')
# Note: uncomment this line for debugging
#client.logger(sys.stdout, prefix=name)
client.timeout(2)
return client
prompt = ':\) '
end_of_block = r'.*\xe2\x94\x82\r\n.*\xe2\x94\x98\r\n'
client1 = client('client1>')
client1.expect(prompt)
client1.send('DROP TABLE IF EXISTS test.lv')
client1.expect(prompt)
client1.send(' DROP TABLE IF EXISTS test.mt')
client1.expect(prompt)
client1.send('CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()')
client1.expect(prompt)
client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt')
client1.expect(prompt)
client2 = client('client2>', ['bash', '--noediting'])
client2.expect('\$ ')
client2.send('wget -O- -q "http://localhost:8123/?query=WATCH test.lv"')
client2.expect('.*0\t1\r\n')
client1.send('INSERT INTO test.mt VALUES (1),(2),(3)')
client1.expect(prompt)
client2.expect('.*6\t2\r\n')
## send Ctrl-C
os.kill(client2.process.pid,signal.SIGINT)
client1.send('DROP TABLE test.lv')
client1.expect(prompt)
client1.send('DROP TABLE test.mt')
client1.expect(prompt)

View File

@ -102,10 +102,12 @@ class IO(object):
def write(self, data):
return os.write(self.master, data)
def expect(self, pattern, timeout=None):
def expect(self, pattern, timeout=None, escape=False):
self.match = None
self.before = None
self.after = None
if escape:
pattern = re.escape(pattern)
pattern = re.compile(pattern)
if timeout is None:
timeout = self._timeout
@ -151,7 +153,7 @@ class IO(object):
pass
return data
def spawn(*command):
def spawn(command):
master, slave = pty.openpty()
process = Popen(command, preexec_fn=os.setsid, stdout=slave, stdin=slave, stderr=slave, bufsize=1)
os.close(slave)
@ -169,7 +171,7 @@ def reader(out, queue):
queue.put(data)
if __name__ == '__main__':
io = spawn('/bin/bash')
io = spawn(['/bin/bash','--noediting'])
prompt = '\$ '
io.logger(sys.stdout)
io.timeout(2)
@ -182,6 +184,6 @@ if __name__ == '__main__':
io.send('SELECT 1')
io.expect(prompt)
io.send('SHOW TABLES')
io.expect('test')
io.expect('.*\r\n.*')
io.expect(prompt)
io.close()