Search in sources :

Example 6 with BackupManager

use of org.apache.geode.internal.cache.persistence.BackupManager in project geode by apache.

the class BackupJUnitTest method testBackupEmptyDiskStore.

@Test
public void testBackupEmptyDiskStore() throws IOException, InterruptedException {
    DiskStoreImpl ds = createDiskStore();
    BackupManager backup = cache.startBackup(cache.getInternalDistributedSystem().getDistributedMember());
    backup.prepareBackup();
    backup.finishBackup(backupDir, null, false);
    assertEquals("No backup files should have been created", Collections.emptyList(), Arrays.asList(backupDir.list()));
}
Also used : BackupManager(org.apache.geode.internal.cache.persistence.BackupManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with BackupManager

use of org.apache.geode.internal.cache.persistence.BackupManager in project geode by apache.

the class BackupJUnitTest method testBackupCacheXml.

@Test
public void testBackupCacheXml() throws Exception {
    DiskStoreImpl ds = createDiskStore();
    createRegion();
    BackupManager backup = cache.startBackup(cache.getInternalDistributedSystem().getDistributedMember());
    backup.prepareBackup();
    backup.finishBackup(backupDir, null, false);
    Collection<File> fileCollection = FileUtils.listFiles(backupDir, new RegexFileFilter("cache.xml"), DirectoryFileFilter.DIRECTORY);
    assertEquals(1, fileCollection.size());
    File cacheXmlBackup = fileCollection.iterator().next();
    assertTrue(cacheXmlBackup.exists());
    byte[] expectedBytes = getBytes(cacheXmlFile);
    byte[] backupBytes = getBytes(cacheXmlBackup);
    assertEquals(expectedBytes.length, backupBytes.length);
    for (int i = 0; i < expectedBytes.length; i++) {
        assertEquals("byte " + i, expectedBytes[i], backupBytes[i]);
    }
}
Also used : RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) BackupManager(org.apache.geode.internal.cache.persistence.BackupManager) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with BackupManager

use of org.apache.geode.internal.cache.persistence.BackupManager in project geode by apache.

the class DistributedSystemBridgeJUnitTest method testPrepareErrorAbortsBackup.

@Test
public void testPrepareErrorAbortsBackup() throws Exception {
    DM dm = cache.getDistributionManager();
    PersistentMemberManager memberManager = mock(PersistentMemberManager.class);
    BackupManager backupManager = mock(BackupManager.class);
    when(cache.startBackup(any())).thenReturn(backupManager);
    when(cache.getPersistentMemberManager()).thenReturn(memberManager);
    when(cache.getBackupManager()).thenReturn(backupManager);
    when(dm.putOutgoing(isA(PrepareBackupRequest.class))).thenThrow(new RuntimeException("Fail the prepare"));
    DistributedSystemBridge bridge = new DistributedSystemBridge(null);
    try {
        bridge.backupAllMembers("/tmp", null);
        fail("Should have failed with an exception");
    } catch (RuntimeException expected) {
    }
    verify(dm).putOutgoing(isA(FinishBackupRequest.class));
    verify(backupManager).finishBackup(any(), any(), eq(true));
}
Also used : PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) DM(org.apache.geode.distributed.internal.DM) BackupManager(org.apache.geode.internal.cache.persistence.BackupManager) PrepareBackupRequest(org.apache.geode.admin.internal.PrepareBackupRequest) FinishBackupRequest(org.apache.geode.admin.internal.FinishBackupRequest) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 9 with BackupManager

use of org.apache.geode.internal.cache.persistence.BackupManager in project geode by apache.

the class DistributedSystemBridgeJUnitTest method createCache.

@Before
public void createCache() throws IOException {
    cache = Fakes.cache();
    PersistentMemberManager memberManager = mock(PersistentMemberManager.class);
    backupManager = mock(BackupManager.class);
    when(cache.startBackup(any())).thenReturn(backupManager);
    when(cache.getPersistentMemberManager()).thenReturn(memberManager);
    when(cache.getBackupManager()).thenReturn(backupManager);
    DLockService dlock = mock(DLockService.class);
    when(dlock.lock(any(), anyLong(), anyLong())).thenReturn(true);
    DLockService.addLockServiceForTests(BackupDataStoreHelper.LOCK_SERVICE_NAME, dlock);
    GemFireCacheImpl.setInstanceForTests(cache);
}
Also used : PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) DLockService(org.apache.geode.distributed.internal.locks.DLockService) BackupManager(org.apache.geode.internal.cache.persistence.BackupManager) Before(org.junit.Before)

Example 10 with BackupManager

use of org.apache.geode.internal.cache.persistence.BackupManager in project geode by apache.

the class GemFireCacheImpl method startBackup.

public BackupManager startBackup(InternalDistributedMember sender) throws IOException {
    BackupManager manager = new BackupManager(sender, this);
    if (!this.backupManager.compareAndSet(null, manager)) {
        throw new IOException("Backup already in progress");
    }
    manager.start();
    return manager;
}
Also used : IOException(java.io.IOException) BackupManager(org.apache.geode.internal.cache.persistence.BackupManager)

Aggregations

BackupManager (org.apache.geode.internal.cache.persistence.BackupManager)11 Test (org.junit.Test)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 IOException (java.io.IOException)3 DiskStore (org.apache.geode.cache.DiskStore)3 Region (org.apache.geode.cache.Region)3 File (java.io.File)2 PersistentID (org.apache.geode.cache.persistence.PersistentID)2 PersistentMemberManager (org.apache.geode.internal.cache.persistence.PersistentMemberManager)2 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)1 FinishBackupRequest (org.apache.geode.admin.internal.FinishBackupRequest)1 PrepareBackupRequest (org.apache.geode.admin.internal.PrepareBackupRequest)1 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)1 DM (org.apache.geode.distributed.internal.DM)1 DLockService (org.apache.geode.distributed.internal.locks.DLockService)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 RestoreScript (org.apache.geode.internal.cache.persistence.RestoreScript)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 DiskStoreAttributesCreation (org.apache.geode.internal.cache.xmlcache.DiskStoreAttributesCreation)1 DiskBackupResult (org.apache.geode.management.DiskBackupResult)1