[Bps-public-commit] SD branch, master, updated. 003086fcb2062b831c6404aa5b107b614899f902
jesse
jesse at bestpractical.com
Fri May 29 16:00:46 EDT 2009
The branch, master has been updated
via 003086fcb2062b831c6404aa5b107b614899f902 (commit)
via 6746257d389be543fd4c7f6adcbf2052ac58980a (commit)
via 11f127b4e2b97bc14f820454345734550494782b (commit)
via 76cc1896c3f05f5ef9063499a1ef33f614ce0c0e (commit)
via 47f311075594e3a95b6277edaefb738edae056da (commit)
via 2d28e2aa641809fb298c52b76a06576f78583dc4 (commit)
via 5c44257a118604a86b4772a5d26dc6dd21ae8e75 (commit)
via 831d7fa1857c79b1546da0caeb14755811e85600 (commit)
via 2534bf35fa5632440c39ac648c0a64aca6f8d504 (commit)
from 9d6a0232273b1752073bccb063296a6d1731253e (commit)
Summary of changes:
lib/App/SD/ForeignReplica.pm | 3 +-
lib/App/SD/ForeignReplica/PullEncoder.pm | 12 +++--
lib/App/SD/ForeignReplica/PushEncoder.pm | 7 +--
lib/App/SD/Replica/rt.pm | 2 +-
lib/App/SD/Replica/rt/PullEncoder.pm | 33 +++++++-----
lib/App/SD/Replica/rt/PushEncoder.pm | 7 +--
lib/App/SD/Replica/trac/PullEncoder.pm | 1 -
t/sd-rt/rt-auto-open-conflict.t | 85 ++++++++++++++++++++++++++++++
t/sd-trac/basic.t | 2 +-
9 files changed, 121 insertions(+), 31 deletions(-)
create mode 100644 t/sd-rt/rt-auto-open-conflict.t
- Log -----------------------------------------------------------------
commit 2534bf35fa5632440c39ac648c0a64aca6f8d504
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:06:59 2009 -0400
We want to check if the ForeignReplica has seen the changeset, not the local one
diff --git a/lib/App/SD/ForeignReplica.pm b/lib/App/SD/ForeignReplica.pm
index 47dd5b5..e7378ad 100644
--- a/lib/App/SD/ForeignReplica.pm
+++ b/lib/App/SD/ForeignReplica.pm
@@ -17,7 +17,7 @@ sub integrate_changeset {
);
my $changeset = $args{'changeset'};
- return if $self->app_handle->handle->last_changeset_from_source( $changeset->original_source_uuid) >= $changeset->original_sequence_no;
+ return if $self->last_changeset_from_source( $changeset->original_source_uuid) >= $changeset->original_sequence_no;
$self->SUPER::integrate_changeset(%args);
}
@@ -45,6 +45,7 @@ sub integrate_change {
# don't push internal records
return if $change->record_type =~ /^__/;
+
Prophet::App->require( $self->push_encoder());
my $recoder = $self->push_encoder->new( { sync_source => $self } );
$recoder->integrate_change($change,$changeset);
commit 831d7fa1857c79b1546da0caeb14755811e85600
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:07:35 2009 -0400
Remove commented out code
diff --git a/lib/App/SD/ForeignReplica/PushEncoder.pm b/lib/App/SD/ForeignReplica/PushEncoder.pm
index 1ac01ec..d553f66 100644
--- a/lib/App/SD/ForeignReplica/PushEncoder.pm
+++ b/lib/App/SD/ForeignReplica/PushEncoder.pm
@@ -17,13 +17,10 @@ sub integrate_change {
# XXX TODO - this logic should be at the changeset level, not the cahnge level, as it applies to all
# changes in the changeset
-# return
-# if $self->sync_source->app_handle->handle->last_changeset_from_source(
-# $changeset->original_source_uuid
-# ) >= $changeset->original_sequence_no;
-#
+
my $before_integration = time();
+
eval {
if ( $change->record_type eq 'ticket'
and $change->change_type eq 'add_file' ) {
commit 5c44257a118604a86b4772a5d26dc6dd21ae8e75
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:44:27 2009 -0400
remove debugging info from new test file
diff --git a/t/sd-rt/rt-auto-open-conflict.t b/t/sd-rt/rt-auto-open-conflict.t
new file mode 100644
index 0000000..d25fad5
--- /dev/null
+++ b/t/sd-rt/rt-auto-open-conflict.t
@@ -0,0 +1,85 @@
+#!/usr/bin/perl -w
+
+# to run:
+#
+# RT_DBA_USER=root RT_DBA_PASSWORD= prove -lv -I/Users/clkao/work/bps/rt-3.7/lib t/sd-rt.t
+use strict;
+
+use Prophet::Test;
+use Path::Class;
+
+BEGIN {
+ unless ( eval 'use RT::Test; 1' ) {
+ diag $@ if $ENV{'TEST_VERBOSE'};
+ plan skip_all => 'requires RT 3.8 or newer to run tests.';
+ }
+}
+
+plan tests => 10;
+use App::SD::Test;
+
+no warnings 'once';
+
+RT::Handle->InsertData( $RT::EtcPath . '/initialdata' );
+
+BEGIN {
+ require File::Temp;
+ $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb';
+ diag "export SD_REPO=" . $ENV{'PROPHET_REPO'} . "\n";
+}
+
+my $IMAGE_FILE = qw|t/data/bplogo.gif|;
+
+$RT::Test::SKIP_REQUEST_WORK_AROUND = 1;
+
+my ( $url, $m ) = RT::Test->started_ok;
+
+use RT::Client::REST;
+use RT::Client::REST::Ticket;
+my $rt = RT::Client::REST->new( server => $url );
+$rt->login( username => 'root', password => 'password' );
+
+$url =~ s|http://|http://root:password@|;
+my $sd_rt_url = "rt:$url|General|Status!='resolved'";
+
+my $ticket = RT::Client::REST::Ticket->new( rt => $rt, queue => 'General', status => 'new', subject => 'helium',)->store( text => "Ticket Comment" );
+diag("Clone from RT");
+my ( $ret, $out, $err ) = run_script( 'sd', [ 'clone', '--from', $sd_rt_url ] );
+ok( $ret, $out );
+diag($err);
+my $helium_id;
+run_output_matches(
+ 'sd',
+ [ 'ticket', 'list', '--regex', 'helium' ],
+ [qr/(.*?)(?{ $helium_id = $1 }) helium new/]
+);
+
+diag("Comment on ticket in sd");
+( $ret, $out, $err ) = run_script( 'sd', [ 'ticket', 'comment', $helium_id, '--content', 'helium is a noble gas' ] );
+ok( $ret, $out );
+like( $out, qr/Created comment/ );
+diag($out);
+diag($err);
+{ # resolve a ticket
+
+ diag("Resolve a ticket in SD");
+ ( $ret, $out, $err ) = run_script( 'sd', [ 'ticket', 'resolve', $helium_id ] );
+ ok( $ret, $out );
+ like( $out, qr/Ticket .* updated/ );
+ sleep(1);
+ diag("Push to rt");
+ ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url, '--prefer', 'source' ] );
+ ok( $ret, $out );
+ diag($err);
+ sleep(1);
+ ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url, '--prefer', 'source'] );
+ ok( $ret, $out );
+ diag($err);
+ my $fetched_ticket = RT::Client::REST::Ticket->new(
+ rt => $rt,
+ id => $ticket->id
+ )->retrieve;
+
+ warn "Ticket id is ".$ticket->id;
+ is( $fetched_ticket->status, "resolved" );
+}
commit 2d28e2aa641809fb298c52b76a06576f78583dc4
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:51:47 2009 -0400
Removed a debugging statement
diff --git a/lib/App/SD/Replica/trac/PullEncoder.pm b/lib/App/SD/Replica/trac/PullEncoder.pm
index 7fb67db..551a43a 100644
--- a/lib/App/SD/Replica/trac/PullEncoder.pm
+++ b/lib/App/SD/Replica/trac/PullEncoder.pm
@@ -168,7 +168,6 @@ sub transcode_create_txn {
$changeset->add_change( { change => $change } );
if ( my $att = $txn->attachment ) {
- warn $att->filename;
$self->_recode_attachment_create(
ticket => $ticket,
txn => $txn,
commit 47f311075594e3a95b6277edaefb738edae056da
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:51:52 2009 -0400
When doing a pull from trac after a magic-background status update, specify a conflict resolution algorithm
diff --git a/t/sd-trac/basic.t b/t/sd-trac/basic.t
index 8ae1b31..23ea721 100644
--- a/t/sd-trac/basic.t
+++ b/t/sd-trac/basic.t
@@ -117,7 +117,7 @@ is( $new_ticket->status, 'new', "The ticket is new before we push to trac" );
# Push the changes to our ticket to trac
#
-( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
+( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url, '--prefer','source' ] );
diag($out);
diag($err);
commit 76cc1896c3f05f5ef9063499a1ef33f614ce0c0e
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:55:51 2009 -0400
When pulling from a foreign replica, we should record merge information
on the foreign replica that describes the ticket changesets. We need to
do this because otherwise the foreign replica can't resolve the changeset's
original_source_uuid as something it's seen
diff --git a/lib/App/SD/ForeignReplica/PullEncoder.pm b/lib/App/SD/ForeignReplica/PullEncoder.pm
index 61ce9c1..fe5bb75 100644
--- a/lib/App/SD/ForeignReplica/PullEncoder.pm
+++ b/lib/App/SD/ForeignReplica/PullEncoder.pm
@@ -34,9 +34,15 @@ sub run {
}
my $cs_counter = 0;
- for (@changesets) {
+ for my $changeset (@changesets) {
$self->sync_source->log( "Applying changeset " . ++$cs_counter . " of " . scalar @changesets );
- $args{callback}->($_);
+ $args{callback}->($changeset);
+
+ # We're treating each individual ticket in the foreign system as its own 'replica'
+ # because of that, we need to hint to the push side of the system what the most recent
+ # txn on each ticket it has.
+ $self->sync_source->record_last_changeset_from_replica(
+ $changeset->original_source_uuid => $changeset->original_sequence_no );
}
$self->sync_source->record_upstream_last_modified_date($last_modified)
@@ -54,7 +60,6 @@ sub transcode_ticket {
if ( my $ticket_last_modified = $self->ticket_last_modified($ticket) ) {
- warn "My last modified = " .$ticket_last_modified;
$last_modified = $ticket_last_modified if ( !$last_modified || $ticket_last_modified > $last_modified );
}
@@ -87,7 +92,6 @@ sub transcode_history {
for my $txn ( sort { $b->{'serial'} <=> $a->{'serial'} } @$transactions ) {
$last_modified = $txn->{timestamp} if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
-
$self->sync_source->log( "$ticket_id Transcoding transaction " . ++$txn_counter . " of " . scalar @$transactions );
my $changeset = $self->transcode_one_txn( $txn, $initial_state, $final_state );
commit 11f127b4e2b97bc14f820454345734550494782b
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:57:27 2009 -0400
tidy
diff --git a/lib/App/SD/Replica/rt/PushEncoder.pm b/lib/App/SD/Replica/rt/PushEncoder.pm
index 6694a1b..263bc67 100644
--- a/lib/App/SD/Replica/rt/PushEncoder.pm
+++ b/lib/App/SD/Replica/rt/PushEncoder.pm
@@ -17,7 +17,6 @@ sub integrate_ticket_update {
{ isa => 'Prophet::Change' },
{ isa => 'Prophet::ChangeSet' }
);
-
# Figure out the remote site's ticket ID for this change's record
my $remote_ticket_id = $self->sync_source->remote_id_for_uuid( $change->record_uuid );
my $ticket = RT::Client::REST::Ticket->new(
@@ -51,11 +50,11 @@ sub integrate_comment {
my $self = shift;
my ($change, $changeset) = validate_pos( @_, { isa => 'Prophet::Change' }, {isa => 'Prophet::ChangeSet'} );
+ my %props = map { $_->name => $_->new_value } $change->prop_changes;
+ my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
# Figure out the remote site's ticket ID for this change's record
- my %props = map { $_->name => $_->new_value } $change->prop_changes;
- my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
my $ticket = RT::Client::REST::Ticket->new( rt => $self->sync_source->rt, id => $ticket_id);
my %content = ( message => $props{'content'},
@@ -72,7 +71,6 @@ sub integrate_comment {
sub integrate_attachment {
my ($self, $change, $changeset ) = validate_pos( @_, { isa => 'App::SD::Replica::rt::PushEncoder'}, { isa => 'Prophet::Change' }, { isa => 'Prophet::ChangeSet' });
-
my %props = map { $_->name => $_->new_value } $change->prop_changes;
my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'});
my $ticket = RT::Client::REST::Ticket->new( rt => $self->sync_source->rt, id => $ticket_id );
@@ -87,7 +85,6 @@ sub integrate_attachment {
return $ticket_id;
}
-
sub _recode_props_for_integrate {
my $self = shift;
my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
commit 6746257d389be543fd4c7f6adcbf2052ac58980a
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 15:57:52 2009 -0400
reverse sort rt transactions on something sane
diff --git a/lib/App/SD/Replica/rt.pm b/lib/App/SD/Replica/rt.pm
index 8638f09..a0cfa7f 100644
--- a/lib/App/SD/Replica/rt.pm
+++ b/lib/App/SD/Replica/rt.pm
@@ -63,7 +63,7 @@ sub get_txn_list_by_date {
return { id => $_->id, creator => $_->creator, created => $txn_created }
}
- sort { $b->{'Created'} <=> $a->{'Created'} }
+ sort { $b->id <=> $a->id }
RT::Client::REST::Ticket->new( rt => $self->rt, id => $ticket )->transactions->get_iterator->();
return @txns;
}
commit 003086fcb2062b831c6404aa5b107b614899f902
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Fri May 29 16:00:31 2009 -0400
tidy
diff --git a/lib/App/SD/Replica/rt/PullEncoder.pm b/lib/App/SD/Replica/rt/PullEncoder.pm
index 9675556..f056d0e 100644
--- a/lib/App/SD/Replica/rt/PullEncoder.pm
+++ b/lib/App/SD/Replica/rt/PullEncoder.pm
@@ -102,33 +102,40 @@ sub find_matching_transactions {
my @txns;
my $rt_handle = $self->sync_source->rt;
-
- my $ticket_id = $self->ticket_id($args{ticket});
- my $latest = $self->sync_source->app_handle->handle->last_changeset_from_source($self->sync_source->uuid_for_remote_id( $ticket_id )) || 0;
- for my $txn ( sort $rt_handle->get_transaction_ids( parent_id => $ticket_id)) {
+ my $ticket_id = $self->ticket_id( $args{ticket} );
+
+ my $latest = $self->sync_source->app_handle->handle->last_changeset_from_source(
+ $self->sync_source->uuid_for_remote_id($ticket_id) ) || 0;
+
+ for my $txn ( sort $rt_handle->get_transaction_ids( parent_id => $ticket_id ) ) {
+
# Skip things calling code told us to skip
- next if $txn < $args{'starting_transaction'};
+ next if $txn < $args{'starting_transaction'};
+
# skip things we had on our last pull
- next if $txn <= $latest;
- # Skip things we've pushed
- next if $self->sync_source->foreign_transaction_originated_locally($txn, $ticket_id);
+ next if $txn <= $latest;
- my $txn_hash = $rt_handle->get_transaction( parent_id => $ticket_id, id => $txn, type => 'ticket');
+ # Skip things we've pushed
+ next if $self->sync_source->foreign_transaction_originated_locally( $txn, $ticket_id );
+ my $txn_hash = $rt_handle->get_transaction( parent_id => $ticket_id, id => $txn, type => 'ticket' );
if ( my $attachments = delete $txn_hash->{'Attachments'} ) {
for my $attach ( split( /\n/, $attachments ) ) {
next unless ( $attach =~ /^(\d+):/ );
my $id = $1;
- my $a = $rt_handle->get_attachment( parent_id => $ticket_id, id => $id);
+ my $a = $rt_handle->get_attachment( parent_id => $ticket_id, id => $id );
push( @{ $txn_hash->{_attachments} }, $a ) if ( $a->{Filename} );
}
}
- push @txns, { timestamp => App::SD::Util::string_to_datetime( $txn_hash->{Created} ),
- serial => $txn_hash->{id},
- object => $txn_hash};
+ push @txns,
+ {
+ timestamp => App::SD::Util::string_to_datetime( $txn_hash->{Created} ),
+ serial => $txn_hash->{id},
+ object => $txn_hash
+ };
}
return \@txns;
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list