Insac

Test Suite

Oct 29th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ "$3" -ne "0" ]; then
  4. echo "First table"
  5. mysql mydb -e "use mydb; source test_table$1.sql;"
  6.  
  7. echo "temp table"
  8. mysql mydb -e "use mydb;DROP TABLE IF EXISTS tmp$1; CREATE TABLE tmp$1 ( id integer NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
  9.  
  10. echo "fill temp table"
  11. mysql mydb -e "use mydb;INSERT INTO tmp$1 (id) select x from (select (t1.id-1)*100+(t2.id-1)*10+t3.id as x from (select 1 id union all select 2 id union all select 3 id union all select 4 id union all sel
  12. ect 5 id union all select 6 id union all select 7 id union all select 8 id union all select 9 id union all select 10 id) t1, (select 1 id union all select 2 id union all select 3 id union all select 4 id
  13. union all select 5 id union all select 6 id union all select 7 id union all select 8 id union all select 9 id union all select 10 id) t2, (select 1 id union all select 2 id union all select 3 id union all
  14. select 4 id union all select 5 id union all select 6 id union all select 7 id union all select 8 id union all select 9 id union all select 10 id) t3) tt;"
  15.  
  16. echo "fill table"
  17.  
  18.  
  19. let "limitValue=$2+20"
  20. read -d '' sqlcommand1 <<- EOF
  21. /*---------SQL BEGIN------------*/
  22. use mydb;
  23.  
  24. create table if not exists test_results (
  25.  id int not null auto_increment primary key,
  26.  tablename varchar(16),
  27.  query_descr varchar(255),
  28.  num_rows integer,
  29.  completed tinyint(4),
  30.  start_ts timestamp(6) default current_timestamp(6),
  31.  end_ts timestamp(6) on update current_timestamp(6)
  32. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  33.  
  34. SET autocommit=0;
  35. SET unique_checks=0;
  36. SET foreign_key_checks=0;
  37.  
  38. SET @rank=0;
  39. insert into data$1 (uri, category, value)
  40.   select concat('uri',rank), 1, 'foo' from (select @rank:=@rank+1 as rank from tmp$1 t1, tmp$1 t2, tmp$1 t3 limit $2) dd;
  41.  
  42.  
  43. SET @rank=$2-20;
  44. insert into data$1 (uri, category, value)
  45.        select concat('uri',rank), 2, rank%5 from (select @rank:=@rank+1 as rank from tmp$1 t1, tmp$1 t2, tmp$1 t3 limit $limitValue ) dd;
  46.  
  47. SET autocommit=1;
  48. SET unique_checks=1;
  49. SET foreign_key_checks=1;
  50.  
  51. /*---------SQL END--------------*/
  52.  
  53. EOF
  54.  
  55. mysql mydb -e "${sqlcommand1}"
  56. fi;
  57.  
  58. echo "start query suite"
  59.  
  60. for testfile in query_*.sql
  61. do
  62. description="$(echo "$testfile"| cut -c7-| cut -d\. -f1)"
  63. query=$(cat $testfile| sed -e s/@tablename/data$1/g)
  64. read -d '' sqlcommand <<- EOF
  65. /*---------SQL BEGIN------------*/
  66. use mydb;
  67.  
  68. delete from test_results where tablename='data$1' and num_rows=$2 and completed=0;
  69. insert into test_results (tablename, completed, num_rows, query_descr, end_ts) values ('data$1',0,$2,'$description',null);
  70.  
  71. RESET QUERY CACHE;
  72.  
  73. $query
  74.  
  75. update test_results set completed=1 where tablename='data$1' and num_rows=$2 and query_descr='$description';
  76. /*---------SQL END--------------*/
  77.  
  78. EOF
  79. mysql mydb -e "${sqlcommand}"
Advertisement
Add Comment
Please, Sign In to add comment