Author: marrs
Date: Fri Jun 15 14:43:10 2012
New Revision: 1350640
URL: http://svn.apache.org/viewvc?rev=1350640&view=rev
Log:
ACE-278 First part of the implementation, tests and implementation for storing
files in subfolders of the BundleFileStore.
Modified:
ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
ace/trunk/ace-obr-storage/src/test/java/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
Modified:
ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
URL:
http://svn.apache.org/viewvc/ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java?rev=1350640&r1=1350639&r2=1350640&view=diff
==============================================================================
---
ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
(original)
+++
ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
Fri Jun 15 14:43:10 2012
@@ -77,6 +77,10 @@ public class BundleFileStore implements
boolean success = false;
if (!file.exists()) {
+ File folder = file.getAbsoluteFile().getParentFile();
+ if (!folder.isDirectory() && !folder.mkdirs()) {
+ throw new IOException("Could not create folder " + folder);
+ }
try {
// the reason for first writing to a temporary file is that we
want to minimize
// the window where someone could be looking at a "partial"
file that is still being
Modified:
ace/trunk/ace-obr-storage/src/test/java/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/ace-obr-storage/src/test/java/org/apache/ace/obr/storage/file/BundleFileStoreTest.java?rev=1350640&r1=1350639&r2=1350640&view=diff
==============================================================================
---
ace/trunk/ace-obr-storage/src/test/java/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
(original)
+++
ace/trunk/ace-obr-storage/src/test/java/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
Fri Jun 15 14:43:10 2012
@@ -20,6 +20,7 @@ package org.apache.ace.obr.storage.file;
import static org.apache.ace.test.utils.TestUtils.UNIT;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -249,27 +250,42 @@ public class BundleFileStoreTest {
@Test(groups = { UNIT })
public void putBundle() throws Exception {
- m_bundleStore.put("filename", new InputStream() {
- private int i = 0;
+ String fileName = "filename";
+ m_bundleStore.put(fileName, new ByteArrayInputStream("a".getBytes()));
+ File file = new File(m_directory, fileName);
+ FileInputStream input = new FileInputStream(file);
+ assert input.read() == 'a';
+ assert input.read() == -1;
+ input.close();
+ }
- @Override
- public int read() throws IOException {
- if (i < 1) {
- i++;
- return 'a';
- }
- else {
- return -1;
- }
- }
- });
- File file = new File(m_directory, "filename");
+ @Test(groups = { UNIT })
+ public void putBundleInPathAndRemoveItAgain() throws Exception {
+ String fileName = "path/to/filename";
+ m_bundleStore.put(fileName, new ByteArrayInputStream("a".getBytes()));
+ File file = new File(m_directory, fileName);
FileInputStream input = new FileInputStream(file);
assert input.read() == 'a';
assert input.read() == -1;
input.close();
+ assert m_bundleStore.remove(fileName);
+ }
+
+ @Test(groups = { UNIT })
+ public void putBundleInInvalidPathShouldFail() throws Exception {
+ String fileName = "path/to/name";
+ String fileName2 = "path/to/name/invalid";
+ m_bundleStore.put(fileName, new ByteArrayInputStream("a".getBytes()));
+ try {
+ m_bundleStore.put(fileName2, new
ByteArrayInputStream("a".getBytes()));
+ assert false;
+ }
+ catch (IOException e) {
+ // we expect this to happen
+ }
}
+
@Test(groups = { UNIT })
public void removeExistingBundle() throws Exception {
m_bundleStore.put("filename", new InputStream() {