[Bps-public-commit] r16697 - in Prophet/branches/init-and-clone: . lib/Prophet

jesse at bestpractical.com jesse at bestpractical.com
Thu Nov 6 01:52:45 EST 2008


Author: jesse
Date: Thu Nov  6 01:52:44 2008
New Revision: 16697

Modified:
   Prophet/branches/init-and-clone/   (props changed)
   Prophet/branches/init-and-clone/lib/Prophet/Replica.pm
   Prophet/branches/init-and-clone/lib/Prophet/Test.pm
   Prophet/branches/init-and-clone/t/real-conflicting-merge.t
   Prophet/branches/init-and-clone/t/simple-conflicting-merge.t
   Prophet/branches/init-and-clone/t/simple-push.t

Log:
 r49323 at 31b:  jesse | 2008-11-06 05:38:12 +0900
 * down to one failing test


Modified: Prophet/branches/init-and-clone/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/branches/init-and-clone/lib/Prophet/Replica.pm	(original)
+++ Prophet/branches/init-and-clone/lib/Prophet/Replica.pm	Thu Nov  6 01:52:44 2008
@@ -1103,6 +1103,7 @@
 sub log {
     my $self = shift;
     my ($msg) = validate_pos(@_, 1);
+    Carp::confess unless ($self->app_handle);
     $self->app_handle->log($self->display_name_for_uuid." (".$self->scheme.":".$self->url." )".": " .$msg);
 }
 
@@ -1142,8 +1143,7 @@
     my $self = shift;
     my $uuid = shift || $self->uuid;
 
-    return $uuid if !$self->has_app_handle;
-    Carp::confess unless $self->app_handle;
+    return $uuid if !$self->app_handle;
 
     return $self->app_handle->config->display_name_for_uuid($uuid);
 }

Modified: Prophet/branches/init-and-clone/lib/Prophet/Test.pm
==============================================================================
--- Prophet/branches/init-and-clone/lib/Prophet/Test.pm	(original)
+++ Prophet/branches/init-and-clone/lib/Prophet/Test.pm	Thu Nov  6 01:52:44 2008
@@ -3,7 +3,7 @@
 
 package Prophet::Test;
 use base qw/Test::More Exporter/;
-our @EXPORT = qw/as_alice as_bob as_charlie as_david as_user run_ok repo_uri_for run_script run_output_matches run_output_matches_unordered replica_last_rev replica_merge_tickets replica_uuid_for fetch_newest_changesets ok_added_revisions replica_uuid database_uuid database_uuid_for
+our @EXPORT = qw/as_alice as_bob as_charlie as_david as_user run_ok repo_uri_for run_script run_output_matches run_output_matches_unordered replica_last_rev replica_merge_tickets replica_uuid_for ok_added_revisions replica_uuid database_uuid database_uuid_for
     serialize_conflict serialize_changeset in_gladiator diag is_script_output run_command set_editor load_record
     /;
 
@@ -322,19 +322,6 @@
     return $DATABASE_UUIDS{$user};
 }
 
-=head2 fetch_newest_changesets COUNT
-
-Returns C<COUNT> newest L<Prophet::ChangeSet> objects in the current user's replica.
-
-=cut
-
-sub fetch_newest_changesets {
-    my $count = shift;
-    my $source = Prophet::Replica->new( { url => repo_uri_for( $ENV{'PROPHET_USER'} ) } );
-    return @{ $source->fetch_changesets( after => ( replica_last_rev() - $count ) ) };
-
-}
-
 =head2 ensure_new_revisions { CODE }, $numbers_of_new_revisions, $msg
 
 =cut

Modified: Prophet/branches/init-and-clone/t/real-conflicting-merge.t
==============================================================================
--- Prophet/branches/init-and-clone/t/real-conflicting-merge.t	(original)
+++ Prophet/branches/init-and-clone/t/real-conflicting-merge.t	Thu Nov  6 01:52:44 2008
@@ -4,7 +4,7 @@
 use strict;
 use Test::Exception;
 
-use Prophet::Test tests => 21;
+use Prophet::Test tests => 18;
 
 as_alice {
     run_command(qw(init));
@@ -15,12 +15,11 @@
 diag('Bob syncs from alice');
 
 my $record_id;
-
+diag(repo_uri_for('alice'));
 as_bob {
 
-    run_command(qw(init));
+    run_command(qw(clone --from), repo_uri_for('alice')  );
     like(run_command(qw(create --type Dummy -- --ignore yes)), qr/Created Dummy/);
-    like(run_command('merge', '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice'), '--force'), qr/Merged one changeset/, "Sync ran ok!");
 
     # check our local replicas
     my $out = run_command(qw(search --type Bug --regex .));
@@ -63,12 +62,16 @@
 
 };
 
+my ($alice, $bob, $alice_app, $bob_app);
 # This conflict, we can autoresolve
+as_bob { $bob_app = Prophet::CLI->new()->app_handle; $bob = $bob_app->handle;};
+as_alice { $alice_app = Prophet::CLI->new()->app_handle; $alice = $alice_app->handle};
+
 
 as_bob {
     use_ok('Prophet::Replica');
-    my $source = Prophet::Replica->new( { url => repo_uri_for('alice') } );
-    my $target = Prophet::Replica->new( { url => repo_uri_for('bob') } );
+    my $source = $alice;
+    my $target = $bob;
 
     my $conflict_obj;
 
@@ -99,19 +102,18 @@
         '3 revisions since the merge'
     );
 
-    my @changesets = fetch_newest_changesets(3);
+    my @changesets = @{ $target->fetch_changesets( after => ( $target->latest_sequence_no - 3) ) } ;
 
     my $resolution = $changesets[2];
     ok( $resolution->is_resolution, 'marked as resolution' );
-    my $repo = repo_uri_for('bob');
-
-    #    diag `svn log -v $repo`;
-
     check_bob_final_state_ok(@changesets);
 };
+
+
+
 as_alice {
-    my $source = Prophet::Replica->new( { url => repo_uri_for('bob') } );
-    my $target = Prophet::Replica->new( { url => repo_uri_for('alice') } );
+    my $source = $bob;
+    my $target = $alice;
     throws_ok {
         $target->import_changesets( from => $source, force => 1 );
     }
@@ -138,8 +140,8 @@
 };
 
 as_bob {
-    my $source = Prophet::Replica->new( { url => repo_uri_for('alice') } );
-    my $target = Prophet::Replica->new( { url => repo_uri_for('bob') } );
+    my $source = $alice;
+    my $target = $bob;
 
     lives_and {
         ok_added_revisions(
@@ -152,7 +154,7 @@
 
     };
 
-    check_bob_final_state_ok( fetch_newest_changesets(3) );
+    check_bob_final_state_ok( @{ $target->fetch_changesets( after => ( $target->latest_sequence_no - 3) ) });
 
 };
 

Modified: Prophet/branches/init-and-clone/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/branches/init-and-clone/t/simple-conflicting-merge.t	(original)
+++ Prophet/branches/init-and-clone/t/simple-conflicting-merge.t	Thu Nov  6 01:52:44 2008
@@ -43,7 +43,13 @@
     );
 };
 
-my ($alice);
+
+my ($alice, $bob, $alice_app, $bob_app);
+# This conflict, we can autoresolve
+as_bob { $bob_app = Prophet::CLI->new()->app_handle; $bob = $bob_app->handle;};
+as_alice { $alice_app = Prophet::CLI->new()->app_handle; $alice = $alice_app->handle};
+
+
 as_alice {
     run_ok( 'prophet', [ 'update', '--type', 'Bug', '--uuid', $record_id, '--', '--status' => 'stalled' ] );
     run_output_matches(
@@ -60,11 +66,11 @@
     );
 
 
-    $alice = Prophet::CLI->new();
 };
 
 # This conflict, we can autoresolve
 
+diag("prebob");
 as_bob {
 
     # XXX TODO: this should actually fail right now.
@@ -72,10 +78,9 @@
 
 
     my $conflict_obj;
-    my $bob =  Prophet::CLI->new;
     lives_ok {
-        $bob->handle->import_changesets(
-            from              => $alice->handle,
+        $bob->import_changesets(
+            from              => $alice,
             force             => 1,
             conflict_callback => sub {
                 $conflict_obj = shift;
@@ -85,7 +90,7 @@
 
     isa_ok( $conflict_obj, 'Prophet::Conflict' );
 
-    my $conflicts = serialize_conflict($conflict_obj);
+    my $conflicts = eval { serialize_conflict($conflict_obj)} ;
 
     is_deeply(
         $conflicts,
@@ -134,7 +139,7 @@
     );
 
     # replay the last two changesets for bob's replica
-    my @changesets = fetch_newest_changesets(2);
+    my @changesets =  @{ $bob->fetch_changesets( after => ( $bob->latest_sequence_no - 2) ) };
 
     # is the second most recent change:
     my $applied_null    = shift @changesets;
@@ -160,7 +165,7 @@
             is_resolution        => undef,
             source_uuid          => undef,
             sequence_no          => undef,
-            original_sequence_no => as_alice { replica_last_rev() },
+            original_sequence_no => $alice->latest_sequence_no,
             original_source_uuid => replica_uuid_for('alice'),
             changes              => [
                 {
@@ -175,8 +180,8 @@
                     record_type  => '_merge_tickets',
                     prop_changes => {
                         'last-changeset' => {
-                            old_value => as_alice { replica_last_rev() - 1 },
-                            new_value => as_alice { replica_last_rev() }
+                            old_value => ($alice->latest_sequence_no-1),
+                            new_value => $alice->latest_sequence_no
                         }
                     }
 
@@ -190,3 +195,4 @@
 
 };
 
+diag("postbob");

Modified: Prophet/branches/init-and-clone/t/simple-push.t
==============================================================================
--- Prophet/branches/init-and-clone/t/simple-push.t	(original)
+++ Prophet/branches/init-and-clone/t/simple-push.t	Thu Nov  6 01:52:44 2008
@@ -6,20 +6,36 @@
 use Prophet::Test tests => 16;
 
 as_alice {
-    run_ok( 'prophet', [qw(init)]);
-    run_ok( 'prophet', [qw(create --type Bug -- --status new --from alice )], "Created a record as alice" );
-    run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/new/], " Found our record" );
+    run_ok( 'prophet', [qw(init)] );
+    run_ok(
+        'prophet',
+        [qw(create --type Bug -- --status new --from alice )],
+        "Created a record as alice"
+    );
+    run_output_matches(
+        'prophet', [qw(search --type Bug --regex .)],
+        [qr/new/], " Found our record"
+    );
 
     # update the record
     # show the record history
     # show the record
 };
 
-diag(repo_uri_for('alice'));
+diag( repo_uri_for('alice') );
 as_bob {
-    run_ok( 'prophet', [qw(clone --from), repo_uri_for('alice')]);
-    run_ok( 'prophet', [qw(create --type Bug -- --status open --from bob )], "Created a record as bob" );
-    run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/open/, qr/new/], " Found our record" );
+    run_ok( 'prophet', [ qw(clone --from), repo_uri_for('alice') ] );
+    run_ok(
+        'prophet',
+        [qw(create --type Bug -- --status open --from bob )],
+        "Created a record as bob"
+    );
+    run_output_matches(
+        'prophet',
+        [qw(search --type Bug --regex .)],
+        [ qr/open/, qr/new/ ],
+        " Found our record"
+    );
 
     # update the record
     # show the record history
@@ -27,63 +43,59 @@
 
 };
 
-my $alice; 
-my $bob;
-
-as_alice { $alice = Prophet::CLI->new; };
-as_bob { $bob = Prophet::CLI->new; };
+my ($alice, $alice_app);
+my ($bob, $bob_app);
 
+as_alice { $alice_app = Prophet::CLI->new->app_handle; $alice= $alice_app->handle };
+as_bob { $bob_app = Prophet::CLI->new->app_handle; $bob = $bob_app->handle };
 
-is( $bob->app_handle->handle->db_uuid,
-    $alice->app_handle->handle->db_uuid,
+is( $bob->db_uuid, $alice->db_uuid,
     "bob and alice's replicas need to have the same uuid for them to be able to sync without issues"
 );
 
-
 my $openbug = '';
 as_bob {
-    my ( $ret, $stdout, $stderr ) = run_script( 'prophet', [qw(search --type Bug --regex open)] );
+    my ( $ret, $stdout, $stderr )
+        = run_script( 'prophet', [qw(search --type Bug --regex open)] );
     if ( $stdout =~ /^(.*?)\s/ ) {
         $openbug = $1;
     }
-    diag ("As bob, the last changeset I've seen from alice is ".$bob->app_handle->handle->last_changeset_from_source($alice->app_handle->handle->uuid));
-    diag ("As alice, my latest sequence no is ".$alice->app_handle->handle->latest_sequence_no);
-    diag ("As bob, I believe that alice's uuid is " .$alice->app_handle->handle->uuid);
-    die ("We're getting the wrong uuid for alice and the wrong seqno for alice. why?");
-    is($bob->app_handle->handle->last_changeset_from_source($alice->app_handle->handle->uuid) => $alice->app_handle->handle->latest_sequence_no);
+    diag(
+        "As bob, the last changeset I've seen from alice is "
+            . $bob->last_changeset_from_source(
+            $alice->uuid
+            )
+    );
+    is( $bob->last_changeset_from_source( $alice->uuid ) =>
+            $alice->latest_sequence_no );
 
 };
 
 my $changesets;
-    $bob->app_handle->handle->traverse_new_changesets( for => $alice->app_handle->handle, force => 1,
-            callback => sub {
-                my $cs = shift;
-                return unless $cs->has_changes,
-                push @{$changesets}, $cs->as_hash;
-            }
-        
-        
-    );
-
+$bob->traverse_new_changesets(
+    for      => $alice,
+    force    => 1,
+    callback => sub {
+        my $cs = shift;
+        return unless $cs->has_changes, push @{$changesets}, $cs->as_hash;
+    }
+);
 
-my $seq = delete $changesets->[0]->{'sequence_no'};
+my $seq      = delete $changesets->[0]->{'sequence_no'};
 my $orig_seq = delete $changesets->[0]->{'original_sequence_no'};
-is($seq, $orig_seq);
-
+is( $seq, $orig_seq );
 
 is_deeply(
-   $changesets,
-    [ 
-        {   #'sequence_no'          => 3,
-            #'original_sequence_no' => 3, # the number is different on different replica types
+    $changesets,
+    [   {    #'sequence_no'          => 3,
+             #'original_sequence_no' => 3, # the number is different on different replica types
             'creator'              => 'bob',
             'created'              => $changesets->[0]->{created},
             'original_source_uuid' => replica_uuid_for('bob'),
             'is_resolution'        => undef,
             'source_uuid'          => replica_uuid_for('bob'),
             'changes'              => [
-                {
-                    'change_type'  => 'add_file',
+                {   'change_type'  => 'add_file',
                     'prop_changes' => {
                         'from' => {
                             'new_value' => 'bob',
@@ -117,49 +129,56 @@
 
     # sync from bob
     diag('Alice syncs from bob');
-    is($alice->app_handle->handle->last_changeset_from_source($bob->app_handle->handle->uuid) => 0);
-    run_ok( 'prophet', [ 'pull', '--from', repo_uri_for('bob'), '--to' ], "Sync ran ok!" );
-    is($alice->app_handle->handle->last_changeset_from_source($bob->app_handle->handle->uuid) => $bob->app_handle->handle->latest_sequence_no);
+    is( $alice->last_changeset_from_source( $bob->uuid ) => 0 );
+    run_ok( 'prophet', [ 'pull', '--from', repo_uri_for('bob'), '--to' ],
+        "Sync ran ok!" );
+    is( $alice->last_changeset_from_source( $bob->uuid ) =>
+            $bob->latest_sequence_no );
 };
 
 my $last_id;
 
 as_bob {
-    run_ok( 'prophet', [qw(create --type Bug -- --status new --from bob )], "Created a record as bob" );
-    my ( $ret, $stdout, $stderr ) = run_script( 'prophet', [qw(search --type Bug --regex new)] );
+    run_ok(
+        'prophet',
+        [qw(create --type Bug -- --status new --from bob )],
+        "Created a record as bob"
+    );
+    my ( $ret, $stdout, $stderr )
+        = run_script( 'prophet', [qw(search --type Bug --regex new)] );
     if ( $stdout =~ /^(.*?)\s/ ) {
         $last_id = $1;
     }
 };
 
 my $new_changesets;
-    $bob->handle->traverse_new_changesets( for => $alice->app_handle->handle, force => 1,
-            callback => sub {
-                my $cs = shift;
-                return unless $cs->has_changes,
-                push @{$new_changesets}, $cs->as_hash;
-            }
-        
-        
-    );
+$bob->traverse_new_changesets(
+    for      => $alice_app->handle,
+    force    => 1,
+    callback => sub {
+        my $cs = shift;
+        return unless $cs->has_changes, push @{$new_changesets}, $cs->as_hash;
+        }
 
+);
 
-is( delete $new_changesets->[0]->{'sequence_no'}, delete $new_changesets->[0]->{'original_sequence_no'});
+is( delete $new_changesets->[0]->{'sequence_no'},
+    delete $new_changesets->[0]->{'original_sequence_no'}
+);
 
 is_deeply(
     $new_changesets,
-    [   {  
-        
-        #     'sequence_no'          => 4,  # the number varies based on replica type
-        #    'original_sequence_no' => 4,
+    [   {
+
+   #     'sequence_no'          => 4,  # the number varies based on replica type
+   #    'original_sequence_no' => 4,
             'creator'              => 'bob',
             'created'              => $new_changesets->[0]->{created},
             'original_source_uuid' => replica_uuid_for('bob'),
             'is_resolution'        => undef,
             'source_uuid'          => replica_uuid_for('bob'),
             'changes'              => [
-                {
-                    'change_type'  => 'add_file',
+                {   'change_type'  => 'add_file',
                     'prop_changes' => {
                         'from' => {
                             'new_value' => 'bob',



More information about the Bps-public-commit mailing list