/
test.py
56 lines (43 loc) · 1.27 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import unittest
import subprocess
import pykafka
from pykafka.cli import kafka_tools
import elasticsearch
import time
import socket
import os.path
def isolate(*names):
subprocess.check_call(('vagga', '_network', 'isolate') + names)
def restore():
subprocess.check_call(('vagga', '_network', 'fullmesh'))
def wait_for_logstash():
logstash_stdout_file = "/work/logstash.out"
while not os.path.isfile(logstash_stdout_file):
time.sleep(2)
pass
while True:
num_lines = 0
with open(logstash_stdout_file) as f:
for l in f:
num_lines += 1
if num_lines > 50:
break
def wait_for_kafka():
while True:
try:
socket.create_connection(("kafka", 9092)).close()
break
except ConnectionRefusedError:
pass
class TestKafka(unittest.TestCase):
@classmethod
def setUpClass(cls):
wait_for_kafka()
wait_for_logstash()
def test_offsets(self):
# check consumer offsets
client = pykafka.KafkaClient(hosts="kafka:9092")
avro_test_topic = client.topics[b'avro_meet_kafka']
print(kafka_tools.fetch_consumer_lag(client, avro_test_topic, b'logstash'))
if __name__ == '__main__':
unittest.main()