[Bps-public-commit] r11317 - in SVN-PropDB: . lib/Prophet t

jesse at bestpractical.com jesse at bestpractical.com
Mon Mar 31 22:15:33 EDT 2008


Author: jesse
Date: Mon Mar 31 22:15:32 2008
New Revision: 11317

Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/lib/Prophet/Test.pm
   SVN-PropDB/lib/Prophet/Test/Arena.pm
   SVN-PropDB/lib/Prophet/Test/Participant.pm
   SVN-PropDB/t/generalized_sync_n_merge.t

Log:
 r28869 at 70-5-78-234:  jesse | 2008-03-31 16:15:17 -1000
 * Rough harness that lets chickens run around with their heads cut off


Modified: SVN-PropDB/lib/Prophet/Test.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test.pm	Mon Mar 31 22:15:32 2008
@@ -222,7 +222,7 @@
   my $coderef = shift;
   local $ENV{'PROPHET_USER'} = $username;
   local $ENV{'PROPHET_REPO'} = repo_path_for($username);
-  diag("I am $username. My replica id is ".replica_uuid());
+#  diag("I am $username. My replica id is ".replica_uuid());
  my $ret=  $coderef->();
  $REPLICA_UUIDS{$username} = replica_uuid();
  return $ret;

Modified: SVN-PropDB/lib/Prophet/Test/Arena.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test/Arena.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test/Arena.pm	Mon Mar 31 22:15:32 2008
@@ -4,11 +4,10 @@
 
 package Prophet::Test::Arena;
 use base qw/Class::Accessor/;
-
+__PACKAGE__->mk_accessors(qw/chickens/);
 
 use Acme::MetaSyntactic;
 use Prophet::Test;
-__PACKAGE__->mk_accessors(qw/chickens/);
 
 
 sub setup {
@@ -22,15 +21,19 @@
     my $meta = Acme::MetaSyntactic->new();
     
     for my $name ($meta->name(pause_id => $count)) {
-        push @chickens,Prophet::Test::Participant->new( { name => $name } );
+        push @chickens,Prophet::Test::Participant->new( { name => $name, arena => $self } );
 
     }
-
-    $self->chickens(\@chickens);
+    $self->chickens(@chickens);
         
 }
 
-sub act_like_chickens {
+sub step {
+    my $self = shift;
+    for my $chicken (@{$self->chickens}) {
+        as_user($chicken->name, sub {$chicken->take_one_step()});
+    }
+
     # for x rounds, have each participant execute a random action
 }
 

Modified: SVN-PropDB/lib/Prophet/Test/Participant.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test/Participant.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test/Participant.pm	Mon Mar 31 22:15:32 2008
@@ -4,15 +4,16 @@
 
 package Prophet::Test::Participant;
 use base qw/Class::Accessor/;
-__PACKAGE__->mk_accessors(qw/name/);
+__PACKAGE__->mk_accessors(qw/name arena/);
 use Prophet::Test;
-
+use Scalar::Util qw/weaken/;
 
 sub new {
 
     my $self = shift->SUPER::new(@_);
     $self->_setup();
-    
+    weaken($self->{'arena'});
+    return $self;
 }
 
 sub _setup {
@@ -22,12 +23,48 @@
 
 }
 
+use List::Util qw(shuffle);
+
+my @CHICKEN_DO = qw(create_record delete_record update_record sync_from_peer noop);
+
+sub take_one_step {
+    my $self = shift;
+    my $action = (shuffle(@CHICKEN_DO))[0];
+    $self->$action();
+
+
+}
+
+
+sub noop {
+    my $self = shift;
+    diag($self->name, ' - NOOP');
+}
+sub delete_record {
+    my $self = shift;
+    diag($self->name, ' - delete a random record');
+   # run_ok('prophet-node-delete');
+
+}
+sub create_record {
+    my $self = shift;
+    diag($self->name, ' - create a record');
+    #run_ok('prophet-node-create', [qw(--type Scratch --foo), $self->name. rand(100)]);
+}
+sub update_record {
+    my $self = shift;
+    diag($self->name, ' - update a record');
 
+}
+sub sync_from_peer {
+    my $self = shift;
+    my $lucky = (shuffle(@{$self->arena->chickens}))[0];
+  
+#    my $lucky = shift @peers;
+    diag($self->name, ' - sync from a random peer - ' . $lucky->name);
 
 
-sub create_random_record {}
-sub update_random_record {}
-sub sync_from_random_peer {}
+}
 sub sync_from_all_peers {}
 sub dump_state {}
 sub dump_history {}

Modified: SVN-PropDB/t/generalized_sync_n_merge.t
==============================================================================
--- SVN-PropDB/t/generalized_sync_n_merge.t	(original)
+++ SVN-PropDB/t/generalized_sync_n_merge.t	Mon Mar 31 22:15:32 2008
@@ -8,7 +8,12 @@
 use_ok('Prophet::Test::Participant');
 
 my $arena = Prophet::Test::Arena->new();
-$arena->setup(30);
+$arena->setup(5);
+
+
+for(1..10) {
+    $arena->step();
+}
 
 exit;
 



More information about the Bps-public-commit mailing list