@Test public void asyncBackups_whenForceSyncEnabled() { setup(true); // when forceSync is enabled, then async should always be 0 assertEquals(0, backupHandler.asyncBackups(0, 0, FORCE_SYNC_ENABLED)); assertEquals(0, backupHandler.asyncBackups(0, 1, FORCE_SYNC_ENABLED)); assertEquals(0, backupHandler.asyncBackups(2, 0, FORCE_SYNC_ENABLED)); assertEquals(0, backupHandler.asyncBackups(2, 1, FORCE_SYNC_ENABLED)); // see what happens when we reach maximum number of backups assertEquals(0, backupHandler.asyncBackups(0, BACKUPS + 1, FORCE_SYNC_ENABLED)); }
@Test public void asyncBackups_whenForceSyncDisabled() { setup(BACKPRESSURE_ENABLED); // when forceSync disabled, only the async matters assertEquals(0, backupHandler.asyncBackups(0, 0, FORCE_SYNC_DISABLED)); assertEquals(1, backupHandler.asyncBackups(0, 1, FORCE_SYNC_DISABLED)); assertEquals(0, backupHandler.asyncBackups(2, 0, FORCE_SYNC_DISABLED)); assertEquals(1, backupHandler.asyncBackups(2, 1, FORCE_SYNC_DISABLED)); // see what happens when we reach maximum number of backups assertEquals(BACKUPS, backupHandler.asyncBackups(0, BACKUPS + 1, FORCE_SYNC_DISABLED)); }
@Test public void syncBackups_whenForceSyncDisabled() { setup(BACKPRESSURE_ENABLED); // when force-sync disabled, we only look at the sync backups assertEquals(0, backupHandler.syncBackups(0, 0, FORCE_SYNC_DISABLED)); assertEquals(1, backupHandler.syncBackups(1, 0, FORCE_SYNC_DISABLED)); assertEquals(0, backupHandler.syncBackups(0, 0, FORCE_SYNC_DISABLED)); assertEquals(1, backupHandler.syncBackups(1, 1, FORCE_SYNC_DISABLED)); // checking to see what happens when we are at or above the maximum number of backups assertEquals(BACKUPS, backupHandler.syncBackups(BACKUPS, 0, FORCE_SYNC_DISABLED)); assertEquals(BACKUPS, backupHandler.syncBackups(BACKUPS + 1, 0, FORCE_SYNC_DISABLED)); }
@Test public void syncBackups_whenForceSyncEnabled() { setup(BACKPRESSURE_ENABLED); // when force sync enabled, we sum tot sync and asyncs assertEquals(0, backupHandler.syncBackups(0, 0, FORCE_SYNC_ENABLED)); assertEquals(1, backupHandler.syncBackups(1, 0, FORCE_SYNC_ENABLED)); assertEquals(0, backupHandler.syncBackups(0, 0, FORCE_SYNC_ENABLED)); assertEquals(3, backupHandler.syncBackups(1, 2, FORCE_SYNC_ENABLED)); // checking to see what happens when we are at or above the maximum number of backups assertEquals(BACKUPS, backupHandler.syncBackups(BACKUPS, 0, FORCE_SYNC_ENABLED)); assertEquals(BACKUPS, backupHandler.syncBackups(BACKUPS + 1, 0, FORCE_SYNC_ENABLED)); assertEquals(BACKUPS, backupHandler.syncBackups(BACKUPS, 1, FORCE_SYNC_ENABLED)); }
@Test(expected = IllegalArgumentException.class) public void backup_whenTooLargeSumOfSyncAndAsync() throws Exception { setup(BACKPRESSURE_ENABLED); BackupAwareOperation op = makeOperation(1, MAX_BACKUP_COUNT); backupHandler.backup(op); }
@Test(expected = IllegalArgumentException.class) public void backup_whenNegativeAsyncBackupCount() throws Exception { setup(BACKPRESSURE_ENABLED); BackupAwareOperation op = makeOperation(0, -1); backupHandler.backup(op); }
private void assertBackup(final int syncBackups, final int asyncBackups, int expectedResult) throws Exception { final DummyBackupAwareOperation backupAwareOp = makeOperation(syncBackups, asyncBackups); int result = backupHandler.backup(backupAwareOp); assertEquals(expectedResult, result); assertTrueEventually( new AssertTask() { @Override public void run() throws Exception { Integer completed = backupCompletedMap.get(backupAwareOp.backupKey); if (completed == null) { completed = 0; } int totalBackups = min(BACKUPS, syncBackups + asyncBackups); assertEquals(new Integer(totalBackups), completed); } }); }