Skip to content

Commit f6d970a

Browse files
author
Artur Zakirov
committed
Added tests, and TAP tests
1 parent b9d31eb commit f6d970a

File tree

5 files changed

+249
-0
lines changed

5 files changed

+249
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ top_builddir = ../..
2222
include $(top_builddir)/src/Makefile.global
2323
include $(top_srcdir)/contrib/contrib-global.mk
2424
endif
25+
26+
wal-check: temp-install
27+
$(prove_check)

data/rum.data

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
As a reward for your reformation I write to you on this precious sheet.
2+
You see I have come to be wonderfully attached to Heidelberg, the
3+
beautiful, the quaint, the historically poetic, learned and picturesque
4+
old town on the Neckar. It seems like another home. So I could not show
5+
my appreciation of you in a more complimentary way than by sending this
6+
little series of pictures. Have you ever been here, I wonder? You did
7+
not say, but you wrote as if you knew it by sight as well as by heart.
8+
As I cannot know, I will venture an explanation. The panorama speaks for
9+
itself. Put on your “specs” and look at the castle, half way up the
10+
_berg_, “the Jettenhuhl, a wooded spur of the Konigestuhl.” Look at it
11+
from the “Terrasse.” Thus you’ll get something of an idea of it. The
12+
Gesprente Thurm is the one that was blown up by the French. The
13+
thickness of the walls, twenty-one feet, and the solid masonry, held it
14+
so well that only a fragment, as it were, gave way. It still hangs as if
15+
ready to be replaced. “Das Grosse Fass Gebaude,” too, you will have no
16+
difficulty in making out. If you only had it with its 49,000 gallons of
17+
wine, but wouldn’t you divide with your neighbors! The columns in the
18+
portico that shows in the Schlosshof are the four brought from
19+
Charlemagne’s palace at Ingelheim by the Count Palatine Ludwig, some
20+
time between 1508-44. The Zum Ritter has nothing to do with the castle,
21+
but is an ancient structure (1592) in the Renaissance style, and one of
22+
the few that escaped destruction in 1693. It is a beautiful, highly
23+
ornamental building, and I wish you could see it, if you have not seen
24+
it.
25+
26+
All the above information, I beg you to believe, I do not intend you
27+
to think was evolved from my inner consciousness, but gathered from
28+
the--nearest guide-book!
29+
30+
I am so much obliged to you for mapping out Switzerland to me. I have
31+
been trying my best to get all those “passes” into my brain. Now, thanks
32+
to your letter, I have them all in the handiest kind of a bunch. Ariel
33+
like, “I’ll do my bidding gently,” and as surely, if I get there. But
34+
there are dreadful reports of floods and roads caved in and bridges
35+
swept away and snows and--enough of such exciting items as sets one
36+
thinking--“to go or not to go?” We are this far on the way. Reached
37+
here this afternoon. Have spent the evening sauntering in the gardens,
38+
the Conversationhaus, the bazaar, mingling with the throng, listening to
39+
the band, and comparing what it is with what it was. It was a gay and
40+
curious spectacle, but on the whole had “the banquet-hall deserted”
41+
look. The situation is most beautiful. It lies, you know, at the
42+
entrance of the Black Forest, among picturesque, thickly-wooded hills,
43+
in the valley of the Oos, and extends up the slope of some of the hills.
44+
The Oos is a most turbid, turbulent stream; dashes through part of the
45+
town with angry, headlong speed. There is an avenue along its bank of
46+
oaks, limes and maples, bordered with flower-beds and shrubberies, and
47+
adorned with fountains and handsome villas. We shall devote to-morrow to
48+
seeing all there is to be seen, and go to Strassburg to-morrow evening
49+
for two or three days. From there to Constance, and then hold _our_
50+
“Council” as to further movements.

expected/rum.out

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
CREATE EXTENSION rum;
2+
CREATE TABLE test_rum( t text, a tsvector );
3+
CREATE TRIGGER tsvectorupdate
4+
BEFORE UPDATE OR INSERT ON test_rum
5+
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
6+
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
7+
\copy test_rum(t) from 'data/rum.data';
8+
SET enable_seqscan=off;
9+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
10+
count
11+
-------
12+
2
13+
(1 row)
14+
15+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'have&wish');
16+
count
17+
-------
18+
1
19+
(1 row)
20+
21+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'knew&brain');
22+
count
23+
-------
24+
0
25+
(1 row)
26+
27+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'among');
28+
count
29+
-------
30+
1
31+
(1 row)
32+
33+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'structure&ancient');
34+
count
35+
-------
36+
1
37+
(1 row)
38+
39+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(complimentary|sight)&(sending|heart)');
40+
count
41+
-------
42+
2
43+
(1 row)
44+
45+
INSERT INTO test_rum (t) VALUES ('foo bar foo the over foo qq bar');
46+
INSERT INTO test_rum (t) VALUES ('345 qwerty copyright');
47+
INSERT INTO test_rum (t) VALUES ('345 qwerty');
48+
INSERT INTO test_rum (t) VALUES ('A fat cat has just eaten a rat.');
49+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar');
50+
count
51+
-------
52+
1
53+
(1 row)
54+
55+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'qwerty&345');
56+
count
57+
-------
58+
2
59+
(1 row)
60+
61+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '345');
62+
count
63+
-------
64+
2
65+
(1 row)
66+
67+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'rat');
68+
count
69+
-------
70+
1
71+
(1 row)
72+
73+
SELECT a FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar') ORDER BY a;
74+
a
75+
------------------------------
76+
'bar':2,8 'foo':1,3,6 'qq':7
77+
(1 row)
78+
79+
DELETE FROM test_rum;
80+
SELECT count(*) from test_rum;
81+
count
82+
-------
83+
0
84+
(1 row)
85+

sql/rum.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CREATE EXTENSION rum;
2+
3+
CREATE TABLE test_rum( t text, a tsvector );
4+
5+
CREATE TRIGGER tsvectorupdate
6+
BEFORE UPDATE OR INSERT ON test_rum
7+
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
8+
9+
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
10+
11+
\copy test_rum(t) from 'data/rum.data';
12+
13+
SET enable_seqscan=off;
14+
15+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
16+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'have&wish');
17+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'knew&brain');
18+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'among');
19+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'structure&ancient');
20+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(complimentary|sight)&(sending|heart)');
21+
22+
INSERT INTO test_rum (t) VALUES ('foo bar foo the over foo qq bar');
23+
INSERT INTO test_rum (t) VALUES ('345 qwerty copyright');
24+
INSERT INTO test_rum (t) VALUES ('345 qwerty');
25+
INSERT INTO test_rum (t) VALUES ('A fat cat has just eaten a rat.');
26+
27+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar');
28+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'qwerty&345');
29+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '345');
30+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'rat');
31+
32+
SELECT a FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar') ORDER BY a;
33+
34+
DELETE FROM test_rum;
35+
36+
SELECT count(*) from test_rum;

t/001_wal.pl

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Test generic xlog record work for rum index replication.
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 31;
7+
8+
my $node_master;
9+
my $node_standby;
10+
11+
# Run few queries on both master and standby and check their results match.
12+
sub test_index_replay
13+
{
14+
my ($test_name) = @_;
15+
16+
# Wait for standby to catch up
17+
my $applname = $node_standby->name;
18+
my $caughtup_query =
19+
"SELECT pg_current_xlog_location() <= write_location FROM pg_stat_replication WHERE application_name = '$applname';";
20+
$node_master->poll_query_until('postgres', $caughtup_query)
21+
or die "Timed out while waiting for standby 1 to catch up";
22+
23+
my $queries = qq(SET enable_seqscan=off;
24+
SET enable_bitmapscan=on;
25+
SET enable_indexscan=on;
26+
SELECT * FROM tst WHERE i = 0;
27+
SELECT * FROM tst WHERE i = 3;
28+
SELECT * FROM tst WHERE t \@@ to_tsquery('simple', 'b');
29+
SELECT * FROM tst WHERE t \@@ to_tsquery('simple', 'f');
30+
SELECT * FROM tst WHERE i = 3 AND t \@@ to_tsquery('simple', 'c');
31+
SELECT * FROM tst WHERE i = 7 AND t \@@ to_tsquery('simple', 'e');
32+
);
33+
34+
# Run test queries and compare their result
35+
my $master_result = $node_master->psql("postgres", $queries);
36+
my $standby_result = $node_standby->psql("postgres", $queries);
37+
38+
is($master_result, $standby_result, "$test_name: query result matches");
39+
}
40+
41+
# Initialize master node
42+
$node_master = get_new_node('master');
43+
$node_master->init(allows_streaming => 1);
44+
$node_master->start;
45+
my $backup_name = 'my_backup';
46+
47+
# Take backup
48+
$node_master->backup($backup_name);
49+
50+
# Create streaming standby linking to master
51+
$node_standby = get_new_node('standby');
52+
$node_standby->init_from_backup($node_master, $backup_name,
53+
has_streaming => 1);
54+
$node_standby->start;
55+
56+
# Create some rum index on master
57+
$node_master->psql("postgres", "CREATE EXTENSION rum;");
58+
$node_master->psql("postgres", "CREATE TABLE tst (i int4, t tsvector);");
59+
$node_master->psql("postgres", "INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(1,100000) i;");
60+
$node_master->psql("postgres", "CREATE INDEX rumidx ON tst USING rum (t rum_tsvector_ops);");
61+
62+
# Test that queries give same result
63+
test_index_replay('initial');
64+
65+
# Run 10 cycles of table modification. Run test queries after each modification.
66+
for my $i (1..10)
67+
{
68+
$node_master->psql("postgres", "DELETE FROM tst WHERE i = $i;");
69+
test_index_replay("delete $i");
70+
$node_master->psql("postgres", "VACUUM tst;");
71+
test_index_replay("vacuum $i");
72+
my ($start, $end) = (100001 + ($i - 1) * 10000, 100000 + $i * 10000);
73+
$node_master->psql("postgres", "INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series($start,$end) i;");
74+
test_index_replay("insert $i");
75+
}

0 commit comments

Comments
 (0)