Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression tests local run script #171

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,25 @@ run: build_images
docker-compose build client
docker-compose run --entrypoint /bin/bash client

proxy_2sh_run:
./spqr-router run -c ./examples/2shardproxy.yaml -d

proxy_run:
./spqr-router run -c ./config-example/router.yaml
./spqr-router run -c ./examples/router.yaml

coordinator_run:
./spqr-coordinator run -c ./config-example/coordinator.yaml
./spqr-coordinator run -c ./examples/coordinator.yaml

pooler_run:
./spqr-router run -c ./config-example/localrouter.yaml
./spqr-router run -c ./examples/localrouter.yaml

clean:
rm -f spqr-router spqr-coordinator spqr-mover spqr-worldmock spqr-balancer


regress_local: proxy_2sh_run
./script/regress_local.sh

regress: build_images
docker-compose -f test/regress/docker-compose.yaml up --remove-orphans --exit-code-from regress --build coordinator router shard1 shard2 regress

Expand Down
4 changes: 3 additions & 1 deletion cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
rcfgPath string
saveProfie bool
profileFile string
daemonize bool
)

var rootCmd = &cobra.Command{
Expand All @@ -39,6 +40,7 @@ var rootCmd = &cobra.Command{
func init() {
rootCmd.PersistentFlags().StringVarP(&rcfgPath, "config", "c", "/etc/spqr/router.yaml", "path to config file")
rootCmd.PersistentFlags().StringVarP(&profileFile, "profile-file", "p", "/etc/spqr/router.prof", "path to profile file")
rootCmd.PersistentFlags().BoolVarP(&daemonize, "daemonize", "d", false, "daemonize router binary or not")
rootCmd.PersistentFlags().BoolVar(&saveProfie, "profile", false, "path to config file")
rootCmd.AddCommand(runCmd)
}
Expand All @@ -53,7 +55,7 @@ var runCmd = &cobra.Command{
}

spqrlog.RebornLogger(rcfg.LogFileName)
if rcfg.Daemonize {
if rcfg.Daemonize || daemonize {
cntxt := &daemon.Context{
PidFileName: rcfg.PidFileName,
PidFilePerm: 0644,
Expand Down
7 changes: 7 additions & 0 deletions script/regress_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

for name in `ls -1 test/regress/tests/router/sql/`;
do
cat test/regress/tests/router/sql/$name | psql "host=localhost port=6432 dbname=db1" --echo-all --quiet > test/regress/tests/router/expected/$(basename $name .sql).out 2>&1;
done

40 changes: 38 additions & 2 deletions test/regress/tests/router/expected/shard_routing.out
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ INSERT INTO xxtt1 (i, w_id, j) VALUES(-12, 15, 123123);
NOTICE: send query to shard(s) : sh1
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 23);
NOTICE: send query to shard(s) : sh2
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
NOTICE: send query to shard(s) : sh2
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
NOTICE: send query to shard(s) : sh2
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
NOTICE: send query to shard(s) : sh2
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
NOTICE: send query to shard(s) : sh2
SELECT * FROM xxtt1 WHERE w_id >= 1;
NOTICE: send query to shard(s) : sh1
i | j | w_id
Expand Down Expand Up @@ -138,7 +146,11 @@ NOTICE: send query to shard(s) : sh2
12 | | 21
2121221 | | 21
-211212 | 2121221 | 23
(5 rows)
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
(9 rows)

-- check that aliases works
SELECT * FROM xxtt1 a WHERE a.w_id >= 1;
Expand Down Expand Up @@ -172,7 +184,31 @@ NOTICE: send query to shard(s) : sh2
12 | | 21
2121221 | | 21
-211212 | 2121221 | 23
(5 rows)
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
(9 rows)

SELECT * FROM xxtt1 a WHERE a.w_id = 21 and j + i != 0;
NOTICE: send query to shard(s) : sh2
i | j | w_id
---------+---------+------
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
(4 rows)

SELECT * FROM xxtt1 a WHERE a.w_id = 21 and w_id <= 30 and j + i != 0;
NOTICE: send query to shard(s) : sh2
i | j | w_id
---------+---------+------
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
-211212 | 2121221 | 21
(4 rows)

-- check that `INSERT FROM SELECT` works
INSERT INTO xx SELECT * FROM xx a WHERE a.w_id = 20;
Expand Down
8 changes: 8 additions & 0 deletions test/regress/tests/router/sql/shard_routing.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ INSERT INTO xxtt1 (i, w_id) VALUES(2121221, 21);
INSERT INTO xxtt1 (i, j, w_id) VALUES(-12, 1, 1);
INSERT INTO xxtt1 (i, w_id, j) VALUES(-12, 15, 123123);
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 23);
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);
INSERT INTO xxtt1 (j, i, w_id) VALUES(2121221, -211212, 21);

SELECT * FROM xxtt1 WHERE w_id >= 1;
SELECT * FROM xxtt1 WHERE w_id >= 20;
Expand All @@ -52,6 +56,10 @@ SELECT * FROM xxtt1 a WHERE a.w_id >= 1;
SELECT * FROM xxtt1 a WHERE a.w_id >= 20;
SELECT * FROM xxtt1 a WHERE a.w_id >= 21;


SELECT * FROM xxtt1 a WHERE a.w_id = 21 and j + i != 0;
SELECT * FROM xxtt1 a WHERE a.w_id = 21 and w_id <= 30 and j + i != 0;

-- check that `INSERT FROM SELECT` works
INSERT INTO xx SELECT * FROM xx a WHERE a.w_id = 20;
SELECT * FROM xx WHERE w_id >= 20;
Expand Down
Loading