~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Validator/QueryProperties.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2009 Sun Microsystems, Inc. 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::QueryProperties;
19
 
 
20
 
require Exporter;
21
 
@ISA = qw(GenTest::Validator GenTest);
22
 
 
23
 
use strict;
24
 
 
25
 
use GenTest;
26
 
use Data::Dumper;
27
 
use GenTest::Constants;
28
 
use GenTest::Result;
29
 
use GenTest::Validator;
30
 
 
31
 
my @properties = (
32
 
        'RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW',
33
 
        'RESULTSET_IS_SINGLE_INTEGER_ONE',
34
 
        'RESULTSET_HAS_ZERO_OR_ONE_ROWS',
35
 
        'RESULTSET_HAS_ONE_ROW',
36
 
        'QUERY_IS_REPLICATION_SAFE'
37
 
);
38
 
 
39
 
my %properties;
40
 
foreach my $property (@properties) {
41
 
        $properties{$property} = 1;
42
 
};
43
 
 
44
 
sub validate {
45
 
        my ($validator, $executors, $results) = @_;
46
 
 
47
 
        my $query = $results->[0]->query();
48
 
        my @query_properties = $query =~ m{((?:RESULTSET_|ERROR_|QUERY_).*?)[^A-Z_0-9]}sog;
49
 
 
50
 
        return STATUS_WONT_HANDLE if $#query_properties == -1;
51
 
 
52
 
        my $query_status = STATUS_OK;
53
 
 
54
 
        foreach my $result (@$results) {
55
 
                foreach my $query_property (@query_properties) {
56
 
                        my $property_status = STATUS_OK;
57
 
                        if (exists $properties{$query_property}) {
58
 
                                #
59
 
                                # This is a named property, call the respective validation procedure
60
 
                                #
61
 
                                $property_status = $validator->$query_property($result);
62
 
                        } elsif (my ($error) = $query_property =~ m{ERROR_(.*)}so) {
63
 
                                #
64
 
                                # This is an error code, check that the query returned that error code
65
 
                                #
66
 
 
67
 
                                if ($error !~ m{^\d*$}) {
68
 
                                        say("Query: $query needs to use a numeric code in in query property $query_property.");
69
 
                                        return STATUS_ENVIRONMENT_FAILURE;
70
 
                                } elsif ($result->err() != $error) {
71
 
                                        say("Query: $query did not fail with error $error.");
72
 
                                        $property_status = STATUS_ERROR_MISMATCH;
73
 
                                }
74
 
                        }
75
 
                        $query_status = $property_status if $property_status > $query_status;
76
 
                }
77
 
        }
78
 
 
79
 
        if ($query_status != STATUS_OK) {
80
 
                say("Query: $query does not have the declared properties: ".join(', ', @query_properties));
81
 
                print Dumper $results if rqg_debug();
82
 
        }
83
 
        
84
 
        return $query_status;
85
 
}
86
 
 
87
 
 
88
 
sub RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW {
89
 
        my ($validator, $result) = @_;
90
 
 
91
 
        return STATUS_OK if not defined $result->data();
92
 
        return STATUS_OK if $result->rows() < 2;
93
 
 
94
 
        my %data_hash;
95
 
        foreach my $row (@{$result->data()}) {
96
 
                my $data_item = join('<field>', @{$row});
97
 
                $data_hash{$data_item}++;
98
 
        }
99
 
        
100
 
        if (keys(%data_hash) > 1) {
101
 
                return STATUS_CONTENT_MISMATCH;
102
 
        } else {
103
 
                return STATUS_OK;
104
 
        }
105
 
}
106
 
 
107
 
sub RESULTSET_HAS_ZERO_OR_ONE_ROWS {
108
 
        my ($validator, $result) = @_;
109
 
        
110
 
        if ($result->rows() > 1) {
111
 
                return STATUS_LENGTH_MISMATCH;
112
 
        } else {
113
 
                return STATUS_OK;
114
 
        }
115
 
}
116
 
 
117
 
sub RESULTSET_HAS_ONE_ROW {
118
 
        my ($validator, $result) = @_;
119
 
        
120
 
        if ($result->rows() != 1) {
121
 
                return STATUS_LENGTH_MISMATCH;
122
 
        } else {
123
 
                return STATUS_OK;
124
 
        }
125
 
}
126
 
 
127
 
sub RESULTSET_IS_SINGLE_INTEGER_ONE {
128
 
        my ($validator, $result) = @_;
129
 
        
130
 
        if (
131
 
                (not defined $result->data()) ||
132
 
                ($#{$result->data()} != 0) ||
133
 
                ($result->rows() != 1) ||
134
 
                ($#{$result->data()->[0]} != 0) ||
135
 
                ($result->data()->[0]->[0] != 1)
136
 
        ) {
137
 
                return STATUS_CONTENT_MISMATCH;
138
 
        } else {
139
 
                return STATUS_OK;
140
 
        }
141
 
}
142
 
 
143
 
sub QUERY_IS_REPLICATION_SAFE {
144
 
 
145
 
        my ($validator, $result) = @_;
146
 
 
147
 
        my $warnings = $result->warnings();
148
 
 
149
 
        if (defined $warnings) {
150
 
                foreach my $warning (@$warnings) {
151
 
                        return STATUS_ENVIRONMENT_FAILURE if $warning->[1] == 1592;
152
 
                }
153
 
        }
154
 
        return STATUS_OK;
155
 
}
156
 
 
157
 
1;