@Test(expectedExceptions = IllegalArgumentException.class) public void willErrorWithALimitBelowMinusOne() throws IOException { final MantaClient clientSpy = spy(client); final MantaHttpHeaders headers = new MantaHttpHeaders(); final String path = "/user/stor/dir1/dir2/object.txt"; Mockito.doNothing().when(clientSpy) .delete(startsWith("/user/stor"), any(MantaHttpHeaders.class), isNull()); pruneParentDirectories(clientSpy, headers, path, -2); }
static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int maxDepth) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Pruning first object: {}", path); } client.delete(path, headers, null); final String[] directories = extractOrderedWriteableAncestorPaths(path); final int effectiveMaxDepth; if (maxDepth > directories.length) { if (LOG.isDebugEnabled()) { LOG.debug("Limit [{}] was set to greater than the number of " + "directories in path [{}]", maxDepth, directories.length); } effectiveMaxDepth = directories.length; } else if (maxDepth == PRUNE_ALL_PARENTS) { effectiveMaxDepth = directories.length; } else if (maxDepth < PRUNE_ALL_PARENTS) { final String msg = String.format("The prune directory limit " + "specified [%d] is less than the minimum value of -1", maxDepth); throw new IllegalArgumentException(msg); } else { effectiveMaxDepth = maxDepth; } for (int i = 0; i < effectiveMaxDepth; i++) { try { if (LOG.isDebugEnabled()) { LOG.debug("Pruning directory[{}] at path: {}", i, directories[i]); } client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { switch (responseException.getServerCode()) { case RESOURCE_NOT_FOUND_ERROR: LOG.debug("Directory not found: {}", directories[i]); return; case DIRECTORY_NOT_EMPTY_ERROR: LOG.debug("Directory not empty: {}", directories[i]); return; default: throw responseException; } } } }
PruneEmptyParentDirectoryStrategy { static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int maxDepth) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Pruning first object: {}", path); } client.delete(path, headers, null); final String[] directories = extractOrderedWriteableAncestorPaths(path); final int effectiveMaxDepth; if (maxDepth > directories.length) { if (LOG.isDebugEnabled()) { LOG.debug("Limit [{}] was set to greater than the number of " + "directories in path [{}]", maxDepth, directories.length); } effectiveMaxDepth = directories.length; } else if (maxDepth == PRUNE_ALL_PARENTS) { effectiveMaxDepth = directories.length; } else if (maxDepth < PRUNE_ALL_PARENTS) { final String msg = String.format("The prune directory limit " + "specified [%d] is less than the minimum value of -1", maxDepth); throw new IllegalArgumentException(msg); } else { effectiveMaxDepth = maxDepth; } for (int i = 0; i < effectiveMaxDepth; i++) { try { if (LOG.isDebugEnabled()) { LOG.debug("Pruning directory[{}] at path: {}", i, directories[i]); } client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { switch (responseException.getServerCode()) { case RESOURCE_NOT_FOUND_ERROR: LOG.debug("Directory not found: {}", directories[i]); return; case DIRECTORY_NOT_EMPTY_ERROR: LOG.debug("Directory not empty: {}", directories[i]); return; default: throw responseException; } } } } }
PruneEmptyParentDirectoryStrategy { static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int maxDepth) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Pruning first object: {}", path); } client.delete(path, headers, null); final String[] directories = extractOrderedWriteableAncestorPaths(path); final int effectiveMaxDepth; if (maxDepth > directories.length) { if (LOG.isDebugEnabled()) { LOG.debug("Limit [{}] was set to greater than the number of " + "directories in path [{}]", maxDepth, directories.length); } effectiveMaxDepth = directories.length; } else if (maxDepth == PRUNE_ALL_PARENTS) { effectiveMaxDepth = directories.length; } else if (maxDepth < PRUNE_ALL_PARENTS) { final String msg = String.format("The prune directory limit " + "specified [%d] is less than the minimum value of -1", maxDepth); throw new IllegalArgumentException(msg); } else { effectiveMaxDepth = maxDepth; } for (int i = 0; i < effectiveMaxDepth; i++) { try { if (LOG.isDebugEnabled()) { LOG.debug("Pruning directory[{}] at path: {}", i, directories[i]); } client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { switch (responseException.getServerCode()) { case RESOURCE_NOT_FOUND_ERROR: LOG.debug("Directory not found: {}", directories[i]); return; case DIRECTORY_NOT_EMPTY_ERROR: LOG.debug("Directory not empty: {}", directories[i]); return; default: throw responseException; } } } } private  PruneEmptyParentDirectoryStrategy(); }
PruneEmptyParentDirectoryStrategy { static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int maxDepth) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Pruning first object: {}", path); } client.delete(path, headers, null); final String[] directories = extractOrderedWriteableAncestorPaths(path); final int effectiveMaxDepth; if (maxDepth > directories.length) { if (LOG.isDebugEnabled()) { LOG.debug("Limit [{}] was set to greater than the number of " + "directories in path [{}]", maxDepth, directories.length); } effectiveMaxDepth = directories.length; } else if (maxDepth == PRUNE_ALL_PARENTS) { effectiveMaxDepth = directories.length; } else if (maxDepth < PRUNE_ALL_PARENTS) { final String msg = String.format("The prune directory limit " + "specified [%d] is less than the minimum value of -1", maxDepth); throw new IllegalArgumentException(msg); } else { effectiveMaxDepth = maxDepth; } for (int i = 0; i < effectiveMaxDepth; i++) { try { if (LOG.isDebugEnabled()) { LOG.debug("Pruning directory[{}] at path: {}", i, directories[i]); } client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { switch (responseException.getServerCode()) { case RESOURCE_NOT_FOUND_ERROR: LOG.debug("Directory not found: {}", directories[i]); return; case DIRECTORY_NOT_EMPTY_ERROR: LOG.debug("Directory not empty: {}", directories[i]); return; default: throw responseException; } } } } private  PruneEmptyParentDirectoryStrategy();  }
PruneEmptyParentDirectoryStrategy { static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int maxDepth) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Pruning first object: {}", path); } client.delete(path, headers, null); final String[] directories = extractOrderedWriteableAncestorPaths(path); final int effectiveMaxDepth; if (maxDepth > directories.length) { if (LOG.isDebugEnabled()) { LOG.debug("Limit [{}] was set to greater than the number of " + "directories in path [{}]", maxDepth, directories.length); } effectiveMaxDepth = directories.length; } else if (maxDepth == PRUNE_ALL_PARENTS) { effectiveMaxDepth = directories.length; } else if (maxDepth < PRUNE_ALL_PARENTS) { final String msg = String.format("The prune directory limit " + "specified [%d] is less than the minimum value of -1", maxDepth); throw new IllegalArgumentException(msg); } else { effectiveMaxDepth = maxDepth; } for (int i = 0; i < effectiveMaxDepth; i++) { try { if (LOG.isDebugEnabled()) { LOG.debug("Pruning directory[{}] at path: {}", i, directories[i]); } client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { switch (responseException.getServerCode()) { case RESOURCE_NOT_FOUND_ERROR: LOG.debug("Directory not found: {}", directories[i]); return; case DIRECTORY_NOT_EMPTY_ERROR: LOG.debug("Directory not empty: {}", directories[i]); return; default: throw responseException; } } } } private  PruneEmptyParentDirectoryStrategy();  static final Integer PRUNE_ALL_PARENTS; }