~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/lib/GenTest/Validator/ResultsetComparatorGIS.pm

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2008, 2011 Oracle and/or its affiliates. All rights reserved.
2
 
# Use is subject to license terms.
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; version 2 of the License.
7
 
#
8
 
# This program is distributed in the hope that it will be useful, but
9
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
 
# General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16
 
# USA
17
 
 
18
 
package GenTest::Validator::ResultsetComparatorGIS;
19
 
 
20
 
require Exporter;
21
 
@ISA = qw(GenTest GenTest::Validator);
22
 
 
23
 
use strict;
24
 
 
25
 
use GenTest;
26
 
use GenTest::Constants;
27
 
use GenTest::Comparator;
28
 
use GenTest::Result;
29
 
use GenTest::Validator;
30
 
 
31
 
sub validate {
32
 
        my ($comparator, $executors, $results) = @_;
33
 
 
34
 
        return STATUS_OK if $#$results != 1;
35
 
 
36
 
        my $query = $results->[0]->query();
37
 
        my $compare_outcome = GenTest::Comparator::compare($results->[0], $results->[1]);
38
 
 
39
 
        return STATUS_WONT_HANDLE if $results->[0]->status() == STATUS_SEMANTIC_ERROR || $results->[1]->status() == STATUS_SEMANTIC_ERROR;
40
 
        return STATUS_WONT_HANDLE if $results->[0]->status() == STATUS_SYNTAX_ERROR || $results->[1]->status() == STATUS_SYNTAX_ERROR;
41
 
        return STATUS_WONT_HANDLE if $results->[0]->query() =~ m{EXPLAIN}sio;
42
 
 
43
 
        if ($results->[0]->rows() == 0 || $results->[1]->rows() == 0) {
44
 
#               say("Problematic query: ".$results->[0]->query()."\n");
45
 
                return STATUS_WONT_HANDLE;
46
 
        }
47
 
 
48
 
        my @geometries = (
49
 
                $results->[0]->data()->[0]->[0],
50
 
                $results->[1]->data()->[0]->[0]
51
 
        );
52
 
 
53
 
        my $area_queries = [];
54
 
        my $area_results = [];
55
 
        if (defined $geometries[0] && defined $geometries[1]) {
56
 
                $geometries[0] =~ s{GEOMETRYCOLLECTION\(\)}{GEOMETRYCOLLECTION EMPTY}sgio;
57
 
                $area_queries = [
58
 
                        "SELECT ST_LENGTH(ST_GEOMCOLLFROMTEXT(' $geometries[0] '))",
59
 
                        "SELECT ST_LENGTH(ST_GEOMCOLLFROMTEXT(' $geometries[1] '))"
60
 
                ];
61
 
 
62
 
                $area_results = [
63
 
                        $executors->[0]->execute($area_queries->[0]),
64
 
                        $executors->[0]->execute($area_queries->[1])
65
 
                ];
66
 
 
67
 
                if ($area_results->[0]->status() == STATUS_OK && $area_results->[1]->status() == STATUS_OK) {
68
 
                        my $compare_outcome_areas = GenTest::Comparator::compare($area_results->[0], $area_results->[1]);
69
 
                        if (abs($area_results->[0]->data()->[0]->[0] - $area_results->[1]->data()->[0]->[0]) < 10) {
70
 
                                $compare_outcome = STATUS_OK;
71
 
                        }
72
 
                } else {
73
 
                        use Data::Dumper;
74
 
                        print Dumper $area_results;
75
 
                }
76
 
        }
77
 
 
78
 
        if ( ($compare_outcome == STATUS_LENGTH_MISMATCH) ||
79
 
             ($compare_outcome == STATUS_CONTENT_MISMATCH) 
80
 
        ) {
81
 
                say("---------- RESULT COMPARISON ISSUE START ----------");
82
 
        }
83
 
 
84
 
        if ($compare_outcome == STATUS_LENGTH_MISMATCH) {
85
 
                if ($query =~ m{^\s*select}io) {
86
 
                        say("Query: $query failed: result length mismatch between servers (".$results->[0]->rows()." vs. ".$results->[1]->rows().")");
87
 
                        say(GenTest::Comparator::dumpDiff($results->[0], $results->[1]));
88
 
                } else {
89
 
                        say("Query: $query failed: affected_rows mismatch between servers (".$results->[0]->affectedRows()." vs. ".$results->[1]->affectedRows().")");
90
 
                }
91
 
        } elsif ($compare_outcome == STATUS_CONTENT_MISMATCH) {
92
 
                say("Query: ".$results->[0]->query()." failed: result content mismatch between servers.");
93
 
                say(GenTest::Comparator::dumpDiff($results->[0], $results->[1]));
94
 
                say(GenTest::Comparator::dumpDiff($area_results->[0], $area_results->[1])) if defined $area_results->[0] && defined $area_results->[1];
95
 
        }
96
 
 
97
 
        if ( ($compare_outcome == STATUS_LENGTH_MISMATCH) ||
98
 
             ($compare_outcome == STATUS_CONTENT_MISMATCH) 
99
 
        ) {
100
 
                say("---------- RESULT COMPARISON ISSUE END ------------");
101
 
        }
102
 
 
103
 
        #
104
 
        # If the discrepancy is found on SELECT, we reduce the severity of the error so that the test can continue
105
 
        # hopefully finding further errors in the same run or providing an indication as to how frequent the error is
106
 
        #
107
 
        # If the discrepancy is on an UPDATE, then the servers have diverged and the test can not continue safely.
108
 
        # 
109
 
 
110
 
        if ($query =~ m{^[\s/*!0-9]*(EXPLAIN|SELECT|ALTER|LOAD\s+INDEX|CACHE\s+INDEX)}io) {
111
 
                return $compare_outcome - STATUS_SELECT_REDUCTION;
112
 
        } else {
113
 
                return $compare_outcome;
114
 
        }
115
 
}
116
 
 
117
 
1;