Merge lp:~jameinel/u1db/u1db-client-remote-sync into lp:u1db

Proposed by John A Meinel
Status: Merged
Merged at revision: 102
Proposed branch: lp:~jameinel/u1db/u1db-client-remote-sync
Merge into: lp:u1db
Prerequisite: lp:~jameinel/u1db/u1db-client-commandline
Diff against target: 66 lines (+32/-3)
2 files modified
u1db/commandline/client.py (+12/-3)
u1db/tests/commandline/test_client.py (+20/-0)
To merge this branch: bzr merge lp:~jameinel/u1db/u1db-client-remote-sync
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+80897@code.launchpad.net

Description of the change

This implements 'u1db-client sync SOURCE u1db://remote/target'

We can't actually land this until Samuele's changes land to finish off remote sync. I have tests that will fail, but after merging his branch they pass.

We'll want this for the demo this week, etc.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

+1 (test passed once merged with trunk now that remote sync has landed)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1db/commandline/client.py'
2--- u1db/commandline/client.py 2011-11-01 13:42:24 +0000
3+++ u1db/commandline/client.py 2011-11-01 13:42:24 +0000
4@@ -24,6 +24,7 @@
5 from u1db.backends import sqlite_backend
6 from u1db.remote import (
7 client,
8+ sync_target,
9 )
10
11
12@@ -66,12 +67,20 @@
13 sys.stdout)
14
15
16+def _open_target(target_db):
17+ if target_db.startswith('u1db://'):
18+ target = sync_target.RemoteSyncTarget.connect(target_db)
19+ else:
20+ db = sqlite_backend.SQLiteDatabase.open_database(target_db)
21+ target = db.get_sync_target()
22+ return target
23+
24+
25 def cmd_sync(source_db, target_db):
26 """Start a Sync request."""
27 source = sqlite_backend.SQLiteDatabase.open_database(source_db)
28- target = sqlite_backend.SQLiteDatabase.open_database(target_db)
29- st = target.get_sync_target()
30- syncer = sync.Synchronizer(source, st)
31+ target = _open_target(target_db)
32+ syncer = sync.Synchronizer(source, target)
33 syncer.sync()
34
35
36
37=== modified file 'u1db/tests/commandline/test_client.py'
38--- u1db/tests/commandline/test_client.py 2011-11-01 13:42:24 +0000
39+++ u1db/tests/commandline/test_client.py 2011-11-01 13:42:24 +0000
40@@ -166,6 +166,26 @@
41 self.db.get_doc('my-test-id'))
42
43
44+class TestCmdSyncRemote(tests.TestCaseWithSyncServer, TestCaseWithDB):
45+
46+ def setUp(self):
47+ super(TestCmdSyncRemote, self).setUp()
48+ self.startServer()
49+ self.db2 = self.request_state._create_database('test2.db')
50+
51+ def test_sync_remote(self):
52+ doc1_id, doc1_rev = self.db.create_doc(tests.simple_doc)
53+ doc2_id, doc2_rev = self.db2.create_doc(tests.nested_doc)
54+ db2_url = self.getURL('test2.db')
55+ self.assertTrue(db2_url.startswith('u1db://'))
56+ self.assertTrue(db2_url.endswith('/test2.db'))
57+ client.cmd_sync(self.db_path, db2_url)
58+ self.assertEqual((doc1_rev, tests.simple_doc, False),
59+ self.db2.get_doc(doc1_id))
60+ self.assertEqual((doc2_rev, tests.nested_doc, False),
61+ self.db.get_doc(doc2_id))
62+
63+
64 class TestCommandLine(TestCaseWithDB):
65
66 def _get_u1db_client_path(self):

Subscribers

People subscribed via source and target branches