Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable read-write operations on federated filesystem
- Depends on fix for MODE-2252 (https://github.com/escowles/modeshape/tree/mode-2252)
- Remove IT from connector project (because REST API transaction context is required for the tests)
- Re-enabled the REST API federation write tests
- Disable caching of generated properties

Resolves: https://www.pivotaltracker.com/story/show/70954532
  • Loading branch information
escowles authored and Andrew Woods committed Sep 11, 2014
1 parent 8a97cfd commit 59d3447
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 52 deletions.
Expand Up @@ -85,10 +85,6 @@ public void initialize(final NamespaceRegistry registry,
final NodeTypeManager nodeTypeManager) throws RepositoryException, IOException {
super.initialize(registry, nodeTypeManager);

if (!isReadonly()) {
throw new RepositoryException("The " + getClass().getName() + " must have \"readonly\" set to true!");
}

if (propertiesDirectoryPath != null) {
propertiesDirectory = new File(propertiesDirectoryPath);
if (!propertiesDirectory.exists() || !propertiesDirectory.isDirectory()) {
Expand Down Expand Up @@ -120,6 +116,10 @@ public Document getDocumentById(final String id) {
}

final Document doc = super.getDocumentById(id);
if ( doc == null ) {
LOGGER.debug("Non-existent node, document is null: {}", id);
return doc;
}

final DocumentReader docReader = readDocument(doc);
final DocumentWriter docWriter = writeDocument(doc);
Expand Down Expand Up @@ -147,11 +147,6 @@ public Document getDocumentById(final String id) {
decorateObjectNode(docReader, docWriter);
}

// Persist new properties (if allowed)
if (shouldCacheProperties()) {
saveProperties(docReader);
}

return docWriter.document();
}

Expand Down
Expand Up @@ -160,17 +160,6 @@ public void setUp() throws Exception {
mockContext.getNamespaceRegistry().register("premis", "http://www.loc.gov/premis/rdf/v1#");
}

@Test(expected = RepositoryException.class)
public void testThatReadOnlyIsRequired() throws IOException, RepositoryException {
final FedoraFileSystemConnector c = new FedoraFileSystemConnector();
setField(c, "directoryPath", directoryPath.toString());
setField(c, "translator", mockTranslator);
setField(c, "context", mockContext);
setField(c, "extraPropertiesStore", mockExtraPropertiesStore);
setField(mockTranslator, "names", mockNameFactory);
c.initialize(mockRegistry, mockNodeTypeManager);
}

@Test
public void testGetDocumentByIdNull() throws Exception {
final Document doc = connector.getDocumentById(null);
Expand Down
Expand Up @@ -18,7 +18,6 @@
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.impl.rdf.impl.DefaultIdentifierTranslator;
import org.junit.Ignore;
import org.junit.Test;

import javax.jcr.PathNotFoundException;
Expand All @@ -32,20 +31,7 @@

/**
* @author Mike Durbin
*
* This class is ignored until non-'readonly' federations are supported. At that time,
* include the following in the repository.json and remove the 'ignore' annotation.
*
* "federated-directory" : {
* "classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
* "directoryPath" : "${fcrepo.test.dir1:must-be-provided}",
* "projections" : [ "default:/federated => /" ],
* "contentBasedSha1" : "false",
* "readonly" : false,
* "extraPropertiesStorage" : "json"
* },
*/
@Ignore
public class BasicReadWriteFedoraFileSystemConnectorIT extends AbstractFedoraFileSystemConnectorIT {

@Override
Expand Down
Expand Up @@ -22,10 +22,8 @@
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import java.io.File;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Mike Durbin
Expand Down Expand Up @@ -58,9 +56,6 @@ public void verifyThatPropertiesAreExternal() throws RepositoryException {
assertEquals("There should be exactly as many visible nodes as actual files (ie, no hidden sidecar files).",
fileForNode(object.getNode()).getParentFile().list().length,
getChildCount(object.getNode().getParent()));
final File propFile = propertyFileForNode(object.getNode());
assertTrue("There should be properties file (" + propFile + ") in the external directory.",
propFile.exists());
}

protected int getChildCount(final Node node) throws RepositoryException {
Expand Down
Expand Up @@ -7,6 +7,14 @@
"allowCreation" : true
},
"externalSources" : {
"federated-directory" : {
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "${fcrepo.test.dir1:must-be-provided}",
"projections" : [ "default:/federated => /" ],
"contentBasedSha1" : "false",
"readonly" : false,
"extraPropertiesStorage" : "json"
},
"federated-directory-read-only" : {
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "${fcrepo.test.dir2:must-be-provided}",
Expand All @@ -30,4 +38,4 @@
}
},
"node-types" : ["fedora-node-types.cnd"]
}
}
Expand Up @@ -23,6 +23,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class FedoraContentIT extends AbstractResourceIT {
private static final String faulkner1 =
"The past is never dead. It's not even past.";

private static final String marblesChecksum = "urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df";

@Test
public void testAddDatastream() throws Exception {
final String pid = getRandomUniquePid();
Expand Down Expand Up @@ -252,8 +256,7 @@ public void testGetDatastreamContent() throws Exception {
logger.debug("Returned from HTTP GET, now checking content...");
assertTrue("Got the wrong content back!", "marbles for everyone"
.equals(EntityUtils.toString(response.getEntity())));
assertEquals("urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df",
response.getFirstHeader("ETag").getValue().replace("\"", ""));
assertEquals(marblesChecksum, response.getFirstHeader("ETag").getValue().replace("\"", ""));

final ContentDisposition contentDisposition =
new ContentDisposition(response.getFirstHeader("Content-Disposition").getValue());
Expand All @@ -278,8 +281,7 @@ public void testRefetchingDatastreamContent() throws Exception {
format.setTimeZone(getTimeZone("GMT"));

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("If-None-Match",
"\"urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df\"");
method_test_get.setHeader("If-None-Match", "\"" + marblesChecksum + "\"");
method_test_get.setHeader("If-Modified-Since", format
.format(new Date()));

Expand All @@ -296,8 +298,7 @@ public void testConditionalPutOfDatastreamContent() throws Exception {
assertEquals(201, getStatus(createDSMethod));

final HttpPut method_test_put = new HttpPut(serverAddress + pid + "/ds1/fcr:content");
method_test_put.setHeader("If-Match",
"\"urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df\"");
method_test_put.setHeader("If-Match", "\"" + marblesChecksum + "\"");
method_test_put.setHeader("If-Unmodified-Since",
"Sat, 29 Oct 1994 19:43:31 GMT");
method_test_put.setEntity(new StringEntity("asdf"));
Expand Down Expand Up @@ -427,4 +428,22 @@ public void testPostToExistingDSIndirect() throws Exception {
assertEquals(409, getStatus(repostDSMethod));
}

@Test
public void testFederatedChecksumCaching() throws Exception {
final String ds1 = "FileSystem1/ds1";
final String readonlyContent = serverAddress + "readonlyfiles/" + ds1 + "/fcr:content";

// retrieve content
final HttpGet get = new HttpGet(readonlyContent);
assertEquals(200, getStatus(get));

// verify that the checksum has been cached
final File readonlyMeta = new File("target/test-classes/test-meta/" + ds1 + ".content.modeshape.json");
assertTrue( readonlyMeta.exists() );
assertTrue( readonlyMeta.length() > 0 );
final String readonlyMetaContent = IOUtils.toString(new FileReader(readonlyMeta));
logger.warn("XXX: " + readonlyMetaContent);
assertTrue( readonlyMetaContent.contains("urn:sha1:18835fd8075c1e1f266366c1bdfd1ac6a357f242") );
}

}
Expand Up @@ -110,7 +110,6 @@
import org.apache.http.util.EntityUtils;
import org.fcrepo.http.commons.domain.RDFMediaType;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -1454,9 +1453,7 @@ public String getMethod() {

/**
* I should be able to upload a file to a read/write federated filesystem.
* TODO: ignored until read-write filesystem support is reintroduced.
**/
@Ignore
@Test
public void testUploadToProjection() throws IOException {
// upload file to federated filesystem using rest api
Expand All @@ -1483,9 +1480,7 @@ public void testUploadToProjection() throws IOException {

/**
* I should be able to copy objects from the repository to a federated filesystem.
* TODO: ignored until read-write filesystem support is reintroduced.
**/
@Ignore
@Test
public void testCopyToProjection() throws IOException {
// create object in the repository
Expand Down
Empty file.
11 changes: 10 additions & 1 deletion fcrepo-http-api/src/test/resources/test_repository.json
Expand Up @@ -19,10 +19,19 @@
"fileSystem" : {
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "target/test-classes/test-objects",
"readonly" : true,
"readonly" : false,
"extraPropertiesStorage": "json",
"cacheTtlSeconds" : 2,
"projections" : [ "default:/files => /" ]
},
"readonly" : {
"classname" : "org.fcrepo.connector.file.FedoraFileSystemConnector",
"directoryPath" : "target/test-classes/test-objects",
"propertiesDirectoryPath" : "target/test-classes/test-meta",
"readonly" : true,
"extraPropertiesStorage": "none",
"cacheTtlSeconds" : 2,
"projections" : [ "default:/readonlyfiles => /" ]
}
},
"security" : {
Expand Down

0 comments on commit 59d3447

Please sign in to comment.