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

« back to all changes in this revision

Viewing changes to tests/test_tools/randgen/lib/GenTest/Reporter/BackupInterop.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (20.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131029154340-j36v7gxq9tm1gi5f
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) 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
#####################################################################
 
19
#
 
20
# Author: Hema Sridharan
 
21
# Date: May 2009
 
22
#
 
23
# Purpose: Implementation of WL#4732: The test is intended to verify
 
24
# the interoperability of MySQL BACKUP / RESTORE operations with other
 
25
# server operations.
 
26
# This reporter file will execute periodic backup and restore of db1
 
27
# while the test is running.
 
28
#
 
29
#  Associated files are:
 
30
#  mysql-test/gentest/conf/backup/backup_obj.yy
 
31
#  mysql-test/gentest/conf/backup/backup_interop.yy
 
32
#  mysql-test/gentest/lib/Gentest/Reporter/BackupInterop.pm
 
33
#
 
34
#####################################################################
 
35
package GenTest::Reporter::BackupInterop;
 
36
 
 
37
require Exporter;
 
38
@ISA = qw(GenTest::Reporter);
 
39
 
 
40
use strict;
 
41
use GenTest;
 
42
use GenTest::Reporter;
 
43
use GenTest::Constants;
 
44
 
 
45
my $count = 0;
 
46
my $file = '/tmp/inter.bak';
 
47
 
 
48
sub monitor 
 
49
{
 
50
  my $reporter = shift;
 
51
  my $dsn = $reporter->dsn();
 
52
  
 
53
  # Execute BACKUP periodically
 
54
  my $dbh = DBI->connect($dsn);
 
55
 
 
56
  unlink('/tmp/inter.bak');
 
57
  say("Executing BACKUP DATABASE.");
 
58
  $dbh->do("BACKUP DATABASE db1 TO '/tmp/inter.bak'");
 
59
  $count++;
 
60
 
 
61
  if (defined $dbh->err()) 
 
62
  {
 
63
  return STATUS_DATABASE_CORRUPTION;
 
64
  } 
 
65
  else 
 
66
  {
 
67
  return STATUS_OK;
 
68
  }
 
69
}
 
70
 
 
71
my $tables;
 
72
sub report 
 
73
{
 
74
  my $reporter = shift;
 
75
  my $dsn = $reporter->dsn();
 
76
  my $dbh = DBI->connect($dsn);
 
77
  my $results;
 
78
 
 
79
  my $query="SELECT COUNT(table_name) FROM INFORMATION_SCHEMA.TABLES
 
80
              WHERE TABLE_SCHEMA='db1'";     
 
81
 
 
82
#################################################################
 
83
# Dump the database db1 that is being backed up by using 
 
84
# mysqldump program
 
85
#################################################################
 
86
 
 
87
our $database = 'db1';
 
88
my $file_bak =  '/tmp/db1_dump.bak';
 
89
my $file_res= '/tmp/db1_dump_res.bak';
 
90
my $mysqldump_result = system("mysqldump --compact --order-by-primary --skip-triggers --skip-extended-insert --no-create-info --host=127.0.0.1 --port=13000 --user=root $database | sort > $file_bak");
 
91
 return STATUS_UNKNOWN_ERROR if $mysqldump_result > 0;
 
92
  
 
93
# PERFORM RESTORE
 
94
 
 
95
  say("Executing RESTORE FROM.");
 
96
  $dbh->do("RESTORE FROM '/tmp/inter.bak' OVERWRITE");
 
97
 
 
98
  if (defined $dbh->err()) 
 
99
  {
 
100
  return STATUS_DATABASE_CORRUPTION;
 
101
  } 
 
102
  else 
 
103
  {
 
104
  return STATUS_OK;
 
105
  }
 
106
 
 
107
  my $mysqldump_result = system("mysqldump --compact --order-by-primary --skip-triggers --skip-extended-insert --no-create-info --host=localhost --port=13000 --user=root $database | sort > $file_res");
 
108
 return STATUS_UNKNOWN_ERROR if $mysqldump_result > 0;
 
109
 
 
110
  my $diff_result = system("diff --unified $file_bak $file_res");
 
111
  $diff_result = $diff_result >> 8;
 
112
  return STATUS_UNKNOWN_ERROR if $diff_result > 1;
 
113
 
 
114
  if ($diff_result == 1)
 
115
  {
 
116
  say("Differences between the files were found after query ".$results->[0]->query());
 
117
  return STATUS_UNKNOWN_ERROR;
 
118
  }
 
119
  else 
 
120
  {
 
121
  return STATUS_OK;
 
122
  }
 
123
 
 
124
# Cleanup
 
125
  $dbh->do("DROP DATABASE db1");
 
126
 
 
127
  return STATUS_OK;
 
128
 
 
129
}
 
130
 
 
131
sub type 
 
132
{
 
133
  return REPORTER_TYPE_PERIODIC | REPORTER_TYPE_SUCCESS;
 
134
}
 
135
 
 
136
1;
 
137