Search in sources :

Example 1 with BackupProgressStatus

use of com.thoughtworks.go.server.domain.BackupProgressStatus 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();
}
Also used : ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) BackupUpdateListener(com.thoughtworks.go.server.service.backup.BackupUpdateListener) BackupProgressStatus(com.thoughtworks.go.server.domain.BackupProgressStatus) Semaphore(java.util.concurrent.Semaphore) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 2 with BackupProgressStatus

use of com.thoughtworks.go.server.domain.BackupProgressStatus 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();
}
Also used : ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) BackupUpdateListener(com.thoughtworks.go.server.service.backup.BackupUpdateListener) BackupProgressStatus(com.thoughtworks.go.server.domain.BackupProgressStatus) Semaphore(java.util.concurrent.Semaphore) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) Test(org.junit.jupiter.api.Test)

Aggregations

BackupProgressStatus (com.thoughtworks.go.server.domain.BackupProgressStatus)2 ServerBackup (com.thoughtworks.go.server.domain.ServerBackup)2 BackupUpdateListener (com.thoughtworks.go.server.service.backup.BackupUpdateListener)2 Semaphore (java.util.concurrent.Semaphore)2 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)2 Test (org.junit.jupiter.api.Test)2 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1