Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
start unit testing LowLevelStorageService
- Loading branch information
Showing
8 changed files
with
176 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
fcrepo-kernel/src/main/java/org/fcrepo/services/functions/CheckCacheEntryFixity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.fcrepo.services.functions; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import java.net.URI; | ||
import java.security.MessageDigest; | ||
|
||
import org.fcrepo.services.LowLevelStorageService; | ||
import org.fcrepo.utils.FixityResult; | ||
import org.fcrepo.utils.LowLevelCacheEntry; | ||
import org.modeshape.jcr.value.binary.BinaryStoreException; | ||
import org.slf4j.Logger; | ||
|
||
import com.google.common.base.Function; | ||
|
||
public class CheckCacheEntryFixity implements Function<LowLevelCacheEntry, FixityResult> { | ||
|
||
private static final Logger logger = getLogger(LowLevelStorageService.class); | ||
|
||
private MessageDigest digest; | ||
private URI dsChecksum; | ||
private long dsSize; | ||
public CheckCacheEntryFixity(final MessageDigest digest, | ||
final URI dsChecksum, final long dsSize) { | ||
this.digest = digest; | ||
this.dsChecksum = dsChecksum; | ||
this.dsSize = dsSize; | ||
} | ||
@Override | ||
public FixityResult apply(LowLevelCacheEntry input) { | ||
logger.debug("Checking fixity for resource in cache store " + input.toString()); | ||
FixityResult result = null; | ||
try { | ||
result = input.checkFixity(dsChecksum, dsSize, digest); | ||
} catch (BinaryStoreException e) { | ||
logger.error("Exception checking low-level fixity: {}", e); | ||
throw new IllegalStateException(e); | ||
} | ||
return result; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
fcrepo-kernel/src/main/java/org/fcrepo/services/functions/GetBinaryKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.fcrepo.services.functions; | ||
|
||
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT; | ||
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.PathNotFoundException; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.ValueFormatException; | ||
|
||
import org.modeshape.jcr.value.BinaryKey; | ||
import org.modeshape.jcr.value.BinaryValue; | ||
|
||
import com.google.common.base.Function; | ||
|
||
public class GetBinaryKey implements Function<Node, BinaryKey>{ | ||
|
||
@Override | ||
public BinaryKey apply(Node input) { | ||
try { | ||
return ((BinaryValue) input.getNode(JCR_CONTENT).getProperty( | ||
JCR_DATA).getBinary()).getKey(); | ||
} catch (RepositoryException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
fcrepo-kernel/src/main/java/org/fcrepo/services/functions/GetBinaryStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.fcrepo.services.functions; | ||
|
||
import javax.jcr.Repository; | ||
|
||
import org.modeshape.jcr.JcrRepository; | ||
import org.modeshape.jcr.value.binary.BinaryStore; | ||
|
||
import com.google.common.base.Function; | ||
|
||
public class GetBinaryStore implements Function<Repository, BinaryStore>{ | ||
/** | ||
* Extract the BinaryStore out of Modeshape (infinspan, jdbc, file, transient, etc) | ||
* @return | ||
*/ | ||
@Override | ||
public BinaryStore apply(Repository input) { | ||
try { | ||
return ((JcrRepository)input).getConfiguration() | ||
.getBinaryStorage().getBinaryStore(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.