Skip to content

Commit d0f060a

Browse files
committed
Add TAP test for raftable.
1 parent 6980df9 commit d0f060a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

contrib/raftable/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ OBJS = raftable.o worker.o state.o blockmem.o
33
EXTENSION = raftable
44
DATA = raftable--1.0.sql
55

6+
EXTRA_INSTALL = contrib/raftable
7+
68
RAFT_PREFIX = $(HOME)/raft
79
override LDFLAGS += -L$(RAFT_PREFIX)/lib -Wl,-whole-archive -lraft -Wl,-no-whole-archive
810
override CFLAGS += -Wfatal-errors
@@ -18,3 +20,6 @@ top_builddir = ../..
1820
include $(top_builddir)/src/Makefile.global
1921
include $(top_srcdir)/contrib/contrib-global.mk
2022
endif
23+
24+
check:
25+
$(prove_check)

contrib/raftable/t/000_basic.pl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 4;
7+
8+
sub genstr
9+
{
10+
my $len = shift;
11+
my @chars = ("A".."Z", "a".."z");
12+
my $string;
13+
$string .= $chars[rand @chars] for 1..$len;
14+
return $string;
15+
}
16+
17+
sub create_nodes
18+
{
19+
my $nodenum = shift;
20+
my $nodesref = {};
21+
my @cfg = ();
22+
for (my $i = 0; $i < $nodenum; $i++)
23+
{
24+
$nodesref->{$i} = get_new_node();
25+
my $extranode = get_new_node(); # just to find an extra port for raft
26+
push @cfg, "$i:127.0.0.1:${\$extranode->port}"
27+
}
28+
return $nodesref, join(',', @cfg);
29+
}
30+
31+
sub init_nodes
32+
{
33+
my ($nodesref, $cfg) = @_;
34+
print("cfg = $cfg\n");
35+
while (my ($id, $node) = each(%$nodesref))
36+
{
37+
$node->init;
38+
$node->append_conf("postgresql.conf", qq(
39+
shared_preload_libraries = raftable
40+
raftable.id = $id
41+
raftable.peers = '$cfg'
42+
));
43+
}
44+
}
45+
46+
sub start_nodes
47+
{
48+
my $nodesref = shift;
49+
while (my ($id, $node) = each(%$nodesref))
50+
{
51+
$node->start;
52+
$node->psql('postgres', "create extension raftable;");
53+
}
54+
}
55+
56+
my ($nodesref, $cfg) = create_nodes(3);
57+
init_nodes($nodesref, $cfg);
58+
start_nodes($nodesref);
59+
60+
my $able = $nodesref->{0};
61+
my $baker = $nodesref->{1};
62+
my $charlie = $nodesref->{2};
63+
64+
my %tests = (
65+
hello => genstr(1),
66+
and => genstr(100),
67+
goodbye => genstr(1000),
68+
world => genstr(3000),
69+
);
70+
71+
$able->psql('postgres', "select raftable('hello', '$tests{hello}');");
72+
$baker->psql('postgres', "select raftable('and', '$tests{and}');");
73+
$charlie->psql('postgres', "select raftable('goodbye', '$tests{goodbye}');");
74+
#$baker->stop;
75+
$able->psql('postgres', "select raftable('world', '$tests{world}');");
76+
77+
#$baker->start;
78+
while (my ($key, $value) = each(%tests))
79+
{
80+
my $o = $baker->psql('postgres', "select raftable('$key');");
81+
is($o, $value, "Check that baker has all the state replicated");
82+
}
83+
84+
exit(0);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy