~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# ==== Purpose ====
2
#
3
# Check if the two given tables (possibly residing on different
4
# master/slave servers) are equal.
5
#
6
# ==== Usage ====
7
#
8
# The tables to check are given by the test language variables
9
# $diff_table_1 and $diff_table_2.  They must be of the
10
# following form:
11
#
12
#  [master:|slave:]database.table
13
#
14
# I.e., both database and table must be speicified.  Optionally, you
15
# can prefix the name with 'master:' (to read the table on master) or
16
# with 'slave:' (to read the table on slave).  If no prefix is given,
17
# reads the table from the current connection.  If one of these
18
# variables has a prefix, both should have a prefix.
19
#
20
# ==== Side effects ====
21
#
22
# - Prints "Comparing tables $diff_table_1 and $diff_tables_2".
23
#
24
# - If the tables are different, prints the difference in a
25
#   system-specific format (unified diff if supported) and generates
26
#   an error.
27
#
28
# - If $diff_table_1 or $diff_table_2 begins with 'master:' or
29
#   'slave:', it will stay connected to one of those hosts after
30
#   execution.  The host is only guaranteed to remain unchanged if
31
#   none of $diff_table_1 or $diff_table_2 begins with 'master:' or
32
#   'slave:'.
33
#
34
# ==== Bugs ====
35
#
36
# - It is currently not possible to use this for tables that are
37
#   supposed to be different, because if the files are different:
38
#    - 'diff' produces system-dependent output,
39
#    - the output includes the absolute path of the compared files,
40
#    - the output includes a timestamp.
41
#   To fix that, we'd probably have to use SQL to compute the
42
#   symmetric difference between the tables.  I'm not sure how to do
43
#   that efficiently.  If we implement this, it would be nice to
44
#   compare the table definitions too.
45
#
46
# - It actually compares the result of "SELECT * FROM table ORDER BY
47
#   col1, col2, ..., colN INTO OUTFILE 'file'".  Hence, it is assumed
48
#   that the comparison orders for both tables are equal and that two
49
#   rows that are equal in the comparison order cannot differ, e.g.,
50
#   by character case.
51
52
53
# ==== Save both tables to file ====
54
55
--echo Comparing tables $diff_table_1 and $diff_table_2
56
disable_query_log;
57
58
--error 0,1
1819.2.2 by patrick crews
Adjustments to tests to deal with the name changes. Also fixed passed/failed reporting post-run in test-run.pl
59
--remove_file $DRIZZLETEST_VARDIR/tmp/diff_table_1
1 by brian
clean slate
60
--error 0,1
1819.2.2 by patrick crews
Adjustments to tests to deal with the name changes. Also fixed passed/failed reporting post-run in test-run.pl
61
--remove_file $DRIZZLETEST_VARDIR/tmp/diff_table_2
1 by brian
clean slate
62
63
let $_diff_table=$diff_table_2;
64
let $_diff_i=2;
65
while ($_diff_i) {
66
67
  # Parse out any leading "master:" or "slave:" from the table
1543.1.1 by patrick crews
Added drizzledump_restore.test - a basic test of whether or not we can restore a table from drizzledump output. The test dumps a table, alters the original table name (<table_name>_orig), restores from the dump file, then compares the original and restored tables. Also included a minor change to test-run.pl so that we can call the drizzle client to restore from a dump file as well as a partial port of the fix for mysql bug#51057, which was a weakness in include/diff_tables.inc that would cause the test to run until timeout if one of the expected tables did not exist. Had to alter diff_tables.inc to work for this test, but this is the only test using this include file. The altered code is merely commented out for now, to see if we need it
68
  # specification and connect to the appropriate server.
1 by brian
clean slate
69
  let $_diff_conn_master=`SELECT SUBSTR('$_diff_table', 1, 7) = 'master:'`;
70
  if ($_diff_conn_master) {
71
    let $_diff_table=`SELECT SUBSTR('$_diff_table', 8)`;
72
    connection master;
73
  }
74
  let $_diff_conn_slave=`SELECT SUBSTR('$_diff_table', 1, 6) = 'slave:'`;
75
  if ($_diff_conn_slave) {
76
    let $_diff_table=`SELECT SUBSTR('$_diff_table', 7)`;
77
    connection slave;
78
  }
79
80
  # Sanity-check the input.
1543.1.1 by patrick crews
Added drizzledump_restore.test - a basic test of whether or not we can restore a table from drizzledump output. The test dumps a table, alters the original table name (<table_name>_orig), restores from the dump file, then compares the original and restored tables. Also included a minor change to test-run.pl so that we can call the drizzle client to restore from a dump file as well as a partial port of the fix for mysql bug#51057, which was a weakness in include/diff_tables.inc that would cause the test to run until timeout if one of the expected tables did not exist. Had to alter diff_tables.inc to work for this test, but this is the only test using this include file. The altered code is merely commented out for now, to see if we need it
81
  if (`SELECT '$_diff_table' NOT LIKE '_%._%'`) {
82
    --echo !!!ERROR IN TEST: \$diff_table_$_diff_i='$_diff_table'
83
    --echo                   is not in the form   database.table
84
    --die
85
  }
86
87
  # Check if the table exists
88
  if (`SELECT COUNT(*) = 0 FROM data_dictionary.tables
89
       WHERE CONCAT(table_schema, '.', table_name) = '$_diff_table'`) {
90
    --echo !!!ERROR IN TEST: The table '$_diff_table' does not exist
91
    --die
92
  }
93
94
95
  #let $_diff_column_list=$_diff_column_index;
96
  #dec $_diff_column_index;
97
  #while ($_diff_column_index) {
98
  #  let $_diff_column_list=$_diff_column_index, $_diff_column_list;
99
  #  dec $_diff_column_index;
100
  #}
1 by brian
clean slate
101
102
  # Now that we have the comma-separated list of columns, we can write
103
  # the table to a file.
1543.1.1 by patrick crews
Added drizzledump_restore.test - a basic test of whether or not we can restore a table from drizzledump output. The test dumps a table, alters the original table name (<table_name>_orig), restores from the dump file, then compares the original and restored tables. Also included a minor change to test-run.pl so that we can call the drizzle client to restore from a dump file as well as a partial port of the fix for mysql bug#51057, which was a weakness in include/diff_tables.inc that would cause the test to run until timeout if one of the expected tables did not exist. Had to alter diff_tables.inc to work for this test, but this is the only test using this include file. The altered code is merely commented out for now, to see if we need it
104
  eval SELECT * FROM $_diff_table ORDER BY 1 
1819.2.2 by patrick crews
Adjustments to tests to deal with the name changes. Also fixed passed/failed reporting post-run in test-run.pl
105
              INTO OUTFILE '$DRIZZLETEST_VARDIR/tmp/diff_table_$_diff_i';
1 by brian
clean slate
106
107
  # Do the same for $diff_table_1.
108
  dec $_diff_i;
109
  let $_diff_table=$diff_table_1;
110
}
111
112
113
# ==== Compare the generated files ====
114
1819.3.1 by patrick crews
Fixed include file causing test failure + updated tests/include.am to use dtr vs. mtr
115
diff_files $DRIZZLETEST_VARDIR/tmp/diff_table_1 $DRIZZLETEST_VARDIR/tmp/diff_table_2;
1 by brian
clean slate
116
1819.2.2 by patrick crews
Adjustments to tests to deal with the name changes. Also fixed passed/failed reporting post-run in test-run.pl
117
--remove_file $DRIZZLETEST_VARDIR/tmp/diff_table_1
118
--remove_file $DRIZZLETEST_VARDIR/tmp/diff_table_2
1 by brian
clean slate
119
120
enable_query_log;