Skip to content

Commit

Permalink
maybe this is more reliable on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcin committed Sep 4, 2020
1 parent b339918 commit 2a3d45e
Showing 1 changed file with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,28 @@

package net.adamcin.oakpal.webster;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.oak.run.cli.NodeStoreFixture;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.run.cli.NodeStoreFixture;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class JcrFactoryTest {
final File testBaseDir = new File("target/repos/JcrFactoryTest");
Expand Down Expand Up @@ -86,7 +85,8 @@ public void testGetReadOnlyFixture() throws Exception {
session.save();
});
final File globalDir = new File(testBaseDir, "testGetReadOnlyFixture/globalRepo/segmentstore");
TestUtil.prepareRepo(globalDir, session -> {});
TestUtil.prepareRepo(globalDir, session -> {
});

try (NodeStoreFixture fixture = JcrFactory.getReadOnlyFixture(seedDir);
NodeStoreFixture globalFixture = JcrFactory.getReadOnlyFixture(globalDir)) {
Expand All @@ -105,7 +105,8 @@ public void testGetReadWriteFixture() throws Exception {
session.save();
});
final File globalDir = new File(testBaseDir, "testGetReadWriteFixture/globalRepo/segmentstore");
TestUtil.prepareRepo(globalDir, session -> {});
TestUtil.prepareRepo(globalDir, session -> {
});

try (NodeStoreFixture fixture = JcrFactory.getReadWriteFixture(seedDir);
NodeStoreFixture globalFixture = JcrFactory.getReadWriteFixture(globalDir)) {
Expand All @@ -116,21 +117,20 @@ public void testGetReadWriteFixture() throws Exception {
}
}

private static void recursiveDeleteWithRetry(final File toDelete) throws IOException {
try {
FileUtils.deleteDirectory(toDelete);
} catch (IOException e) {
// retry if failed.
if (toDelete.exists()) {
FileUtils.deleteDirectory(toDelete);
private static void recursiveDelete(final File toDelete) throws IOException {
if (toDelete.exists()) {
try (Stream<Path> walk = Files.walk(toDelete.toPath())) {
walk.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
}
}

@Test
public void testGetNodeStoreFixture_withWithoutFDS() throws Exception {
final File seedRepoHome = new File(testBaseDir, "testGetNodeStoreFixture_withFDS/seedRepo");
recursiveDeleteWithRetry(seedRepoHome);
recursiveDelete(seedRepoHome);
final File seedDir = new File(seedRepoHome, "segmentstore");
final File fdsDir = new File(seedRepoHome, "datastore");

Expand All @@ -139,7 +139,7 @@ public void testGetNodeStoreFixture_withWithoutFDS() throws Exception {
assertNull("blob store should be null without datastore dir", fixture.getBlobStore());
}

recursiveDeleteWithRetry(seedRepoHome);
recursiveDelete(seedRepoHome);
fdsDir.mkdirs();
assertTrue("fds dir should exist @ " + fdsDir.getAbsolutePath(), fdsDir.exists());
try (NodeStoreFixture fixture = JcrFactory.getNodeStoreFixture(false, seedDir)) {
Expand Down

0 comments on commit 2a3d45e

Please sign in to comment.