@Test public void syncExistingDatabase() { final Identifier identifier = new Identifier("oldId"); when(mGoogleDriveSyncMetadata.getDatabaseSyncIdentifier()).thenReturn(identifier); when(mDriveStreamsManager.updateDriveFile(identifier, mDatabaseFile)).thenReturn(Single.just(identifier)); mDriveDatabaseManager.syncDatabase(); verify(mGoogleDriveSyncMetadata).setDatabaseSyncIdentifier(identifier); }
@SuppressLint("CheckResult") public void syncDatabase() { final File filesDir = mContext.getExternalFilesDir(null); if (filesDir != null) { final File dbFile = new File(filesDir, DatabaseConstants.DATABASE_NAME); if (dbFile.exists()) { if (!mIsSyncInProgress.getAndSet(true)) { getSyncDatabaseObservable(dbFile) .observeOn(mObserveOnScheduler) .subscribeOn(mSubscribeOnScheduler) .subscribe(identifier -> { Logger.info(DriveDatabaseManager.this, "Successfully synced our database"); mGoogleDriveSyncMetadata.setDatabaseSyncIdentifier(identifier); mIsSyncInProgress.set(false); }, throwable -> { mIsSyncInProgress.set(false); mAnalytics.record(new ErrorEvent(DriveDatabaseManager.this, throwable)); Logger.error(DriveDatabaseManager.this, "Failed to sync our database", throwable); }); } else { Logger.debug(DriveDatabaseManager.this, "A sync is already in progress. Ignoring subsequent one for now"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database storage directory"); } }
DriveDatabaseManager { @SuppressLint("CheckResult") public void syncDatabase() { final File filesDir = mContext.getExternalFilesDir(null); if (filesDir != null) { final File dbFile = new File(filesDir, DatabaseConstants.DATABASE_NAME); if (dbFile.exists()) { if (!mIsSyncInProgress.getAndSet(true)) { getSyncDatabaseObservable(dbFile) .observeOn(mObserveOnScheduler) .subscribeOn(mSubscribeOnScheduler) .subscribe(identifier -> { Logger.info(DriveDatabaseManager.this, "Successfully synced our database"); mGoogleDriveSyncMetadata.setDatabaseSyncIdentifier(identifier); mIsSyncInProgress.set(false); }, throwable -> { mIsSyncInProgress.set(false); mAnalytics.record(new ErrorEvent(DriveDatabaseManager.this, throwable)); Logger.error(DriveDatabaseManager.this, "Failed to sync our database", throwable); }); } else { Logger.debug(DriveDatabaseManager.this, "A sync is already in progress. Ignoring subsequent one for now"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database storage directory"); } } }
DriveDatabaseManager { @SuppressLint("CheckResult") public void syncDatabase() { final File filesDir = mContext.getExternalFilesDir(null); if (filesDir != null) { final File dbFile = new File(filesDir, DatabaseConstants.DATABASE_NAME); if (dbFile.exists()) { if (!mIsSyncInProgress.getAndSet(true)) { getSyncDatabaseObservable(dbFile) .observeOn(mObserveOnScheduler) .subscribeOn(mSubscribeOnScheduler) .subscribe(identifier -> { Logger.info(DriveDatabaseManager.this, "Successfully synced our database"); mGoogleDriveSyncMetadata.setDatabaseSyncIdentifier(identifier); mIsSyncInProgress.set(false); }, throwable -> { mIsSyncInProgress.set(false); mAnalytics.record(new ErrorEvent(DriveDatabaseManager.this, throwable)); Logger.error(DriveDatabaseManager.this, "Failed to sync our database", throwable); }); } else { Logger.debug(DriveDatabaseManager.this, "A sync is already in progress. Ignoring subsequent one for now"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database storage directory"); } } DriveDatabaseManager(@NonNull Context context, @NonNull DriveStreamsManager driveTaskManager,
                                @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                                @NonNull Analytics analytics);  DriveDatabaseManager(@NonNull Context context, @NonNull DriveStreamsManager driveTaskManager, @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                                @NonNull Analytics analytics, @NonNull Scheduler observeOnScheduler, @NonNull Scheduler subscribeOnScheduler); }
DriveDatabaseManager { @SuppressLint("CheckResult") public void syncDatabase() { final File filesDir = mContext.getExternalFilesDir(null); if (filesDir != null) { final File dbFile = new File(filesDir, DatabaseConstants.DATABASE_NAME); if (dbFile.exists()) { if (!mIsSyncInProgress.getAndSet(true)) { getSyncDatabaseObservable(dbFile) .observeOn(mObserveOnScheduler) .subscribeOn(mSubscribeOnScheduler) .subscribe(identifier -> { Logger.info(DriveDatabaseManager.this, "Successfully synced our database"); mGoogleDriveSyncMetadata.setDatabaseSyncIdentifier(identifier); mIsSyncInProgress.set(false); }, throwable -> { mIsSyncInProgress.set(false); mAnalytics.record(new ErrorEvent(DriveDatabaseManager.this, throwable)); Logger.error(DriveDatabaseManager.this, "Failed to sync our database", throwable); }); } else { Logger.debug(DriveDatabaseManager.this, "A sync is already in progress. Ignoring subsequent one for now"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database storage directory"); } } DriveDatabaseManager(@NonNull Context context, @NonNull DriveStreamsManager driveTaskManager,
                                @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                                @NonNull Analytics analytics);  DriveDatabaseManager(@NonNull Context context, @NonNull DriveStreamsManager driveTaskManager, @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                                @NonNull Analytics analytics, @NonNull Scheduler observeOnScheduler, @NonNull Scheduler subscribeOnScheduler); @SuppressLint("CheckResult") void syncDatabase(); }
DriveDatabaseManager { @SuppressLint("CheckResult") public void syncDatabase() { final File filesDir = mContext.getExternalFilesDir(null); if (filesDir != null) { final File dbFile = new File(filesDir, DatabaseConstants.DATABASE_NAME); if (dbFile.exists()) { if (!mIsSyncInProgress.getAndSet(true)) { getSyncDatabaseObservable(dbFile) .observeOn(mObserveOnScheduler) .subscribeOn(mSubscribeOnScheduler) .subscribe(identifier -> { Logger.info(DriveDatabaseManager.this, "Successfully synced our database"); mGoogleDriveSyncMetadata.setDatabaseSyncIdentifier(identifier); mIsSyncInProgress.set(false); }, throwable -> { mIsSyncInProgress.set(false); mAnalytics.record(new ErrorEvent(DriveDatabaseManager.this, throwable)); Logger.error(DriveDatabaseManager.this, "Failed to sync our database", throwable); }); } else { Logger.debug(DriveDatabaseManager.this, "A sync is already in progress. Ignoring subsequent one for now"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database"); } } else { Logger.error(DriveDatabaseManager.this, "Failed to find our main database storage directory"); } } DriveDatabaseManager(@NonNull Context context, @NonNull DriveStreamsManager driveTaskManager,
                                @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                                @NonNull Analytics analytics);  DriveDatabaseManager(@NonNull Context context, @NonNull DriveStreamsManager driveTaskManager, @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                                @NonNull Analytics analytics, @NonNull Scheduler observeOnScheduler, @NonNull Scheduler subscribeOnScheduler); @SuppressLint("CheckResult") void syncDatabase();  }