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

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Validator/DrizzleTransformer.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,2010 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::DrizzleTransformer;
19
 
 
20
 
require Exporter;
21
 
@ISA = qw(GenTest::Validator GenTest);
22
 
 
23
 
use strict;
24
 
 
25
 
use GenTest;
26
 
use GenTest::Constants;
27
 
use GenTest::Comparator;
28
 
#use GenTest::Simplifier::SQL;
29
 
#use GenTest::Simplifier::Test;
30
 
use GenTest::Translator;
31
 
use GenTest::Translator::Mysqldump2ANSI;
32
 
use GenTest::Translator::Mysqldump2javadb;
33
 
use GenTest::Translator::MysqlDML2ANSI;
34
 
 
35
 
my @transformer_names;
36
 
my @transformers;
37
 
my $database_created = 0;
38
 
 
39
 
sub BEGIN {
40
 
        @transformer_names = (
41
 
                'DrizzleExecuteString',
42
 
                'DrizzleExecuteVariable'
43
 
        );
44
 
 
45
 
        say("Transformer Validator will use the following Transformers: ".join(', ', @transformer_names));
46
 
 
47
 
        foreach my $transformer_name (@transformer_names) {
48
 
                eval ("require GenTest::Transform::'".$transformer_name) or die $@;
49
 
                my $transformer = ('GenTest::Transform::'.$transformer_name)->new();
50
 
                push @transformers, $transformer;
51
 
        }
52
 
}
53
 
 
54
 
sub validate {
55
 
        my ($validator, $executors, $results) = @_;
56
 
 
57
 
        my $executor = $executors->[0];
58
 
        my $original_result = $results->[0];
59
 
        my $original_query = $original_result->query();
60
 
 
61
 
        if ($database_created == 0) {
62
 
                $executor->dbh()->do("CREATE DATABASE IF NOT EXISTS transforms");
63
 
                $database_created = 1;
64
 
        }
65
 
 
66
 
        return STATUS_WONT_HANDLE if $original_query !~ m{^\s*SELECT}sio;
67
 
        return STATUS_WONT_HANDLE if defined $results->[0]->warnings();
68
 
        return STATUS_WONT_HANDLE if $results->[0]->status() != STATUS_OK;
69
 
 
70
 
        my $max_transformer_status; 
71
 
        foreach my $transformer (@transformers) {
72
 
                my $transformer_status = $validator->transform($transformer, $executor, $results);
73
 
                $transformer_status = STATUS_OK if ($transformer_status == STATUS_CONTENT_MISMATCH) && ($original_query =~ m{LIMIT}sio);
74
 
                return $transformer_status if $transformer_status > STATUS_CRITICAL_FAILURE;
75
 
                $max_transformer_status = $transformer_status if $transformer_status > $max_transformer_status;
76
 
        }
77
 
 
78
 
        return $max_transformer_status > STATUS_SELECT_REDUCTION ? $max_transformer_status - STATUS_SELECT_REDUCTION : $max_transformer_status;
79
 
}
80
 
 
81
 
sub transform {
82
 
        my ($validator, $transformer, $executor, $results) = @_;
83
 
 
84
 
        my $original_result = $results->[0];
85
 
        my $original_query = $original_result->query();
86
 
 
87
 
        my ($transform_outcome, $transformed_queries, $transformed_results) = $transformer->transformExecuteValidate($original_query, $original_result, $executor);
88
 
        return $transform_outcome if ($transform_outcome > STATUS_CRITICAL_FAILURE) || ($transform_outcome eq STATUS_OK);
89
 
 
90
 
        say("Original query: $original_query failed transformation with Transformer ".$transformer->name());
91
 
        say("Transformed query: ".join('; ', @$transformed_queries));
92
 
 
93
 
        say(GenTest::Comparator::dumpDiff($original_result, $transformed_results->[0]));
94
 
 
95
 
        # NOTE:  Removed Simplification code from here
96
 
 
97
 
        return $transform_outcome;
98
 
}
99
 
 
100
 
sub DESTROY {
101
 
        @transformers = ();
102
 
}
103
 
 
104
 
1;