/** * Creates a new instance of {@link alluxio.util.webui.UIFileInfo}. * * @param info underlying {@link FileInfo} */ public UIFileInfo(FileInfo info) { this(new URIStatus(info)); }
/** * Informs the mock that the given fileInfos are children of the parent. */ private void setChildren(String parent, FileInfo... children) throws Exception { List<URIStatus> statuses = new ArrayList<>(); for (FileInfo child : children) { statuses.add(new URIStatus(child)); } when(mMockFileSystem.listStatus(new AlluxioURI(parent))) .thenReturn(Lists.newArrayList(statuses)); }
/** * Creates a mock {@link FileInStream} which will supply the given bytes. * * @param context file system context * @param bytes the bytes to supply */ public MockFileInStream(FileSystemContext context, byte[] bytes, AlluxioConfiguration conf) { super(new URIStatus(new FileInfo()), new InStreamOptions(new URIStatus(new FileInfo()), conf), context); mStream = new ByteArrayInputStream(bytes); }
@Override public List<URIStatus> listStatus(final AlluxioURI path, final ListStatusPOptions options) throws AlluxioStatusException { return retryRPC(() -> { List<URIStatus> result = new ArrayList<>(); for (alluxio.grpc.FileInfo fileInfo : mClient.listStatus(ListStatusPRequest.newBuilder() .setPath(path.getPath()).setOptions(options).build()) .getFileInfosList()) { result.add(new URIStatus(GrpcUtils.fromProto(fileInfo))); } return result; }, "ListStatus"); }
@Test public void constructor() { try { new URIStatus(null); Assert.fail("Cannot create a URIStatus from a null FileInfo"); } catch (Exception e) { Assert.assertTrue(e instanceof NullPointerException); Assert.assertThat(e.getMessage(), CoreMatchers.containsString("Cannot create a URIStatus from a null FileInfo")); } }
/** * Tests that the worker will not delete the source directory if the directory still contains * files. */ @Test public void dontDeleteNonEmptySourceTest() throws Exception { when(mMockFileSystem.listStatus(new AlluxioURI(TEST_DIR))) .thenReturn(Lists.newArrayList(new URIStatus(new FileInfo()))); runTask(TEST_DIR, TEST_SOURCE, TEST_DESTINATION, WriteType.THROUGH); verify(mMockFileSystem, times(0)).delete(eq(new AlluxioURI(TEST_DIR)), any(DeletePOptions.class)); }
private FileInfo createFileWithNoLocations(String testFile, int numOfBlocks) throws Exception { FileInfo testFileInfo = new FileInfo(); AlluxioURI uri = new AlluxioURI(testFile); List<FileBlockInfo> blockInfos = Lists.newArrayList(); for (int i = 0; i < numOfBlocks; i++) { blockInfos.add(new FileBlockInfo() .setBlockInfo(new BlockInfo().setLocations(Lists.<BlockLocation>newArrayList()))); } testFileInfo.setFolder(false).setPath(testFile).setFileBlockInfos(blockInfos); Mockito.when(mMockFileSystem.listStatus(uri)) .thenReturn(Lists.newArrayList(new URIStatus(testFileInfo))); Mockito.when(mMockFileSystem.getStatus(uri)).thenReturn(new URIStatus(testFileInfo)); return testFileInfo; } }
/** * Tests that the worker will delete the source directory if the directory contains only * directories. */ @Test public void deleteDirsOnlySourceDir() throws Exception { String inner = TEST_DIR + "/innerDir"; when(mMockFileSystem.listStatus(new AlluxioURI(TEST_DIR))).thenReturn( Lists.newArrayList(new URIStatus(new FileInfo().setPath(inner).setFolder(true)))); when(mMockFileSystem.listStatus(new AlluxioURI(inner))) .thenReturn(Lists.<URIStatus>newArrayList()); runTask(TEST_DIR, TEST_SOURCE, TEST_DESTINATION, WriteType.THROUGH); verify(mMockFileSystem).delete(eq(new AlluxioURI(TEST_DIR)), any(DeletePOptions.class)); }
@Test public void testEquals() throws Exception { FileInfo fileInfo = FileInfoTest.createRandom(); URIStatus uriStatus1 = new URIStatus(fileInfo); URIStatus uriStatus2 = new URIStatus(fileInfo); Assert.assertTrue(uriStatus1.equals(uriStatus2)); Assert.assertEquals(uriStatus1.hashCode(), uriStatus2.hashCode()); } }
/** * Creates a directory with the given name. * * @return file info for the created directory */ private FileInfo createDirectory(String name) throws Exception { // Call all directories mount points to force cross-mount functionality. FileInfo info = new FileInfo().setFolder(true).setPath(name).setMountPoint(true); when(mMockFileSystem.getStatus(new AlluxioURI(name))).thenReturn(new URIStatus(info)); return info; }
/** * Tests for the {@link BaseFileSystem#listStatus(AlluxioURI, ListStatusPOptions)} method. */ @Test public void listStatus() throws Exception { AlluxioURI file = new AlluxioURI("/file"); List<URIStatus> infos = new ArrayList<>(); infos.add(new URIStatus(new FileInfo())); ListStatusPOptions listStatusOptions = ListStatusPOptions.getDefaultInstance(); when(mFileSystemMasterClient.listStatus(file, listStatusOptions)).thenReturn(infos); assertSame(infos, mFileSystem.listStatus(file, listStatusOptions)); verify(mFileSystemMasterClient).listStatus(file, listStatusOptions); verifyFilesystemContextAcquiredAndReleased(); }
@Override public URIStatus getStatus(final AlluxioURI path, final GetStatusPOptions options) throws AlluxioStatusException { return retryRPC(() -> new URIStatus(GrpcUtils .fromProto(mClient.getStatus(GetStatusPRequest.newBuilder().setPath(path.getPath()) .setOptions(options).build()).getFileInfo())), "GetStatus"); }
@Test public void getInStreamMissingBlock() throws Exception { URIStatus dummyStatus = new URIStatus( new FileInfo().setPersisted(false).setBlockIds(Collections.singletonList(0L))); InStreamOptions options = new InStreamOptions(dummyStatus, OpenFilePOptions.getDefaultInstance(), sConf); when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo()); when(mMasterClient.getWorkerInfoList()).thenReturn(Collections.emptyList()); mException.expect(NotFoundException.class); mException.expectMessage("unavailable in both Alluxio and UFS"); mBlockStore.getInStream(BLOCK_ID, options).getAddress(); }
@Test public void getInStreamNoWorkers() throws Exception { URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L))); InStreamOptions options = new InStreamOptions(dummyStatus, OpenFilePOptions.getDefaultInstance(), sConf); when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo()); when(mMasterClient.getWorkerInfoList()).thenReturn(Collections.emptyList()); mException.expect(UnavailableException.class); mException.expectMessage("No Alluxio worker available"); mBlockStore.getInStream(BLOCK_ID, options).getAddress(); }
/** * Tests for the {@link BaseFileSystem#openFile(AlluxioURI, OpenFilePOptions)} method to * complete successfully. */ @Test public void openFile() throws Exception { AlluxioURI file = new AlluxioURI("/file"); URIStatus status = new URIStatus(new FileInfo()); GetStatusPOptions getStatusOptions = GetStatusPOptions.getDefaultInstance(); when(mFileSystemMasterClient.getStatus(file, getStatusOptions)).thenReturn(status); mFileSystem.openFile(file, OpenFilePOptions.getDefaultInstance()); verify(mFileSystemMasterClient).getStatus(file, getStatusOptions); verifyFilesystemContextAcquiredAndReleased(); }
/** * Tests the creation of a file via the * {@link BaseFileSystem#createFile(AlluxioURI, CreateFilePOptions)} method. */ @Test public void createFile() throws Exception { doNothing().when(mFileSystemMasterClient) .createFile(any(AlluxioURI.class), any(CreateFilePOptions.class)); URIStatus status = new URIStatus(new FileInfo()); AlluxioURI file = new AlluxioURI("/file"); GetStatusPOptions getStatusOptions = GetStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER).build(); when(mFileSystemMasterClient.getStatus(file, getStatusOptions)).thenReturn(status); FileOutStream out = mFileSystem.createFile(file, CreateFilePOptions.getDefaultInstance()); verify(mFileSystemMasterClient).createFile(file, CreateFilePOptions.getDefaultInstance()); assertEquals(out.mUri, file); verifyFilesystemContextAcquiredAndReleased(); }
/** * Tests for the {@link BaseFileSystem#getStatus(AlluxioURI, GetStatusPOptions)} method. */ @Test public void getStatus() throws Exception { AlluxioURI file = new AlluxioURI("/file"); URIStatus status = new URIStatus(new FileInfo()); GetStatusPOptions getStatusOptions = GetStatusPOptions.getDefaultInstance(); when(mFileSystemMasterClient.getStatus(file, getStatusOptions)).thenReturn(status); assertSame(status, mFileSystem.getStatus(file, getStatusOptions)); verify(mFileSystemMasterClient).getStatus(file, getStatusOptions); verifyFilesystemContextAcquiredAndReleased(); }
@Test public void getInStreamRemote() throws Exception { WorkerNetAddress remote1 = new WorkerNetAddress().setHost("remote1"); WorkerNetAddress remote2 = new WorkerNetAddress().setHost("remote2"); BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays .asList(new BlockLocation().setWorkerAddress(remote1), new BlockLocation().setWorkerAddress(remote2))); when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info); // We should sometimes get remote1 and sometimes get remote2. Set<WorkerNetAddress> results = new HashSet<>(); for (int i = 0; i < 40; i++) { results.add(mBlockStore.getInStream(BLOCK_ID, new InStreamOptions( new URIStatus(new FileInfo().setBlockIds(Lists.newArrayList(BLOCK_ID))), sConf)) .getAddress()); } assertEquals(Sets.newHashSet(remote1, remote2), results); }
@Test public void selectExecutorsMissingLocationTest() throws Exception { AlluxioURI uri = new AlluxioURI("/test"); PersistConfig config = new PersistConfig(uri.getPath(), -1, true, ""); long blockId = 1; BlockInfo blockInfo = new BlockInfo().setBlockId(blockId); FileBlockInfo fileBlockInfo = new FileBlockInfo().setBlockInfo(blockInfo); FileInfo testFileInfo = new FileInfo(); testFileInfo.setFileBlockInfos(Lists.newArrayList(fileBlockInfo)); Mockito.when(mMockFileSystem.getStatus(uri)).thenReturn(new URIStatus(testFileInfo)); try { new PersistDefinition(mMockFileSystemContext, mMockFileSystem).selectExecutors(config, Lists.newArrayList(new WorkerInfo()), mMockJobMasterContext); } catch (Exception e) { Assert.assertEquals("Block " + blockId + " does not exist", e.getMessage()); } } }
@Test public void getStatus() throws Exception { FileInfo fileInfo = new FileInfo() .setLastModificationTimeMs(111L) .setFolder(false) .setOwner("user1") .setGroup("group1") .setMode(00755); Path path = new Path("/dir"); alluxio.client.file.FileSystem alluxioFs = mock(alluxio.client.file.FileSystem.class); when(alluxioFs.getStatus(new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)))) .thenReturn(new URIStatus(fileInfo)); FileSystem alluxioHadoopFs = new FileSystem(alluxioFs); FileStatus fileStatus = alluxioHadoopFs.getFileStatus(path); assertFileInfoEqualsFileStatus(fileInfo, fileStatus); }