Skip to content

Commit

Permalink
reapply 'remove synchronous updateRepositorySize...' which got revert…
Browse files Browse the repository at this point in the history
…ed too.
  • Loading branch information
cbeer committed Apr 19, 2013
1 parent 1420263 commit 3726cab
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 48 deletions.
Expand Up @@ -55,41 +55,6 @@ public static void dumpMetrics(final PrintStream os) {
RegistryService.dumpMetrics(os);
}

/**
* Alter the total repository size.
*
* @param change
* the amount by which to [de|in]crement the total repository
* size
* @param session
* the javax.jcr.Session in which the originating mutation is
* occurring
* @throws PathNotFoundException
* @throws RepositoryException
*/
public void updateRepositorySize(final Long change, final Session session)
throws PathNotFoundException, RepositoryException {
try {
logger.debug("updateRepositorySize called with change quantity: " +
change);

final Node objectStore = findOrCreateNode(session, "/objects");

final Property sizeProperty = objectStore.getProperty(FEDORA_SIZE);

final Long previousSize = sizeProperty.getLong();
logger.debug("Previous repository size: " + previousSize);
synchronized (sizeProperty) {
sizeProperty.setValue(previousSize + change);
session.save();
}
logger.debug("Current repository size: " + sizeProperty.getLong());
} catch (final RepositoryException e) {
logger.warn(e.toString());
throw e;
}
}

/**
*
* @return a double of the size of the fedora:datastream binary content
Expand Down
Expand Up @@ -125,13 +125,10 @@ public void testDeleteOBject() throws RepositoryException {
final Node mockObjectsNode = mock(Node.class);
final Property mockProp = mock(Property.class);
final Node mockObjNode = mock(Node.class);
when(mockObjectsNode.getProperty(FEDORA_SIZE)).thenReturn(mockProp);
when(mockSession.getRootNode()).thenReturn(mockRootNode);
when(mockRootNode.getNode("objects")).thenReturn(mockObjectsNode);
when(mockSession.getNode(objPath)).thenReturn(mockObjNode);
PowerMockito.mockStatic(ServiceHelpers.class);
final long mockSize = new SecureRandom().nextLong();
when(ServiceHelpers.getObjectSize(mockObjNode)).thenReturn(mockSize); // testing with a random value
final ObjectService testObj = new ObjectService();
testObj.deleteObject("foo", mockSession);
verify(mockSession).getNode(objPath);
Expand Down
Expand Up @@ -148,16 +148,6 @@ public void testDumpMetrics() {
RepositoryService.dumpMetrics(mockPrintStream);
}

@Test
public void testUpdateRepositorySize() throws PathNotFoundException,
RepositoryException {
final String content = "asdf";
final Node mockContent = TestHelpers.getContentNodeMock(content);
when(mockDsNode.getNode(Node.JCR_CONTENT)).thenReturn(mockContent);
testObj.updateRepositorySize(expectedSize, mockSession);
assertEquals(expectedSize, testObj.getRepositorySize(mockSession));
}

@Test
public void testGetRepositorySize() throws RepositoryException {
final Long actual = testObj.getRepositorySize(mockSession);
Expand Down

0 comments on commit 3726cab

Please sign in to comment.