Search in sources :

Example 11 with BackupStatus

use of org.apache.geode.admin.BackupStatus in project geode by apache.

the class BackupDUnitTest method testBackupStatusCleanedUpAfterFailureOnOneMember.

@Test
public void testBackupStatusCleanedUpAfterFailureOnOneMember() throws Throwable {
    IgnoredException.addIgnoredException("Uncaught exception");
    IgnoredException.addIgnoredException("Stop processing");
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    // Create an observer that will fail a backup
    // When this member receives a prepare
    DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {

        @Override
        public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof PrepareBackupRequest) {
                DistributionMessageObserver.setInstance(null);
                IOException exception = new IOException("Backup in progess");
                AdminFailureResponse response = AdminFailureResponse.create(dm, message.getSender(), exception);
                response.setMsgId(((PrepareBackupRequest) message).getMsgId());
                dm.putOutgoing(response);
                throw new RuntimeException("Stop processing");
            }
        }
    };
    vm0.invoke(() -> {
        disconnectFromDS();
        DistributionMessageObserver.setInstance(observer);
    });
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    createData(vm0, 0, 5, "A", "region1");
    createData(vm0, 0, 5, "B", "region2");
    try {
        backup(vm2);
        fail("Backup should have failed with in progress exception");
    } catch (Exception expected) {
    // that's ok, hte backup should have failed
    }
    // A second backup should succeed because the observer
    // has been cleared and the backup state should be cleared.
    BackupStatus status = backup(vm2);
    assertEquals(2, status.getBackedUpDiskStores().size());
    assertEquals(Collections.emptySet(), status.getOfflineDiskStores());
}
Also used : AdminFailureResponse(org.apache.geode.internal.admin.remote.AdminFailureResponse) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) FileNotFoundException(java.io.FileNotFoundException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) IOException(java.io.IOException) PrepareBackupRequest(org.apache.geode.admin.internal.PrepareBackupRequest) BackupStatus(org.apache.geode.admin.BackupStatus) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 12 with BackupStatus

use of org.apache.geode.admin.BackupStatus in project geode by apache.

the class IncrementalBackupDUnitTest method baseline.

/**
   * Invokes {@link AdminDistributedSystem#backupAllMembers(File)} on a member.
   * 
   * @param vm a member of the distributed system
   * @return the status of the backup.
   */
private BackupStatus baseline(VM vm) {
    return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members.") {

        @Override
        public Object call() {
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                return adminDS.backupAllMembers(getBaselineDir());
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
}
Also used : AdminException(org.apache.geode.admin.AdminException) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) BackupStatus(org.apache.geode.admin.BackupStatus)

Example 13 with BackupStatus

use of org.apache.geode.admin.BackupStatus in project geode by apache.

the class IncrementalBackupDUnitTest method incremental.

/**
   * Invokes {@link AdminDistributedSystem#backupAllMembers(File, File)} on a member.
   * 
   * @param vm a member of the distributed system.
   * @return a status of the backup operation.
   */
private BackupStatus incremental(VM vm) {
    return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members.") {

        @Override
        public Object call() {
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                return adminDS.backupAllMembers(getIncrementalDir(), getBaselineBackupDir());
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
}
Also used : AdminException(org.apache.geode.admin.AdminException) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) BackupStatus(org.apache.geode.admin.BackupStatus)

Aggregations

BackupStatus (org.apache.geode.admin.BackupStatus)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)4 AdminException (org.apache.geode.admin.AdminException)4 DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 File (java.io.File)3 PersistentID (org.apache.geode.cache.persistence.PersistentID)3 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 HashSet (java.util.HashSet)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 FileNotFoundException (java.io.FileNotFoundException)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1