use of com.thoughtworks.go.server.service.backup.BackupUpdateListener in project gocd by gocd.
the class BackupServiceIntegrationTest method shouldReturnBackupRunningSinceValue_inISO8601_format.
@Test
public void shouldReturnBackupRunningSinceValue_inISO8601_format() throws InterruptedException {
assertThat(backupService.backupRunningSinceISO8601(), is(Optional.empty()));
final Semaphore waitForBackupToStart = new Semaphore(1);
final Semaphore waitForAssertionToCompleteWhileBackupIsOn = new Semaphore(1);
final BackupUpdateListener backupUpdateListener = new BackupUpdateListener() {
private boolean backupStarted = false;
@Override
public void updateStep(BackupProgressStatus step) {
if (!backupStarted) {
backupStarted = true;
waitForBackupToStart.release();
try {
waitForAssertionToCompleteWhileBackupIsOn.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void error(String message) {
}
@Override
public void completed(String message) {
}
};
waitForAssertionToCompleteWhileBackupIsOn.acquire();
waitForBackupToStart.acquire();
Thread backupThd = new Thread(() -> backupService.startBackup(admin, backupUpdateListener));
backupThd.start();
waitForBackupToStart.acquire();
String backupStartedTimeString = backupService.backupRunningSinceISO8601().get();
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
DateTime backupTime = dateTimeFormatter.parseDateTime(backupStartedTimeString);
ServerBackup runningBackup = (ServerBackup) ReflectionUtil.getField(backupService, "runningBackup");
assertThat(new DateTime(runningBackup.getTime()), is(backupTime));
waitForAssertionToCompleteWhileBackupIsOn.release();
backupThd.join();
}
use of com.thoughtworks.go.server.service.backup.BackupUpdateListener in project gocd by gocd.
the class BackupServiceIntegrationTest method shouldReturnBackupStartedBy.
@Test
public void shouldReturnBackupStartedBy() throws InterruptedException {
assertThat(backupService.backupStartedBy(), is(Optional.empty()));
final Semaphore waitForBackupToStart = new Semaphore(1);
final Semaphore waitForAssertionToCompleteWhileBackupIsOn = new Semaphore(1);
final BackupUpdateListener backupUpdateListener = new BackupUpdateListener() {
private boolean backupStarted = false;
@Override
public void updateStep(BackupProgressStatus step) {
if (!backupStarted) {
backupStarted = true;
waitForBackupToStart.release();
try {
waitForAssertionToCompleteWhileBackupIsOn.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void error(String message) {
}
@Override
public void completed(String message) {
}
};
waitForAssertionToCompleteWhileBackupIsOn.acquire();
waitForBackupToStart.acquire();
Thread backupThd = new Thread(() -> backupService.startBackup(admin, backupUpdateListener));
backupThd.start();
waitForBackupToStart.acquire();
String backupStartedBy = backupService.backupStartedBy().get();
ServerBackup runningBackup = (ServerBackup) ReflectionUtil.getField(backupService, "runningBackup");
assertThat(runningBackup.getUsername(), is(backupStartedBy));
waitForAssertionToCompleteWhileBackupIsOn.release();
backupThd.join();
}
Aggregations