Bug 1408585 - Remove RepositorySession createSession delegates r=rnewman

MozReview-Commit-ID: KezYHeSWDiL

--HG--
extra : rebase_source : c63f69a7d5b16d152fa809560a70c14ae1da5715
This commit is contained in:
Grigory Kruglov 2017-11-14 14:37:05 -05:00
Родитель 45de7880f9
Коммит 2c2f325436
45 изменённых файлов: 481 добавлений и 1044 удалений

Просмотреть файл

@ -907,7 +907,6 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
'sync/middleware/BufferingMiddlewareRepositorySession.java', 'sync/middleware/BufferingMiddlewareRepositorySession.java',
'sync/middleware/Crypto5MiddlewareRepository.java', 'sync/middleware/Crypto5MiddlewareRepository.java',
'sync/middleware/Crypto5MiddlewareRepositorySession.java', 'sync/middleware/Crypto5MiddlewareRepositorySession.java',
'sync/middleware/MiddlewareRepository.java',
'sync/middleware/MiddlewareRepositorySession.java', 'sync/middleware/MiddlewareRepositorySession.java',
'sync/middleware/storage/BufferStorage.java', 'sync/middleware/storage/BufferStorage.java',
'sync/middleware/storage/MemoryBufferStorage.java', 'sync/middleware/storage/MemoryBufferStorage.java',
@ -969,17 +968,13 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
'sync/repositories/android/PasswordsRepositorySession.java', 'sync/repositories/android/PasswordsRepositorySession.java',
'sync/repositories/android/RepoUtils.java', 'sync/repositories/android/RepoUtils.java',
'sync/repositories/android/SessionHelper.java', 'sync/repositories/android/SessionHelper.java',
'sync/repositories/android/ThreadedRepository.java',
'sync/repositories/android/VisitsHelper.java', 'sync/repositories/android/VisitsHelper.java',
'sync/repositories/BookmarkNeedsReparentingException.java', 'sync/repositories/BookmarkNeedsReparentingException.java',
'sync/repositories/BookmarksRepository.java',
'sync/repositories/ConfigurableServer15Repository.java', 'sync/repositories/ConfigurableServer15Repository.java',
'sync/repositories/delegates/DeferrableRepositorySessionCreationDelegate.java',
'sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java', 'sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java',
'sync/repositories/delegates/DeferredRepositorySessionFinishDelegate.java', 'sync/repositories/delegates/DeferredRepositorySessionFinishDelegate.java',
'sync/repositories/delegates/DeferredRepositorySessionStoreDelegate.java', 'sync/repositories/delegates/DeferredRepositorySessionStoreDelegate.java',
'sync/repositories/delegates/RepositorySessionCleanDelegate.java', 'sync/repositories/delegates/RepositorySessionCleanDelegate.java',
'sync/repositories/delegates/RepositorySessionCreationDelegate.java',
'sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java', 'sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java',
'sync/repositories/delegates/RepositorySessionFinishDelegate.java', 'sync/repositories/delegates/RepositorySessionFinishDelegate.java',
'sync/repositories/delegates/RepositorySessionStoreDelegate.java', 'sync/repositories/delegates/RepositorySessionStoreDelegate.java',
@ -1003,7 +998,6 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
'sync/repositories/downloaders/BatchingDownloaderDelegate.java', 'sync/repositories/downloaders/BatchingDownloaderDelegate.java',
'sync/repositories/FetchFailedException.java', 'sync/repositories/FetchFailedException.java',
'sync/repositories/HashSetStoreTracker.java', 'sync/repositories/HashSetStoreTracker.java',
'sync/repositories/HistoryRepository.java',
'sync/repositories/IdentityRecordFactory.java', 'sync/repositories/IdentityRecordFactory.java',
'sync/repositories/InactiveSessionException.java', 'sync/repositories/InactiveSessionException.java',
'sync/repositories/InvalidBookmarkTypeException.java', 'sync/repositories/InvalidBookmarkTypeException.java',
@ -1041,6 +1035,7 @@ sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozil
'sync/repositories/VersioningDelegateHelper.java', 'sync/repositories/VersioningDelegateHelper.java',
'sync/Server15PreviousPostFailedException.java', 'sync/Server15PreviousPostFailedException.java',
'sync/Server15RecordPostFailedException.java', 'sync/Server15RecordPostFailedException.java',
'sync/SessionCreateException.java',
'sync/setup/activities/ActivityUtils.java', 'sync/setup/activities/ActivityUtils.java',
'sync/setup/activities/WebURLFinder.java', 'sync/setup/activities/WebURLFinder.java',
'sync/setup/Constants.java', 'sync/setup/Constants.java',

Просмотреть файл

@ -13,17 +13,15 @@ import org.mozilla.gecko.background.sync.helpers.ExpectFinishDelegate;
import org.mozilla.gecko.background.sync.helpers.ExpectInvalidTypeStoreDelegate; import org.mozilla.gecko.background.sync.helpers.ExpectInvalidTypeStoreDelegate;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.Utils; import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NullCursorException; import org.mozilla.gecko.sync.repositories.NullCursorException;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.android.BookmarksDataAccessor; import org.mozilla.gecko.sync.repositories.android.BookmarksDataAccessor;
import org.mozilla.gecko.sync.repositories.android.BookmarksRepository; import org.mozilla.gecko.sync.repositories.android.BookmarksRepository;
import org.mozilla.gecko.sync.repositories.android.BookmarksRepositorySession; import org.mozilla.gecko.sync.repositories.android.BookmarksRepositorySession;
import org.mozilla.gecko.sync.repositories.android.ThreadedRepository;
import org.mozilla.gecko.sync.repositories.android.DataAccessor; import org.mozilla.gecko.sync.repositories.android.DataAccessor;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.RepoUtils; import org.mozilla.gecko.sync.repositories.android.RepoUtils;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
@ -34,7 +32,7 @@ import android.database.Cursor;
public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTestCase { public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTestCase {
@Override @Override
protected ThreadedRepository getRepository() { protected Repository getRepository() {
/** /**
* Override this chain in order to avoid our test code having to create two * Override this chain in order to avoid our test code having to create two
@ -42,15 +40,13 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
*/ */
return new BookmarksRepository() { return new BookmarksRepository() {
@Override @Override
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) {
BookmarksRepositorySession session; return new BookmarksRepositorySession(this, context) {
session = new BookmarksRepositorySession(this, context) {
@Override @Override
protected synchronized void trackGUID(String guid) { protected synchronized void trackGUID(String guid) {
System.out.println("Ignoring trackGUID call: this is a test!"); System.out.println("Ignoring trackGUID call: this is a test!");
} }
}; };
delegate.deferredCreationDelegate().onSessionCreated(session);
} }
}; };
} }
@ -87,7 +83,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
// to store a folder first, store your record in "mobile" or one of the folders // to store a folder first, store your record in "mobile" or one of the folders
// that always exists. // that always exists.
public void testFetchOneWithChildren() { public void testFetchOneWithChildren() throws Exception {
BookmarkRecord folder = BookmarkHelpers.createFolder1(); BookmarkRecord folder = BookmarkHelpers.createFolder1();
BookmarkRecord bookmark1 = BookmarkHelpers.createBookmark1(); BookmarkRecord bookmark1 = BookmarkHelpers.createBookmark1();
BookmarkRecord bookmark2 = BookmarkHelpers.createBookmark2(); BookmarkRecord bookmark2 = BookmarkHelpers.createBookmark2();
@ -159,7 +155,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
} }
public void testStoreFolder() { public void testStoreFolder() throws Exception {
basicStoreTest(BookmarkHelpers.createFolder1()); basicStoreTest(BookmarkHelpers.createFolder1());
} }
@ -190,7 +186,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
} }
*/ */
protected void basicStoreFailTest(Record record) { protected void basicStoreFailTest(Record record) throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
performWait(storeRunnable(session, record, new ExpectInvalidTypeStoreDelegate())); performWait(storeRunnable(session, record, new ExpectInvalidTypeStoreDelegate()));
dispose(session); dispose(session);
@ -201,7 +197,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
*/ */
// Insert two records missing parent, then insert their parent. // Insert two records missing parent, then insert their parent.
// Make sure they end up with the correct parent on fetch. // Make sure they end up with the correct parent on fetch.
public void testBasicReparenting() throws InactiveSessionException { public void testBasicReparenting() throws Exception {
Record[] expected = new Record[] { Record[] expected = new Record[] {
BookmarkHelpers.createBookmark1(), BookmarkHelpers.createBookmark1(),
BookmarkHelpers.createBookmark2(), BookmarkHelpers.createBookmark2(),
@ -212,7 +208,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
// Insert 3 folders and 4 bookmarks in different orders // Insert 3 folders and 4 bookmarks in different orders
// and make sure they come out parented correctly // and make sure they come out parented correctly
public void testMultipleFolderReparenting1() throws InactiveSessionException { public void testMultipleFolderReparenting1() throws Exception {
Record[] expected = new Record[] { Record[] expected = new Record[] {
BookmarkHelpers.createBookmark1(), BookmarkHelpers.createBookmark1(),
BookmarkHelpers.createBookmark2(), BookmarkHelpers.createBookmark2(),
@ -225,7 +221,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
doMultipleFolderReparentingTest(expected); doMultipleFolderReparentingTest(expected);
} }
public void testMultipleFolderReparenting2() throws InactiveSessionException { public void testMultipleFolderReparenting2() throws Exception {
Record[] expected = new Record[] { Record[] expected = new Record[] {
BookmarkHelpers.createBookmark1(), BookmarkHelpers.createBookmark1(),
BookmarkHelpers.createBookmark2(), BookmarkHelpers.createBookmark2(),
@ -238,7 +234,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
doMultipleFolderReparentingTest(expected); doMultipleFolderReparentingTest(expected);
} }
public void testMultipleFolderReparenting3() throws InactiveSessionException { public void testMultipleFolderReparenting3() throws Exception {
Record[] expected = new Record[] { Record[] expected = new Record[] {
BookmarkHelpers.createBookmark1(), BookmarkHelpers.createBookmark1(),
BookmarkHelpers.createBookmark2(), BookmarkHelpers.createBookmark2(),
@ -251,7 +247,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
doMultipleFolderReparentingTest(expected); doMultipleFolderReparentingTest(expected);
} }
private void doMultipleFolderReparentingTest(Record[] expected) throws InactiveSessionException { private void doMultipleFolderReparentingTest(Record[] expected) throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
doStore(session, expected); doStore(session, expected);
ExpectFetchDelegate delegate = preparedExpectFetchDelegate(expected); ExpectFetchDelegate delegate = preparedExpectFetchDelegate(expected);
@ -277,7 +273,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
* Store a record after with the new guid as the parent * Store a record after with the new guid as the parent
* and make sure it works as well. * and make sure it works as well.
*/ */
public void testStoreIdenticalFoldersWithChildren() { public void testStoreIdenticalFoldersWithChildren() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
Record record0 = BookmarkHelpers.createFolder1(); Record record0 = BookmarkHelpers.createFolder1();
@ -368,7 +364,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
BookmarkHelpers.createFolder1()); BookmarkHelpers.createFolder1());
} }
public void testBasicPositioning() { public void testBasicPositioning() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
Record[] expected = new Record[] { Record[] expected = new Record[] {
BookmarkHelpers.createBookmark1(), BookmarkHelpers.createBookmark1(),
@ -404,7 +400,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
dispose(session); dispose(session);
} }
public void testSqlInjectPurgeDeleteAndUpdateByGuid() { public void testSqlInjectPurgeDeleteAndUpdateByGuid() throws Exception {
// Some setup. // Some setup.
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
DataAccessor db = getDataAccessor(); DataAccessor db = getDataAccessor();
@ -485,7 +481,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
return cur; return cur;
} }
public void testSqlInjectFetch() { public void testSqlInjectFetch() throws Exception {
// Some setup. // Some setup.
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
DataAccessor db = getDataAccessor(); DataAccessor db = getDataAccessor();
@ -533,7 +529,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
dispose(session); dispose(session);
} }
public void testSqlInjectDelete() { public void testSqlInjectDelete() throws Exception {
// Some setup. // Some setup.
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
DataAccessor db = getDataAccessor(); DataAccessor db = getDataAccessor();
@ -578,7 +574,7 @@ public class TestAndroidBrowserBookmarksRepository extends ThreadedRepositoryTes
* Verify that data accessor's bulkInsert actually inserts. * Verify that data accessor's bulkInsert actually inserts.
* @throws NullCursorException * @throws NullCursorException
*/ */
public void testBulkInsert() throws NullCursorException { public void testBulkInsert() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
DataAccessor db = getDataAccessor(); DataAccessor db = getDataAccessor();

Просмотреть файл

@ -11,15 +11,14 @@ import org.mozilla.gecko.background.sync.helpers.HistoryHelpers;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.Utils; import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.repositories.NullCursorException; import org.mozilla.gecko.sync.repositories.NullCursorException;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.android.HistoryDataAccessor; import org.mozilla.gecko.sync.repositories.android.HistoryDataAccessor;
import org.mozilla.gecko.sync.repositories.android.HistoryRepository; import org.mozilla.gecko.sync.repositories.android.HistoryRepository;
import org.mozilla.gecko.sync.repositories.android.HistoryRepositorySession; import org.mozilla.gecko.sync.repositories.android.HistoryRepositorySession;
import org.mozilla.gecko.sync.repositories.android.ThreadedRepository;
import org.mozilla.gecko.sync.repositories.android.DataAccessor; import org.mozilla.gecko.sync.repositories.android.DataAccessor;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.RepoUtils; import org.mozilla.gecko.sync.repositories.android.RepoUtils;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; import org.mozilla.gecko.sync.repositories.domain.HistoryRecord;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
@ -31,7 +30,7 @@ import android.net.Uri;
public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestCase { public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestCase {
@Override @Override
protected ThreadedRepository getRepository() { protected Repository getRepository() {
/** /**
* Override this chain in order to avoid our test code having to create two * Override this chain in order to avoid our test code having to create two
@ -39,15 +38,13 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
*/ */
return new HistoryRepository() { return new HistoryRepository() {
@Override @Override
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) {
HistoryRepositorySession session; return new HistoryRepositorySession(this, context) {
session = new HistoryRepositorySession(this, context) {
@Override @Override
protected synchronized void trackGUID(String guid) { protected synchronized void trackGUID(String guid) {
System.out.println("Ignoring trackGUID call: this is a test!"); System.out.println("Ignoring trackGUID call: this is a test!");
} }
}; };
delegate.onSessionCreated(session);
} }
}; };
} }
@ -202,7 +199,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
* and doing a fetch. * and doing a fetch.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testAddOneVisit() { public void testAddOneVisit() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
HistoryRecord record0 = HistoryHelpers.createHistory3(); HistoryRecord record0 = HistoryHelpers.createHistory3();
@ -229,7 +226,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testAddMultipleVisits() { public void testAddMultipleVisits() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
HistoryRecord record0 = HistoryHelpers.createHistory4(); HistoryRecord record0 = HistoryHelpers.createHistory4();
@ -270,7 +267,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
closeDataAccessor(dataAccessor); closeDataAccessor(dataAccessor);
} }
public void testInvalidHistoryItemIsSkipped() throws NullCursorException { public void testInvalidHistoryItemIsSkipped() throws Exception {
final HistoryRepositorySession session = (HistoryRepositorySession) createAndBeginSession(); final HistoryRepositorySession session = (HistoryRepositorySession) createAndBeginSession();
final DataAccessor dbHelper = new HistoryDataAccessor(getApplicationContext()); final DataAccessor dbHelper = new HistoryDataAccessor(getApplicationContext());
@ -312,7 +309,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
session.abort(); session.abort();
} }
public void testSqlInjectPurgeDelete() { public void testSqlInjectPurgeDelete() throws Exception {
// Some setup. // Some setup.
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
final DataAccessor db = getDataAccessor(); final DataAccessor db = getDataAccessor();
@ -397,7 +394,7 @@ public class TestAndroidBrowserHistoryRepository extends ThreadedRepositoryTestC
return cur; return cur;
} }
public void testDataAccessorBulkInsert() throws NullCursorException { public void testDataAccessorBulkInsert() throws Exception {
final HistoryRepositorySession session = (HistoryRepositorySession) createAndBeginSession(); final HistoryRepositorySession session = (HistoryRepositorySession) createAndBeginSession();
final HistoryDataAccessor db = new HistoryDataAccessor(getApplicationContext()); final HistoryDataAccessor db = new HistoryDataAccessor(getApplicationContext());

Просмотреть файл

@ -14,7 +14,6 @@ import org.mozilla.gecko.R;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
import org.mozilla.gecko.background.sync.helpers.BookmarkHelpers; import org.mozilla.gecko.background.sync.helpers.BookmarkHelpers;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessCreationDelegate;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate; import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate; import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate; import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate;
@ -48,7 +47,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
/** /**
* Trivial test that pinned items will be skipped if present in the DB. * Trivial test that pinned items will be skipped if present in the DB.
*/ */
public void testPinnedItemsAreNotRetrieved() { public void testPinnedItemsAreNotRetrieved() throws SyncException {
final BookmarksRepository repo = new BookmarksRepository(); final BookmarksRepository repo = new BookmarksRepository();
// Ensure that they exist. // Ensure that they exist.
@ -69,7 +68,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
assertFalse(guids.contains("dapinneditem")); assertFalse(guids.contains("dapinneditem"));
} }
public void testRetrieveFolderHasAccurateChildren() { public void testRetrieveFolderHasAccurateChildren() throws SyncException {
BookmarksRepository repo = new BookmarksRepository(); BookmarksRepository repo = new BookmarksRepository();
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
@ -179,7 +178,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
assertChildrenAreOrdered(repo, folderGUID, children); assertChildrenAreOrdered(repo, folderGUID, children);
} }
public void testMergeFoldersPreservesSaneOrder() { public void testMergeFoldersPreservesSaneOrder() throws SyncException {
BookmarksRepository repo = new BookmarksRepository(); BookmarksRepository repo = new BookmarksRepository();
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
@ -271,7 +270,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
* stored in the database. Verify that the parent folder is not flagged * stored in the database. Verify that the parent folder is not flagged
* for reupload (i.e., that its modified time is *ahem* unmodified). * for reupload (i.e., that its modified time is *ahem* unmodified).
*/ */
public void testNoReorderingMeansNoReupload() { public void testNoReorderingMeansNoReupload() throws SyncException {
BookmarksRepository repo = new BookmarksRepository(); BookmarksRepository repo = new BookmarksRepository();
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
@ -355,7 +354,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
* marked as deleted. In a database with constraints, this would fail * marked as deleted. In a database with constraints, this would fail
* if we simply deleted the records, so we move them first. * if we simply deleted the records, so we move them first.
*/ */
public void testFolderDeletionOrphansChildren() { public void testFolderDeletionOrphansChildren() throws SyncException {
BookmarksRepository repo = new BookmarksRepository(); BookmarksRepository repo = new BookmarksRepository();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -467,7 +466,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
* new GUID), whilst adding children to it. Verifies that replace and insert * new GUID), whilst adding children to it. Verifies that replace and insert
* co-operate. * co-operate.
*/ */
public void testInsertAndReplaceGuid() { public void testInsertAndReplaceGuid() throws SyncException {
BookmarksRepository repo = new BookmarksRepository(); BookmarksRepository repo = new BookmarksRepository();
wipe(); wipe();
@ -517,7 +516,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
* new title but the same GUID), whilst adding children to it. Verifies that * new title but the same GUID), whilst adding children to it. Verifies that
* replace and insert co-operate. * replace and insert co-operate.
*/ */
public void testInsertAndReplaceTitle() { public void testInsertAndReplaceTitle() throws SyncException {
BookmarksRepository repo = new BookmarksRepository(); BookmarksRepository repo = new BookmarksRepository();
wipe(); wipe();
@ -562,30 +561,6 @@ public class TestBookmarks extends AndroidSyncTestCase {
assertEquals(bmk2.title, fetchGUID(repo, bmk2.guid).title); assertEquals(bmk2.title, fetchGUID(repo, bmk2.guid).title);
} }
/**
* Create and begin a new session, handing control to the delegate when started.
* Returns when the delegate has notified.
*/
private void inBegunSession(final BookmarksRepository repo) {
Runnable go = new Runnable() {
@Override
public void run() {
repo.createSession(new SimpleSuccessCreationDelegate() {
@Override
public void onSessionCreated(final RepositorySession session) {
try {
session.begin();
performNotify();
} catch (SyncException e) {
performNotify("Begin failed", e);
}
}
}, getApplicationContext());
}
};
performWait(go);
}
/** /**
* Finish the provided session, notifying on success. * Finish the provided session, notifying on success.
* *
@ -616,127 +591,109 @@ public class TestBookmarks extends AndroidSyncTestCase {
*/ */
private void storeRecordsInSession(BookmarksRepository repo, private void storeRecordsInSession(BookmarksRepository repo,
final BookmarkRecord[] records, final BookmarkRecord[] records,
final Collection<String> tracked) { final Collection<String> tracked) throws SyncException {
repo.createSession(new SimpleSuccessCreationDelegate() { final RepositorySession session = repo.createSession(getApplicationContext());
session.begin();
RepositorySessionStoreDelegate storeDelegate = new SimpleSuccessStoreDelegate() {
@Override @Override
public void onSessionCreated(final RepositorySession session) { public void onStoreCompleted() {
try { // Pass back whatever we tracked.
session.begin(); if (tracked != null) {
} catch (SyncException e) { Iterator<String> iter = session.getTrackedRecordIDs();
performNotify("Begin failed", e); while (iter.hasNext()) {
} tracked.add(iter.next());
RepositorySessionStoreDelegate storeDelegate = new SimpleSuccessStoreDelegate() {
@Override
public void onStoreCompleted() {
// Pass back whatever we tracked.
if (tracked != null) {
Iterator<String> iter = session.getTrackedRecordIDs();
while (iter.hasNext()) {
tracked.add(iter.next());
}
}
finishAndNotify(session);
}
@Override
public void onRecordStoreSucceeded(String guid) {
}
@Override
public void onRecordStoreReconciled(String guid, String oldGuid, Integer newVersion) {
}
@Override
public void onStoreFailed(Exception e) {
}
};
session.setStoreDelegate(storeDelegate);
for (BookmarkRecord record : records) {
try {
session.store(record);
} catch (NoStoreDelegateException e) {
// Never happens.
} }
} }
session.storeDone(); finishAndNotify(session);
} }
}, getApplicationContext());
@Override
public void onRecordStoreSucceeded(String guid) {
}
@Override
public void onRecordStoreReconciled(String guid, String oldGuid, Integer newVersion) {
}
@Override
public void onStoreFailed(Exception e) {
}
};
session.setStoreDelegate(storeDelegate);
for (BookmarkRecord record : records) {
try {
session.store(record);
} catch (NoStoreDelegateException e) {
// Never happens.
}
}
session.storeDone();
} }
public ArrayList<String> fetchGUIDs(BookmarksRepository repo) { private ArrayList<String> fetchGUIDs(BookmarksRepository repo) throws SyncException {
final ArrayList<String> fetchedGUIDs = new ArrayList<String>(); final ArrayList<String> fetchedGUIDs = new ArrayList<>();
repo.createSession(new SimpleSuccessCreationDelegate() { final RepositorySession session = repo.createSession(getApplicationContext());
session.begin();
RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
@Override @Override
public void onSessionCreated(final RepositorySession session) { public void onFetchedRecord(Record record) {
try { fetchedGUIDs.add(record.guid);
session.begin();
} catch (SyncException e) {
performNotify("Begin failed", e);
}
RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
@Override
public void onFetchedRecord(Record record) {
fetchedGUIDs.add(record.guid);
}
@Override
public void onFetchCompleted() {
finishAndNotify(session);
}
@Override
public void onBatchCompleted() {
}
};
session.fetchModified(fetchDelegate);
} }
}, getApplicationContext());
@Override
public void onFetchCompleted() {
finishAndNotify(session);
}
@Override
public void onBatchCompleted() {
}
};
session.fetchModified(fetchDelegate);
return fetchedGUIDs; return fetchedGUIDs;
} }
private BookmarkRecord fetchGUID(BookmarksRepository repo, private BookmarkRecord fetchGUID(BookmarksRepository repo,
final String guid) { final String guid) throws SyncException {
Logger.info(LOG_TAG, "Fetching for " + guid); Logger.info(LOG_TAG, "Fetching for " + guid);
final ArrayList<Record> fetchedRecords = new ArrayList<>(); final ArrayList<Record> fetchedRecords = new ArrayList<>();
repo.createSession(new SimpleSuccessCreationDelegate() { final RepositorySession session = repo.createSession(getApplicationContext());
session.begin();
final RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
@Override @Override
public void onSessionCreated(final RepositorySession session) { public void onFetchedRecord(Record record) {
fetchedRecords.add(record);
}
@Override
public void onFetchCompleted() {
finishAndNotify(session);
}
@Override
public void onBatchCompleted() {
}
};
performWait(new Runnable() {
@Override
public void run() {
try { try {
session.begin(); session.fetch(new String[]{guid}, fetchDelegate);
} catch (SyncException e) {
performNotify("Begin failed", e);
}
RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() {
@Override
public void onFetchedRecord(Record record) {
fetchedRecords.add(record);
}
@Override
public void onFetchCompleted() {
finishAndNotify(session);
}
@Override
public void onBatchCompleted() {
}
};
try {
session.fetch(new String[] { guid }, fetchDelegate);
} catch (InactiveSessionException e) { } catch (InactiveSessionException e) {
performNotify("Session is inactive.", e); performNotify(e);
} }
} }
}, getApplicationContext()); });
assertEquals(1, fetchedRecords.size()); assertEquals(1, fetchedRecords.size());
Record fetchedRecord = fetchedRecords.get(0); Record fetchedRecord = fetchedRecords.get(0);
@ -746,7 +703,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
} }
public JSONArray fetchChildrenForGUID(BookmarksRepository repo, public JSONArray fetchChildrenForGUID(BookmarksRepository repo,
final String guid) { final String guid) throws SyncException {
return fetchGUID(repo, guid).children; return fetchGUID(repo, guid).children;
} }
@ -927,7 +884,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
getDataAccessor().wipe(); getDataAccessor().wipe();
} }
protected void assertChildrenAreOrdered(BookmarksRepository repo, String guid, Record[] expected) { protected void assertChildrenAreOrdered(BookmarksRepository repo, String guid, Record[] expected) throws SyncException {
Logger.debug(getName(), "Fetching children..."); Logger.debug(getName(), "Fetching children...");
JSONArray folderChildren = fetchChildrenForGUID(repo, guid); JSONArray folderChildren = fetchChildrenForGUID(repo, guid);
@ -939,7 +896,7 @@ public class TestBookmarks extends AndroidSyncTestCase {
} }
} }
protected void assertChildrenAreUnordered(BookmarksRepository repo, String guid, Record[] expected) { protected void assertChildrenAreUnordered(BookmarksRepository repo, String guid, Record[] expected) throws SyncException {
Logger.debug(getName(), "Fetching children..."); Logger.debug(getName(), "Fetching children...");
JSONArray folderChildren = fetchChildrenForGUID(repo, guid); JSONArray folderChildren = fetchChildrenForGUID(repo, guid);

Просмотреть файл

@ -10,13 +10,13 @@ import org.mozilla.gecko.background.sync.helpers.SessionTestHelper;
import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate; import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.Clients; import org.mozilla.gecko.db.BrowserContract.Clients;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.repositories.NoContentProviderException; import org.mozilla.gecko.sync.repositories.NoContentProviderException;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository; import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository.FennecTabsRepositorySession; import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository.FennecTabsRepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.domain.ClientRecord; import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
import org.mozilla.gecko.sync.repositories.domain.TabsRecord; import org.mozilla.gecko.sync.repositories.domain.TabsRecord;
@ -106,10 +106,9 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
*/ */
return new FennecTabsRepository(clientsDataDelegate) { return new FennecTabsRepository(clientsDataDelegate) {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) throws SessionCreateException {
Context context) {
try { try {
final FennecTabsRepositorySession session = new FennecTabsRepositorySession(this, context) { return new FennecTabsRepositorySession(this, context) {
@Override @Override
protected synchronized void trackGUID(String guid) { protected synchronized void trackGUID(String guid) {
} }
@ -124,9 +123,8 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
return TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS; return TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS;
} }
}; };
delegate.onSessionCreated(session);
} catch (Exception e) { } catch (Exception e) {
delegate.onSessionCreateFailed(e); throw new SessionCreateException(e);
} }
} }
}; };
@ -212,7 +210,7 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
} }
} }
public void testFetchAll() throws NoContentProviderException, RemoteException { public void testFetchAll() throws Exception {
final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord(); final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
final FennecTabsRepositorySession session = createAndBeginSession(); final FennecTabsRepositorySession session = createAndBeginSession();
@ -221,7 +219,7 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
session.abort(); session.abort();
} }
public void testFetchSince() throws NoContentProviderException, RemoteException { public void testFetchSince() throws Exception {
final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord(); final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
final FennecTabsRepositorySession session = createAndBeginSession(); final FennecTabsRepositorySession session = createAndBeginSession();
@ -248,7 +246,7 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase {
// Verify that storing a tabs record writes a clients record with the correct // Verify that storing a tabs record writes a clients record with the correct
// device type to the Fennec clients provider. // device type to the Fennec clients provider.
public void testStore() throws NoContentProviderException, RemoteException { public void testStore() throws Exception {
// Get a valid tabsRecord to write. // Get a valid tabsRecord to write.
final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord(); final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
deleteAllTestTabs(tabsClient); deleteAllTestTabs(tabsClient);

Просмотреть файл

@ -13,13 +13,13 @@ import org.mozilla.gecko.background.sync.helpers.ExpectStoredDelegate;
import org.mozilla.gecko.background.sync.helpers.SessionTestHelper; import org.mozilla.gecko.background.sync.helpers.SessionTestHelper;
import org.mozilla.gecko.background.testhelpers.WaitHelper; import org.mozilla.gecko.background.testhelpers.WaitHelper;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoContentProviderException; import org.mozilla.gecko.sync.repositories.NoContentProviderException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.FormHistoryRepositorySession; import org.mozilla.gecko.sync.repositories.android.FormHistoryRepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
import org.mozilla.gecko.sync.repositories.domain.FormHistoryRecord; import org.mozilla.gecko.sync.repositories.domain.FormHistoryRecord;
@ -69,17 +69,15 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
*/ */
return new FormHistoryRepositorySession.FormHistoryRepository() { return new FormHistoryRepositorySession.FormHistoryRepository() {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) throws SessionCreateException {
Context context) {
try { try {
final FormHistoryRepositorySession session = new FormHistoryRepositorySession(this, context) { return new FormHistoryRepositorySession(this, context) {
@Override @Override
protected synchronized void trackGUID(String guid) { protected synchronized void trackGUID(String guid) {
} }
}; };
delegate.onSessionCreated(session);
} catch (Exception e) { } catch (Exception e) {
delegate.onSessionCreateFailed(e); throw new SessionCreateException(e);
} }
} }
}; };
@ -98,7 +96,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
getRepository()); getRepository());
} }
public void testAcquire() throws NoContentProviderException { public void testAcquire() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
assertNotNull(session.getFormsProvider()); assertNotNull(session.getFormsProvider());
session.abort(); session.abort();
@ -186,7 +184,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
after4 = System.currentTimeMillis(); after4 = System.currentTimeMillis();
} }
public void testWipe() throws NoContentProviderException, RemoteException { public void testWipe() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertTwoRecords(session); insertTwoRecords(session);
@ -248,7 +246,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
}; };
} }
public void testFetchAll() throws NoContentProviderException, RemoteException { public void testFetchAll() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertTwoRecords(session); insertTwoRecords(session);
@ -258,7 +256,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
session.abort(); session.abort();
} }
public void testFetchByGuid() throws NoContentProviderException, RemoteException { public void testFetchByGuid() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertTwoRecords(session); insertTwoRecords(session);
@ -279,7 +277,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
session.abort(); session.abort();
} }
public void testFetchSince() throws NoContentProviderException, RemoteException { public void testFetchSince() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertFourRecords(session); insertFourRecords(session);
@ -313,7 +311,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
}; };
} }
public void testStoreRemoteNew() throws NoContentProviderException, RemoteException { public void testStoreRemoteNew() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertTwoRecords(session); insertTwoRecords(session);
@ -335,7 +333,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
session.abort(); session.abort();
} }
public void testStoreRemoteNewer() throws NoContentProviderException, RemoteException { public void testStoreRemoteNewer() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertFourRecords(session); insertFourRecords(session);
@ -370,7 +368,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
session.abort(); session.abort();
} }
public void testStoreRemoteOlder() throws NoContentProviderException, RemoteException { public void testStoreRemoteOlder() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
long oldTimestamp = System.currentTimeMillis() - 100; long oldTimestamp = System.currentTimeMillis() - 100;
@ -401,7 +399,7 @@ public class TestFormHistoryRepositorySession extends AndroidSyncTestCase {
session.abort(); session.abort();
} }
public void testStoreDifferentGuid() throws NoContentProviderException, RemoteException { public void testStoreDifferentGuid() throws Exception {
final FormHistoryRepositorySession session = createAndBeginSession(); final FormHistoryRepositorySession session = createAndBeginSession();
insertTwoRecords(session); insertTwoRecords(session);

Просмотреть файл

@ -23,7 +23,6 @@ import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.mozilla.gecko.sync.repositories.android.PasswordsRepositorySession; import org.mozilla.gecko.sync.repositories.android.PasswordsRepositorySession;
import org.mozilla.gecko.sync.repositories.android.RepoUtils; import org.mozilla.gecko.sync.repositories.android.RepoUtils;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate;
import org.mozilla.gecko.sync.repositories.domain.PasswordRecord; import org.mozilla.gecko.sync.repositories.domain.PasswordRecord;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
@ -32,7 +31,6 @@ import android.content.ContentProviderClient;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.os.RemoteException;
public class TestPasswordsRepository extends AndroidSyncTestCase { public class TestPasswordsRepository extends AndroidSyncTestCase {
private final String NEW_PASSWORD1 = "password"; private final String NEW_PASSWORD1 = "password";
@ -44,7 +42,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
assertTrue(WaitHelper.getTestWaiter().isIdle()); assertTrue(WaitHelper.getTestWaiter().isIdle());
} }
public void testFetchAll() { public void testFetchAll() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
Record[] expected = new Record[] { PasswordHelpers.createPassword1(), Record[] expected = new Record[] { PasswordHelpers.createPassword1(),
PasswordHelpers.createPassword2() }; PasswordHelpers.createPassword2() };
@ -56,7 +54,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testFetchSinceOneRecord() { public void testFetchSinceOneRecord() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
// Passwords fetchModified checks timePasswordChanged, not insertion time. // Passwords fetchModified checks timePasswordChanged, not insertion time.
@ -77,7 +75,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testFetchSinceReturnNoRecords() { public void testFetchSinceReturnNoRecords() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
performWait(storeRunnable(session, PasswordHelpers.createPassword2())); performWait(storeRunnable(session, PasswordHelpers.createPassword2()));
@ -88,7 +86,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testFetchOneRecordByGuid() { public void testFetchOneRecordByGuid() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
Record record = PasswordHelpers.createPassword1(); Record record = PasswordHelpers.createPassword1();
performWait(storeRunnable(session, record)); performWait(storeRunnable(session, record));
@ -100,7 +98,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testFetchMultipleRecordsByGuids() { public void testFetchMultipleRecordsByGuids() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
PasswordRecord record1 = PasswordHelpers.createPassword1(); PasswordRecord record1 = PasswordHelpers.createPassword1();
PasswordRecord record2 = PasswordHelpers.createPassword2(); PasswordRecord record2 = PasswordHelpers.createPassword2();
@ -116,7 +114,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testFetchNoRecordByGuid() { public void testFetchNoRecordByGuid() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
Record record = PasswordHelpers.createPassword1(); Record record = PasswordHelpers.createPassword1();
@ -127,13 +125,13 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testStore() { public void testStore() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
performWait(storeRunnable(session, PasswordHelpers.createPassword1())); performWait(storeRunnable(session, PasswordHelpers.createPassword1()));
dispose(session); dispose(session);
} }
public void testRemoteNewerTimeStamp() { public void testRemoteNewerTimeStamp() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
// Store updated local record. // Store updated local record.
@ -183,7 +181,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testLocalNewerTimeStamp() { public void testLocalNewerTimeStamp() throws Exception {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
// Remote record updated before local record. // Remote record updated before local record.
PasswordRecord remote = PasswordHelpers.createPassword1(); PasswordRecord remote = PasswordHelpers.createPassword1();
@ -242,7 +240,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
* Store two records that are identical except for guid. Expect to find the * Store two records that are identical except for guid. Expect to find the
* remote one after reconciling. * remote one after reconciling.
*/ */
public void testStoreIdenticalExceptGuid() { public void testStoreIdenticalExceptGuid() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
PasswordRecord record = PasswordHelpers.createPassword1(); PasswordRecord record = PasswordHelpers.createPassword1();
record.guid = "before1"; record.guid = "before1";
@ -276,7 +274,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
* to the same site and there are multiple records for that site. Expect to * to the same site and there are multiple records for that site. Expect to
* find the remote one after reconciling. * find the remote one after reconciling.
*/ */
public void testStoreIdenticalExceptGuidOnSameSite() { public void testStoreIdenticalExceptGuidOnSameSite() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
PasswordRecord record1 = PasswordHelpers.createPassword1(); PasswordRecord record1 = PasswordHelpers.createPassword1();
record1.encryptedUsername = "original"; record1.encryptedUsername = "original";
@ -304,7 +302,7 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
dispose(session); dispose(session);
} }
public void testRawFetch() throws RemoteException { public void testRawFetch() throws Exception {
RepositorySession session = createAndBeginSession(); RepositorySession session = createAndBeginSession();
Record[] expected = new Record[] { PasswordHelpers.createPassword1(), Record[] expected = new Record[] { PasswordHelpers.createPassword1(),
PasswordHelpers.createPassword2() }; PasswordHelpers.createPassword2() };
@ -343,15 +341,12 @@ public class TestPasswordsRepository extends AndroidSyncTestCase {
*/ */
return new PasswordsRepositorySession.PasswordsRepository() { return new PasswordsRepositorySession.PasswordsRepository() {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new PasswordsRepositorySession(this, context) {
PasswordsRepositorySession session;
session = new PasswordsRepositorySession(this, context) {
@Override @Override
protected synchronized void trackGUID(String guid) { protected synchronized void trackGUID(String guid) {
} }
}; };
delegate.onSessionCreated(session);
} }
}; };
} }

Просмотреть файл

@ -10,7 +10,6 @@ import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
import org.mozilla.gecko.background.sync.helpers.DefaultCleanDelegate; import org.mozilla.gecko.background.sync.helpers.DefaultCleanDelegate;
import org.mozilla.gecko.background.sync.helpers.DefaultFetchDelegate; import org.mozilla.gecko.background.sync.helpers.DefaultFetchDelegate;
import org.mozilla.gecko.background.sync.helpers.DefaultFinishDelegate; import org.mozilla.gecko.background.sync.helpers.DefaultFinishDelegate;
import org.mozilla.gecko.background.sync.helpers.DefaultSessionCreationDelegate;
import org.mozilla.gecko.background.sync.helpers.DefaultStoreDelegate; import org.mozilla.gecko.background.sync.helpers.DefaultStoreDelegate;
import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate;
import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate; import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate;
@ -624,8 +623,9 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
public void testCreateSessionNullContext() { public void testCreateSessionNullContext() {
Logger.debug(LOG_TAG, "In testCreateSessionNullContext."); Logger.debug(LOG_TAG, "In testCreateSessionNullContext.");
Repository repo = getRepository(); Repository repo = getRepository();
try { try {
repo.createSession(new DefaultSessionCreationDelegate(), null); repo.createSession(null);
fail("Should throw."); fail("Should throw.");
} catch (Exception ex) { } catch (Exception ex) {
assertNotNull(ex); assertNotNull(ex);
@ -675,7 +675,7 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
fail("Should have caught InvalidSessionTransitionException."); fail("Should have caught InvalidSessionTransitionException.");
} }
public void testBeginOnFinishedSession() throws InactiveSessionException { public void testBeginOnFinishedSession() {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
performWait(finishRunnable(session, new ExpectFinishDelegate())); performWait(finishRunnable(session, new ExpectFinishDelegate()));
try { try {
@ -692,7 +692,7 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
fail("Should have caught InvalidSessionTransitionException."); fail("Should have caught InvalidSessionTransitionException.");
} }
public void testFinishOnFinishedSession() throws InactiveSessionException { public void testFinishOnFinishedSession() {
final RepositorySession session = createAndBeginSession(); final RepositorySession session = createAndBeginSession();
performWait(finishRunnable(session, new ExpectFinishDelegate())); performWait(finishRunnable(session, new ExpectFinishDelegate()));
try { try {
@ -704,7 +704,7 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
fail("Should have caught InactiveSessionException."); fail("Should have caught InactiveSessionException.");
} }
public void testFetchOnInactiveSession() throws InactiveSessionException { public void testFetchOnInactiveSession() {
final RepositorySession session = createSession(); final RepositorySession session = createSession();
try { try {
session.fetch(new String[] { Utils.generateGuid() }, new DefaultFetchDelegate()); session.fetch(new String[] { Utils.generateGuid() }, new DefaultFetchDelegate());
@ -730,12 +730,6 @@ public abstract class ThreadedRepositoryTestCase extends AndroidSyncTestCase {
fail("Should have caught InactiveSessionException."); fail("Should have caught InactiveSessionException.");
} }
private static void verifyInactiveException(Exception ex) {
if (!(ex instanceof InactiveSessionException)) {
fail("Wrong exception type");
}
}
protected void closeDataAccessor(DataAccessor dataAccessor) { protected void closeDataAccessor(DataAccessor dataAccessor) {
} }
} }

Просмотреть файл

@ -10,20 +10,16 @@ import junit.framework.AssertionFailedError;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessCreationDelegate;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate; import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate; import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate;
import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate; import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate;
import org.mozilla.gecko.background.testhelpers.WBORepository; import org.mozilla.gecko.background.testhelpers.WBORepository;
import org.mozilla.gecko.sync.CryptoRecord; import org.mozilla.gecko.sync.CryptoRecord;
import org.mozilla.gecko.sync.ExtendedJSONObject; import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
import org.mozilla.gecko.sync.synchronizer.Synchronizer; import org.mozilla.gecko.sync.synchronizer.Synchronizer;
@ -134,30 +130,33 @@ public class TestStoreTracking extends AndroidSyncTestCase {
} }
}; };
session.setStoreDelegate(storeDelegate); final Runnable doStore = new Runnable() {
try { @Override
Logger.debug(getName(), "Storing..."); public void run() {
session.store(record); session.setStoreDelegate(storeDelegate);
session.storeDone(); try {
} catch (NoStoreDelegateException e) { Logger.debug(getName(), "Storing...");
// Should not happen. session.store(record);
} session.storeDone();
} catch (NoStoreDelegateException e) {
throw new IllegalStateException(e);
}
}
};
performWait(doStore);
} }
private void doTestNewSessionRetrieveByTime(final WBORepository repository, private void doTestNewSessionRetrieveByTime(final WBORepository repository,
final String expectedGUID) { final String expectedGUID) throws Exception {
final SimpleSuccessCreationDelegate createDelegate = new SimpleSuccessCreationDelegate() { final RepositorySession session = repository.createSession(getApplicationContext());
@Override Logger.debug(getName(), "Session created.");
public void onSessionCreated(final RepositorySession session) { session.begin();
Logger.debug(getName(), "Session created.");
try {
session.begin();
} catch (SyncException e) {
e.printStackTrace();
performNotify(e);
}
// Now we get a result. // Now we get a result.
final Runnable doFetch = new Runnable() {
@Override
public void run() {
session.fetchModified(new SimpleSuccessFetchDelegate() { session.fetchModified(new SimpleSuccessFetchDelegate() {
@Override @Override
public void onFetchedRecord(Record record) { public void onFetchedRecord(Record record) {
@ -171,9 +170,13 @@ public class TestStoreTracking extends AndroidSyncTestCase {
@Override @Override
public void onFinishSucceeded(RepositorySession session, public void onFinishSucceeded(RepositorySession session,
RepositorySessionBundle bundle) { RepositorySessionBundle bundle) {
// Hooray!
performNotify(); performNotify();
} }
@Override
public void onFinishFailed(Exception ex) {
performNotify(ex);
}
}); });
} catch (InactiveSessionException e) { } catch (InactiveSessionException e) {
performNotify(e); performNotify(e);
@ -186,14 +189,8 @@ public class TestStoreTracking extends AndroidSyncTestCase {
}); });
} }
}; };
Runnable create = new Runnable() {
@Override
public void run() {
repository.createSession(createDelegate, getApplicationContext());
}
};
performWait(create); performWait(doFetch);
} }
/** /**
@ -204,49 +201,20 @@ public class TestStoreTracking extends AndroidSyncTestCase {
* *
* Invokes doTestStoreRetrieveByGUID, doTestNewSessionRetrieveByTime. * Invokes doTestStoreRetrieveByGUID, doTestNewSessionRetrieveByTime.
*/ */
public void testStoreRetrieveByGUID() { public void testStoreRetrieveByGUID() throws Exception {
Logger.debug(getName(), "Started."); Logger.debug(getName(), "Started.");
final WBORepository r = new TrackingWBORepository(); final WBORepository r = new TrackingWBORepository();
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final String expectedGUID = "abcdefghijkl"; final String expectedGUID = "abcdefghijkl";
final Record record = new BookmarkRecord(expectedGUID, "bookmarks", now , false); final Record record = new BookmarkRecord(expectedGUID, "bookmarks", now , false);
final RepositorySessionCreationDelegate createDelegate = new SimpleSuccessCreationDelegate() {
@Override
public void onSessionCreated(RepositorySession session) {
Logger.debug(getName(), "Session created: " + session);
try {
session.begin();
} catch (SyncException e) {
e.printStackTrace();
performNotify(e);
}
doTestStoreRetrieveByGUID(r, session, expectedGUID, record);
}
};
final Context applicationContext = getApplicationContext(); final Context applicationContext = getApplicationContext();
// This has to happen on a new thread so that we final RepositorySession session = r.createSession(applicationContext);
// can wait for it! session.begin();
Runnable create = onThreadRunnable(new Runnable() { doTestStoreRetrieveByGUID(r, session, expectedGUID, record);
@Override
public void run() {
r.createSession(createDelegate, applicationContext);
}
});
Runnable retrieve = onThreadRunnable(new Runnable() { doTestNewSessionRetrieveByTime(r, expectedGUID);
@Override
public void run() {
doTestNewSessionRetrieveByTime(r, expectedGUID);
performNotify();
}
});
performWait(create);
performWait(retrieve);
} }
private Runnable onThreadRunnable(final Runnable r) { private Runnable onThreadRunnable(final Runnable r) {
@ -276,9 +244,8 @@ public class TestStoreTracking extends AndroidSyncTestCase {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new CountingWBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new CountingWBORepositorySession(this));
} }
} }

Просмотреть файл

@ -1,53 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.background.sync.helpers;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
public class DefaultSessionCreationDelegate extends DefaultDelegate implements
RepositorySessionCreationDelegate {
@Override
public void onSessionCreateFailed(Exception ex) {
performNotify("Session creation failed", ex);
}
@Override
public void onSessionCreated(RepositorySession session) {
performNotify("Should not have been created.", null);
}
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
final RepositorySessionCreationDelegate self = this;
return new RepositorySessionCreationDelegate() {
@Override
public void onSessionCreated(final RepositorySession session) {
new Thread(new Runnable() {
@Override
public void run() {
self.onSessionCreated(session);
}
}).start();
}
@Override
public void onSessionCreateFailed(final Exception ex) {
new Thread(new Runnable() {
@Override
public void run() {
self.onSessionCreateFailed(ex);
}
}).start();
}
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
return this;
}
};
}
}

Просмотреть файл

@ -5,71 +5,34 @@ package org.mozilla.gecko.background.sync.helpers;
import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNotNull;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.background.testhelpers.WaitHelper;
import org.mozilla.gecko.sync.SyncException; import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import android.content.Context; import android.content.Context;
public class SessionTestHelper { public class SessionTestHelper {
private static RepositorySession prepareRepositorySession(
protected static RepositorySession prepareRepositorySession(
final Context context, final Context context,
final boolean begin, final boolean begin,
final Repository repository) { final Repository repository) {
final WaitHelper testWaiter = WaitHelper.getTestWaiter(); final RepositorySession session;
final String logTag = "prepareRepositorySession";
class CreationDelegate extends DefaultSessionCreationDelegate {
private RepositorySession session;
synchronized void setSession(RepositorySession session) {
this.session = session;
}
synchronized RepositorySession getSession() {
return this.session;
}
@Override
public void onSessionCreated(final RepositorySession session) {
assertNotNull(session);
Logger.info(logTag, "Setting session to " + session);
setSession(session);
if (begin) {
Logger.info(logTag, "Calling session.begin on new session.");
// The begin callbacks will notify.
try {
session.begin();
} catch (SyncException e) {
testWaiter.performNotify(e);
}
testWaiter.performNotify();
} else {
Logger.info(logTag, "Notifying after setting new session.");
testWaiter.performNotify();
}
}
}
final CreationDelegate delegate = new CreationDelegate();
try { try {
Runnable runnable = new Runnable() { session = repository.createSession(context);
@Override assertNotNull(session);
public void run() { } catch (SessionCreateException e) {
repository.createSession(delegate, context); throw new IllegalStateException(e);
}
};
testWaiter.performWait(runnable);
} catch (IllegalArgumentException ex) {
Logger.warn(logTag, "Caught IllegalArgumentException.");
} }
Logger.info(logTag, "Retrieving new session."); if (begin) {
final RepositorySession session = delegate.getSession(); try {
assertNotNull(session); session.begin();
} catch (SyncException e) {
throw new IllegalStateException(e);
}
}
return session; return session;
} }

Просмотреть файл

@ -1,18 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.background.sync.helpers;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
public abstract class SimpleSuccessCreationDelegate extends DefaultDelegate implements RepositorySessionCreationDelegate {
@Override
public void onSessionCreateFailed(Exception ex) {
performNotify("Session creation failed", ex);
}
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
return this;
}
}

Просмотреть файл

@ -14,8 +14,8 @@ import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RecordFilter; import org.mozilla.gecko.sync.repositories.RecordFilter;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession; import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
@ -212,9 +212,8 @@ public class WBORepository extends Repository {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new WBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this));
} }
public ConcurrentHashMap<String, Record> cloneWBOs() { public ConcurrentHashMap<String, Record> cloneWBOs() {

Просмотреть файл

@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync;
public class SessionCreateException extends SyncException {
private static final long serialVersionUID = -3852991560658529574L;
public SessionCreateException(Exception e) {
super(e);
}
}

Просмотреть файл

@ -6,10 +6,10 @@ package org.mozilla.gecko.sync.middleware;
import android.content.Context; import android.content.Context;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.middleware.storage.BufferStorage; import org.mozilla.gecko.sync.middleware.storage.BufferStorage;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
/** /**
* A buffering-enabled middleware which is intended to wrap local repositories. Configurable with * A buffering-enabled middleware which is intended to wrap local repositories. Configurable with
@ -17,33 +17,11 @@ import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDe
* *
* @author grisha * @author grisha
*/ */
public class BufferingMiddlewareRepository extends MiddlewareRepository { public class BufferingMiddlewareRepository extends Repository {
private final long syncDeadline; private final long syncDeadline;
private final Repository inner; private final Repository inner;
private final BufferStorage bufferStorage; private final BufferStorage bufferStorage;
private class BufferingMiddlewareRepositorySessionCreationDelegate extends MiddlewareRepository.SessionCreationDelegate {
private final BufferingMiddlewareRepository repository;
private final RepositorySessionCreationDelegate outerDelegate;
private BufferingMiddlewareRepositorySessionCreationDelegate(BufferingMiddlewareRepository repository, RepositorySessionCreationDelegate outerDelegate) {
this.repository = repository;
this.outerDelegate = outerDelegate;
}
@Override
public void onSessionCreateFailed(Exception ex) {
this.outerDelegate.onSessionCreateFailed(ex);
}
@Override
public void onSessionCreated(RepositorySession session) {
outerDelegate.onSessionCreated(new BufferingMiddlewareRepositorySession(
session, this.repository, syncDeadline, bufferStorage
));
}
}
public BufferingMiddlewareRepository(long syncDeadline, BufferStorage bufferStore, Repository wrappedRepository) { public BufferingMiddlewareRepository(long syncDeadline, BufferStorage bufferStore, Repository wrappedRepository) {
this.syncDeadline = syncDeadline; this.syncDeadline = syncDeadline;
this.inner = wrappedRepository; this.inner = wrappedRepository;
@ -51,10 +29,8 @@ public class BufferingMiddlewareRepository extends MiddlewareRepository {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) throws SessionCreateException {
this.inner.createSession( final RepositorySession innerSession = this.inner.createSession(context);
new BufferingMiddlewareRepositorySessionCreationDelegate(this, delegate), return new BufferingMiddlewareRepositorySession(innerSession, this, syncDeadline, bufferStorage);
context
);
} }
} }

Просмотреть файл

@ -11,6 +11,7 @@ import org.mozilla.gecko.sync.SyncDeadlineReachedException;
import org.mozilla.gecko.sync.middleware.storage.BufferStorage; import org.mozilla.gecko.sync.middleware.storage.BufferStorage;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate;
@ -33,7 +34,7 @@ import java.util.Collection;
private final long syncDeadlineMillis; private final long syncDeadlineMillis;
/* package-local */ BufferingMiddlewareRepositorySession( /* package-local */ BufferingMiddlewareRepositorySession(
RepositorySession repositorySession, MiddlewareRepository repository, RepositorySession repositorySession, BufferingMiddlewareRepository repository,
long syncDeadlineMillis, BufferStorage bufferStorage) { long syncDeadlineMillis, BufferStorage bufferStorage) {
super(repositorySession, repository); super(repositorySession, repository);
this.syncDeadlineMillis = syncDeadlineMillis; this.syncDeadlineMillis = syncDeadlineMillis;

Просмотреть файл

@ -4,13 +4,13 @@
package org.mozilla.gecko.sync.middleware; package org.mozilla.gecko.sync.middleware;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.repositories.IdentityRecordFactory; import org.mozilla.gecko.sync.repositories.IdentityRecordFactory;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import android.content.Context; import android.content.Context;
@ -21,39 +21,9 @@ import android.content.Context;
* @author rnewman * @author rnewman
* *
*/ */
public class Crypto5MiddlewareRepository extends MiddlewareRepository { public class Crypto5MiddlewareRepository extends Repository {
public RecordFactory recordFactory = new IdentityRecordFactory(); public RecordFactory recordFactory = new IdentityRecordFactory();
public class Crypto5MiddlewareRepositorySessionCreationDelegate extends MiddlewareRepository.SessionCreationDelegate {
private final Crypto5MiddlewareRepository repository;
private final RepositorySessionCreationDelegate outerDelegate;
public Crypto5MiddlewareRepositorySessionCreationDelegate(Crypto5MiddlewareRepository repository, RepositorySessionCreationDelegate outerDelegate) {
this.repository = repository;
this.outerDelegate = outerDelegate;
}
@Override
public void onSessionCreateFailed(Exception ex) {
this.outerDelegate.onSessionCreateFailed(ex);
}
@Override
public void onSessionCreated(RepositorySession session) {
// Do some work, then report success with the wrapping session.
Crypto5MiddlewareRepositorySession cryptoSession;
try {
// Synchronous, baby.
cryptoSession = new Crypto5MiddlewareRepositorySession(session, this.repository, recordFactory);
} catch (Exception ex) {
this.outerDelegate.onSessionCreateFailed(ex);
return;
}
this.outerDelegate.onSessionCreated(cryptoSession);
}
}
public KeyBundle keyBundle; public KeyBundle keyBundle;
private final Repository inner; private final Repository inner;
@ -62,10 +32,11 @@ public class Crypto5MiddlewareRepository extends MiddlewareRepository {
this.inner = inner; this.inner = inner;
this.keyBundle = keys; this.keyBundle = keys;
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) throws SessionCreateException {
Crypto5MiddlewareRepositorySessionCreationDelegate delegateWrapper = new Crypto5MiddlewareRepositorySessionCreationDelegate(this, delegate); final RepositorySession innerSession = inner.createSession(context);
inner.createSession(delegateWrapper, context); return new Crypto5MiddlewareRepositorySession(innerSession, this, recordFactory);
} }
@Override @Override

Просмотреть файл

@ -1,22 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.middleware;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
public abstract class MiddlewareRepository extends Repository {
public static abstract class SessionCreationDelegate implements
RepositorySessionCreationDelegate {
// We call through to our inner repository, so we don't need our own
// deferral scheme.
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
return this;
}
}
}

Просмотреть файл

@ -9,6 +9,7 @@ import java.util.concurrent.ExecutorService;
import org.mozilla.gecko.sync.SyncException; import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
@ -18,7 +19,7 @@ public abstract class MiddlewareRepositorySession extends RepositorySession {
private static final String LOG_TAG = "MiddlewareSession"; private static final String LOG_TAG = "MiddlewareSession";
protected final RepositorySession inner; protected final RepositorySession inner;
public MiddlewareRepositorySession(RepositorySession innerSession, MiddlewareRepository repository) { /* package-private */ MiddlewareRepositorySession(RepositorySession innerSession, Repository repository) {
super(repository); super(repository);
this.inner = innerSession; this.inner = innerSession;
} }
@ -37,7 +38,7 @@ public abstract class MiddlewareRepositorySession extends RepositorySession {
private final MiddlewareRepositorySession outerSession; private final MiddlewareRepositorySession outerSession;
private final RepositorySessionFinishDelegate next; private final RepositorySessionFinishDelegate next;
public MiddlewareRepositorySessionFinishDelegate(MiddlewareRepositorySession outerSession, RepositorySessionFinishDelegate next) { /* package-private */ MiddlewareRepositorySessionFinishDelegate(MiddlewareRepositorySession outerSession, RepositorySessionFinishDelegate next) {
this.outerSession = outerSession; this.outerSession = outerSession;
this.next = next; this.next = next;
} }

Просмотреть файл

@ -1,16 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.repositories;
/**
* Shared interface for repositories that consume and produce
* bookmark records.
*
* @author rnewman
*
*/
public interface BookmarksRepository {
}

Просмотреть файл

@ -1,16 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.repositories;
/**
* Shared interface for repositories that consume and produce
* history records.
*
* @author rnewman
*
*/
public interface HistoryRepository {
}

Просмотреть файл

@ -4,13 +4,13 @@
package org.mozilla.gecko.sync.repositories; package org.mozilla.gecko.sync.repositories;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import android.content.Context; import android.content.Context;
public abstract class Repository { public abstract class Repository {
public abstract void createSession(RepositorySessionCreationDelegate delegate, Context context); public abstract RepositorySession createSession(Context context) throws SessionCreateException;
public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) { public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
delegate.onCleaned(this); delegate.onCleaned(this);

Просмотреть файл

@ -23,7 +23,7 @@ import org.mozilla.gecko.sync.repositories.domain.Record;
* *
*<ul> *<ul>
* <li>Construct, with a reference to its parent {@link Repository}, by calling * <li>Construct, with a reference to its parent {@link Repository}, by calling
* {@link Repository#createSession(org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate, android.content.Context)}.</li> * {@link Repository#createSession(android.content.Context)}.</li>
* <li>Populate with saved information by calling {@link #unbundle(RepositorySessionBundle)}.</li> * <li>Populate with saved information by calling {@link #unbundle(RepositorySessionBundle)}.</li>
* <li>Begin a sync by calling {@link #begin()}. <code>begin()</code> * <li>Begin a sync by calling {@link #begin()}. <code>begin()</code>
* is an appropriate place to initialize expensive resources.</li> * is an appropriate place to initialize expensive resources.</li>

Просмотреть файл

@ -10,7 +10,6 @@ import java.net.URISyntaxException;
import org.mozilla.gecko.sync.InfoCollections; import org.mozilla.gecko.sync.InfoCollections;
import org.mozilla.gecko.sync.InfoConfiguration; import org.mozilla.gecko.sync.InfoConfiguration;
import org.mozilla.gecko.sync.net.AuthHeaderProvider; import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -73,9 +72,8 @@ public class Server15Repository extends Repository {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new Server15RepositorySession(this);
delegate.onSessionCreated(new Server15RepositorySession(this));
} }
public URI collectionURI() { public URI collectionURI() {

Просмотреть файл

@ -4,21 +4,33 @@
package org.mozilla.gecko.sync.repositories.android; package org.mozilla.gecko.sync.repositories.android;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
import android.content.Context; import android.content.Context;
public class BookmarksRepository extends ThreadedRepository implements org.mozilla.gecko.sync.repositories.BookmarksRepository { public class BookmarksRepository extends Repository {
@Override @Override
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) {
BookmarksRepositorySession session = new BookmarksRepositorySession(BookmarksRepository.this, context); return new BookmarksRepositorySession(this, context);
final RepositorySessionCreationDelegate deferredCreationDelegate = delegate.deferredCreationDelegate();
deferredCreationDelegate.onSessionCreated(session);
} }
@Override @Override
protected DataAccessor getDataAccessor(Context context) { public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
return new BookmarksDataAccessor(context); if (!success) {
return;
}
final BookmarksDataAccessor dataAccessor = new BookmarksDataAccessor(context);
try {
dataAccessor.purgeDeleted();
} catch (Exception e) {
delegate.onCleanFailed(this, e);
return;
}
delegate.onCleaned(this);
} }
} }

Просмотреть файл

@ -18,7 +18,6 @@ import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
@ -62,8 +61,8 @@ public class BookmarksValidationRepository extends Repository {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) {
delegate.onSessionCreated(new BookmarksValidationRepositorySession(this, context)); return new BookmarksValidationRepositorySession(this, context);
} }
public class BookmarksValidationRepositorySession extends RepositorySession { public class BookmarksValidationRepositorySession extends RepositorySession {

Просмотреть файл

@ -10,13 +10,13 @@ import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.background.db.Tab; import org.mozilla.gecko.background.db.Tab;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.Clients; import org.mozilla.gecko.db.BrowserContract.Clients;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoContentProviderException; import org.mozilla.gecko.sync.repositories.NoContentProviderException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
@ -309,13 +309,11 @@ public class FennecTabsRepository extends Repository {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) throws SessionCreateException {
Context context) {
try { try {
final FennecTabsRepositorySession session = new FennecTabsRepositorySession(this, context); return new FennecTabsRepositorySession(this, context);
delegate.onSessionCreated(session);
} catch (Exception e) { } catch (Exception e) {
delegate.onSessionCreateFailed(e); throw new SessionCreateException(e);
} }
} }

Просмотреть файл

@ -13,14 +13,15 @@ import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory; import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory;
import org.mozilla.gecko.db.BrowserContract.FormHistory; import org.mozilla.gecko.db.BrowserContract.FormHistory;
import org.mozilla.gecko.sync.SessionCreateException;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoContentProviderException; import org.mozilla.gecko.sync.repositories.NoContentProviderException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.NullCursorException; import org.mozilla.gecko.sync.repositories.NullCursorException;
import org.mozilla.gecko.sync.repositories.RecordFilter; import org.mozilla.gecko.sync.repositories.RecordFilter;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession; import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
@ -49,13 +50,11 @@ public class FormHistoryRepositorySession extends
public static class FormHistoryRepository extends Repository { public static class FormHistoryRepository extends Repository {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) throws SessionCreateException {
Context context) {
try { try {
final FormHistoryRepositorySession session = new FormHistoryRepositorySession(this, context); return new FormHistoryRepositorySession(this, context);
delegate.onSessionCreated(session);
} catch (Exception e) { } catch (Exception e) {
delegate.onSessionCreateFailed(e); throw new SessionCreateException(e);
} }
} }
} }

Просмотреть файл

@ -4,21 +4,33 @@
package org.mozilla.gecko.sync.repositories.android; package org.mozilla.gecko.sync.repositories.android;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
import android.content.Context; import android.content.Context;
public class HistoryRepository extends ThreadedRepository implements org.mozilla.gecko.sync.repositories.HistoryRepository { public class HistoryRepository extends Repository {
@Override @Override
protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) { public RepositorySession createSession(Context context) {
HistoryRepositorySession session = new HistoryRepositorySession(HistoryRepository.this, context); return new HistoryRepositorySession(this, context);
delegate.onSessionCreated(session);
} }
@Override @Override
protected DataAccessor getDataAccessor(Context context) { public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
return new HistoryDataAccessor(context); if (!success) {
} return;
}
final HistoryDataAccessor dataAccessor = new HistoryDataAccessor(context);
try {
dataAccessor.purgeDeleted();
} catch (Exception e) {
delegate.onCleanFailed(this, e);
return;
}
delegate.onCleaned(this);
}
} }

Просмотреть файл

@ -14,9 +14,9 @@ import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.NullCursorException; import org.mozilla.gecko.sync.repositories.NullCursorException;
import org.mozilla.gecko.sync.repositories.RecordFilter; import org.mozilla.gecko.sync.repositories.RecordFilter;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession; import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
import org.mozilla.gecko.sync.repositories.android.RepoUtils.QueryHelper; import org.mozilla.gecko.sync.repositories.android.RepoUtils.QueryHelper;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
@ -36,11 +36,8 @@ public class PasswordsRepositorySession extends
public static class PasswordsRepository extends Repository { public static class PasswordsRepository extends Repository {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new PasswordsRepositorySession(this, context);
PasswordsRepositorySession session = new PasswordsRepositorySession(PasswordsRepository.this, context);
final RepositorySessionCreationDelegate deferredCreationDelegate = delegate.deferredCreationDelegate();
deferredCreationDelegate.onSessionCreated(session);
} }
} }

Просмотреть файл

@ -1,73 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.repositories.android;
import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import android.content.Context;
public abstract class ThreadedRepository extends Repository {
@Override
public void createSession(RepositorySessionCreationDelegate delegate, Context context) {
new CreateSessionThread(delegate, context).start();
}
@Override
public void clean(boolean success, RepositorySessionCleanDelegate delegate, Context context) {
// Only clean deleted records if success
if (success) {
new CleanThread(delegate, context).start();
}
}
class CleanThread extends Thread {
private final RepositorySessionCleanDelegate delegate;
private final Context context;
public CleanThread(RepositorySessionCleanDelegate delegate, Context context) {
if (context == null) {
throw new IllegalArgumentException("context is null");
}
this.delegate = delegate;
this.context = context;
}
@Override
public void run() {
try {
getDataAccessor(context).purgeDeleted();
} catch (Exception e) {
delegate.onCleanFailed(ThreadedRepository.this, e);
return;
}
delegate.onCleaned(ThreadedRepository.this);
}
}
protected abstract DataAccessor getDataAccessor(Context context);
protected abstract void sessionCreator(RepositorySessionCreationDelegate delegate, Context context);
class CreateSessionThread extends Thread {
private final RepositorySessionCreationDelegate delegate;
private final Context context;
public CreateSessionThread(RepositorySessionCreationDelegate delegate, Context context) {
if (context == null) {
throw new IllegalArgumentException("context is null.");
}
this.delegate = delegate;
this.context = context;
}
@Override
public void run() {
sessionCreator(delegate, context);
}
}
}

Просмотреть файл

@ -1,41 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.repositories.delegates;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.repositories.RepositorySession;
public abstract class DeferrableRepositorySessionCreationDelegate implements RepositorySessionCreationDelegate {
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
final RepositorySessionCreationDelegate self = this;
return new RepositorySessionCreationDelegate() {
// TODO: rewrite to use ExecutorService.
@Override
public void onSessionCreated(final RepositorySession session) {
ThreadPool.run(new Runnable() {
@Override
public void run() {
self.onSessionCreated(session);
}});
}
@Override
public void onSessionCreateFailed(final Exception ex) {
ThreadPool.run(new Runnable() {
@Override
public void run() {
self.onSessionCreateFailed(ex);
}});
}
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
return this;
}
};
}
}

Просмотреть файл

@ -1,15 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync.repositories.delegates;
import org.mozilla.gecko.sync.repositories.RepositorySession;
// Used to provide the sessionCallback and storeCallback
// mechanism to repository instances.
public interface RepositorySessionCreationDelegate {
public void onSessionCreateFailed(Exception ex);
public void onSessionCreated(RepositorySession session);
public RepositorySessionCreationDelegate deferredCreationDelegate();
}

Просмотреть файл

@ -27,7 +27,6 @@ import org.mozilla.gecko.sync.net.SyncStorageRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse; import org.mozilla.gecko.sync.net.SyncStorageResponse;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
import org.mozilla.gecko.sync.repositories.NonPersistentRepositoryStateProvider; import org.mozilla.gecko.sync.repositories.NonPersistentRepositoryStateProvider;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
@ -35,7 +34,6 @@ import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import org.mozilla.gecko.sync.repositories.RepositoryStateProvider; import org.mozilla.gecko.sync.repositories.RepositoryStateProvider;
import org.mozilla.gecko.sync.repositories.Server15Repository; import org.mozilla.gecko.sync.repositories.Server15Repository;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
import org.mozilla.gecko.sync.synchronizer.ServerLocalSynchronizer; import org.mozilla.gecko.sync.synchronizer.ServerLocalSynchronizer;
@ -313,83 +311,76 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
final Runnable doWipe = new Runnable() { final Runnable doWipe = new Runnable() {
@Override @Override
public void run() { public void run() {
r.createSession(new RepositorySessionCreationDelegate() { final RepositorySession localSession;
try {
localSession = r.createSession(context);
} catch (Exception e) {
synchronized (monitor) {
monitor.notify(e, false);
}
return;
}
try {
localSession.begin();
} catch (SyncException e) {
Logger.error(LOG_TAG, "Couldn't begin session", e);
localSession.abort();
synchronized (monitor) {
monitor.notify(e, true);
}
return;
}
localSession.wipe(new RepositorySessionWipeDelegate() {
@Override @Override
public void onSessionCreated(final RepositorySession session) { public void onWipeSucceeded() {
try { try {
session.begin(); localSession.finish(new RepositorySessionFinishDelegate() {
} catch (SyncException e) {
Logger.error(LOG_TAG, "Couldn't begin session", e); @Override
session.abort(); public void onFinishSucceeded(RepositorySession session,
RepositorySessionBundle bundle) {
// Hurrah.
synchronized (monitor) {
monitor.notify();
}
}
@Override
public void onFinishFailed(Exception ex) {
// Assume that no finish => no wipe.
synchronized (monitor) {
monitor.notify(ex, true);
}
}
@Override
public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) {
return this;
}
});
} catch (InactiveSessionException e) {
// Cannot happen. Call for safety.
synchronized (monitor) { synchronized (monitor) {
monitor.notify(e, true); monitor.notify(e, true);
} }
return;
} }
session.wipe(new RepositorySessionWipeDelegate() {
@Override
public void onWipeSucceeded() {
try {
session.finish(new RepositorySessionFinishDelegate() {
@Override
public void onFinishSucceeded(RepositorySession session,
RepositorySessionBundle bundle) {
// Hurrah.
synchronized (monitor) {
monitor.notify();
}
}
@Override
public void onFinishFailed(Exception ex) {
// Assume that no finish => no wipe.
synchronized (monitor) {
monitor.notify(ex, true);
}
}
@Override
public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) {
return this;
}
});
} catch (InactiveSessionException e) {
// Cannot happen. Call for safety.
synchronized (monitor) {
monitor.notify(e, true);
}
}
}
@Override
public void onWipeFailed(Exception ex) {
session.abort();
synchronized (monitor) {
monitor.notify(ex, true);
}
}
@Override
public RepositorySessionWipeDelegate deferredWipeDelegate(ExecutorService executor) {
return this;
}
});
} }
@Override @Override
public void onSessionCreateFailed(Exception ex) { public void onWipeFailed(Exception ex) {
localSession.abort();
synchronized (monitor) { synchronized (monitor) {
monitor.notify(ex, false); monitor.notify(ex, true);
} }
} }
@Override @Override
public RepositorySessionCreationDelegate deferredCreationDelegate() { public RepositorySessionWipeDelegate deferredWipeDelegate(ExecutorService executor) {
return this; return this;
} }
}, context); });
} }
}; };

Просмотреть файл

@ -8,16 +8,10 @@ package org.mozilla.gecko.sync.stage;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.Nullable;
import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.MetaGlobalException; import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SynchronizerConfiguration;
import org.mozilla.gecko.sync.middleware.BufferingMiddlewareRepository;
import org.mozilla.gecko.sync.middleware.MiddlewareRepository;
import org.mozilla.gecko.sync.middleware.storage.MemoryBufferStorage;
import org.mozilla.gecko.sync.repositories.ConfigurableServer15Repository; import org.mozilla.gecko.sync.repositories.ConfigurableServer15Repository;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
@ -28,7 +22,6 @@ import org.mozilla.gecko.sync.repositories.domain.VersionConstants;
import org.mozilla.gecko.sync.telemetry.TelemetryCollector; import org.mozilla.gecko.sync.telemetry.TelemetryCollector;
import org.mozilla.gecko.sync.telemetry.TelemetryStageCollector; import org.mozilla.gecko.sync.telemetry.TelemetryStageCollector;
import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

Просмотреть файл

@ -40,11 +40,6 @@ public class Synchronizer implements SynchronizerSessionDelegate {
return session; return session;
} }
@Override
public void onInitialized(SynchronizerSession session) {
session.synchronize();
}
@Override @Override
public void onSynchronized(SynchronizerSession synchronizerSession) { public void onSynchronized(SynchronizerSession synchronizerSession) {
Logger.debug(LOG_TAG, "Got onSynchronized."); Logger.debug(LOG_TAG, "Got onSynchronized.");
@ -83,7 +78,7 @@ public class Synchronizer implements SynchronizerSessionDelegate {
public void synchronize(Context context, SynchronizerDelegate delegate) { public void synchronize(Context context, SynchronizerDelegate delegate) {
this.synchronizerDelegate = delegate; this.synchronizerDelegate = delegate;
this.session = newSynchronizerSession(); this.session = newSynchronizerSession();
this.session.init(context, bundleA, bundleB); this.session.initAndSynchronize(context, bundleA, bundleB);
} }
public SynchronizerConfiguration save() { public SynchronizerConfiguration save() {

Просмотреть файл

@ -9,11 +9,11 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import org.mozilla.gecko.sync.repositories.delegates.DeferrableRepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.DeferredRepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.DeferredRepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
@ -46,10 +46,7 @@ import android.content.Context;
* I always call exactly one of my delegate's `onSynchronized` or * I always call exactly one of my delegate's `onSynchronized` or
* `onSynchronizeFailed` callback methods if I have not seen an error. * `onSynchronizeFailed` callback methods if I have not seen an error.
*/ */
public class SynchronizerSession public class SynchronizerSession implements RecordsChannelDelegate, RepositorySessionFinishDelegate {
extends DeferrableRepositorySessionCreationDelegate
implements RecordsChannelDelegate,
RepositorySessionFinishDelegate {
protected static final String LOG_TAG = "SynchronizerSession"; protected static final String LOG_TAG = "SynchronizerSession";
protected Synchronizer synchronizer; protected Synchronizer synchronizer;
@ -104,12 +101,63 @@ implements RecordsChannelDelegate,
this.synchronizer = synchronizer; this.synchronizer = synchronizer;
} }
public void init(Context context, RepositorySessionBundle bundleA, RepositorySessionBundle bundleB) { public void initAndSynchronize(Context context, RepositorySessionBundle bundleA, RepositorySessionBundle bundleB) {
this.context = context; this.context = context;
this.bundleA = bundleA; this.bundleA = bundleA;
this.bundleB = bundleB; this.bundleB = bundleB;
// Begin sessionA and sessionB, call onInitialized in callbacks.
this.getSynchronizer().repositoryA.createSession(this, context); try {
this.sessionA = this.getSynchronizer().repositoryA.createSession(context);
} catch (SyncException e) {
// We no longer need a reference to our context.
this.context = null;
this.delegate.onSynchronizeFailed(this, e, "Failed to create session");
return;
}
try {
this.sessionA.unbundle(bundleA);
} catch (Exception e) {
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle first session.");
return;
}
try {
this.sessionB = this.getSynchronizer().repositoryB.createSession(context);
} catch (final SyncException createException) {
// We no longer need a reference to our context.
this.context = null;
// Finish already created sessionA.
try {
this.sessionA.finish(new RepositorySessionFinishDelegate() {
@Override
public void onFinishFailed(Exception ex) {
SynchronizerSession.this.delegate.onSynchronizeFailed(SynchronizerSession.this, createException, "Failed to create second session.");
}
@Override
public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) {
SynchronizerSession.this.delegate.onSynchronizeFailed(SynchronizerSession.this, createException, "Failed to create second session.");
}
@Override
public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) {
return new DeferredRepositorySessionFinishDelegate(this, executor);
}
});
} catch (InactiveSessionException finishException) {
SynchronizerSession.this.delegate.onSynchronizeFailed(SynchronizerSession.this, createException, "Failed to create second session.");
}
return;
}
try {
this.sessionB.unbundle(bundleB);
} catch (Exception e) {
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle second session.");
}
synchronize();
} }
/** /**
@ -172,7 +220,7 @@ implements RecordsChannelDelegate,
/** /**
* Please don't call this until you've been notified with onInitialized. * Please don't call this until you've been notified with onInitialized.
*/ */
public synchronized void synchronize() { private synchronized void synchronize() {
numInboundRecords.set(-1); numInboundRecords.set(-1);
numInboundRecordsStored.set(-1); numInboundRecordsStored.set(-1);
numInboundRecordsFailed.set(-1); numInboundRecordsFailed.set(-1);
@ -304,82 +352,6 @@ implements RecordsChannelDelegate,
Logger.warn(LOG_TAG, "Second RecordsChannel onFlowStoreFailed. Logging remote store error.", ex); Logger.warn(LOG_TAG, "Second RecordsChannel onFlowStoreFailed. Logging remote store error.", ex);
} }
/*
* RepositorySessionCreationDelegate methods.
*/
/**
* I could be called twice: once for sessionA and once for sessionB.
*
* I try to clean up sessionA if it is not null, since the creation of
* sessionB must have failed.
*/
@Override
public void onSessionCreateFailed(Exception ex) {
// Attempt to finish the first session, if the second is the one that failed.
if (this.sessionA != null) {
try {
// We no longer need a reference to our context.
this.context = null;
this.sessionA.finish(this);
} catch (Exception e) {
// Never mind; best-effort finish.
}
}
// We no longer need a reference to our context.
this.context = null;
this.delegate.onSynchronizeFailed(this, ex, "Failed to create session");
}
/**
* I should be called twice: first for sessionA and second for sessionB.
*
* If I am called for sessionB, I call my delegate's `onInitialized` callback
* method because my repository sessions are correctly initialized.
*/
// TODO: some of this "finish and clean up" code can be refactored out.
@Override
public void onSessionCreated(RepositorySession session) {
if (session == null ||
this.sessionA == session) {
// TODO: clean up sessionA.
this.delegate.onSynchronizeFailed(this, new UnexpectedSessionException(session), "Failed to create session.");
return;
}
if (this.sessionA == null) {
this.sessionA = session;
// Unbundle.
try {
this.sessionA.unbundle(this.bundleA);
} catch (Exception e) {
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle first session.");
// TODO: abort
return;
}
this.getSynchronizer().repositoryB.createSession(this, this.context);
return;
}
if (this.sessionB == null) {
this.sessionB = session;
// We no longer need a reference to our context.
this.context = null;
// Unbundle. We unbundled sessionA when that session was created.
try {
this.sessionB.unbundle(this.bundleB);
} catch (Exception e) {
this.delegate.onSynchronizeFailed(this, new UnbundleError(e, sessionA), "Failed to unbundle second session.");
return;
}
this.delegate.onInitialized(this);
return;
}
// TODO: need a way to make sure we don't call any more delegate methods.
this.delegate.onSynchronizeFailed(this, new UnexpectedSessionException(session), "Failed to create session.");
}
/* /*
* RepositorySessionFinishDelegate methods. * RepositorySessionFinishDelegate methods.
*/ */

Просмотреть файл

@ -5,8 +5,6 @@
package org.mozilla.gecko.sync.synchronizer; package org.mozilla.gecko.sync.synchronizer;
public interface SynchronizerSessionDelegate { public interface SynchronizerSessionDelegate {
public void onInitialized(SynchronizerSession session);
public void onSynchronized(SynchronizerSession session); public void onSynchronized(SynchronizerSession session);
public void onSynchronizeFailed(SynchronizerSession session, Exception lastException, String reason); public void onSynchronizeFailed(SynchronizerSession session, Exception lastException, String reason);
public void onSynchronizeSkipped(SynchronizerSession synchronizerSession); public void onSynchronizeSkipped(SynchronizerSession synchronizerSession);

Просмотреть файл

@ -12,8 +12,8 @@ import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.repositories.FetchFailedException; import org.mozilla.gecko.sync.repositories.FetchFailedException;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.StoreFailedException; import org.mozilla.gecko.sync.repositories.StoreFailedException;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
@ -57,9 +57,8 @@ public class SynchronizerHelpers {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new WBORepositorySession(this) {
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this) {
@Override @Override
public void fetchModified(final RepositorySessionFetchRecordsDelegate delegate) { public void fetchModified(final RepositorySessionFetchRecordsDelegate delegate) {
super.fetchModified(new RepositorySessionFetchRecordsDelegate() { super.fetchModified(new RepositorySessionFetchRecordsDelegate() {
@ -93,7 +92,7 @@ public class SynchronizerHelpers {
} }
}); });
} }
}); };
} }
} }
@ -108,9 +107,8 @@ public class SynchronizerHelpers {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new WBORepositorySession(this) {
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this) {
@Override @Override
public void store(final Record record) throws NoStoreDelegateException { public void store(final Record record) throws NoStoreDelegateException {
if (storeDelegate == null) { if (storeDelegate == null) {
@ -127,7 +125,7 @@ public class SynchronizerHelpers {
super.store(record); super.store(record);
} }
} }
}); };
} }
} }
@ -216,9 +214,8 @@ public class SynchronizerHelpers {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new BatchFailStoreWBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new BatchFailStoreWBORepositorySession(this));
} }
} }
@ -239,9 +236,8 @@ public class SynchronizerHelpers {
public static class BeginErrorWBORepository extends TrackingWBORepository { public static class BeginErrorWBORepository extends TrackingWBORepository {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new BeginErrorWBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new BeginErrorWBORepositorySession(this));
} }
public class BeginErrorWBORepositorySession extends WBORepositorySession { public class BeginErrorWBORepositorySession extends WBORepositorySession {
@ -258,9 +254,8 @@ public class SynchronizerHelpers {
public static class FinishErrorWBORepository extends TrackingWBORepository { public static class FinishErrorWBORepository extends TrackingWBORepository {
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new FinishErrorWBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new FinishErrorWBORepositorySession(this));
} }
public class FinishErrorWBORepositorySession extends WBORepositorySession { public class FinishErrorWBORepositorySession extends WBORepositorySession {
@ -283,9 +278,8 @@ public class SynchronizerHelpers {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new DataAvailableWBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new DataAvailableWBORepositorySession(this));
} }
public class DataAvailableWBORepositorySession extends WBORepositorySession { public class DataAvailableWBORepositorySession extends WBORepositorySession {
@ -308,9 +302,8 @@ public class SynchronizerHelpers {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new ShouldSkipWBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new ShouldSkipWBORepositorySession(this));
} }
public class ShouldSkipWBORepositorySession extends WBORepositorySession { public class ShouldSkipWBORepositorySession extends WBORepositorySession {

Просмотреть файл

@ -7,7 +7,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mozilla.android.sync.test.SynchronizerHelpers.FailFetchWBORepository; import org.mozilla.android.sync.test.SynchronizerHelpers.FailFetchWBORepository;
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionCreationDelegate;
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate; import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate;
import org.mozilla.gecko.background.testhelpers.TestRunner; import org.mozilla.gecko.background.testhelpers.TestRunner;
import org.mozilla.gecko.background.testhelpers.WBORepository; import org.mozilla.gecko.background.testhelpers.WBORepository;
@ -109,24 +108,8 @@ public class TestRecordsChannel {
} }
private void createSessions() { private void createSessions() {
WaitHelper.getTestWaiter().performWait(new Runnable() { sourceSession = sourceRepository.createSession(null);
@Override sinkSession = sinkRepository.createSession(null);
public void run() {
sourceRepository.createSession(new ExpectSuccessRepositorySessionCreationDelegate(WaitHelper.getTestWaiter()) {
@Override
public void onSessionCreated(RepositorySession session) {
sourceSession = session;
sinkRepository.createSession(new ExpectSuccessRepositorySessionCreationDelegate(WaitHelper.getTestWaiter()) {
@Override
public void onSessionCreated(RepositorySession session) {
sinkSession = session;
WaitHelper.getTestWaiter().performNotify();
}
}, null);
}
}, null);
}
});
} }
public void doFlow() throws Exception { public void doFlow() throws Exception {

Просмотреть файл

@ -4,6 +4,7 @@
package org.mozilla.android.sync.test; package org.mozilla.android.sync.test;
import android.content.Context; import android.content.Context;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -87,18 +88,6 @@ public class TestSynchronizer {
synchronizer.repositoryA = repoA; synchronizer.repositoryA = repoA;
synchronizer.repositoryB = repoB; synchronizer.repositoryB = repoB;
final SynchronizerSession syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() { final SynchronizerSession syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() {
@Override
public void onInitialized(SynchronizerSession session) {
assertFalse(repoA.wbos.containsKey(guidB));
assertFalse(repoA.wbos.containsKey(guidC));
assertFalse(repoB.wbos.containsKey(guidA));
assertTrue(repoA.wbos.containsKey(guidA));
assertTrue(repoB.wbos.containsKey(guidB));
assertTrue(repoB.wbos.containsKey(guidC));
session.synchronize();
}
@Override @Override
public void onSynchronized(SynchronizerSession session) { public void onSynchronized(SynchronizerSession session) {
try { try {
@ -125,7 +114,13 @@ public class TestSynchronizer {
WaitHelper.getTestWaiter().performWait(new Runnable() { WaitHelper.getTestWaiter().performWait(new Runnable() {
@Override @Override
public void run() { public void run() {
syncSession.init(context, new RepositorySessionBundle(0), new RepositorySessionBundle(0)); assertFalse(repoA.wbos.containsKey(guidB));
assertFalse(repoA.wbos.containsKey(guidC));
assertFalse(repoB.wbos.containsKey(guidA));
assertTrue(repoA.wbos.containsKey(guidA));
assertTrue(repoB.wbos.containsKey(guidB));
assertTrue(repoB.wbos.containsKey(guidC));
syncSession.initAndSynchronize(context, new RepositorySessionBundle(0), new RepositorySessionBundle(0));
} }
}); });

Просмотреть файл

@ -84,11 +84,6 @@ public class TestSynchronizerSession {
synchronizer.repositoryA = repoA; synchronizer.repositoryA = repoA;
synchronizer.repositoryB = repoB; synchronizer.repositoryB = repoB;
syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() { syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() {
@Override
public void onInitialized(SynchronizerSession session) {
session.synchronize();
}
@Override @Override
public void onSynchronized(SynchronizerSession session) { public void onSynchronized(SynchronizerSession session) {
WaitHelper.getTestWaiter().performNotify(); WaitHelper.getTestWaiter().performNotify();
@ -128,7 +123,7 @@ public class TestSynchronizerSession {
@Override @Override
public void run() { public void run() {
final Context context = null; final Context context = null;
syncSession.init(context, syncSession.initAndSynchronize(context,
new RepositorySessionBundle(0), new RepositorySessionBundle(0),
new RepositorySessionBundle(0)); new RepositorySessionBundle(0));
} }
@ -247,11 +242,6 @@ public class TestSynchronizerSession {
synchronizer.repositoryB = repoB; synchronizer.repositoryB = repoB;
syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() { syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() {
@Override
public void onInitialized(SynchronizerSession session) {
session.synchronize();
}
@Override @Override
public void onSynchronized(SynchronizerSession session) { public void onSynchronized(SynchronizerSession session) {
WaitHelper.getTestWaiter().performNotify(new RuntimeException("Not expecting onSynchronized")); WaitHelper.getTestWaiter().performNotify(new RuntimeException("Not expecting onSynchronized"));
@ -272,7 +262,7 @@ public class TestSynchronizerSession {
@Override @Override
public void run() { public void run() {
final Context context = null; final Context context = null;
syncSession.init(context, syncSession.initAndSynchronize(context,
new RepositorySessionBundle(100), new RepositorySessionBundle(100),
new RepositorySessionBundle(200)); new RepositorySessionBundle(200));
} }

Просмотреть файл

@ -1,36 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.android.sync.test.helpers;
import junit.framework.AssertionFailedError;
import org.mozilla.gecko.background.testhelpers.WaitHelper;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
public class ExpectSuccessRepositorySessionCreationDelegate extends
ExpectSuccessDelegate implements RepositorySessionCreationDelegate {
public ExpectSuccessRepositorySessionCreationDelegate(WaitHelper waitHelper) {
super(waitHelper);
}
@Override
public void onSessionCreateFailed(Exception ex) {
log("Session creation failed.", ex);
performNotify(new AssertionFailedError("onSessionCreateFailed: session creation should not have failed."));
}
@Override
public void onSessionCreated(RepositorySession session) {
log("Session creation succeeded.");
performNotify();
}
@Override
public RepositorySessionCreationDelegate deferredCreationDelegate() {
log("Session creation deferred.");
return this;
}
}

Просмотреть файл

@ -10,8 +10,8 @@ import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RecordFilter; import org.mozilla.gecko.sync.repositories.RecordFilter;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession; import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
@ -211,9 +211,8 @@ public class WBORepository extends Repository {
} }
@Override @Override
public void createSession(RepositorySessionCreationDelegate delegate, public RepositorySession createSession(Context context) {
Context context) { return new WBORepositorySession(this);
delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this));
} }
public ConcurrentHashMap<String, Record> cloneWBOs() { public ConcurrentHashMap<String, Record> cloneWBOs() {

Просмотреть файл

@ -7,7 +7,6 @@ import junit.framework.AssertionFailedError;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionCreationDelegate;
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFetchRecordsDelegate; import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFetchRecordsDelegate;
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate; import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate;
import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionStoreDelegate; import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionStoreDelegate;
@ -17,22 +16,17 @@ import org.mozilla.gecko.background.testhelpers.TestRunner;
import org.mozilla.gecko.background.testhelpers.WBORepository; import org.mozilla.gecko.background.testhelpers.WBORepository;
import org.mozilla.gecko.background.testhelpers.WaitHelper; import org.mozilla.gecko.background.testhelpers.WaitHelper;
import org.mozilla.gecko.sync.CryptoRecord; import org.mozilla.gecko.sync.CryptoRecord;
import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncException; import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.crypto.CryptoException; import org.mozilla.gecko.sync.crypto.CryptoException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository; import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository;
import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepositorySession; import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepositorySession;
import org.mozilla.gecko.sync.repositories.InactiveSessionException; import org.mozilla.gecko.sync.repositories.InactiveSessionException;
import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; import org.mozilla.gecko.sync.repositories.NoStoreDelegateException;
import org.mozilla.gecko.sync.repositories.RepositorySession; import org.mozilla.gecko.sync.repositories.RepositorySession;
import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
@ -77,68 +71,50 @@ public class TestCrypto5MiddlewareRepositorySession {
cmwSession = null; cmwSession = null;
} }
/** public void beginSessionAndAssertSuccess() throws Exception{
* Run `runnable` in performWait(... onBeginSucceeded { } ). cmwSession = (Crypto5MiddlewareRepositorySession) cmwRepo.createSession(null);
* assertSame(RepositorySession.SessionStatus.UNSTARTED, cmwSession.getStatus());
* The Crypto5MiddlewareRepositorySession is available in self.cmwSession. cmwSession.begin();
* assertSame(RepositorySession.SessionStatus.ACTIVE, cmwSession.getStatus());
* @param runnable
*/
public void runInOnBeginSucceeded(final Runnable runnable) {
final TestCrypto5MiddlewareRepositorySession self = this;
performWait(onThreadRunnable(new Runnable() {
@Override
public void run() {
cmwRepo.createSession(new ExpectSuccessRepositorySessionCreationDelegate(getTestWaiter()) {
@Override
public void onSessionCreated(RepositorySession session) {
self.cmwSession = (Crypto5MiddlewareRepositorySession)session;
assertSame(RepositorySession.SessionStatus.UNSTARTED, cmwSession.getStatus());
try {
session.begin();
} catch (SyncException e) {
TestCrypto5MiddlewareRepositorySession.performNotify(e);
}
runnable.run();
}
}, null);
}
}));
} }
@Test @Test
/** /**
* Verify that the status is actually being advanced. * Verify that the status is actually being advanced.
*/ */
public void testStatus() { public void testStatus() throws Exception {
runInOnBeginSucceeded(new Runnable() { beginSessionAndAssertSuccess();
@Override public void run() { performWait(onThreadRunnable(new Runnable() {
assertSame(RepositorySession.SessionStatus.ACTIVE, cmwSession.getStatus()); @Override
public void run() {
try { try {
cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter())); cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter()));
} catch (InactiveSessionException e) { } catch (InactiveSessionException e) {
performNotify(e); performNotify(e);
} }
assertSame(RepositorySession.SessionStatus.DONE, cmwSession.getStatus());
} }
}); }));
assertSame(RepositorySession.SessionStatus.DONE, cmwSession.getStatus());
} }
@Test @Test
/** /**
* Verify that wipe is actually wiping the underlying repository. * Verify that wipe is actually wiping the underlying repository.
*/ */
public void testWipe() { public void testWipe() throws Exception {
Record record = new MockRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); Record record = new MockRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
wboRepo.wbos.put(record.guid, record); wboRepo.wbos.put(record.guid, record);
assertEquals(1, wboRepo.wbos.size()); assertEquals(1, wboRepo.wbos.size());
runInOnBeginSucceeded(new Runnable() { beginSessionAndAssertSuccess();
@Override public void run() {
performWait(onThreadRunnable(new Runnable() {
@Override
public void run() {
cmwSession.wipe(new ExpectSuccessRepositoryWipeDelegate(getTestWaiter())); cmwSession.wipe(new ExpectSuccessRepositoryWipeDelegate(getTestWaiter()));
} }
}); }));
performWait(onThreadRunnable(new Runnable() { performWait(onThreadRunnable(new Runnable() {
@Override public void run() { @Override public void run() {
try { try {
@ -155,12 +131,15 @@ public class TestCrypto5MiddlewareRepositorySession {
/** /**
* Verify that store is actually writing encrypted data to the underlying repository. * Verify that store is actually writing encrypted data to the underlying repository.
*/ */
public void testStoreEncrypts() throws NonObjectJSONException, CryptoException, IOException { public void testStoreEncrypts() throws Exception {
final BookmarkRecord record = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); final BookmarkRecord record = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
record.title = "unencrypted title"; record.title = "unencrypted title";
runInOnBeginSucceeded(new Runnable() { beginSessionAndAssertSuccess();
@Override public void run() {
performWait(onThreadRunnable(new Runnable() {
@Override
public void run() {
try { try {
try { try {
cmwSession.setStoreDelegate(new ExpectSuccessRepositorySessionStoreDelegate(getTestWaiter())); cmwSession.setStoreDelegate(new ExpectSuccessRepositorySessionStoreDelegate(getTestWaiter()));
@ -174,7 +153,8 @@ public class TestCrypto5MiddlewareRepositorySession {
performNotify(e); performNotify(e);
} }
} }
}); }));
assertEquals(1, wboRepo.wbos.size()); assertEquals(1, wboRepo.wbos.size());
assertTrue(wboRepo.wbos.containsKey(record.guid)); assertTrue(wboRepo.wbos.containsKey(record.guid));
@ -192,7 +172,7 @@ public class TestCrypto5MiddlewareRepositorySession {
/** /**
* Verify that fetch is actually retrieving encrypted data from the underlying repository and is correctly decrypting it. * Verify that fetch is actually retrieving encrypted data from the underlying repository and is correctly decrypting it.
*/ */
public void testFetchDecrypts() throws UnsupportedEncodingException, CryptoException { public void testFetchDecrypts() throws Exception {
final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
record1.title = "unencrypted title"; record1.title = "unencrypted title";
final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false); final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false);
@ -209,7 +189,8 @@ public class TestCrypto5MiddlewareRepositorySession {
wboRepo.wbos.put(record2.guid, encryptedRecord2); wboRepo.wbos.put(record2.guid, encryptedRecord2);
final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter()); final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter());
runInOnBeginSucceeded(new Runnable() { beginSessionAndAssertSuccess();
performWait(onThreadRunnable(new Runnable() {
@Override public void run() { @Override public void run() {
try { try {
cmwSession.fetch(new String[] { record1.guid }, fetchRecordsDelegate); cmwSession.fetch(new String[] { record1.guid }, fetchRecordsDelegate);
@ -217,7 +198,7 @@ public class TestCrypto5MiddlewareRepositorySession {
performNotify(e); performNotify(e);
} }
} }
}); }));
performWait(onThreadRunnable(new Runnable() { performWait(onThreadRunnable(new Runnable() {
@Override public void run() { @Override public void run() {
try { try {
@ -238,7 +219,7 @@ public class TestCrypto5MiddlewareRepositorySession {
/** /**
* Verify that fetchAll is actually retrieving encrypted data from the underlying repository and is correctly decrypting it. * Verify that fetchAll is actually retrieving encrypted data from the underlying repository and is correctly decrypting it.
*/ */
public void testFetchAllDecrypts() throws UnsupportedEncodingException, CryptoException { public void testFetchAllDecrypts() throws Exception {
final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false);
record1.title = "unencrypted title"; record1.title = "unencrypted title";
final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false); final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false);
@ -255,11 +236,12 @@ public class TestCrypto5MiddlewareRepositorySession {
wboRepo.wbos.put(record2.guid, encryptedRecord2); wboRepo.wbos.put(record2.guid, encryptedRecord2);
final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchAllRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter()); final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchAllRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter());
runInOnBeginSucceeded(new Runnable() { beginSessionAndAssertSuccess();
performWait(onThreadRunnable(new Runnable() {
@Override public void run() { @Override public void run() {
cmwSession.fetchAll(fetchAllRecordsDelegate); cmwSession.fetchAll(fetchAllRecordsDelegate);
} }
}); }));
performWait(onThreadRunnable(new Runnable() { performWait(onThreadRunnable(new Runnable() {
@Override public void run() { @Override public void run() {
try { try {