[Bps-public-commit] r11322 - in SVN-PropDB: bin doc lib/Prophet lib/Prophet/Test t

jesse at bestpractical.com jesse at bestpractical.com
Mon Mar 31 23:36:36 EDT 2008


Author: jesse
Date: Mon Mar 31 23:36:36 2008
New Revision: 11322

Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/bin/prophet-node-delete
   SVN-PropDB/doc/todo
   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:
 r28871 at 70-5-78-234:  jesse | 2008-03-31 17:36:28 -1000
  * a bit more work on crazy distributed testing


Modified: SVN-PropDB/bin/prophet-node-delete
==============================================================================
--- SVN-PropDB/bin/prophet-node-delete	(original)
+++ SVN-PropDB/bin/prophet-node-delete	Mon Mar 31 23:36:36 2008
@@ -8,7 +8,7 @@
 $cli->parse_record_cmd_args();
 
 my $record = Prophet::Record->new(handle => $cli->handle, type => $cli->type);
-$record->load(uuid => $cli->uuid)
+$record->load(uuid => $cli->uuid);
 if( $record->delete ) {
     print $record->type." ".$record->uuid." deleted.\n";
 } else {

Modified: SVN-PropDB/doc/todo
==============================================================================
--- SVN-PropDB/doc/todo	(original)
+++ SVN-PropDB/doc/todo	Mon Mar 31 23:36:36 2008
@@ -1,8 +1,9 @@
 
 Todo
 
+- test byzantine sync behaviour
+
 - prompt for resolution of conflicts
-- ability to 'pull' conflicting updates from a remote db
 - handle conflicting conflict resolutions
 
 
@@ -25,3 +26,4 @@
 - implement merge of conflicts with: "local always wins"
 - record conflict resolution data 
 - reuse conflict resolution data on repeated resolve
+- ability to 'pull' conflicting updates from a remote db

Modified: SVN-PropDB/lib/Prophet/Test.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test.pm	Mon Mar 31 23:36:36 2008
@@ -55,6 +55,7 @@
     my $args = shift || [];
     my ($stdout, $stderr);
     my @cmd = _get_perl_cmd($script);
+#    diag(join(' ', @cmd, @$args));
     my $ret = run3 [@cmd, @$args], undef, \$stdout, \$stderr;
     Carp::croak $stderr if $?;
     Test::More::diag $stderr;

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 23:36:36 2008
@@ -30,8 +30,9 @@
 
 sub step {
     my $self = shift;
+    my $step_name = shift || undef;
     for my $chicken (@{$self->chickens}) {
-        as_user($chicken->name, sub {$chicken->take_one_step()});
+        as_user($chicken->name, sub {$chicken->take_one_step($step_name)});
     }
 
     # 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 23:36:36 2008
@@ -8,11 +8,15 @@
 use Prophet::Test;
 use Scalar::Util qw/weaken/;
 
+
+
+
 sub new {
 
     my $self = shift->SUPER::new(@_);
     $self->_setup();
     weaken($self->{'arena'});
+    
     return $self;
 }
 
@@ -25,34 +29,75 @@
 
 use List::Util qw(shuffle);
 
-my @CHICKEN_DO = qw(create_record delete_record update_record sync_from_peer noop);
+my @CHICKEN_DO = qw(create_record create_record delete_record  update_record update_record update_record update_record update_record update_record update_record update_record sync_from_peer sync_from_peer noop);
 
 sub take_one_step {
     my $self = shift;
-    my $action = (shuffle(@CHICKEN_DO))[0];
+    my $action = shift || (shuffle(@CHICKEN_DO))[0];
+    diag("We're taking a step: $action");
     $self->$action();
 
 
 }
 
 
+sub _random_props {
+     my @prop_values = Acme::MetaSyntactic->new->name( batman=>5);
+     my @prop_keys = Acme::MetaSyntactic->new->name( lotr=>5);
+
+    return( map { "--".$prop_keys[$_] => $prop_values[$_] } (0..4));
+        
+
+        
+}
+
+sub _permute_props {
+    my %props = (@_);
+    @props{keys %props} = shuffle(values %props);
+
+    for(keys %props) {
+        if(int(rand(10) < 2)){
+            delete $props{$_};
+        }
+    }
+    
+    if (int(rand(10) < 3)) {
+     $props{Acme::MetaSyntactic->new->name( 'lotr')} = Acme::MetaSyntactic->new->name( 'batman');
+    }
+    
+
+    return %props;
+}
+
 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');
+    run_ok('prophet-node-delete', [qw(--type Scratch --uuid),  get_random_local_record()]);
 
 }
 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)]);
+    run_ok('prophet-node-create', [qw(--type Scratch),   _random_props()    ], "Created a record");
 }
+
 sub update_record {
     my $self = shift;
+    my $update_record = get_random_local_record();
+    
+    my ($ok, $stdout, $stderr) = run_script('prophet-node-show', [qw(--type Scratch --uuid), $update_record]);
+    diag($stdout);
+    
+    my %props = map { split(/: /,$_,2) } split(/\n/,$stdout);
+    delete $props{id};
+    
+    %props =      _permute_props(%props); 
+    
+    run_ok('prophet-node-update', [qw(--type Scratch --uuid), $update_record,        map { '--'.$_ => $props{$_} } keys %props  ], "Updated a record");
+
+
     diag($self->name, ' - update a record');
 
 }
@@ -62,9 +107,19 @@
   
 #    my $lucky = shift @peers;
     diag($self->name, ' - sync from a random peer - ' . $lucky->name);
+    run_ok('prophet-merge', ['--from', repo_uri_for($lucky->name), '--to', repo_uri_for($self->name)], "Sync ran ok!");
+
 
 
 }
+
+sub get_random_local_record {
+    my ($ok, $stdout, $stderr) = run_script('prophet-node-search', [qw(--type Scratch --regex .)]);
+    my $update_record = (shuffle( map { $_ =~ /^(\S*)/ } split(/\n/,$stdout)))[0];
+    return $update_record;
+}
+
+
 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 23:36:36 2008
@@ -10,11 +10,16 @@
 my $arena = Prophet::Test::Arena->new();
 $arena->setup(5);
 
+for(1..3) {
+    $arena->step('create_record');
+}
 
 for(1..10) {
     $arena->step();
 }
 
+$arena->
+
 exit;
 
 



More information about the Bps-public-commit mailing list