Adding in testpkeychange regression test.
authorSteve Singer <ssinger@ca.afilias.info>
Fri, 27 May 2011 19:24:39 +0000 (15:24 -0400)
committerSteve Singer <ssinger@ca.afilias.info>
Fri, 27 May 2011 19:24:39 +0000 (15:24 -0400)
This test alters the primary key of a replicated table via
EXECUTE SCRIPT.

Currently slony 2.1.0 is failing this test (it is expected that 2.0 will fail
as well)

clustertest/regression/testpkeychange/README [new file with mode: 0644]
clustertest/regression/testpkeychange/ddl_updates.sql [new file with mode: 0644]
clustertest/regression/testpkeychange/init_schema.sql [new file with mode: 0644]
clustertest/regression/testpkeychange/testpkeychange.js [new file with mode: 0644]

diff --git a/clustertest/regression/testpkeychange/README b/clustertest/regression/testpkeychange/README
new file mode 100644 (file)
index 0000000..964f0d3
--- /dev/null
@@ -0,0 +1,7 @@
+Test changing the primary key of a replicated table.
+This test uses EXECUTE SCRIPT to change add an extra column
+to the primary key of a replicated table.
+
+It then performs a replicated UPDATE statement to check to see
+if slony picks up on the new primary key column.
+
diff --git a/clustertest/regression/testpkeychange/ddl_updates.sql b/clustertest/regression/testpkeychange/ddl_updates.sql
new file mode 100644 (file)
index 0000000..6b8d000
--- /dev/null
@@ -0,0 +1,4 @@
+drop index test1_pkey;
+create unique index test1_pkey on test1(id1,id2);
+update test1 set id1=1;
+
diff --git a/clustertest/regression/testpkeychange/init_schema.sql b/clustertest/regression/testpkeychange/init_schema.sql
new file mode 100644 (file)
index 0000000..7da9d2f
--- /dev/null
@@ -0,0 +1,12 @@
+create table test1 (
+       id1 int4 not null,
+       id2 int4 not null,
+       id3 int4,
+       data text
+);
+create unique index test1_pkey on test1(id1);
+
+insert into test1(id1,id2,id3,data) values (1,1,1,'test');
+insert into test1(id1,id2,id3,data) values (2,2,1,'test2');
+
+
diff --git a/clustertest/regression/testpkeychange/testpkeychange.js b/clustertest/regression/testpkeychange/testpkeychange.js
new file mode 100644 (file)
index 0000000..e18ba43
--- /dev/null
@@ -0,0 +1,80 @@
+
+var NUM_NODES=3;
+coordinator.includeFile('regression/common_tests.js');
+
+
+function get_schema() {
+       var sqlScript = coordinator.readFile('regression/testpkeychange/init_schema.sql');
+       return sqlScript;
+       
+}
+function load_data(coordinator) {
+       var sqlScript = '';
+       psql = coordinator.createPsqlCommand('db1',sqlScript);
+       psql.run();
+       coordinator.join(psql);
+       
+}
+
+function init_cluster() {
+       return 'init cluster(id=1, comment=\'Regress test node\');';
+}
+
+function init_tables() {
+       var script =
+               "set add table (id=1, set id =1, origin=1, fully qualified name= 'public.test1',key='test1_pkey' );\n";
+       
+       return script;
+}
+
+function create_set() {
+       return 'create set (id=1, origin=1);  # no comment - should draw one in automagically\n';
+
+}
+
+function subscribe_set() {
+       var script=
+       "echo 'sleep a couple seconds';"
+       +"sleep (seconds = 2);\n"
+       +"subscribe set ( id = 1, provider = 1, receiver = 2, forward = no);\n"
+       +"sync(id=1);\n"
+       +"wait for event (origin=1, confirmed=2, wait on=1);\n"
+       +"echo 'sleep a couple seconds';\n"
+       +"sleep (seconds = 2);\n"
+       +"subscribe set ( id = 1, provider = 1, receiver = 3, forward = no);\n";
+       return script;
+}
+
+
+
+function exec_ddl(coordinator) {
+       preamble = get_slonik_preamble();
+       var slonikScript = 'EXECUTE SCRIPT(set id=1, FILENAME=\'regression/testpkeychange/ddl_updates.sql\''
+               +',EVENT NODE=1);\n';
+       run_slonik('update ddl',coordinator,preamble,slonikScript);
+}
+
+function change_values() {
+    var sql = "update test1 set data='bar' where id2=2;";
+    return sql;
+}
+
+function do_test(coordinator) {
+
+       exec_ddl(coordinator);
+       wait_for_sync(coordinator);
+       sql = change_values()
+       psql = coordinator.createPsqlCommand('db1',sql);
+       psql.run();
+       coordinator.join(psql);
+       
+}
+
+function get_compare_queries() {
+       var queries=['SELECT id1,id2,id3,data FROM test1 order by id1,id2,id3'
+                    ];
+       return queries;
+}
+
+run_test(coordinator,'testchangepkey');