Search in sources :

Example 1 with PrepareBackupRequest

use of org.apache.geode.admin.internal.PrepareBackupRequest 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)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 BackupStatus (org.apache.geode.admin.BackupStatus)1 PrepareBackupRequest (org.apache.geode.admin.internal.PrepareBackupRequest)1 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)1 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)1 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)1 AdminFailureResponse (org.apache.geode.internal.admin.remote.AdminFailureResponse)1 Host (org.apache.geode.test.dunit.Host)1 IgnoredException (org.apache.geode.test.dunit.IgnoredException)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 Test (org.junit.Test)1