Skip to content

Commit

Permalink
Display more verbose error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cc committed Mar 31, 2017
1 parent 1c309b9 commit e2e3e6f
Showing 1 changed file with 38 additions and 32 deletions.
Expand Up @@ -30,6 +30,7 @@
import alluxio.underfs.sleepfs.SleepingUnderFileSystemOptions; import alluxio.underfs.sleepfs.SleepingUnderFileSystemOptions;
import alluxio.util.CommonUtils; import alluxio.util.CommonUtils;


import com.google.common.base.Joiner;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.io.Files; import com.google.common.io.Files;
import org.junit.AfterClass; import org.junit.AfterClass;
Expand Down Expand Up @@ -148,9 +149,8 @@ public void rootConcurrentRename() throws Exception {
dsts[i] = new AlluxioURI("/renamed" + i); dsts[i] = new AlluxioURI("/renamed" + i);
} }


int errors = concurrentRename(srcs, dsts); assertErrorsSizeEquals(concurrentRename(srcs, dsts), 0);


Assert.assertEquals("More than 0 errors: " + errors, 0, errors);
List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
Collections.sort(files, new IntegerSuffixedPathComparator()); Collections.sort(files, new IntegerSuffixedPathComparator());
for (int i = 0; i < numThreads; i++) { for (int i = 0; i < numThreads; i++) {
Expand All @@ -172,9 +172,8 @@ public void rootConcurrentDelete() throws Exception {
mFileSystem.createFile(paths[i], sCreatePersistedFileOptions).close(); mFileSystem.createFile(paths[i], sCreatePersistedFileOptions).close();
} }


int errors = concurrentDelete(paths); assertErrorsSizeEquals(concurrentDelete(paths), 0);


Assert.assertEquals("More than 0 errors: " + errors, 0, errors);
List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
Assert.assertEquals(0, files.size()); Assert.assertEquals(0, files.size());
} }
Expand All @@ -197,9 +196,9 @@ public void folderConcurrentRename() throws Exception {
mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close(); mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
dsts[i] = dir.join("/renamed" + i); dsts[i] = dir.join("/renamed" + i);
} }
int errors = concurrentRename(srcs, dsts);


Assert.assertEquals("More than 0 errors: " + errors, 0, errors); assertErrorsSizeEquals(concurrentRename(srcs, dsts), 0);

List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/dir")); List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/dir"));
Collections.sort(files, new IntegerSuffixedPathComparator()); Collections.sort(files, new IntegerSuffixedPathComparator());
for (int i = 0; i < numThreads; i++) { for (int i = 0; i < numThreads; i++) {
Expand All @@ -222,9 +221,9 @@ public void folderConcurrentDelete() throws Exception {
paths[i] = dir.join("/file" + i); paths[i] = dir.join("/file" + i);
mFileSystem.createFile(paths[i], sCreatePersistedFileOptions).close(); mFileSystem.createFile(paths[i], sCreatePersistedFileOptions).close();
} }
int errors = concurrentDelete(paths);


Assert.assertEquals("More than 0 errors: " + errors, 0, errors); assertErrorsSizeEquals(concurrentDelete(paths), 0);

List<URIStatus> files = mFileSystem.listStatus(dir); List<URIStatus> files = mFileSystem.listStatus(dir);
Assert.assertEquals(0, files.size()); Assert.assertEquals(0, files.size());
} }
Expand Down Expand Up @@ -253,9 +252,9 @@ public void prefixConcurrentDelete() throws Exception {
} }
mFileSystem.createFile(paths[i], sCreatePersistedFileOptions).close(); mFileSystem.createFile(paths[i], sCreatePersistedFileOptions).close();
} }
int errors = concurrentDelete(paths);


Assert.assertEquals("More than 0 errors: " + errors, 0, errors); assertErrorsSizeEquals(concurrentDelete(paths), 0);

List<URIStatus> files = mFileSystem.listStatus(dir1); List<URIStatus> files = mFileSystem.listStatus(dir1);
// Should only contain a single directory // Should only contain a single directory
Assert.assertEquals(1, files.size()); Assert.assertEquals(1, files.size());
Expand Down Expand Up @@ -284,10 +283,10 @@ public void sameFileConcurrentRename() throws Exception {
// Create the one source file // Create the one source file
mFileSystem.createFile(srcs[0], sCreatePersistedFileOptions).close(); mFileSystem.createFile(srcs[0], sCreatePersistedFileOptions).close();


int errors = concurrentRename(srcs, dsts); ConcurrentHashSet<Throwable> errors = concurrentRename(srcs, dsts);


// We should get an error for all but 1 rename // We should get an error for all but 1 rename
Assert.assertEquals(numThreads - 1, errors); Assert.assertEquals(numThreads - 1, errors.size());


List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));


Expand All @@ -309,10 +308,10 @@ public void sameFileConcurrentDelete() throws Exception {
// Create the single file // Create the single file
mFileSystem.createFile(paths[0], sCreatePersistedFileOptions).close(); mFileSystem.createFile(paths[0], sCreatePersistedFileOptions).close();


int errors = concurrentDelete(paths); ConcurrentHashSet<Throwable> errors = concurrentDelete(paths);


// We should get an error for all but 1 delete // We should get an error for all but 1 delete
Assert.assertEquals(numThreads - 1, errors); Assert.assertEquals(numThreads - 1, errors.size());


List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
Assert.assertEquals(0, files.size()); Assert.assertEquals(0, files.size());
Expand All @@ -335,10 +334,10 @@ public void sameDirConcurrentRename() throws Exception {
mFileSystem.createDirectory(srcs[0]); mFileSystem.createDirectory(srcs[0]);
mFileSystem.createFile(new AlluxioURI("/dir/file"), sCreatePersistedFileOptions).close(); mFileSystem.createFile(new AlluxioURI("/dir/file"), sCreatePersistedFileOptions).close();


int errors = concurrentRename(srcs, dsts); ConcurrentHashSet<Throwable> errors = concurrentRename(srcs, dsts);


// We should get an error for all but 1 rename // We should get an error for all but 1 rename
Assert.assertEquals(numThreads - 1, errors); assertErrorsSizeEquals(errors, numThreads - 1);
// Only one renamed dir should exist // Only one renamed dir should exist
List<URIStatus> existingDirs = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> existingDirs = mFileSystem.listStatus(new AlluxioURI("/"));
Assert.assertEquals(1, existingDirs.size()); Assert.assertEquals(1, existingDirs.size());
Expand All @@ -362,10 +361,10 @@ public void sameDirConcurrentDelete() throws Exception {
// Create the single directory // Create the single directory
mFileSystem.createDirectory(paths[0], sCreatePersistedDirOptions); mFileSystem.createDirectory(paths[0], sCreatePersistedDirOptions);


int errors = concurrentDelete(paths); ConcurrentHashSet<Throwable> errors = concurrentDelete(paths);


// We should get an error for all but 1 delete // We should get an error for all but 1 delete
Assert.assertEquals(numThreads - 1, errors); assertErrorsSizeEquals(errors, numThreads - 1);
List<URIStatus> dirs = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> dirs = mFileSystem.listStatus(new AlluxioURI("/"));
Assert.assertEquals(0, dirs.size()); Assert.assertEquals(0, dirs.size());
} }
Expand All @@ -384,10 +383,10 @@ public void sameDstConcurrentRename() throws Exception {
dsts[i] = new AlluxioURI("/renamed"); dsts[i] = new AlluxioURI("/renamed");
} }


int errors = concurrentRename(srcs, dsts); ConcurrentHashSet<Throwable> errors = concurrentRename(srcs, dsts);


// We should get an error for all but 1 rename. // We should get an error for all but 1 rename.
Assert.assertEquals(numThreads - 1, errors); assertErrorsSizeEquals(errors, numThreads - 1);


List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/")); List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
// Store file names in a set to ensure the names are all unique. // Store file names in a set to ensure the names are all unique.
Expand Down Expand Up @@ -425,10 +424,10 @@ public void twoDirConcurrentRename() throws Exception {
dsts[i] = dir2.join("renamed" + i); dsts[i] = dir2.join("renamed" + i);
} }


int errors = concurrentRename(srcs, dsts); ConcurrentHashSet<Throwable> errors = concurrentRename(srcs, dsts);


// We should get no errors // We should get no errors
Assert.assertEquals(0, errors); assertErrorsSizeEquals(errors, 0);


List<URIStatus> dir1Files = mFileSystem.listStatus(dir1); List<URIStatus> dir1Files = mFileSystem.listStatus(dir1);
List<URIStatus> dir2Files = mFileSystem.listStatus(dir2); List<URIStatus> dir2Files = mFileSystem.listStatus(dir2);
Expand Down Expand Up @@ -466,10 +465,10 @@ public void acrossDirConcurrentRename() throws Exception {
mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close(); mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
} }


int errors = concurrentRename(srcs, dsts); ConcurrentHashSet<Throwable> errors = concurrentRename(srcs, dsts);


// We should get no errors. // We should get no errors.
Assert.assertEquals(0, errors); assertErrorsSizeEquals(errors, 0);


List<URIStatus> dir1Files = mFileSystem.listStatus(dir1); List<URIStatus> dir1Files = mFileSystem.listStatus(dir1);
List<URIStatus> dir2Files = mFileSystem.listStatus(dir2); List<URIStatus> dir2Files = mFileSystem.listStatus(dir2);
Expand Down Expand Up @@ -509,10 +508,10 @@ public void sharedPrefixDirConcurrentRename() throws Exception {
mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close(); mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
} }


int errors = concurrentRename(srcs, dsts); ConcurrentHashSet<Throwable> errors = concurrentRename(srcs, dsts);


// We should get no errors. // We should get no errors.
Assert.assertEquals(0, errors); assertErrorsSizeEquals(errors, 0);


List<URIStatus> dir1Files = mFileSystem.listStatus(dir1); List<URIStatus> dir1Files = mFileSystem.listStatus(dir1);
List<URIStatus> dir2Files = mFileSystem.listStatus(dir2); List<URIStatus> dir2Files = mFileSystem.listStatus(dir2);
Expand All @@ -528,6 +527,13 @@ public void sharedPrefixDirConcurrentRename() throws Exception {
} }
} }


private void assertErrorsSizeEquals(ConcurrentHashSet<Throwable> errors, int expected) {
if (errors.size() != expected) {
Assert.fail(String.format("Expected %d errors, but got %d, errors:\n",
expected, errors.size()) + Joiner.on("\n").join(errors));
}
}

/** /**
* Helper for renaming a list of paths concurrently. Assumes the srcs are already created and * Helper for renaming a list of paths concurrently. Assumes the srcs are already created and
* dsts do not exist. Enforces that the run time of this method is not greater than twice the * dsts do not exist. Enforces that the run time of this method is not greater than twice the
Expand All @@ -536,9 +542,9 @@ public void sharedPrefixDirConcurrentRename() throws Exception {
* *
* @param src list of source paths * @param src list of source paths
* @param dst list of destination paths * @param dst list of destination paths
* @return how many errors occurred * @return the occurred errors
*/ */
private int concurrentRename(final AlluxioURI[] src, final AlluxioURI[] dst) private ConcurrentHashSet<Throwable> concurrentRename(final AlluxioURI[] src, final AlluxioURI[] dst)
throws Exception { throws Exception {
final int numFiles = src.length; final int numFiles = src.length;
final CyclicBarrier barrier = new CyclicBarrier(numFiles); final CyclicBarrier barrier = new CyclicBarrier(numFiles);
Expand Down Expand Up @@ -578,17 +584,17 @@ public void run() {
long durationMs = CommonUtils.getCurrentMs() - startMs; long durationMs = CommonUtils.getCurrentMs() - startMs;
Assert.assertTrue("Execution duration " + durationMs + " took longer than expected " + LIMIT_MS, Assert.assertTrue("Execution duration " + durationMs + " took longer than expected " + LIMIT_MS,
durationMs < LIMIT_MS); durationMs < LIMIT_MS);
return errors.size(); return errors;
} }


/** /**
* Helper for deleting a list of paths concurrently. Enforces that the run time of this method * Helper for deleting a list of paths concurrently. Enforces that the run time of this method
* is not greater than twice the sleep time (to infer concurrent operations). * is not greater than twice the sleep time (to infer concurrent operations).
* *
* @param paths list of paths to delete * @param paths list of paths to delete
* @return how many errors occurred * @return the occurred errors
*/ */
private int concurrentDelete(final AlluxioURI[] paths) private ConcurrentHashSet<Throwable> concurrentDelete(final AlluxioURI[] paths)
throws Exception { throws Exception {
final int numFiles = paths.length; final int numFiles = paths.length;
final CyclicBarrier barrier = new CyclicBarrier(numFiles); final CyclicBarrier barrier = new CyclicBarrier(numFiles);
Expand Down Expand Up @@ -628,7 +634,7 @@ public void run() {
long durationMs = CommonUtils.getCurrentMs() - startMs; long durationMs = CommonUtils.getCurrentMs() - startMs;
Assert.assertTrue("Execution duration " + durationMs + " took longer than expected " + LIMIT_MS, Assert.assertTrue("Execution duration " + durationMs + " took longer than expected " + LIMIT_MS,
durationMs < LIMIT_MS); durationMs < LIMIT_MS);
return errors.size(); return errors;
} }


/** /**
Expand Down

0 comments on commit e2e3e6f

Please sign in to comment.