use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method twoDirConcurrentRename.
/**
* Tests renaming files concurrently from one directory to another succeeds.
*/
@Test
public void twoDirConcurrentRename() throws Exception {
int numThreads = CONCURRENCY_FACTOR;
final AlluxioURI[] srcs = new AlluxioURI[numThreads];
final AlluxioURI[] dsts = new AlluxioURI[numThreads];
AlluxioURI dir1 = new AlluxioURI("/dir1");
AlluxioURI dir2 = new AlluxioURI("/dir2");
mFileSystem.createDirectory(dir1);
mFileSystem.createDirectory(dir2);
for (int i = 0; i < numThreads; i++) {
srcs[i] = dir1.join("file" + i);
mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
dsts[i] = dir2.join("renamed" + i);
}
int errors = concurrentRename(srcs, dsts);
// We should get no errors
Assert.assertEquals(0, errors);
List<URIStatus> dir1Files = mFileSystem.listStatus(dir1);
List<URIStatus> dir2Files = mFileSystem.listStatus(dir2);
Assert.assertEquals(0, dir1Files.size());
Assert.assertEquals(numThreads, dir2Files.size());
Collections.sort(dir2Files, new IntegerSuffixedPathComparator());
for (int i = 0; i < numThreads; i++) {
Assert.assertEquals(dsts[i].getName(), dir2Files.get(i).getName());
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method acrossDirConcurrentRename.
/**
* Tests renaming files concurrently from and to two directories succeeds.
*/
@Test
public void acrossDirConcurrentRename() throws Exception {
int numThreads = CONCURRENCY_FACTOR;
final AlluxioURI[] srcs = new AlluxioURI[numThreads];
final AlluxioURI[] dsts = new AlluxioURI[numThreads];
AlluxioURI dir1 = new AlluxioURI("/dir1");
AlluxioURI dir2 = new AlluxioURI("/dir2");
mFileSystem.createDirectory(dir1);
mFileSystem.createDirectory(dir2);
for (int i = 0; i < numThreads; i++) {
// Dir1 has even files, dir2 has odd files.
if (i % 2 == 0) {
srcs[i] = dir1.join("file" + i);
dsts[i] = dir2.join("renamed" + i);
} else {
srcs[i] = dir2.join("file" + i);
dsts[i] = dir1.join("renamed" + i);
}
mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
}
int errors = concurrentRename(srcs, dsts);
// We should get no errors.
Assert.assertEquals(0, errors);
List<URIStatus> dir1Files = mFileSystem.listStatus(dir1);
List<URIStatus> dir2Files = mFileSystem.listStatus(dir2);
Assert.assertEquals(numThreads / 2, dir1Files.size());
Assert.assertEquals(numThreads / 2, dir2Files.size());
Collections.sort(dir1Files, new IntegerSuffixedPathComparator());
for (int i = 1; i < numThreads; i += 2) {
Assert.assertEquals(dsts[i].getName(), dir1Files.get(i / 2).getName());
}
Collections.sort(dir2Files, new IntegerSuffixedPathComparator());
for (int i = 0; i < numThreads; i += 2) {
Assert.assertEquals(dsts[i].getName(), dir2Files.get(i / 2).getName());
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method sameDirConcurrentRename.
/**
* Tests that many threads concurrently renaming the same directory will only succeed once.
*/
@Test
public void sameDirConcurrentRename() throws Exception {
int numThreads = CONCURRENCY_FACTOR;
final AlluxioURI[] srcs = new AlluxioURI[numThreads];
final AlluxioURI[] dsts = new AlluxioURI[numThreads];
for (int i = 0; i < numThreads; i++) {
srcs[i] = new AlluxioURI("/dir");
dsts[i] = new AlluxioURI("/renamed" + i);
}
// Create the one source directory
mFileSystem.createDirectory(srcs[0]);
mFileSystem.createFile(new AlluxioURI("/dir/file"), sCreatePersistedFileOptions).close();
int errors = concurrentRename(srcs, dsts);
// We should get an error for all but 1 rename
Assert.assertEquals(numThreads - 1, errors);
// Only one renamed dir should exist
List<URIStatus> existingDirs = mFileSystem.listStatus(new AlluxioURI("/"));
Assert.assertEquals(1, existingDirs.size());
Assert.assertTrue(existingDirs.get(0).getName().startsWith("renamed"));
// The directory should contain the file
List<URIStatus> dirChildren = mFileSystem.listStatus(new AlluxioURI(existingDirs.get(0).getPath()));
Assert.assertEquals(1, dirChildren.size());
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method consistentGetFileInfo.
/**
* Tests that getFileInfo (read operation) either returns the correct file info or fails if it
* has been renamed while the operation was waiting for the file lock.
*/
@Test
public void consistentGetFileInfo() throws Exception {
final int iterations = CONCURRENCY_FACTOR;
final AlluxioURI file = new AlluxioURI("/file");
final AlluxioURI dst = new AlluxioURI("/dst");
final CyclicBarrier barrier = new CyclicBarrier(2);
// If there are exceptions, we will store them here.
final ConcurrentHashSet<Throwable> errors = new ConcurrentHashSet<>();
Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread th, Throwable ex) {
errors.add(ex);
}
};
for (int i = 0; i < iterations; i++) {
// Don't want sleeping ufs behavior, so do not write to ufs
mFileSystem.createFile(file, CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE)).close();
Thread renamer = new Thread(new Runnable() {
@Override
public void run() {
try {
AuthenticatedClientUser.set(TEST_USER);
barrier.await();
mFileSystem.rename(file, dst);
mFileSystem.delete(dst);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
});
renamer.setUncaughtExceptionHandler(exceptionHandler);
Thread reader = new Thread(new Runnable() {
@Override
public void run() {
try {
AuthenticatedClientUser.set(TEST_USER);
barrier.await();
URIStatus status = mFileSystem.getStatus(file);
// If the uri status is successfully obtained, then the path should match
Assert.assertEquals(file.getName(), status.getName());
} catch (InvalidPathException | FileDoesNotExistException e) {
// InvalidPathException - if the file is renamed while the thread waits for the lock.
// FileDoesNotExistException - if the file is fully renamed before the getFileInfo call.
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
});
reader.setUncaughtExceptionHandler(exceptionHandler);
renamer.start();
reader.start();
renamer.join();
reader.join();
Assert.assertTrue("Errors detected: " + errors, errors.isEmpty());
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method rootConcurrentRename.
/**
* Tests concurrent renames within the root do not block on each other.
*/
@Test
public void rootConcurrentRename() throws Exception {
final int numThreads = CONCURRENCY_FACTOR;
AlluxioURI[] srcs = new AlluxioURI[numThreads];
AlluxioURI[] dsts = new AlluxioURI[numThreads];
for (int i = 0; i < numThreads; i++) {
srcs[i] = new AlluxioURI("/file" + i);
mFileSystem.createFile(srcs[i], sCreatePersistedFileOptions).close();
dsts[i] = new AlluxioURI("/renamed" + i);
}
int errors = concurrentRename(srcs, dsts);
Assert.assertEquals("More than 0 errors: " + errors, 0, errors);
List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"));
Collections.sort(files, new IntegerSuffixedPathComparator());
for (int i = 0; i < numThreads; i++) {
Assert.assertEquals(dsts[i].getName(), files.get(i).getName());
}
Assert.assertEquals(numThreads, files.size());
}
Aggregations