use of alluxio.underfs.UfsManager in project alluxio by Alluxio.
the class UfsFallbackBlockWriteHandlerTest method before.
@Before
public void before() throws Exception {
mFile = mTestFolder.newFile();
mOutputStream = new FileOutputStream(mFile);
mBlockStore = new TieredBlockStore();
mBlockWorker = new MockBlockWorker();
UnderFileSystem mockUfs = Mockito.mock(UnderFileSystem.class);
UfsManager ufsManager = Mockito.mock(UfsManager.class);
UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> mockUfs, AlluxioURI.EMPTY_URI);
Mockito.when(ufsManager.get(Mockito.anyLong())).thenReturn(ufsClient);
Mockito.when(mockUfs.createNonexistingFile(Mockito.anyString(), Mockito.any(CreateOptions.class))).thenReturn(mOutputStream).thenReturn(new FileOutputStream(mFile, true));
mResponseObserver = Mockito.mock(StreamObserver.class);
mWriteHandler = new UfsFallbackBlockWriteHandler(mBlockWorker, ufsManager, mResponseObserver, mUserInfo, false);
setupResponseTrigger();
// create a partial block in block store first
mBlockStore.createBlock(TEST_SESSION_ID, TEST_BLOCK_ID, AllocateOptions.forCreate(CHUNK_SIZE, BlockStoreLocation.anyDirInTier(Constants.MEDIUM_MEM)));
BlockWriter writer = mBlockStore.getBlockWriter(TEST_SESSION_ID, TEST_BLOCK_ID);
DataBuffer buffer = newDataBuffer(PARTIAL_WRITTEN);
mPartialChecksum = getChecksum(buffer);
writer.append((ByteBuf) buffer.getNettyOutput());
writer.close();
}
use of alluxio.underfs.UfsManager in project alluxio by Alluxio.
the class CacheRequestManagerTest method before.
/**
* Sets up all dependencies before a test runs.
*/
@Before
public void before() throws IOException {
BlockMasterClient blockMasterClient = mock(BlockMasterClient.class);
BlockMasterClientPool blockMasterClientPool = spy(new BlockMasterClientPool());
when(blockMasterClientPool.createNewResource()).thenReturn(blockMasterClient);
TieredBlockStore blockStore = new TieredBlockStore();
FileSystemMasterClient fileSystemMasterClient = mock(FileSystemMasterClient.class);
Sessions sessions = mock(Sessions.class);
// Connect to the real UFS for testing
UfsManager ufsManager = mock(UfsManager.class);
mRootUfs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> UnderFileSystem.Factory.create(mRootUfs, UnderFileSystemConfiguration.defaults(ServerConfiguration.global())), new AlluxioURI(mRootUfs));
when(ufsManager.get(anyLong())).thenReturn(ufsClient);
mBlockWorker = spy(new DefaultBlockWorker(blockMasterClientPool, fileSystemMasterClient, sessions, blockStore, ufsManager));
FileSystemContext context = mock(FileSystemContext.class);
mCacheRequestManager = spy(new CacheRequestManager(GrpcExecutors.CACHE_MANAGER_EXECUTOR, mBlockWorker, context));
// Write an actual file to UFS
String testFilePath = File.createTempFile("temp", null, new File(mRootUfs)).getAbsolutePath();
byte[] buffer = BufferUtils.getIncreasingByteArray(CHUNK_SIZE);
BufferUtils.writeBufferToFile(testFilePath, buffer);
// create options
BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE);
URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setUfsPath(testFilePath).setBlockIds(Collections.singletonList(BLOCK_ID)).setLength(CHUNK_SIZE).setBlockSizeBytes(CHUNK_SIZE).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
OpenFilePOptions readOptions = FileSystemOptions.openFileDefaults(mConf);
InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, mConf);
mOpenUfsBlockOptions = options.getOpenUfsBlockOptions(BLOCK_ID);
}
use of alluxio.underfs.UfsManager in project alluxio by Alluxio.
the class UfsConfigurationJournalTest method testOptionsPersisted.
@Test
public void testOptionsPersisted() throws Exception {
// Set ufs specific options and other mount flags
AlluxioURI mountPoint = new AlluxioURI("/mnt");
ImmutableMap<String, String> options = ImmutableMap.of("k1", "v1", "k2", "v2");
mFs.mount(mountPoint, new AlluxioURI(LOCAL_UFS_PATH), MountPOptions.newBuilder().putAllProperties(options).setReadOnly(true).setShared(true).build());
// Get mount id
MountTable mountTable = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mMountTable");
long mountId = mountTable.resolve(mountPoint).getMountId();
// Restart masters
mLocalAlluxioClusterResource.get().restartMasters();
// Checks all options and flags are persisted after restart
UfsManager ufsManager = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mUfsManager");
try (CloseableResource<UnderFileSystem> resource = ufsManager.get(mountId).acquireUfsResource()) {
UnderFileSystemConfiguration ufsConf = Whitebox.getInternalState(resource.get(), "mConf");
assertEquals(ufsConf.getMountSpecificConf().size(), options.size());
for (Map.Entry<String, String> entry : options.entrySet()) {
assertEquals(entry.getValue(), ufsConf.getMountSpecificConf().get(entry.getKey()));
}
assertTrue(ufsConf.isReadOnly());
assertTrue(ufsConf.isShared());
}
}
Aggregations