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()));
}
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]);
}
}
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));
}
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);
}
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;
}
Aggregations