|
| 1 | +#!/usr/bin/perl |
| 2 | +use strict; |
| 3 | +no warnings; |
| 4 | +use Test::More; |
| 5 | +use DBI; |
| 6 | +use Getopt::Long; |
| 7 | + |
| 8 | +my$dbname; |
| 9 | +my$username; |
| 10 | +my$password; |
| 11 | +my$host; |
| 12 | +GetOptions ("--host=s"=> \$host, |
| 13 | +"--dbname=s"=> \$dbname, |
| 14 | +"--username=s"=> \$username, |
| 15 | +"--password=s"=> \$password); |
| 16 | +my$dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host","$username","$password", |
| 17 | + {PrintError=> 0}); |
| 18 | +ok($dbh->err == 0)or (print$DBI::errstrand BAIL_OUT); |
| 19 | + |
| 20 | +my$query ="DELETE FROM test_results;"; |
| 21 | +$dbh->do($query); |
| 22 | +ok($dbh->err == 0)or (print$DBI::errstrand$dbh->disconnect()and BAIL_OUT); |
| 23 | + |
| 24 | +$query ="SELECT schedule.create_job(NULL, '');"; |
| 25 | +my$sth =$dbh->prepare($query); |
| 26 | +$sth->execute(); |
| 27 | +ok($dbh->err == 0)or (print$DBI::errstrand$dbh->disconnect()and BAIL_OUT); |
| 28 | +my$job_id =$sth->fetchrow_array()and$sth->finish(); |
| 29 | +$sth->finish(); |
| 30 | + |
| 31 | +$query ="SELECT schedule.set_job_attribute(?, 'rule', '{\"onstart\": 1}')"; |
| 32 | +$sth =$dbh->prepare($query); |
| 33 | +$sth->bind_param(1,$job_id); |
| 34 | +ok($sth->execute())or (print$DBI::errstrand$dbh->disconnect()and BAIL_OUT); |
| 35 | +$sth->finish(); |
| 36 | + |
| 37 | +$query ="SELECT schedule.set_job_attributes(?,\'{\"name\":\"Test\", |
| 38 | +\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\", |
| 39 | +\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"], |
| 40 | +\"run_as\":\"tester\", |
| 41 | +\"use_same_transaction\":\"true\" |
| 42 | + }\')"; |
| 43 | +$sth =$dbh->prepare($query); |
| 44 | +$sth->bind_param(1,$job_id); |
| 45 | +ok($sth->execute())or (print$DBI::errstrand$dbh->disconnect()and BAIL_OUT); |
| 46 | +$sth->finish(); |
| 47 | + |
| 48 | +$query ="SELECT schedule.set_job_attribute(?, 'cron', '* * * * *')"; |
| 49 | +$sth =$dbh->prepare($query); |
| 50 | +$sth->bind_param(1,$job_id); |
| 51 | +ok($sth->execute())or (print$DBI::errstrand$dbh->disconnect()and BAIL_OUT); |
| 52 | +$sth->finish(); |
| 53 | + |
| 54 | +sleep 190; |
| 55 | +$query ="SELECT count(*) FROM test_results"; |
| 56 | +$sth =$dbh->prepare($query); |
| 57 | +ok($sth->execute())or (print$DBI::errstrand$dbh->disconnect()and BAIL_OUT); |
| 58 | + |
| 59 | +my$result =$sth->fetchrow_array()and$sth->finish(); |
| 60 | +ok ($result > 2)orprint"Count != 2\n"; |
| 61 | + |
| 62 | +$query ="SELECT schedule.deactivate_job(?)"; |
| 63 | +$sth =$dbh->prepare($query); |
| 64 | +$sth->bind_param(1,$job_id); |
| 65 | +ok($sth->execute())orprint$DBI::errstr ; |
| 66 | +$sth->finish(); |
| 67 | + |
| 68 | +$query ="DELETE FROM test_results;"; |
| 69 | +$dbh->do($query); |
| 70 | +ok($dbh->err == 0)orprint$DBI::errstr; |
| 71 | + |
| 72 | +$query ="SELECT schedule.drop_job(?)"; |
| 73 | +$sth =$dbh->prepare($query); |
| 74 | +$sth->bind_param(1,$job_id); |
| 75 | +ok($sth->execute())orprint$DBI::errstr; |
| 76 | +$sth->finish(); |
| 77 | + |
| 78 | +$dbh->disconnect(); |
| 79 | + |
| 80 | +done_testing(); |