[Rt-commit] rt branch, 4.0/mysql-fts, updated. rt-4.0.0-221-g538c8fe

Ruslan Zakirov ruz at bestpractical.com
Fri May 6 09:37:28 EDT 2011


The branch, 4.0/mysql-fts has been updated
       via  538c8fe0bdcd96c64f92ce107d89a01bb089a650 (commit)
       via  ad2ba5cdead18d56ec83f7c1d30f65f1f6688945 (commit)
       via  201eee7a0d4feb39e926a7591c679abb08d1e474 (commit)
      from  fa5dffcb4e2ce943e7506cd4bc56c608725554a9 (commit)

Summary of changes:
 lib/RT/Handle.pm                |   15 +++++
 lib/RT/Test.pm                  |    4 +
 sbin/rt-setup-fulltext-index.in |   16 +----
 t/fts/indexed_mysql.t           |  127 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+), 13 deletions(-)
 create mode 100644 t/fts/indexed_mysql.t

- Log -----------------------------------------------------------------
commit 201eee7a0d4feb39e926a7591c679abb08d1e474
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri May 6 17:27:11 2011 +0400

    move CheckSphinxSE method into RT::Handle

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index f47729b..90750a2 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -294,6 +294,21 @@ sub CheckCompatibility {
     return (1)
 }
 
+sub CheckSphinxSE {
+    my $self = shift;
+
+    my $dbh = $RT::Handle->dbh;
+    local $dbh->{'RaiseError'} = 0;
+    local $dbh->{'PrintError'} = 0;
+    my $has = ($dbh->selectrow_array("show variables like 'have_sphinx'"))[1];
+    $has ||= ($dbh->selectrow_array(
+        "select 'yes' from INFORMATION_SCHEMA.PLUGINS where PLUGIN_NAME = 'sphinx' AND PLUGIN_STATUS='active'"
+    ))[0];
+
+    return 0 unless lc($has||'') eq "yes";
+    return 1;
+}
+
 =head2 Database maintanance
 
 =head3 CreateDatabase $DBH
diff --git a/sbin/rt-setup-fulltext-index.in b/sbin/rt-setup-fulltext-index.in
index d22099e..678e880 100644
--- a/sbin/rt-setup-fulltext-index.in
+++ b/sbin/rt-setup-fulltext-index.in
@@ -372,18 +372,9 @@ EOT
 }
 
 sub check_sphinx {
-    my $dbh = $RT::Handle->dbh;
-    my $sphinx = ($dbh->selectrow_array("show variables like 'have_sphinx'"))[1];
-    unless ( $sphinx ) {
-        local $dbh->{'PrintError'} = 0;
-        local $dbh->{'RaiseError'} = 0;
-        $sphinx = ($dbh->selectrow_array(
-            "select 'yes' from INFORMATION_SCHEMA.PLUGINS where PLUGIN_NAME = 'sphinx' AND PLUGIN_STATUS='active'"
-        ))[0];
-    }
+    return if $RT::Handle->CheckSphinxSE;
 
-    unless ( lc($sphinx||'') eq 'yes' ) {
-        print STDERR <<EOT;
+    print STDERR <<EOT;
 
 Your Mysql server has not been compiled with the Sphinx storage engine
 (sphinxse).  Either install your system's sphinxse package, the binaries
@@ -391,8 +382,7 @@ from http://sphinxsearch.org/, or recompile mysql according to the
 instructions in Sphinx's documentation.
 
 EOT
-        exit 1;
-    }
+    exit 1;
 }
 
 sub ora_create_datastore {

commit ad2ba5cdead18d56ec83f7c1d30f65f1f6688945
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri May 6 17:28:32 2011 +0400

    RT::Test->temp_directory - returns tmp dir for this test file

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 7da5343..b3f8c0a 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1340,6 +1340,10 @@ sub stop_server {
     @SERVERS = ();
 }
 
+sub temp_directory {
+    return $tmp{'directory'};
+}
+
 sub file_content {
     my $self = shift;
     my $path = shift;

commit 538c8fe0bdcd96c64f92ce107d89a01bb089a650
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri May 6 17:29:34 2011 +0400

    test indexed FTS on mysql

diff --git a/t/fts/indexed_mysql.t b/t/fts/indexed_mysql.t
new file mode 100644
index 0000000..8542b0b
--- /dev/null
+++ b/t/fts/indexed_mysql.t
@@ -0,0 +1,127 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+plan skip_all => 'Not mysql' unless RT->Config->Get('DatabaseType') eq 'mysql';
+plan skip_all => "No SphinxSE in mysql" unless $RT::Handle->CheckSphinxSE;
+
+my %sphinx;
+$sphinx{'searchd'} = RT::Test->find_executable('searchd');
+$sphinx{'indexer'} = RT::Test->find_executable('indexer');
+
+plan skip_all => "No searchd and indexer under PATH"
+    unless $sphinx{'searchd'} && $sphinx{'indexer'};
+
+plan tests => 13;
+
+RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1, Column => 'Content', Table => 'AttachmentsIndex' );
+
+setup_indexing();
+
+my $q = RT::Test->load_or_create_queue( Name => 'General' );
+ok $q && $q->id, 'loaded or created queue';
+my $queue = $q->Name;
+
+sub setup_indexing {
+    my ($exit_code, $output) = RT::Test->run_and_capture(
+        'no-ask'       => 1,
+        command        => $RT::SbinPath .'/rt-setup-fulltext-index',
+        dba            => $ENV{'RT_DBA_USER'},
+        'dba-password' => $ENV{'RT_DBA_PASSWORD'},
+    );
+    ok(!$exit_code, "setted up index");
+    diag "output: $output" if $ENV{'TEST_VERBOSE'};
+
+    my $tmp = $sphinx{'directory'} = File::Spec->catdir( RT::Test->temp_directory, 'sphinx' );
+    mkdir $tmp;
+
+    my $sphinx_conf = $output;
+    $sphinx_conf =~ s/.*?source rt {/source rt {/ms;
+    $sphinx_conf =~ s{\Q$RT::VarPath\E/sphinx/}{$tmp/}g;
+
+    $sphinx{'config'} = File::Spec->catfile( $tmp, 'sphinx.conf' );
+    {
+        open my $fh, ">", $sphinx{'config'};
+        print $fh $sphinx_conf;
+        close $fh;
+    }
+
+    sync_index();
+
+    {
+        my ($exit_code, $output) = RT::Test->run_and_capture(
+            command => $sphinx{'searchd'},
+            config => $sphinx{'config'},
+        );
+        ok(!$exit_code, "setted up index") or diag "output: $output";
+        $sphinx{'started'} = 1 if !$exit_code;
+    }
+}
+
+sub sync_index {
+    local $SIG{'CHLD'} = 'DEFAULT';
+    local $SIG{'PIPE'} = 'DEFAULT';
+    open my $fh, '-|',  $sphinx{'indexer'}, '--all',
+        '--config' => $sphinx{'config'},
+        $sphinx{'started'}? ('--rotate') : (),
+    ;
+    my $output = <$fh>;
+    close $fh;
+    my $exit_code = $?>>8;
+    ok(!$exit_code, "indexed") or diag "output: $output";
+}
+
+sub run_tests {
+    my @test = @_;
+    while ( my ($query, $checks) = splice @test, 0, 2 ) {
+        run_test( $query, %$checks );
+    }
+}
+
+my @tickets;
+sub run_test {
+    my ($query, %checks) = @_;
+    my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+
+    my $tix = RT::Tickets->new(RT->SystemUser);
+    $tix->FromSQL( "( $query_prefix ) AND ( $query )" );
+
+    my $error = 0;
+
+    my $count = 0;
+    $count++ foreach grep $_, values %checks;
+    is($tix->Count, $count, "found correct number of ticket(s) by '$query'") or $error = 1;
+
+    my $good_tickets = ($tix->Count == $count);
+    while ( my $ticket = $tix->Next ) {
+        next if $checks{ $ticket->Subject };
+        diag $ticket->Subject ." ticket has been found when it's not expected";
+        $good_tickets = 0;
+    }
+    ok( $good_tickets, "all tickets are good with '$query'" ) or $error = 1;
+
+    diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error;
+}
+
+ at tickets = RT::Test->create_tickets(
+    { Queue => $q->id },
+    { Subject => 'book', Content => 'book' },
+    { Subject => 'bar', Content => 'bar' },
+);
+sync_index();
+
+run_tests(
+    "Content LIKE 'book'" => { book => 1, bar => 0 },
+    "Content LIKE 'bar'" => { book => 0, bar => 1 },
+);
+
+END {
+    my $Test = RT::Test->builder;
+    return if $Test->{Original_Pid} != $$;
+    return unless $sphinx{'started'};
+
+    my $pid = int RT::Test->file_content([$sphinx{'directory'}, 'searchd.pid']);
+    kill TERM => $pid if $pid;
+}

-----------------------------------------------------------------------


More information about the Rt-commit mailing list