[Bps-public-commit] r16694 - in Prophet/branches/init-and-clone: . lib/Prophet/CLI lib/Prophet/CLI/Command
jesse at bestpractical.com
jesse at bestpractical.com
Thu Nov 6 01:52:19 EST 2008
Author: jesse
Date: Thu Nov 6 01:52:18 2008
New Revision: 16694
Added:
Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Clone.pm
Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm
Modified:
Prophet/branches/init-and-clone/ (props changed)
Prophet/branches/init-and-clone/lib/Prophet/CLI/Dispatcher.pm
Prophet/branches/init-and-clone/t/canonicalize.t
Prophet/branches/init-and-clone/t/cli.t
Prophet/branches/init-and-clone/t/create.t
Prophet/branches/init-and-clone/t/database-settings.t
Prophet/branches/init-and-clone/t/default.t
Prophet/branches/init-and-clone/t/edit.t
Prophet/branches/init-and-clone/t/history.t
Prophet/branches/init-and-clone/t/non-conflicting-merge.t
Prophet/branches/init-and-clone/t/publish-pull.t
Prophet/branches/init-and-clone/t/real-conflicting-merge.t
Prophet/branches/init-and-clone/t/resty-server.t
Prophet/branches/init-and-clone/t/simple-push.t
Log:
r49317 at 31b: jesse | 2008-11-06 02:48:16 +0900
* Clone and Init commands. checkpoint.
Added: Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Clone.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Clone.pm Thu Nov 6 01:52:18 2008
@@ -0,0 +1,37 @@
+package Prophet::CLI::Command::Clone;
+use Moose;
+extends 'Prophet::CLI::Command::Merge';
+
+before 'run' => sub {
+ my $self = shift;
+
+ $self->set_arg( 'to' => $self->app_handle->handle->url() );
+
+ my $source = Prophet::Replica->new(
+ url => $self->arg('from'),
+ app_handle => $self->app_handle,
+ );
+ my $target = Prophet::Replica->new(
+ url => $self->arg('to'),
+ app_handle => $self->app_handle,
+ );
+
+ if ( $target->replica_exists ) {
+ die "The target replica already exists.";
+ }
+
+ if (!$target->can_initialize ) {
+ die "The replica path you specified isn't writable";
+ }
+
+ $target->initialize();
+ $target->set_db_uuid($source->db_uuid);
+ $target->resolution_db_handle->set_db_uuid($source->resolution_db_handle->db_uuid);
+ return $target->_write_cached_upstream_replicas($self->arg('from'));
+
+};
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
Added: Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/init-and-clone/lib/Prophet/CLI/Command/Init.pm Thu Nov 6 01:52:18 2008
@@ -0,0 +1,19 @@
+package Prophet::CLI::Command::Init;
+use Moose;
+extends 'Prophet::CLI::Command';
+
+sub run {
+ my $self = shift;
+
+ $self->app_handle->handle->after_initialize( sub { shift->app_handle->set_db_defaults } );
+ $self->app_handle->handle->initialize;
+ $self->app_handle->log("Initialized");
+
+}
+
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
Modified: Prophet/branches/init-and-clone/lib/Prophet/CLI/Dispatcher.pm
==============================================================================
--- Prophet/branches/init-and-clone/lib/Prophet/CLI/Dispatcher.pm (original)
+++ Prophet/branches/init-and-clone/lib/Prophet/CLI/Dispatcher.pm Thu Nov 6 01:52:18 2008
@@ -16,6 +16,8 @@
on [ ['delete', 'del', 'rm'] ] => run_command("Delete");
on [ ['search', 'list', 'ls' ] ] => run_command("Search");
+on init => run_command("Init");
+on clone => run_command("Clone");
on merge => run_command("Merge");
on pull => run_command("Pull");
on publish => run_command("Publish");
Modified: Prophet/branches/init-and-clone/t/canonicalize.t
==============================================================================
--- Prophet/branches/init-and-clone/t/canonicalize.t (original)
+++ Prophet/branches/init-and-clone/t/canonicalize.t Thu Nov 6 01:52:18 2008
@@ -10,7 +10,6 @@
$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => 0 ) . '/repo-' . $$;
my $cli = Prophet::CLI->new();
my $cxn = $cli->handle;
-$cxn->initialize();
isa_ok($cxn, 'Prophet::Replica');
use_ok('TestApp::Bug');
Modified: Prophet/branches/init-and-clone/t/cli.t
==============================================================================
--- Prophet/branches/init-and-clone/t/cli.t (original)
+++ Prophet/branches/init-and-clone/t/cli.t Thu Nov 6 01:52:18 2008
@@ -4,7 +4,6 @@
use Prophet::Test tests => 2;
as_alice {
- run_command('init');
like(run_command(qw(create --type Bug -- --status new --from alice)), qr/Created Bug/, "Created a record as alice");
like(run_command(qw(show 1 --type Bug --batch)), qr/id: 1/, "'show 1' dwims");
};
Modified: Prophet/branches/init-and-clone/t/create.t
==============================================================================
--- Prophet/branches/init-and-clone/t/create.t (original)
+++ Prophet/branches/init-and-clone/t/create.t Thu Nov 6 01:52:18 2008
@@ -8,8 +8,8 @@
$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => 0 ) . '/repo-' . $$;
my $cli = Prophet::CLI->new();
my $cxn = $cli->handle;
+
isa_ok( $cxn, 'Prophet::Replica', "Got the cxn" );
-$cxn->initialize;
use_ok('Prophet::Record');
my $record = Prophet::Record->new( handle => $cxn, type => 'Person' );
isa_ok( $record, 'Prophet::Record' );
Modified: Prophet/branches/init-and-clone/t/database-settings.t
==============================================================================
--- Prophet/branches/init-and-clone/t/database-settings.t (original)
+++ Prophet/branches/init-and-clone/t/database-settings.t Thu Nov 6 01:52:18 2008
@@ -38,7 +38,7 @@
$alice_cli = Prophet::CLI->new();
my $cxn = $alice_cli->handle;
isa_ok( $cxn, 'Prophet::Replica', "Got the cxn " . $cxn->fs_root );
- $cxn->initialize;
+
# set up an app model class, "ticket"
my $t = MyApp::Model::Task->new(handle => $alice_cli->app_handle->handle);
# set default values for status
@@ -88,7 +88,6 @@
$bob_cli = Prophet::CLI->new();
my $cxn = $bob_cli->handle;
isa_ok( $cxn, 'Prophet::Replica', "Got the cxn " . $cxn->fs_root );
- $cxn->initialize;
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/], " Found our record" );
Modified: Prophet/branches/init-and-clone/t/default.t
==============================================================================
--- Prophet/branches/init-and-clone/t/default.t (original)
+++ Prophet/branches/init-and-clone/t/default.t Thu Nov 6 01:52:18 2008
@@ -9,7 +9,7 @@
my $cli = Prophet::CLI->new();
my $cxn = $cli->handle;
isa_ok($cxn, 'Prophet::Replica');
-$cxn->initialize;
+
use_ok('TestApp::Bug');
my $record = TestApp::Bug->new( handle => $cxn );
Modified: Prophet/branches/init-and-clone/t/edit.t
==============================================================================
--- Prophet/branches/init-and-clone/t/edit.t (original)
+++ Prophet/branches/init-and-clone/t/edit.t Thu Nov 6 01:52:18 2008
@@ -6,8 +6,6 @@
$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => 0 ) . '/repo-' . $$;
my $prophet = Prophet::CLI->new;
-$prophet->handle->initialize();
-
my ($luid, $uuid);
my $created_re = qr/Created Robot Master (\d+)(?{ $luid = $1}) \((\S+)(?{ $uuid = $2 })\)/;
my $updated_re = qr/Robot Master \d+ \((\S+)(?{ $uuid = $1 })\) updated/;
Modified: Prophet/branches/init-and-clone/t/history.t
==============================================================================
--- Prophet/branches/init-and-clone/t/history.t (original)
+++ Prophet/branches/init-and-clone/t/history.t Thu Nov 6 01:52:18 2008
@@ -19,7 +19,6 @@
use Test::Exception;
my $cli = Prophet::CLI->new();
- $cli->app_handle->handle->initialize();
my $rec = App::Record::Thingy->new( handle => $cli->handle, type => 'foo' );
ok( $rec->create( props => { foo => 'bar', point => '123' } ) );
Modified: Prophet/branches/init-and-clone/t/non-conflicting-merge.t
==============================================================================
--- Prophet/branches/init-and-clone/t/non-conflicting-merge.t (original)
+++ Prophet/branches/init-and-clone/t/non-conflicting-merge.t Thu Nov 6 01:52:18 2008
@@ -3,10 +3,9 @@
use warnings;
use strict;
-use Prophet::Test tests => 27;
+use Prophet::Test tests => 25;
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" );
@@ -16,7 +15,6 @@
};
as_bob {
- run_ok('prophet', [qw(init)]);
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/], " Found our record" );
Modified: Prophet/branches/init-and-clone/t/publish-pull.t
==============================================================================
--- Prophet/branches/init-and-clone/t/publish-pull.t (original)
+++ Prophet/branches/init-and-clone/t/publish-pull.t Thu Nov 6 01:52:18 2008
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use warnings;
use strict;
-use Prophet::Test tests => 28;
+use Prophet::Test tests => 24;
use Test::Exception;
use File::Temp 'tempdir';
use Path::Class;
@@ -59,7 +59,8 @@
my $user = shift;
- my $replica = Prophet::Replica->new({ url => repo_uri_for($user), app_handle => Prophet::CLI->new->app_handle() });
+ my $cli = Prophet::CLI->new();
+ my $replica = $cli->handle;
my $changesets = $replica->fetch_changesets(after => 0);
is(@$changesets, 2, "two changesets for $user");
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:18 2008
@@ -4,17 +4,11 @@
use strict;
use Test::Exception;
-use Prophet::Test tests => 18;
+use Prophet::Test tests => 19;
as_alice {
- run_command('init');
- like(
- run_command(qw(create --type Bug -- --status new --from alice)),
- qr/Created Bug/,
- "Created a record as alice"
- );
- like( run_command(qw(search --type Bug --regex .)),
- qr/new/, "Found our record" );
+ like(run_command(qw(create --type Bug -- --status new --from alice)), qr/Created Bug/, "Created a record as alice");
+ like(run_command(qw(search --type Bug --regex .)), qr/new/, "Found our record");
};
diag('Bob syncs from alice');
@@ -23,64 +17,44 @@
as_bob {
- like(
- run_command(
- 'clone',
- '--from',
- repo_uri_for('alice'),
-
- ),
- qr/Merged one changeset/,
- "Sync ran ok!"
- );
- like( run_command(qw(create --type Dummy -- --ignore yes)), qr/Created Dummy/ );
+ 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 .));
- like( $out, qr/new/, "We have the one record from alice" );
+ like($out, qr/new/, "We have the one record from alice" );
if ( $out =~ /^(.*?)\s./ ) {
$record_id = $1;
}
- like(
- run_command(
- 'update', '--type',
- 'Bug', '--uuid',
- $record_id, '--',
- '--status' => 'stalled'
- ),
- qr/Bug .* updated/
- );
+ like(run_command( 'update', '--type', 'Bug', '--uuid', $record_id, '--', '--status' => 'stalled'), qr/Bug .* updated/);
run_output_matches(
'prophet',
[ 'show', '--type', 'Bug', '--uuid', $record_id, '--batch' ],
- [ qr/id: (\d+) \($record_id\)/,
- 'creator: alice',
- 'from: alice',
- 'original_replica: ' . replica_uuid_for('alice'),
- 'status: stalled',
+ [
+ qr/id: (\d+) \($record_id\)/,
+ 'creator: alice',
+ 'from: alice',
+ 'original_replica: ' . replica_uuid_for('alice'),
+ 'status: stalled',
],
'content is correct'
);
};
as_alice {
- like(
- run_command(
- 'update', '--type', 'Bug', '--uuid',
- $record_id, '--', '--status' => 'open'
- ),
- qr/Bug .* updated/
- );
+ like(run_command('update', '--type', 'Bug', '--uuid', $record_id, '--', '--status' => 'open' ), qr/Bug .* updated/);
run_output_matches(
'prophet',
[ 'show', '--type', 'Bug', '--uuid', $record_id, '--batch' ],
- [ qr/id: (\d+) \($record_id\)/,
- 'creator: alice',
- 'from: alice', 'original_replica: ' . replica_uuid_for('alice'),
- 'status: open',
+ [
+ qr/id: (\d+) \($record_id\)/,
+ 'creator: alice',
+ 'from: alice',
+ 'original_replica: ' . replica_uuid_for('alice'),
+ 'status: open',
],
'content is correct'
);
@@ -89,25 +63,21 @@
# This conflict, we can autoresolve
-my $alice_repo;
-my $bob_repo;
-
-as_alice { $alice_repo = Prophet::CLI->new->handle() };
-as_bob { $bob_repo = Prophet::CLI->new->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 $conflict_obj;
throws_ok {
- $bob_repo->import_changesets( from => $alice_repo, force => 1 );
+ $target->import_changesets( from => $source, force => 1);
}
qr/not resolved/;
throws_ok {
- $bob_repo->import_changesets(
- from => $alice_repo,
+ $target->import_changesets(
+ from => $source,
resolver => sub { die "my way of death\n" },
force => 1,
);
@@ -117,8 +87,8 @@
ok_added_revisions(
sub {
- $bob_repo->import_changesets(
- from => $alice_repo,
+ $target->import_changesets(
+ from => $source,
resolver_class => 'Prophet::Resolver::AlwaysTarget',
force => 1,
);
@@ -137,28 +107,26 @@
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') } );
throws_ok {
- $alice_repo->import_changesets( from => $bob_repo, force => 1 );
+ $target->import_changesets( from => $source, force => 1 );
}
qr/not resolved/;
- $alice_repo->import_resolutions_from_remote_replica(
- from => $bob_repo,
- force => 1
- );
+ $target->import_resolutions_from_remote_replica( from => $source, force => 1 );
- $alice_repo->import_changesets(
- from => $bob_repo,
- resdb => $alice_repo->resolution_db_handle,
+ $target->import_changesets(
+ from => $source,
+ resdb => $target->resolution_db_handle,
force => 1,
);
lives_and {
ok_added_revisions(
sub {
- $alice_repo->import_changesets( from => $bob_repo, force => 1 );
+ $target->import_changesets( from => $source, force => 1 );
},
0,
'no more changes to sync'
@@ -168,11 +136,13 @@
};
as_bob {
+ my $source = Prophet::Replica->new( { url => repo_uri_for('alice') } );
+ my $target = Prophet::Replica->new( { url => repo_uri_for('bob') } );
lives_and {
ok_added_revisions(
sub {
- $bob_repo->import_changesets( from => $alice_repo, force => 1 );
+ $target->import_changesets( from => $source, force => 1 );
},
0,
'no more changes to sync'
@@ -216,7 +186,8 @@
source_uuid => replica_uuid(),
original_source_uuid => replica_uuid(),
},
- { creator => 'alice',
+ {
+ creator => 'alice',
created => $changesets[1]->created,
is_nullification => undef,
is_resolution => undef,
@@ -230,8 +201,7 @@
record_type => 'Bug',
change_type => 'update_file',
prop_changes => {
- status =>
- { old_value => 'new', new_value => 'open' }
+ status => { old_value => 'new', new_value => 'open' }
},
},
{
@@ -248,7 +218,8 @@
],
},
- { creator => 'bob',
+ {
+ creator => 'bob',
created => $changesets[2]->created,
is_nullification => undef,
is_resolution => 1,
@@ -262,8 +233,7 @@
record_type => 'Bug',
change_type => 'update_file',
prop_changes => {
- status =>
- { old_value => 'open', new_value => 'stalled' }
+ status => { old_value => 'open', new_value => 'stalled' }
},
}
]
Modified: Prophet/branches/init-and-clone/t/resty-server.t
==============================================================================
--- Prophet/branches/init-and-clone/t/resty-server.t (original)
+++ Prophet/branches/init-and-clone/t/resty-server.t Thu Nov 6 01:52:18 2008
@@ -18,8 +18,6 @@
my $cli = Prophet::CLI->new();
my $s = Prophet::TestServer->new();
-$cli->handle->initialize;
-
$s->app_handle( $cli->app_handle );
my $url_root = $s->started_ok("start up my web server");
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:18 2008
@@ -46,6 +46,10 @@
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);
};
More information about the Bps-public-commit
mailing list