use of alluxio.client.file.FileSystemContext in project alluxio by Alluxio.
the class AbstractFileSystemTest method verifyBlockLocations.
void verifyBlockLocations(List<WorkerNetAddress> blockWorkers, List<String> ufsLocations, List<WorkerNetAddress> allWorkers, List<WorkerNetAddress> expectedWorkers) throws Exception {
FileBlockInfo blockInfo = new FileBlockInfo().setBlockInfo(new BlockInfo().setLocations(blockWorkers.stream().map(addr -> new alluxio.wire.BlockLocation().setWorkerAddress(addr)).collect(toList()))).setUfsLocations(ufsLocations);
FileInfo fileInfo = new FileInfo().setLastModificationTimeMs(111L).setLastAccessTimeMs(123L).setFolder(false).setOwner("user1").setGroup("group1").setMode(00755).setFileBlockInfos(Arrays.asList(blockInfo));
Path path = new Path("/dir/file");
AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
AlluxioBlockStore blockStore = mock(AlluxioBlockStore.class);
PowerMockito.mockStatic(AlluxioBlockStore.class);
PowerMockito.when(AlluxioBlockStore.create(any(FileSystemContext.class))).thenReturn(blockStore);
FileSystemContext fsContext = mock(FileSystemContext.class);
when(fsContext.getClientContext()).thenReturn(ClientContext.create(mConfiguration));
when(fsContext.getClusterConf()).thenReturn(mConfiguration);
when(fsContext.getPathConf(any(AlluxioURI.class))).thenReturn(mConfiguration);
alluxio.client.file.FileSystem fs = alluxio.client.file.FileSystem.Factory.create(fsContext);
alluxio.client.file.FileSystem spyFs = spy(fs);
doReturn(new URIStatus(fileInfo)).when(spyFs).getStatus(uri);
List<BlockWorkerInfo> eligibleWorkerInfos = allWorkers.stream().map(worker -> new BlockWorkerInfo(worker, 0, 0)).collect(toList());
when(fsContext.getCachedWorkers()).thenReturn(eligibleWorkerInfos);
List<HostAndPort> expectedWorkerNames = expectedWorkers.stream().map(addr -> HostAndPort.fromParts(addr.getHost(), addr.getDataPort())).collect(toList());
FileSystem alluxioHadoopFs = new FileSystem(spyFs);
FileStatus file = new FileStatus(0, false, 0, 0, 0, 0, null, null, null, path);
long start = 0;
long len = 100;
BlockLocation[] locations = alluxioHadoopFs.getFileBlockLocations(file, start, len);
assertEquals(1, locations.length);
Collections.sort(expectedWorkerNames, (x, y) -> x.toString().compareTo(y.toString()));
String[] actualNames = locations[0].getNames();
String[] actualHosts = locations[0].getHosts();
Arrays.sort(actualNames);
Arrays.sort(actualHosts);
assertArrayEquals(expectedWorkerNames.stream().map(HostAndPort::toString).toArray(), actualNames);
assertArrayEquals(expectedWorkerNames.stream().map(HostAndPort::getHost).toArray(), actualHosts);
alluxioHadoopFs.close();
}
use of alluxio.client.file.FileSystemContext in project alluxio by Alluxio.
the class TestRunner method runTests.
/**
* Runs combinations of tests of operation, read and write type.
*
* @return the number of failed tests
*/
private int runTests() throws Exception {
mDirectory = PathUtils.concatPath(mDirectory, TEST_DIRECTORY_NAME);
AlluxioURI testDir = new AlluxioURI(mDirectory);
FileSystemContext fsContext = FileSystemContext.create(new InstancedConfiguration(ConfigurationUtils.defaults()));
FileSystem fs = FileSystem.Factory.create(fsContext);
if (fs.exists(testDir)) {
fs.delete(testDir, DeletePOptions.newBuilder().setRecursive(true).setUnchecked(true).build());
}
int failed = 0;
List<ReadType> readTypes = mReadType == null ? READ_TYPES : Lists.newArrayList(ReadType.valueOf(mReadType));
List<WriteType> writeTypes = mWriteType == null ? WRITE_TYPES : Lists.newArrayList(WriteType.valueOf(mWriteType));
List<OperationType> operations = mOperation == null ? Lists.newArrayList(OperationType.values()) : Lists.newArrayList(OperationType.valueOf(mOperation));
for (ReadType readType : readTypes) {
for (WriteType writeType : writeTypes) {
for (OperationType opType : operations) {
System.out.println(String.format("runTest --operation %s --readType %s --writeType %s", opType, readType, writeType));
failed += runTest(opType, readType, writeType, fsContext);
}
}
}
if (failed > 0) {
System.out.println("Number of failed tests: " + failed);
}
return failed;
}
use of alluxio.client.file.FileSystemContext in project alluxio by Alluxio.
the class ImpersonationIntegrationTest method checkCreateFile.
private void checkCreateFile(Subject subject, String expectedUser) throws Exception {
FileSystemContext context = FileSystemContext.create(subject, ServerConfiguration.global());
FileSystem fs = mLocalAlluxioClusterResource.get().getClient(context);
fs.createFile(new AlluxioURI("/impersonation-test")).close();
List<URIStatus> listing = fs.listStatus(new AlluxioURI("/"));
Assert.assertEquals(1, listing.size());
URIStatus status = listing.get(0);
Assert.assertEquals(expectedUser, status.getOwner());
}
use of alluxio.client.file.FileSystemContext in project alluxio by Alluxio.
the class ImpersonationIntegrationTest method impersonationNotUsed.
@Test
@LocalAlluxioClusterResource.Config(confParams = { IMPERSONATION_GROUPS_CONFIG, "*" })
public void impersonationNotUsed() throws Exception {
ServerConfiguration.set(PropertyKey.SECURITY_LOGIN_IMPERSONATION_USERNAME, Constants.IMPERSONATION_NONE);
FileSystemContext context = FileSystemContext.create(createHdfsSubject(), ServerConfiguration.global());
FileSystem fs = mLocalAlluxioClusterResource.get().getClient(context);
fs.createFile(new AlluxioURI("/impersonation-test")).close();
List<URIStatus> listing = fs.listStatus(new AlluxioURI("/"));
Assert.assertEquals(1, listing.size());
URIStatus status = listing.get(0);
Assert.assertNotEquals(IMPERSONATION_USER, status.getOwner());
}
use of alluxio.client.file.FileSystemContext in project alluxio by Alluxio.
the class PathConfigurationIntegrationTest method before.
@Before
public void before() throws Exception {
FileSystemContext metaCtx = FileSystemContext.create(ServerConfiguration.global());
mMetaConfig = new RetryHandlingMetaMasterConfigClient(MasterClientContext.newBuilder(metaCtx.getClientContext()).build());
setPathConfigurations(mMetaConfig);
FileSystemContext fsCtx = FileSystemContext.create(ServerConfiguration.global());
fsCtx.getClientContext().loadConf(fsCtx.getMasterAddress(), true, true);
mFileSystem = mLocalAlluxioClusterResource.get().getClient(fsCtx);
mWriteThrough = CreateFilePOptions.newBuilder().setRecursive(true).setWriteType(WritePType.THROUGH).build();
}
Aggregations