@Test public void shouldPersistBinariesAcrossRestart() throws Exception { String repositoryConfigFile = "config/repo-config-persistent-cache.json"; File persistentFolder = new File("target/persistent_repository"); // remove all persisted content ... FileUtil.delete(persistentFolder); assertDataPersistenceAcrossRestarts(repositoryConfigFile); }
@Before public void beforeClass() { directory = new File("target/fsbs/"); FileUtil.delete(directory); directory.mkdirs(); trash = new File(directory, FileSystemBinaryStore.TRASH_DIRECTORY_NAME); store = new FileSystemBinaryStore(directory); store.setMinimumBinarySizeInBytes(MIN_BINARY_SIZE); store.setMimeTypeDetector(DEFAULT_DETECTOR); print = false; }
@Before @Override public void beforeEach() throws Exception { File backupArea = new File("target/backupArea"); backupDirectory = new File(backupArea, "repoBackups"); backupDirectory2 = new File(backupArea, "repoBackupsAfter"); FileUtil.delete(backupArea); backupDirectory.mkdirs(); backupDirectory2.mkdirs(); new File(backupArea, "backRepo").mkdirs(); new File(backupArea, "restoreRepo").mkdirs(); super.beforeEach(); }
@Test public void shouldPersistBinariesAcrossRestart() throws Exception { File persistentFolder = new File("target/persistent_repository"); // remove all persisted content ... FileUtil.delete(persistentFolder); final List<File> testFiles = new ArrayList<File>(); final Map<String, Long> testFileSizesInBytes = new HashMap<String, Long>(); testFiles.add(getFile("mimetype/test.xml")); testFiles.add(getFile("mimetype/modeshape.doc")); testFiles.add(getFile("mimetype/log4j.properties")); for (File testFile : testFiles) { assertThat(testFile.getPath() + " should exist", testFile.exists(), is(true)); assertThat(testFile.getPath() + " should be a file", testFile.isFile(), is(true)); assertThat(testFile.getPath() + " should be readable", testFile.canRead(), is(true)); testFileSizesInBytes.put(testFile.getName(), testFile.length()); } String repositoryConfigFile = "config/repo-config-persistent-cache.json"; final JcrTools tools = new JcrTools(); startRunStop( new RepositoryOperation() { @Override public Void call() throws Exception { Session session = repository.login(); // Add some content ... session.getRootNode().addNode("testNode"); for (File testFile : testFiles) { String name = testFile.getName(); Node fileNode = tools.uploadFile(session, "/testNode/" + name, testFile); Binary binary = fileNode.getNode("jcr:content").getProperty("jcr:data").getBinary(); assertThat(binary.getSize(), is(testFileSizesInBytes.get(name))); } session.save(); Node testNode = session.getNode("/testNode"); for (File testFile : testFiles) { String name = testFile.getName(); Node fileNode = testNode.getNode(name); assertThat(fileNode, is(notNullValue())); Binary binary = fileNode.getNode("jcr:content").getProperty("jcr:data").getBinary(); assertThat(binary.getSize(), is(testFileSizesInBytes.get(name))); } Query query = session .getWorkspace() .getQueryManager() .createQuery("SELECT * FROM [nt:file]", Query.JCR_SQL2); QueryResult results = query.execute(); NodeIterator iter = results.getNodes(); while (iter.hasNext()) { Node fileNode = iter.nextNode(); assertThat(fileNode, is(notNullValue())); String name = fileNode.getName(); Binary binary = fileNode.getNode("jcr:content").getProperty("jcr:data").getBinary(); assertThat(binary.getSize(), is(testFileSizesInBytes.get(name))); } session.logout(); return null; } }, repositoryConfigFile); startRunStop( new RepositoryOperation() { @Override public Void call() throws Exception { Session session = repository.login(); assertNotNull(session.getNode("/testNode")); for (File testFile : testFiles) { String name = testFile.getName(); Node fileNode = session.getNode("/testNode/" + name); assertNotNull(fileNode); Binary binary = fileNode.getNode("jcr:content").getProperty("jcr:data").getBinary(); assertThat(binary.getSize(), is(testFileSizesInBytes.get(name))); } Query query = session .getWorkspace() .getQueryManager() .createQuery("SELECT * FROM [nt:file]", Query.JCR_SQL2); QueryResult results = query.execute(); NodeIterator iter = results.getNodes(); while (iter.hasNext()) { Node fileNode = iter.nextNode(); String name = fileNode.getName(); Binary binary = fileNode.getNode("jcr:content").getProperty("jcr:data").getBinary(); assertThat(binary.getSize(), is(testFileSizesInBytes.get(name))); } session.logout(); return null; } }, repositoryConfigFile); }
@After public void afterClass() { FileUtil.delete(directory); }