cvs commit: p5ee/App-WorkQueue/t queue-db.t queue.t

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     06/02/28 19:39:09

  Modified:    App-WorkQueue/t queue-db.t queue.t
  Log:
  get tests to work
  
  Revision  Changes    Path
  1.2       +100 -65   p5ee/App-WorkQueue/t/queue-db.t
  
  Index: queue-db.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-WorkQueue/t/queue-db.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- queue-db.t	6 Feb 2006 04:14:23 -0000	1.1
  +++ queue-db.t	1 Mar 2006 03:39:08 -0000	1.2
  @@ -9,6 +9,7 @@
           dbname   => { default => "test", },
           dbuser   => { default => "", },
           dbpass   => { default => "", },
  +        log_level => { default => 0, },
       },
   );
   
  @@ -51,17 +52,17 @@
           },
       },
       debug_sql => $App::options{debug_sql},
  +    log_level => $App::options{log_level},
   );
   
   {
       my $db = $context->repository();
       #cheating... I know its a DBI, but I have to set up the test somehow
       my $dbh     = $db->{dbh};
  -    eval { $dbh->do("drop table t_hotel_shop_subrequest"); };
  +    eval { $dbh->do("drop table t_hotel_shop_request"); };
       my $ddl     = <<EOF;
  -create table t_hotel_shop_subrequest (
  -    shop_subrequest_id     integer       not null auto_increment primary key,
  -    shop_request_id        integer       not null,
  +create table t_hotel_shop_request (
  +    shop_request_id        integer       not null auto_increment primary key,
       org_id                 integer       not null,
   
       prop_id                integer       not null,
  @@ -73,7 +74,7 @@
       begin_arv_dt           date          not null,
       end_arv_dt             date          not null,
       dow                    varchar(13)   null,
  -    comp_id                integer       null,
  +    comp_id                text          null,
   
       scheduled_dttm         datetime      null,
       start_dttm             datetime      null,
  @@ -119,9 +120,8 @@
       actual_data_source     varchar(11)   null,
       report_units           integer       not null default 0,
   
  -    unique hotel_shop_sreq_ak1 (shop_request_id, comp_id, begin_arv_dt, shop_data_source, los),
       index hotel_shop_sreq_ie2  (shop_host, request_status, shop_data_source, actual_data_source,
  -                                shop_priority, shop_request_id, begin_arv_dt, comp_id),
  +                                shop_priority, shop_request_id, begin_arv_dt),
       index hotel_shop_sreq_ie3  (request_status, shop_data_source, actual_data_source)
   ) TYPE=InnoDB
   EOF
  @@ -129,15 +129,14 @@
   }
   
   {
  -    &run("hotel_shop_subrequest");
  -    &run("hotel_shop_subrequest2", 1);
  -    &run("hotel_shop_subrequest3", 1, 1);
  +    &run("hotel_shop_request");
  +    &run("hotel_shop_request2", 1);
   }
   
   sub run {
  -    my ($qname, $rerun, $no_auto) = @_;
  +    my ($qname, $rerun) = @_;
       my $db = $context->repository();
  -    my $table = "t_hotel_shop_subrequest";
  +    my $table = "t_hotel_shop_request";
   
       my ($errmsg, %colidx);
       my $columns = [qw(
  @@ -156,26 +155,6 @@
       for (my $i = 0; $i <= $#$columns; $i++) {
           $colidx{$columns->[$i]} = $i;
       }
  -
  -    my $q = $context->work_queue($qname,
  -        class             => "App::WorkQueue::Repository",
  -        id_attrib         => "shop_request_id,comp_id,begin_arv_dt,shop_data_source,los",
  -        auto_id_attrib    => $no_auto ? undef : "shop_subrequest_id",
  -        status_attrib     => "request_status",
  -        queue_id_attrib   => "shop_host",
  -        queue_id          => $App::options{host},
  -        STATUS_UNBUFFERED => "N",
  -        STATUS_UNACQUIRED => "W",
  -        STATUS_ACQUIRED   => "R",
  -        STATUS_RELEASED   => "S",
  -        BUFFER_SIZE       => 1,
  -        table             => $table,
  -        columns           => $columns,
  -        sort_spec         => "N-shop_priority,N+shop_request_id,begin_arv_dt,comp_id",
  -    );
  -    isa_ok($q, "App::WorkQueue");
  -    isa_ok($q, "App::WorkQueue::Repository");
  -
       my (%num_workers_ds, %num_workers_ads);
       my %state = (
           num_workers => 0,
  @@ -199,6 +178,32 @@
           vic => 1,
           vhy => 1,
       );
  +    my (%total_queued_workers, %total_running_workers, %work_units_accepted, %work_units_running);
  +
  +    my $q = $context->work_queue($qname,
  +        class             => "App::WorkQueue::Repository",
  +        #id_attrib         => "shop_request_id,comp_id,begin_arv_dt,shop_data_source,los",
  +        auto_id_attrib    => "shop_request_id",
  +        status_attrib     => "request_status",
  +        client_id_attrib   => "shop_host",
  +        client_id          => "$App::options{host}:$qname",
  +        STATUS_UNBUFFERED => "N",
  +        STATUS_UNACQUIRED => "N",
  +        STATUS_ACQUIRED   => "R",
  +        STATUS_RELEASED   => "S",
  +        BUFFER_SIZE       => 1,
  +        table             => $table,
  +        columns           => $columns,
  +        sort_spec         => "N-shop_priority,N+shop_request_id,begin_arv_dt,comp_id",
  +        max_workers           => \%max_workers_ads,
  +        total_queued_workers  => \%total_queued_workers,
  +        total_running_workers => \%total_running_workers,
  +        work_units_accepted   => \%work_units_accepted,
  +        work_units_running    => \%work_units_running,
  +    );
  +    isa_ok($q, "App::WorkQueue");
  +    isa_ok($q, "App::WorkQueue::Repository");
  +
       eval {
           $q->set_constraint(\%num_workers_ds,  \%max_workers_ds,  "shop_data_source");
           ok(1, "set_constraint(shop_data_source)");
  @@ -216,21 +221,46 @@
       $errmsg =~ s/ at .*//s if ($errmsg);
       ok($errmsg, "Error on $qname->push(hash) [$errmsg]");
   
  +    if (!$rerun) {
  +        &test_status_counts($q, 0, 0, 0, 0);
  +        &test_resource_buffer_counts($q, "TRV:trv", 0, 0);
  +        &test_resource_buffer_counts($q, "EXP:exp", 0, 0);
  +        &test_resource_buffer_counts($q, "WEB:vhh", 0, 0);
  +    }
  +    else {
  +        &test_status_counts($q, 1, 0, 1, 0);
  +        &test_resource_buffer_counts($q, "TRV:trv", 0, 0);
  +        &test_resource_buffer_counts($q, "EXP:exp", 0, 0);
  +        &test_resource_buffer_counts($q, "WEB:vhh", 0, 0);
  +    }
  +
       my ($shop_request_id, $request_status, $shop_host);
   
       eval {
  -        $q->push([ 1,1,128,"TRV","USD","US",1,1,"2006-04-01","2006-04-30","1,2,3,4,5,6,7",128,"1",
  +        $q->push([ 0,1,128,"TRV","USD","US",1,1,"2006-04-01","2006-04-30","1,2,3,4,5,6,7",128,"1",
               "2006-01-04 12:00:00", "2006-01-04 12:00:00", "2006-01-04 12:00:00", "2006-01-04 12:00:00", 
               "W", "spadkins", "MV", "MV", 90, 0, undef, "sadkins\@therubicongroup.com", "ShopReport", 90, "default",
               0, 0, "x", 2, 1800, "trv", undef, 0, undef, "compare.detail.html", "None", undef, 2, ]);
       };
  -    ok(!$@, "No error on $qname->push(array) [$@]");
  -    ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>1},["shop_request_id","request_status","shop_host"]);
  -    is($shop_request_id, 1, "push(1) made it to the table");
  -    is($request_status, "W", "push(1) is W");
  -    is($shop_host, $App::options{host}, "push(1) is $App::options{host}");
  -    &test_status_counts($q, 0, 1, 0, 0);
  -    &test_resource_buffer_counts($q, "TRV:trv", 1, 1);
  +    if (!$rerun) {
  +        ok(!$@, "No error on $qname->push(array) [$@]");
  +        ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>1},["shop_request_id","request_status","shop_host"]);
  +        is($shop_request_id, 1, "push(1) made it to the table");
  +        is($request_status, "N", "push(1) is N");
  +        #is($shop_host, $App::options{host}, "push(1) is $App::options{host}");
  +        &test_status_counts($q, 1, 0, 0, 0);
  +        &test_resource_buffer_counts($q, "TRV:trv", 1, 1);
  +    }
  +    else {
  +        ok(!$@, "No error on $qname->push(array) [$@]");
  +        ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>6},["shop_request_id","request_status","shop_host"]);
  +        is($shop_request_id, 6, "push(6) made it to the table");
  +        is($request_status, "N", "push(6) is N");
  +        #is($shop_host, $App::options{host}, "push(6) is $App::options{host}");
  +        &test_status_counts($q, 2, 0, 1, 0);
  +        &test_resource_buffer_counts($q, "TRV:trv", 1, 1);
  +    }
  +exit(0) if ($rerun);
   
       $q->push([ 4,1,128,"EXP","USD","US",1,1,"2006-04-01","2006-04-30","1,2,3,4,5,6,7",128,"1",
           "2006-01-04 13:00:00", "2006-01-04 12:00:00", "2006-01-04 12:00:00", "2006-01-04 12:00:00", 
  @@ -238,9 +268,9 @@
           0, 0, "x", 2, 1800, "exp", undef, 0, undef, "compare.detail.html", "None", undef, 2, ]);
       ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>4},["shop_request_id","request_status","shop_host"]);
       is($shop_request_id, 4, "push(4) made it to the table");
  -    is($request_status, "W", "push(4) is W");
  -    is($shop_host, $App::options{host}, "push(4) is $App::options{host}");
  -    &test_status_counts($q, 0, 2, 0, 0);
  +    is($request_status, "N", "push(4) is N");
  +    #is($shop_host, $App::options{host}, "push(4) is $App::options{host}");
  +    &test_status_counts($q, 2, 0, 0, 0);
       &test_resource_buffer_counts($q, "EXP:exp", 1, 1);
   
       $q->push([ 2,1,128,"TRV","USD","US",1,1,"2006-04-01","2006-04-30","1,2,3,4,5,6,7",129,"1",
  @@ -250,8 +280,8 @@
       ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>2},["shop_request_id","request_status","shop_host"]);
       is($shop_request_id, 2, "push(2) made it to the table");
       is($request_status, "N", "push(2) is N");
  -    is($shop_host, $App::options{host}, "push(2) is $App::options{host}");
  -    &test_status_counts($q, 1, 2, 0, 0);
  +    #is($shop_host, $App::options{host}, "push(2) is $App::options{host}");
  +    &test_status_counts($q, 3, 0, 0, 0);
       &test_resource_buffer_counts($q, "TRV:trv", 1, 2);
   
       $q->push([ 3,1,128,"EXP","USD","US",1,1,"2006-04-01","2006-04-30","1,2,3,4,5,6,7",129,"1",
  @@ -260,13 +290,18 @@
           0, 0, "x", 2, 1800, "exp", undef, 0, undef, "compare.detail.html", "None", undef, 2, ]);
       ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>3},["shop_request_id","request_status","shop_host"]);
       is($shop_request_id, 3, "push(3) made it to the table");
  -    is($request_status, "W", "push(3) is W");
  -    is($shop_host, $App::options{host}, "push(3) is $App::options{host}");
  +    is($request_status, "N", "push(3) is N");
  +    #is($shop_host, $App::options{host}, "push(3) is $App::options{host}");
       ($shop_request_id,$request_status,$shop_host)= $db->get($table,{shop_request_id=>4},["shop_request_id","request_status","shop_host"]);
       is($request_status, "N", "push(4) is back to N");
  -    &test_status_counts($q, 2, 2, 0, 0);
  +    &test_status_counts($q, 4, 0, 0, 0);
       &test_resource_buffer_counts($q, "EXP:exp", 1, 2);
   
  +    # locate()
  +    my @entries = $q->locate({shop_request_id => 1});
  +    is($#entries, 0, "locate(): got 1 entry with shop_request_id = 1");
  +    is($entries[0][0], 1, "locate(): got THE entry with shop_request_id = 1");
  +
       my (%counts);
       $q->count_entries_by_attrib("shop_data_source",\%counts);
       is($counts{TRV}, 2, "TRV count");
  @@ -284,14 +319,14 @@
       is($num_workers_ds{TRV},  1, "Entry 1: num_workers_ds{TRV} = 1");
       #is($num_workers_ads{trv}, 1, "Entry 1: num_workers_ads{TRV} = undef");
       is($state{num_workers},   1, "Entry 1: state{num_workers} = 1");
  -    &test_status_counts($q, 1, 2, 1, 0);
  +    &test_status_counts($q, 3, 0, 1, 0);
       &test_resource_buffer_counts($q, "TRV:trv", 1, 1);
   
       $max_workers_ds{EXP} = 0;
       $e3 = $q->acquire();
       is($e3, undef, "No entries to acquire (EXP constraint)");
       delete $max_workers_ds{EXP};
  -    &test_status_counts($q, 1, 2, 1, 0);
  +    &test_status_counts($q, 3, 0, 1, 0);
       &test_resource_buffer_counts($q, "EXP:exp", 1, 2);
   
       $e2 = $q->acquire();
  @@ -300,14 +335,14 @@
       is($num_workers_ds{EXP},  1,     "Entry 3: num_workers_ds{EXP} = 1");
       is($num_workers_ads{EXP}, undef, "Entry 3: num_workers_ads{EXP} = undef");
       is($state{num_workers},   2,     "Entry 3: state{num_workers} = 2");
  -    &test_status_counts($q, 0, 2, 2, 0);
  +    &test_status_counts($q, 2, 0, 2, 0);
       &test_resource_buffer_counts($q, "EXP:exp", 1, 1);
   
       $q->release($e1);
       is($num_workers_ds{TRV},  0,     "Release 1: num_workers_ds{TRV} = 0");
       is($e1->[$colidx{request_status}], "S", "Entry 1 released: request_status = S");
       is($state{num_workers},   1,     "Release 1: state{num_workers} = 1");
  -    &test_status_counts($q, 0, 2, 1, 1);
  +    &test_status_counts($q, 2, 0, 1, 1);
       &test_resource_buffer_counts($q, "TRV:trv", 1, 1);
   
       {
  @@ -343,12 +378,12 @@
       is($num_workers_ds{TRV},  1,     "Entry 2: num_workers_ds{TRV} = 1");
       is($num_workers_ads{TRV}, undef, "Entry 2: num_workers_ads{TRV} = undef");
       is($state{num_workers},   2,     "Entry 2: state{num_workers} = 2");
  -    &test_status_counts($q, 0, 1, 2, 1);
  +    &test_status_counts($q, 1, 0, 2, 1);
       &test_resource_buffer_counts($q, "TRV:trv", 0, 0);
   
       $e3 = $q->acquire();
       is($e3, undef, "No entries to acquire (global constraint)");
  -    &test_status_counts($q, 0, 1, 2, 1);
  +    &test_status_counts($q, 1, 0, 2, 1);
       &test_resource_buffer_counts($q, "TRV:trv", 0, 0);
       &test_resource_buffer_counts($q, "EXP:exp", 1, 1);
   
  @@ -357,23 +392,23 @@
       is($num, 1, "1 entries left total [NW]");
       $num = $q->num_entries("R");
       is($num, 2, "2 entries left [R]");
  -    $num = $q->num_entries("W");
  -    is($num, 1, "1 entries left [W]");
  +    $num = $q->num_entries("N");
  +    is($num, 1, "1 entries left [N]");
   
       is($num_workers_ds{EXP},  1,     "Entry 3: num_workers_ds{EXP} = 1 (still)");
       $q->unacquire($e2);
  -    &test_status_counts($q, 0, 2, 1, 1);
  +    &test_status_counts($q, 2, 0, 1, 1);
       &test_resource_buffer_counts($q, "EXP:exp", 2, 2);
   
       is($num_workers_ds{EXP},  0,     "Entry 3 unacquired: num_workers_ds{EXP} = 0");
  -    is($e2->[$colidx{request_status}], "W", "Entry 3 unacquired: request_status = N");
  +    is($e2->[$colidx{request_status}], "N", "Entry 3 unacquired: request_status = N");
   
       $q->push([ 5,1,128,"WEB","USD","US",1,1,"2006-04-01","2006-04-30","1,2,3,4,5,6,7",128,"1",
           "2006-01-04 12:00:00", "2006-01-04 12:00:00", "2006-01-04 12:00:00", "2006-01-04 12:00:00", 
           "W", "spadkins", "MV", "MV", 90, 0, undef, "sadkins\@therubicongroup.com", "ShopReport", 90, "default",
           0, 0, "pompeii", 4, 1800, "vhh", undef, 0, undef, "compare.detail.html", "None", undef, 2, ]);
       is($q->{data}[0][0], 5, "Entry 5 sorted to top: high priority");
  -    &test_status_counts($q, 0, 3, 1, 1);
  +    &test_status_counts($q, 3, 0, 1, 1);
       &test_resource_buffer_counts($q, "WEB:vhh", 1, 1);
   
       #my $rows = $db->get_rows($table, {}, $columns, {order_by => ["shop_request_id"]});
  @@ -387,22 +422,22 @@
       is($num_workers_ds{WEB},  1,     "Entry 5: num_workers_ds{WEB} = 1");
       is($num_workers_ads{vhh}, 1,     "Entry 5: num_workers_ads{vhh} = 1");
       is($state{num_workers},   2,     "Entry 5: state{num_workers} = 2");
  -    &test_status_counts($q, 0, 2, 2, 1);
  +    &test_status_counts($q, 2, 0, 2, 1);
       &test_resource_buffer_counts($q, "WEB:vhh", 0, 0);
   
       $q->release($e4);
       is($num_workers_ds{WEB},  0,     "Entry 5: num_workers_ds{WEB} = 0");
       is($num_workers_ads{vhh}, 0,     "Entry 5: num_workers_ads{vhh} = 0");
       is($state{num_workers},   1,     "Entry 5: state{num_workers} = 1");
  -    &test_status_counts($q, 0, 2, 1, 2);
  +    &test_status_counts($q, 2, 0, 1, 2);
       &test_resource_buffer_counts($q, "WEB:vhh", 0, 0);
   
       $e4 = $q->acquire();
  -    &test_status_counts($q, 0, 1, 2, 2);
  +    &test_status_counts($q, 1, 0, 2, 2);
       &test_resource_buffer_counts($q, "TRV:trv", 0, 0);
   
       $q->release($e4);
  -    &test_status_counts($q, 0, 1, 1, 3);
  +    &test_status_counts($q, 1, 0, 1, 3);
       &test_resource_buffer_counts($q, "TRV:trv", 0, 0);
   }
   
  @@ -430,8 +465,8 @@
   sub test_resource_buffer_counts {
       my ($q, $resource_key, $buffer, $total) = @_;
       my $resource_counts = $q->_resource_counts();
  -    is($resource_counts->{buffer}{$resource_key}, $buffer, "$resource_key buffer count is $buffer");
  -    is($resource_counts->{total}{$resource_key}, $total, "$resource_key total count is $total");
  +    is($resource_counts->{buffer}{$resource_key}||0, $buffer, "$resource_key buffer count is $buffer");
  +    is($resource_counts->{total}{$resource_key}||0, $total, "$resource_key total count is $total");
   }
   
   exit 0;
  
  
  
  1.2       +6 -6      p5ee/App-WorkQueue/t/queue.t
  
  Index: queue.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-WorkQueue/t/queue.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- queue.t	6 Feb 2006 04:14:23 -0000	1.1
  +++ queue.t	1 Mar 2006 03:39:08 -0000	1.2
  @@ -121,13 +121,13 @@
       my (%num_workers_ds, %num_workers_ads);
       my %state = (
           num_workers => 0,
  -        max_workers => 2,
  +        max_workers => -2,
       );
       my %max_workers_ds = (
  -        TRV => 1,
  -        WEB => 2,
  -        GDS => 2,
  -        _DEFAULT => 2,
  +        TRV => -1,
  +        WEB => -2,
  +        GDS => -2,
  +        _DEFAULT => -2,
       );
       my %max_workers_ads = (
           GDS_VHH => 1,
  @@ -135,7 +135,7 @@
           GDS_VSI => 1,
           GDS_VIC => 1,
           GDS_VHY => 1,
  -        VHH => 1,
  +        VHH => -1,
           VMC => 1,
           VSI => 1,
           VIC => 1,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.