Changeset 15917

Show
Ignore:
Timestamp:
07/17/08 13:29:13 (5 years ago)
Author:
daisuke
Message:

more stats logging

Location:
lang/perl/Mvalve/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Mvalve/trunk/lib/Mvalve/Reader.pm

    r15891 r15917  
    5454    } 
    5555 
     56    my $destination = $message->header( &Mvalve::Const::DESTINATION_HEADER ); 
     57 
    5658    if (&Mvalve::Const::MVALVE_TRACE && $table eq 'q_timed') { 
    5759        Mvalve::trace( "we should have dispatched at " .  
     
    6264    # service name. this /could/ be used by the queue consumer, but it 
    6365    # is *not* a 
    64     my $destination = $message->header( &Mvalve::Const::DESTINATION_HEADER ); 
    6566 
    6667    if ( $qs->is_emergency( $table ) ||  $qs->is_timed( $table ) ) { 
     
    7374        $self->try_push( key => $destination ); 
    7475 
    75         return $message; 
     76        # XXX - This is bad practive, but oh well 
     77        goto RETURN_MESSAGE; 
    7678    } 
    7779 
     
    9092    } 
    9193 
     94RETURN_MESSAGE: 
    9295    # if we got here, we can just return the data 
    9396    Mvalve::trace( "message", $message->id, "being returned") if &Mvalve::Const::MVALVE_TRACE; 
     97    $self->log( 
     98        action => "dequeue", 
     99        destination => $destination, 
     100    ); 
    94101    return $message; 
    95102} 
  • lang/perl/Mvalve/trunk/lib/Mvalve/Writer.pm

    r15914 r15917  
    2626 
    2727    $self->log( 
    28         action      => "insert", 
     28        action      => "enqueue", 
    2929        destination => $data{destination}, 
    3030    ); 
  • lang/perl/Mvalve/trunk/t/05_log.t

    r15914 r15917  
    1212    } else { 
    1313        $messages = $ENV{MVALVE_MESSAGE_COUNT} || 32; 
    14         plan(tests => 5 + 3 * $messages); 
     14        plan(tests => 6 + 3 * $messages); 
    1515    } 
    1616 
     
    3737    ); 
    3838 
     39    my $logger = Mvalve::Logger::Stats->new( 
     40        q4mlog => { 
     41            connect_info => $q_config{args}->{connect_info} 
     42        } 
     43    ); 
     44 
     45    { # XXX Hack: remove everything from stats log first 
     46        $logger->logger->q4m->dbh->do("DELETE FROM q_statslog"); 
     47    } 
     48 
    3949    my $writer = Mvalve::Writer->new( 
    4050        queue => \%q_config, 
    41         logger => Mvalve::Logger::Stats->new( 
    42             q4mlog => { 
    43                 connect_info => $q_config{args}->{connect_info} 
    44             } 
    45         ) 
     51        logger => $logger, 
    4652    ); 
    4753    my $reader = Mvalve::Reader->new( 
    4854        timeout   => 1, 
     55        logger    => $logger, 
    4956        throttler => { 
    5057            module    => 'Data::Valve', 
     
    8289 
    8390    { # check the statslog 
    84         my $queue = Queue::Q4M->new( 
    85             connect_info => $q_config{args}->{connect_info} 
    86         ); 
    87         my $log_count = 0; 
    88         while ($queue->next('q_statslog')) { 
    89             $log_count++; 
    90             last if $log_count == $count; 
    91         } 
     91        # XXX - HACK: get the database handle from stats logger 
     92        my $dbh = $logger->logger->q4m->dbh; 
     93        my $sth = $dbh->prepare("SELECT COUNT(*) FROM q_statslog WHERE action = ?"); 
     94        $sth->execute('enqueue'); 
     95        my ($log_count) = $sth->fetchrow_array(); 
     96 
    9297        is($log_count, $count, "log matches insert count"); 
     98        $dbh->do("DELETE FROM q_statslog"); 
    9399    } 
    94100 
     
    122128        is (keys %messages, 0, "consumed all messages"); 
    123129    } 
     130 
     131    { # check the statslog 
     132        # XXX - HACK: get the database handle from stats logger 
     133        my $dbh = $logger->logger->q4m->dbh; 
     134        my $sth = $dbh->prepare("SELECT COUNT(*) FROM q_statslog WHERE action = ?"); 
     135        $sth->execute('dequeue'); 
     136        my ($log_count) = $sth->fetchrow_array(); 
     137 
     138        is($log_count, $count + 1, "log matches insert count"); 
     139        $dbh->do("DELETE FROM q_statslog"); 
     140    } 
    124141}