コード例 #1
0
    async def run(self):
        await self.client0.connect()

        self.series_float = gen_points(tp=float,
                                       n=10000,
                                       time_precision=TIME_PRECISION,
                                       ts_gap='5m')
        random.shuffle(self.series_float)
        self.series_int = gen_points(tp=int,
                                     n=10000,
                                     time_precision=TIME_PRECISION,
                                     ts_gap='5m')
        random.shuffle(self.series_int)

        self.assertEqual(
            await self.client0.insert({
                'series float': self.series_float,
                'series int': self.series_int
            }), {'success_msg': 'Successfully inserted 20000 point(s).'})

        self.series_float.sort()
        self.series_int.sort()

        await self._test_series(self.client0)

        await self.client0.query('drop series /.*/ set ignore_threshold true')

        # Create some random series and start 25 insert task parallel
        series = gen_series(n=40)

        for i in range(40):
            await self.client0.insert_some_series(series,
                                                  n=0.8,
                                                  timeout=0,
                                                  points=self.GEN_POINTS)

        # Check the result
        await self.assertSeries(self.client0, series)

        for i in range(40):
            await self.client0.insert_some_series(series,
                                                  n=0.8,
                                                  timeout=0,
                                                  points=self.GEN_POINTS)

        # Check the result
        await self.assertSeries(self.client0, series)

        self.client0.close()

        result = await self.server0.stop()
        self.assertTrue(result)

        await self.server0.start(sleep=10)
        await self.client0.connect()

        # Check the result after rebooting the server
        await self.assertSeries(self.client0, series)

        return False
コード例 #2
0
    async def run(self):
        await self.client0.connect()

        points = gen_points(n=10)

        self.assertEqual(
            await self.client0.insert({
                PI: points,
                Klingon: points
            }), {'success_msg': 'Successfully inserted 20 point(s).'})

        self.assertEqual(
            await self.client0.query('select * from "{}"'.format(PI)),
            {PI: sorted(points)})

        self.assertEqual(
            await self.client0.query('select * from "{}"'.format(Klingon)),
            {Klingon: sorted(points)})

        self.assertEqual(await self.client0.insert(data),
                         {'success_msg': 'Successfully inserted 16 point(s).'})

        self.assertAlmostEqual(
            await
            self.client0.query('select * from "string", "integer", "double"'),
            expected)

        self.client0.close()
コード例 #3
0
    async def run(self):
        await self.client0.connect()

        points = gen_points(n=10)

        self.assertEqual(
            await self.client0.insert({
                PI: points,
                Klingon: points
            }), {'success_msg': 'Successfully inserted 20 point(s).'})

        self.assertEqual(
            await self.client0.query('select * from "{}"'.format(PI)),
            {PI: sorted(points)})

        self.assertEqual(
            await self.client0.query('select * from "{}"'.format(Klingon)),
            {Klingon: sorted(points)})

        self.client0.close()
コード例 #4
0
    async def run(self):
        await self.client0.connect()

        x = requests.get(
            f'http://localhost:9020/get-version', auth=('sa', 'siri'))

        self.assertEqual(x.status_code, 200)
        v = x.json()
        self.assertTrue(isinstance(v, list))
        self.assertTrue(isinstance(v[0], str))

        x = requests.post(
            f'http://localhost:9020/insert/dbtest',
            auth=('iris', 'siri'),
            headers={'Content-Type': 'application/json'})

        self.assertEqual(x.status_code, 400)

        series_float = gen_points(
            tp=float, n=10000, time_precision=TIME_PRECISION, ts_gap='5m')

        series_int = gen_points(
            tp=int, n=10000, time_precision=TIME_PRECISION, ts_gap='5m')

        data = {
            'my_float': series_float,
            'my_int': series_int
        }

        x = requests.post(
            f'http://localhost:9020/insert/dbtest',
            data=json.dumps(data),
            auth=('iris', 'siri'),
            headers={'Content-Type': 'application/json'}
        )

        self.assertEqual(x.status_code, 200)
        self.assertDictEqual(x.json(), {
            'success_msg': 'Successfully inserted 20000 point(s).'})

        data = {
            'dbname': 'dbtest',
            'host': 'localhost',
            'port': 9000,
            'username': '******',
            'password': '******'
        }

        x = requests.post(
            f'http://localhost:9021/new-pool',
            data=json.dumps(data),
            auth=('sa', 'siri'),
            headers={'Content-Type': 'application/json'})

        self.assertEqual(x.status_code, 200)
        self.assertEqual(x.json(), 'OK')

        self.db.servers.append(self.server1)
        await self.assertIsRunning(self.db, self.client0, timeout=30)

        data = {'data': [[1579521271, 10], [1579521573, 20]]}
        x = requests.post(
            f'http://localhost:9020/insert/dbtest',
            json=data,
            auth=('iris', 'siri'))

        self.assertEqual(x.status_code, 200)
        self.assertDictEqual(x.json(), {
            'success_msg': 'Successfully inserted 2 point(s).'})

        x = requests.post(
            f'http://localhost:9020/query/dbtest',
            json={'q': 'select * from "data"'},
            auth=('iris', 'siri'))

        self.assertEqual(x.status_code, 200)
        self.assertEqual(x.json(), data)

        x = requests.post(
            f'http://localhost:9020/query/dbtest',
            json={'q': 'select * from "data"', 't': 'ms'},
            auth=('iris', 'siri'))

        data = {
            'data': [[p[0] * 1000, p[1]] for p in data['data']]
        }

        self.assertEqual(x.status_code, 200)
        self.assertEqual(x.json(), data)

        x = requests.post(
            f'http://localhost:9020/query/dbtest',
            data=qpack.packb({
                'q': 'select sum(1579600000) from "data"',
                't': 'ms'}),
            headers={'Content-Type': 'application/qpack'},
            auth=('iris', 'siri'))

        self.assertEqual(x.status_code, 200)
        self.assertEqual(
            qpack.unpackb(x.content, decode='utf8'),
            {'data': [[1579600000000, 30]]})

        x = requests.post(
            f'http://localhost:9021/new-account',
            json={'account': 't', 'password': ''},
            auth=('sa', 'siri'))

        self.assertEqual(x.status_code, 400)
        self.assertEqual(x.json(), {
            'error_msg':
                'service account name should have at least 2 characters'})

        x = requests.post(
            f'http://localhost:9021/new-account',
            json={'account': 'tt', 'password': '******'},
            auth=('sa', 'siri'))

        self.assertEqual(x.status_code, 200)

        data = {
            'dbname': 'dbtest',
            'host': 'localhost',
            'port': 1234,
            'pool': 0,
            'username': '******',
            'password': '******'
        }

        auth = ('tt', 'pass')
        x = requests.post(
            f'http://localhost:9021/new-replica', json=data, auth=auth)

        self.assertEqual(x.status_code, 400)
        self.assertEqual(x.json(), {
            'error_msg': "database name already exists: 'dbtest'"})

        x = requests.post(
            f'http://localhost:9022/new-replica', json=data, auth=auth)
        self.assertEqual(x.status_code, 401)

        auth = ('sa', 'siri')
        x = requests.post(
            f'http://localhost:9022/new-replica', json=data, auth=auth)

        self.assertEqual(x.status_code, 400)
        self.assertEqual(x.json(), {
            'error_msg':
                "connecting to server 'localhost:1234' failed with error: "
                "connection refused"})

        data['port'] = 9000
        x = requests.post(
            f'http://localhost:9022/new-replica', json=data, auth=auth)
        self.assertEqual(x.status_code, 200)
        self.assertEqual(x.json(), 'OK')

        self.db.servers.append(self.server2)
        await self.assertIsRunning(self.db, self.client0, timeout=30)

        x = requests.get(
            f'http://localhost:9022/get-databases', auth=auth)
        self.assertEqual(x.status_code, 200)
        self.assertEqual(x.json(), ['dbtest'])

        self.client0.close()
コード例 #5
0
    async def run(self):
        await self.client0.connect()

        self.assertEqual(await self.client0.insert({}),
                         {'success_msg': 'Successfully inserted 0 point(s).'})

        self.assertEqual(await self.client0.insert([]),
                         {'success_msg': 'Successfully inserted 0 point(s).'})

        self.series_float = gen_points(tp=float,
                                       n=10000,
                                       time_precision=TIME_PRECISION,
                                       ts_gap='5m')
        random.shuffle(self.series_float)
        self.series_int = gen_points(tp=int,
                                     n=10000,
                                     time_precision=TIME_PRECISION,
                                     ts_gap='5m')
        random.shuffle(self.series_int)

        self.assertEqual(
            await self.client0.insert({
                'series float': self.series_float,
                'series int': self.series_int
            }), {'success_msg': 'Successfully inserted 20000 point(s).'})

        self.series_float.sort()
        self.series_int.sort()

        await self._test_series(self.client0)

        with self.assertRaises(InsertError):
            await self.client0.insert('[]')

        with self.assertRaises(InsertError):
            await self.client0.insert('[]')

        with self.assertRaises(InsertError):
            await self.client0.insert([{}])

        with self.assertRaises(InsertError):
            await self.client0.insert({'no points': []})

        with self.assertRaises(InsertError):
            await self.client0.insert({'no points': [[]]})

        with self.assertRaises(InsertError):
            await self.client0.insert([{'name': 'no points', 'points': []}])

        # timestamps should be interger values
        with self.assertRaises(InsertError):
            await self.client0.insert({'invalid ts': [[0.5, 6]]})

        # empty series name is not allowed
        with self.assertRaises(InsertError):
            await self.client0.insert({'': [[1, 0]]})

        # empty series name is not allowed
        with self.assertRaises(InsertError):
            await self.client0.insert([{'name': '', 'points': [[1, 0]]}])

        await self.db.add_replica(self.server1, 0, sleep=3)
        # await self.db.add_pool(self.server1, sleep=3)

        await self.assertIsRunning(self.db, self.client0, timeout=3)

        await self.client1.connect()

        await self._test_series(self.client1)

        # Create some random series and start 25 insert task parallel
        series = gen_series(n=10000)
        tasks = [
            asyncio.ensure_future(
                self.client0.insert_some_series(series,
                                                timeout=0,
                                                points=self.GEN_POINTS))
            for i in range(25)
        ]
        await asyncio.gather(*tasks)

        await asyncio.sleep(2)

        # Check the result
        await self.assertSeries(self.client0, series)
        await self.assertSeries(self.client1, series)

        tasks = [
            asyncio.ensure_future(
                self.client0.query(
                    'drop series /.*/ set ignore_threshold true'))
            for i in range(5)
        ]

        await asyncio.gather(*tasks)

        tasks = [
            asyncio.ensure_future(
                self.client0.query('drop shards set ignore_threshold true'))
            for i in range(5)
        ]

        await asyncio.gather(*tasks)

        await asyncio.sleep(2)

        self.client0.close()
        self.client1.close()
コード例 #6
0
    async def run(self):
        await self.client0.connect()

        await self.db.add_replica(self.server1, 0, sleep=30)
        # await self.db.add_pool(self.server1, sleep=30)

        await self.assertIsRunning(self.db, self.client0, timeout=30)

        await self.client1.connect()

        self.series_float = gen_points(tp=float,
                                       n=10000,
                                       time_precision=TIME_PRECISION,
                                       ts_gap='10m')
        random.shuffle(self.series_float)

        self.series_int = gen_points(tp=int,
                                     n=10000,
                                     time_precision=TIME_PRECISION,
                                     ts_gap='10m')
        random.shuffle(self.series_int)

        self.assertEqual(
            await self.client0.insert({
                'series float': self.series_float,
                'series int': self.series_int
            }), {'success_msg': 'Successfully inserted 20000 point(s).'})

        self.series_float.sort()
        self.series_int.sort()

        await self._test_series(self.client0)

        total = (await self.client0.query('count shards'))['shards']
        rest = (
            await
            self.client0.query('count shards where end > now - 3w'))['shards']

        self.assertGreater(total, rest)

        await self.client0.query('alter database set expiration_num 3w')
        await asyncio.sleep(40)  # wait for optimize to complete

        total = (await self.client0.query('count shards'))['shards']
        self.assertEqual(total, rest)

        await self.client0.query('alter database set expiration_log 2w')
        await self.client0.insert({
            'series_log': [[int(time.time()) - 3600 * 24 * 15, "expired_log"]]
        })

        res = await self.client0.query('list series name, length "series_log"')
        self.assertEqual(len(res['series']), 0)

        await self.client0.insert({
            'series_log': [
                [int(time.time()) - 3600 * 24 * 15, "expired_log"],
                [int(time.time()) - 3600 * 24 * 7, "valid_log"],
            ]
        })

        res = await self.client0.query('list series name, length "series_log"')
        self.assertEqual(len(res['series']), 1)
        self.assertEqual(res['series'], [['series_log', 1]])

        await self.client0.query('alter database set drop_threshold 0.1')

        with self.assertRaisesRegex(QueryError, "This query would drop .*"):
            result = await self.client0.query(
                'alter database set expiration_num 1w')

        total = (await self.client0.query('count shards'))['shards']
        rest = (
            await
            self.client0.query('count shards where end > now - 1w'))['shards']

        result = await self.client0.query(
            'alter database set expiration_num 1w '
            'set ignore_threshold true')

        await asyncio.sleep(40)  # wait for optimize to complete

        total = (await self.client0.query('count shards'))['shards']
        self.assertEqual(total, rest)

        self.client0.close()
        self.client1.close()
コード例 #7
0
}

x = requests.post(f'http://localhost:9020/query/dbtest',
                  data=json.dumps(data),
                  auth=('iris', 'siri'),
                  headers={'Content-Type': 'application/json'})

print(x.status_code)

if x.status_code == 200:
    print(x.json())
else:
    print(x.text)

series_float = gen_points(tp=float,
                          n=10000,
                          time_precision=TIME_PRECISION,
                          ts_gap='5m')

series_int = gen_points(tp=int,
                        n=10000,
                        time_precision=TIME_PRECISION,
                        ts_gap='5m')

data = {'my_float': series_float, 'my_int': series_int}

x = requests.post(f'http://localhost:9020/insert/dbtest',
                  data=json.dumps(data),
                  auth=('iris', 'siri'),
                  headers={'Content-Type': 'application/json'})

print(x.status_code)