@@ -46,8 +46,10 @@ def wrapper(*args, **kwargs):
46
46
47
47
48
48
class Tests (unittest .TestCase ):
49
- def start_new_pathman_cluster (self , name = 'test' ,
50
- allow_streaming = False , test_data = False ):
49
+ def start_new_pathman_cluster (self ,
50
+ name = 'test' ,
51
+ allow_streaming = False ,
52
+ test_data = False ):
51
53
node = get_new_node (name )
52
54
node .init (allow_streaming = allow_streaming )
53
55
node .append_conf ("postgresql.conf" , "shared_preload_libraries='pg_pathman'\n " )
@@ -79,8 +81,7 @@ def catchup_replica(self, master, replica):
79
81
WHERE application_name = '{0}'
80
82
"""
81
83
82
- master .poll_query_until ('postgres' ,
83
- wait_lsn_query .format (replica .name ))
84
+ master .poll_query_until ('postgres' , wait_lsn_query .format (replica .name ))
84
85
85
86
def test_concurrent (self ):
86
87
""" Test concurrent partitioning """
@@ -126,7 +127,7 @@ def test_replication(self):
126
127
replica .psql ('postgres' , 'explain (costs off) select * from abc' ))
127
128
128
129
# enable parent and see if it is enabled in replica
129
- node .psql ('postgres' , ' select enable_parent(\ ' abc\' ' )
130
+ node .psql ('postgres' , " select enable_parent('abc')" )
130
131
131
132
self .catchup_replica (node , replica )
132
133
self .assertEqual (
@@ -139,15 +140,17 @@ def test_replication(self):
139
140
node .execute ('postgres' , 'select count(*) from abc' )[0 ][0 ], 300000 )
140
141
141
142
# check that UPDATE in pathman_config_params invalidates cache
142
- node .psql ('postgres' , 'update pathman_config_params set enable_parent = false' )
143
+ node .psql ('postgres' ,
144
+ 'update pathman_config_params set enable_parent = false' )
143
145
self .catchup_replica (node , replica )
144
146
self .assertEqual (
145
147
node .psql ('postgres' , 'explain (costs off) select * from abc' ),
146
148
replica .psql ('postgres' , 'explain (costs off) select * from abc' ))
147
149
self .assertEqual (
148
150
node .psql ('postgres' , 'select * from abc' ),
149
151
replica .psql ('postgres' , 'select * from abc' ))
150
- self .assertEqual (node .execute ('postgres' , 'select count(*) from abc' )[0 ][0 ], 0 )
152
+ self .assertEqual (
153
+ node .execute ('postgres' , 'select count(*) from abc' )[0 ][0 ], 0 )
151
154
152
155
def test_locks (self ):
153
156
"""
@@ -197,15 +200,14 @@ def add_partition(node, flag, query):
197
200
# Start transaction that will create partition
198
201
with node .connect () as con :
199
202
con .begin ()
200
- con .execute (' select append_range_partition(\ ' abc\' )' )
203
+ con .execute (" select append_range_partition('abc')" )
201
204
202
205
# Start threads that suppose to add new partitions and wait some
203
206
# time
204
207
query = (
205
208
"select prepend_range_partition('abc')" ,
206
209
"select append_range_partition('abc')" ,
207
- "select add_range_partition('abc', 500000, 550000)" ,
208
- )
210
+ "select add_range_partition('abc', 500000, 550000)" , )
209
211
threads = []
210
212
for i in range (3 ):
211
213
thread = threading .Thread (
@@ -245,65 +247,71 @@ def test_tablespace(self):
245
247
246
248
def check_tablespace (node , tablename , tablespace ):
247
249
res = node .execute ('postgres' ,
248
- ' select get_tablespace(\ ' {}\' )' .format (tablename ))
250
+ " select get_tablespace('{}')" .format (tablename ))
249
251
if len (res ) == 0 :
250
252
return False
251
253
252
254
return res [0 ][0 ] == tablespace
253
255
254
256
with get_new_node ('master' ) as node :
255
257
node .init ()
256
- node .append_conf ('postgresql.conf' , 'shared_preload_libraries=\' pg_pathman\' \n ' )
258
+ node .append_conf ('postgresql.conf' ,
259
+ "shared_preload_libraries='pg_pathman'\n " )
257
260
node .start ()
258
261
node .psql ('postgres' , 'create extension pg_pathman' )
259
262
260
263
# create tablespace
261
264
path = os .path .join (node .data_dir , 'test_space_location' )
262
265
os .mkdir (path )
263
- node .psql ('postgres' , 'create tablespace test_space location \' {}\' ' .format (path ))
266
+ node .psql ('postgres' ,
267
+ "create tablespace test_space location '{}'" .format (path ))
264
268
265
269
# create table in this tablespace
266
- node .psql ('postgres' , 'create table abc(a serial, b int) tablespace test_space' )
270
+ node .psql ('postgres' ,
271
+ 'create table abc(a serial, b int) tablespace test_space' )
267
272
268
273
# create three partitions. Excpect that they will be created in the
269
274
# same tablespace as the parent table
270
- node .psql ('postgres' , 'select create_range_partitions(\' abc\' , \' a\' , 1, 10, 3)' )
275
+ node .psql ('postgres' ,
276
+ "select create_range_partitions('abc', 'a', 1, 10, 3)" )
271
277
self .assertTrue (check_tablespace (node , 'abc' , 'test_space' ))
272
278
273
279
# check tablespace for appended partition
274
- node .psql ('postgres' , 'select append_range_partition(\' abc\' , \' abc_appended\' )' )
280
+ node .psql ('postgres' ,
281
+ "select append_range_partition('abc', 'abc_appended')" )
275
282
self .assertTrue (check_tablespace (node , 'abc_appended' , 'test_space' ))
276
283
277
284
# check tablespace for prepended partition
278
285
node .psql ('postgres' ,
279
- ' select prepend_range_partition(\ ' abc\ ' , \ ' abc_prepended\' )' )
286
+ " select prepend_range_partition('abc', 'abc_prepended')" )
280
287
self .assertTrue (check_tablespace (node , 'abc_prepended' , 'test_space' ))
281
288
282
289
# check tablespace for prepended partition
283
290
node .psql ('postgres' ,
284
- ' select add_range_partition(\ ' abc\ ' , 41, 51, \ ' abc_added\' )' )
291
+ " select add_range_partition('abc', 41, 51, 'abc_added')" )
285
292
self .assertTrue (check_tablespace (node , 'abc_added' , 'test_space' ))
286
293
287
294
# check tablespace for split
288
295
node .psql ('postgres' ,
289
- ' select split_range_partition(\ ' abc_added\ ' , 45, \ ' abc_splitted\' )' )
296
+ " select split_range_partition('abc_added', 45, 'abc_splitted')" )
290
297
self .assertTrue (check_tablespace (node , 'abc_splitted' , 'test_space' ))
291
298
292
299
# now let's specify tablespace explicitly
293
300
node .psql (
294
301
'postgres' ,
295
- 'select append_range_partition(\' abc\' , \' abc_appended_2\' , \' pg_default\' )' )
302
+ "select append_range_partition('abc', 'abc_appended_2', 'pg_default')"
303
+ )
296
304
node .psql (
297
305
'postgres' ,
298
- ' select prepend_range_partition(\ ' abc\ ' , \ ' abc_prepended_2\ ' , \ ' pg_default\' )'
306
+ " select prepend_range_partition('abc', 'abc_prepended_2', 'pg_default')"
299
307
)
300
308
node .psql (
301
309
'postgres' ,
302
- ' select add_range_partition(\ ' abc\ ' , 61, 71, \ ' abc_added_2\ ' , \ ' pg_default\' )'
310
+ " select add_range_partition('abc', 61, 71, 'abc_added_2', 'pg_default')"
303
311
)
304
312
node .psql (
305
313
'postgres' ,
306
- ' select split_range_partition(\ ' abc_added_2\ ' , 65, \ ' abc_splitted_2\ ' , \ ' pg_default\' )'
314
+ " select split_range_partition('abc_added_2', 65, 'abc_splitted_2', 'pg_default')"
307
315
)
308
316
309
317
# yapf: disable
@@ -372,13 +380,13 @@ def test_foreign_table(self):
372
380
b'25|foreign\n ' )
373
381
374
382
# Check that we can successfully insert new data into foreign partition
375
- master .safe_psql ('postgres' , ' insert into abc values (26, \ ' part\' )' )
383
+ master .safe_psql ('postgres' , " insert into abc values (26, 'part')" )
376
384
self .assertEqual (
377
385
master .safe_psql ('postgres' , 'select * from ftable order by id' ),
378
386
b'25|foreign\n 26|part\n ' )
379
387
380
388
# Testing drop partitions (including foreign partitions)
381
- master .safe_psql ('postgres' , ' select drop_partitions(\ ' abc\' )' )
389
+ master .safe_psql ('postgres' , " select drop_partitions('abc')" )
382
390
383
391
# HASH partitioning with FDW:
384
392
# - create hash partitioned table in master
@@ -417,7 +425,7 @@ def test_parallel_nodes(self):
417
425
node .init ()
418
426
node .append_conf (
419
427
'postgresql.conf' ,
420
- ' shared_preload_libraries=\ ' pg_pathman, postgres_fdw\ '\n ' )
428
+ " shared_preload_libraries='pg_pathman, postgres_fdw'\n " )
421
429
node .start ()
422
430
423
431
# Check version of postgres server
@@ -468,7 +476,7 @@ def test_parallel_nodes(self):
468
476
469
477
# Check parallel aggregate plan
470
478
test_query = 'select count(*) from range_partitioned where i < 1500'
471
- plan = con .execute (' select query_plan(\ ' %s\' )' % test_query )[0 ][0 ]
479
+ plan = con .execute (" select query_plan('%s')" % test_query )[0 ][0 ]
472
480
expected = json .loads ("""
473
481
[
474
482
{
@@ -532,7 +540,7 @@ def test_parallel_nodes(self):
532
540
533
541
# Check simple parallel seq scan plan with limit
534
542
test_query = 'select * from range_partitioned where i < 1500 limit 5'
535
- plan = con .execute (' select query_plan(\ ' %s\' )' % test_query )[0 ][0 ]
543
+ plan = con .execute (" select query_plan('%s')" % test_query )[0 ][0 ]
536
544
expected = json .loads ("""
537
545
[
538
546
{
@@ -587,7 +595,7 @@ def test_parallel_nodes(self):
587
595
588
596
# Check the case when none partition is selected in result plan
589
597
test_query = 'select * from range_partitioned where i < 1'
590
- plan = con .execute (' select query_plan(\ ' %s\' )' % test_query )[0 ][0 ]
598
+ plan = con .execute (" select query_plan('%s')" % test_query )[0 ][0 ]
591
599
expected = json .loads ("""
592
600
[
593
601
{
@@ -869,7 +877,7 @@ def test_pg_dump(self):
869
877
with get_new_node ('test' ) as node :
870
878
node .init ()
871
879
node .append_conf ('postgresql.conf' , """
872
- shared_preload_libraries=\ ' pg_pathman\ '
880
+ shared_preload_libraries='pg_pathman'
873
881
pg_pathman.override_copy=false
874
882
""" )
875
883
node .start ()
0 commit comments