Search in sources :

Example 11 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project geode by apache.

the class IncrementalBackupDUnitTest method testIncompleteInBaseline.

/**
   * Successful if a member performs a full backup if their backup is marked as incomplete in the
   * baseline.
   */
@Test
public void testIncompleteInBaseline() throws Exception {
    /*
     * Get the member ID for VM 1 and perform a baseline.
     */
    String memberId = getMemberId(Host.getHost(0).getVM(1));
    assertBackupStatus(performBaseline());
    /*
     * Find all of the member's oplogs in the baseline (*.crf,*.krf,*.drf)
     */
    Collection<File> memberBaselineOplogs = FileUtils.listFiles(getBackupDirForMember(getBaselineDir(), memberId), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberBaselineOplogs.isEmpty());
    List<String> memberBaselineOplogNames = new LinkedList<>();
    TransformUtils.transform(memberBaselineOplogs, memberBaselineOplogNames, TransformUtils.fileNameTransformer);
    // Mark the baseline as incomplete (even though it really isn't)
    markAsIncomplete(Host.getHost(0).getVM(1));
    /*
     * Do an incremental. It should discover that the baseline is incomplete and backup all of the
     * operation logs that are in the baseline.
     */
    assertBackupStatus(performIncremental());
    /*
     * Find all of the member's oplogs in the incremental (*.crf,*.krf,*.drf)
     */
    Collection<File> memberIncrementalOplogs = FileUtils.listFiles(getBackupDirForMember(getIncrementalDir(), memberId), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberIncrementalOplogs.isEmpty());
    List<String> memberIncrementalOplogNames = new LinkedList<>();
    TransformUtils.transform(memberIncrementalOplogs, memberIncrementalOplogNames, TransformUtils.fileNameTransformer);
    /*
     * Assert that all of the baseline operation logs are in the incremental backup. If so, then the
     * incomplete marker was discovered in the baseline by the incremental backup process.
     */
    for (String oplog : memberBaselineOplogNames) {
        assertTrue(memberIncrementalOplogNames.contains(oplog));
    }
}
Also used : RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File) LinkedList(java.util.LinkedList) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 12 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project geode by apache.

the class IncrementalBackupDUnitTest method testBackupUserDeployedJarFiles.

/**
   * Successful if a user deployed jar file is included as part of the backup.
   */
@Test
public void testBackupUserDeployedJarFiles() throws Exception {
    final String jarName = "BackupJarDeploymentDUnit";
    final String jarNameRegex = ".*" + jarName + ".*";
    final ClassBuilder classBuilder = new ClassBuilder();
    final byte[] classBytes = classBuilder.createJarFromName(jarName);
    VM vm0 = Host.getHost(0).getVM(0);
    /*
     * Deploy a "dummy" jar to the VM.
     */
    File deployedJarFile = vm0.invoke(() -> {
        DeployedJar deployedJar = ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, classBytes);
        return deployedJar.getFile();
    });
    assertTrue(deployedJarFile.exists());
    /*
     * Perform backup. Make sure it is successful.
     */
    assertBackupStatus(baseline(vm0));
    /*
     * Make sure the user deployed jar is part of the backup.
     */
    Collection<File> memberDeployedJarFiles = FileUtils.listFiles(getBackupDirForMember(getBaselineDir(), getMemberId(vm0)), new RegexFileFilter(jarNameRegex), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberDeployedJarFiles.isEmpty());
    // Shut down our member so we can perform a restore
    PersistentID id = getPersistentID(vm0);
    closeCache(vm0);
    /*
     * Get the VM's user directory.
     */
    final String vmDir = vm0.invoke(() -> System.getProperty("user.dir"));
    File backupDir = getBackupDirForMember(getBaselineDir(), getMemberId(vm0));
    vm0.bounce();
    /*
     * Cleanup "dummy" jar from file system.
     */
    Pattern pattern = Pattern.compile('^' + jarName + ".*#\\d++$");
    deleteMatching(new File("."), pattern);
    // Execute the restore
    performRestore(new File(id.getDirectory()), backupDir);
    /*
     * Make sure the user deployed jar is part of the restore.
     */
    Collection<File> restoredJars = FileUtils.listFiles(new File(vmDir), new RegexFileFilter(jarNameRegex), DirectoryFileFilter.DIRECTORY);
    assertFalse(restoredJars.isEmpty());
    List<String> restoredJarNames = new LinkedList<>();
    TransformUtils.transform(memberDeployedJarFiles, restoredJarNames, TransformUtils.fileNameTransformer);
    for (String name : restoredJarNames) {
        assertTrue(name.contains(jarName));
    }
    // Restart the member
    openCache(vm0);
    /*
     * Remove the "dummy" jar from the VM.
     */
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            for (DeployedJar jarClassLoader : ClassPathLoader.getLatest().getJarDeployer().findDeployedJars()) {
                if (jarClassLoader.getJarName().startsWith(jarName)) {
                    ClassPathLoader.getLatest().getJarDeployer().undeploy(jarClassLoader.getJarName());
                }
            }
            return null;
        }
    });
    /*
     * Cleanup "dummy" jar from file system.
     */
    pattern = Pattern.compile('^' + jarName + ".*#\\d++$");
    deleteMatching(new File(vmDir), pattern);
}
Also used : DeployedJar(org.apache.geode.internal.DeployedJar) Pattern(java.util.regex.Pattern) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) ClassBuilder(org.apache.geode.internal.ClassBuilder) LinkedList(java.util.LinkedList) AdminException(org.apache.geode.admin.AdminException) IOException(java.io.IOException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) File(java.io.File) PersistentID(org.apache.geode.cache.persistence.PersistentID) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 13 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter 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 14 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project geode by apache.

the class BackupJUnitTest method restoreBackup.

private void restoreBackup(boolean expectFailure) throws IOException, InterruptedException {
    Collection<File> restoreScripts = FileUtils.listFiles(backupDir, new RegexFileFilter(".*restore.*"), DirectoryFileFilter.DIRECTORY);
    assertNotNull(restoreScripts);
    assertEquals("Restore scripts " + restoreScripts, 1, restoreScripts.size());
    for (File script : restoreScripts) {
        execute(script, expectFailure);
    }
}
Also used : RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File)

Example 15 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project geode by apache.

the class PersistentPartitionedRegionTestBase method restoreBackup.

protected void restoreBackup(int expectedNumScripts) throws IOException, InterruptedException {
    Collection<File> restoreScripts = FileUtils.listFiles(getBackupDir(), new RegexFileFilter(".*restore.*"), DirectoryFileFilter.DIRECTORY);
    assertEquals("Restore scripts " + restoreScripts, expectedNumScripts, restoreScripts.size());
    for (File script : restoreScripts) {
        execute(script);
    }
}
Also used : RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File)

Aggregations

File (java.io.File)15 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)15 Test (org.junit.Test)7 LinkedList (java.util.LinkedList)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 PersistentID (org.apache.geode.cache.persistence.PersistentID)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 AdminException (org.apache.geode.admin.AdminException)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 Gson (com.google.gson.Gson)1 FileReader (java.io.FileReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1