forked from orioledb/orioledb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpointer_test.py
103 lines (83 loc) · 2.71 KB
/
checkpointer_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
# coding: utf-8
import unittest
import testgres
import time
import re
import os
from .base_test import BaseTest
from .base_test import wait_checkpointer_stopevent
from .base_test import generate_string
from testgres.enums import NodeStatus
import string
import random
class CheckpointerTest(BaseTest):
def test_checkpoint_by_time(self):
node = self.node
node.append_conf('postgresql.conf',
"orioledb.debug_checkpoint_timeout = 2s\n"
"orioledb.enable_stopevents = true\n")
node.start()
con1 = node.connect()
node.safe_psql('postgres',
"CREATE EXTENSION IF NOT EXISTS orioledb;\n")
node.safe_psql('postgres',
"CREATE TABLE IF NOT EXISTS o_test (\n"
" id integer NOT NULL,\n"
" val text,\n"
" PRIMARY KEY (id)\n"
") USING orioledb;\n")
con1.execute("SELECT pg_stopevent_set('checkpoint_step', 'true');")
node.safe_psql('postgres',
"INSERT INTO o_test\n"
" (SELECT id, id || 'val' FROM generate_series(1, 1000, 1) id);\n")
wait_checkpointer_stopevent(node)
con1.execute("SELECT pg_stopevent_reset('checkpoint_step')")
con1.close()
node.stop(['-m', 'immediate'])
self.assertTrue(self.is_checkpoint_exist())
node.start()
self.assertEqual(
str(node.execute('postgres',
'SELECT * FROM o_test WHERE id BETWEEN 1 and 8;')),
"[(1, '1val'), (2, '2val'), (3, '3val'), (4, '4val'), (5, '5val'),"
" (6, '6val'), (7, '7val'), (8, '8val')]")
node.stop()
def test_checkpoint_by_wal_size(self):
node = self.node
node.append_conf('postgresql.conf',
"orioledb.main_buffers = 500MB\n"
"max_wal_size = 32MB\n"
"orioledb.enable_stopevents = true\n")
node.start()
node.safe_psql('postgres',
"CREATE EXTENSION IF NOT EXISTS orioledb;\n")
con1 = node.connect()
node.safe_psql('postgres',
"CREATE TABLE IF NOT EXISTS o_test (\n"
" val text\n"
") USING orioledb;\n"
"TRUNCATE o_test;\n"
)
con1.execute("SELECT pg_stopevent_set('checkpoint_step', 'true');")
con2 = node.connect()
val = generate_string(2000)
for _ in range(0, 10000):
con2.execute("INSERT INTO o_test VALUES ('%s');" % (val))
con2.commit()
wait_checkpointer_stopevent(node)
con1.execute("SELECT pg_stopevent_reset('checkpoint_step')")
con1.close()
con2.close()
node.stop(['-m', 'immediate'])
self.assertTrue(self.is_checkpoint_exist())
node.start()
self.assertEqual(node.execute('postgres', 'SELECT count(*) FROM o_test;')[0][0], 10000)
node.stop()
def is_checkpoint_exist(self):
orioledb_dir = self.node.data_dir + "/orioledb_data"
exist = False
for f in os.listdir(orioledb_dir):
if re.match(".*[1-9]\.map$", f):
exist = True
return exist