use of alluxio.client.block.stream.TestBlockOutStream in project alluxio by Alluxio.
the class ReplicateDefinitionTest method runTaskNoBlockWorker.
@Test
public void runTaskNoBlockWorker() throws Exception {
byte[] input = BufferUtils.getIncreasingByteArray(0, (int) TEST_BLOCK_SIZE);
TestBlockInStream mockInStream = new TestBlockInStream(input, TEST_BLOCK_ID, input.length, false, BlockInStreamSource.NODE_LOCAL);
TestBlockOutStream mockOutStream = new TestBlockOutStream(ByteBuffer.allocate(MAX_BYTES), TEST_BLOCK_SIZE);
mThrown.expect(NotFoundException.class);
mThrown.expectMessage(ExceptionMessage.NO_LOCAL_BLOCK_WORKER_LOAD_TASK.getMessage(TEST_BLOCK_ID));
runTaskReplicateTestHelper(Lists.<BlockWorkerInfo>newArrayList(), mockInStream, mockOutStream);
}
use of alluxio.client.block.stream.TestBlockOutStream in project alluxio by Alluxio.
the class FileOutStreamTest method before.
/**
* Sets up the different contexts and clients before a test runs.
*/
@Before
public void before() throws Exception {
GroupMappingServiceTestUtils.resetCache();
ClientTestUtils.setSmallBufferSizes(sConf);
mClientContext = ClientContext.create(sConf);
// PowerMock enums and final classes
mFileSystemContext = PowerMockito.mock(FileSystemContext.class);
when(mFileSystemContext.getClientContext()).thenReturn(mClientContext);
when(mFileSystemContext.getClusterConf()).thenReturn(sConf);
when(mFileSystemContext.getPathConf(any(AlluxioURI.class))).thenReturn(sConf);
mBlockStore = PowerMockito.mock(AlluxioBlockStore.class);
mFileSystemMasterClient = PowerMockito.mock(FileSystemMasterClient.class);
PowerMockito.mockStatic(AlluxioBlockStore.class);
PowerMockito.when(AlluxioBlockStore.create(mFileSystemContext)).thenReturn(mBlockStore);
when(mFileSystemContext.acquireMasterClientResource()).thenReturn(new DummyCloseableResource<>(mFileSystemMasterClient));
when(mFileSystemMasterClient.getStatus(any(AlluxioURI.class), any(GetStatusPOptions.class))).thenReturn(new URIStatus(new FileInfo()));
// Return sequentially increasing numbers for new block ids
when(mFileSystemMasterClient.getNewBlockIdForFile(FILE_NAME)).thenAnswer(new Answer<Long>() {
private long mCount = 0;
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
return mCount++;
}
});
// Set up out streams. When they are created, add them to outStreamMap
final Map<Long, TestBlockOutStream> outStreamMap = new HashMap<>();
when(mBlockStore.getOutStream(anyLong(), eq(BLOCK_LENGTH), any(OutStreamOptions.class))).thenAnswer(new Answer<TestBlockOutStream>() {
@Override
public TestBlockOutStream answer(InvocationOnMock invocation) throws Throwable {
Long blockId = invocation.getArgument(0, Long.class);
if (!outStreamMap.containsKey(blockId)) {
TestBlockOutStream newStream = new TestBlockOutStream(ByteBuffer.allocate(1000), BLOCK_LENGTH);
outStreamMap.put(blockId, newStream);
}
return outStreamMap.get(blockId);
}
});
BlockWorkerInfo workerInfo = new BlockWorkerInfo(new WorkerNetAddress().setHost("localhost").setTieredIdentity(TieredIdentityFactory.fromString("node=localhost", sConf)).setRpcPort(1).setDataPort(2).setWebPort(3), Constants.GB, 0);
when(mFileSystemContext.getCachedWorkers()).thenReturn(Lists.newArrayList(workerInfo));
mAlluxioOutStreamMap = outStreamMap;
// Create an under storage stream so that we can check whether it has been flushed
final AtomicBoolean underStorageFlushed = new AtomicBoolean(false);
mUnderStorageOutputStream = new TestUnderFileSystemFileOutStream(ByteBuffer.allocate(5000)) {
@Override
public void flush() throws IOException {
super.flush();
underStorageFlushed.set(true);
}
};
mUnderStorageFlushed = underStorageFlushed;
PowerMockito.mockStatic(UnderFileSystemFileOutStream.class);
PowerMockito.when(UnderFileSystemFileOutStream.create(any(FileSystemContext.class), any(WorkerNetAddress.class), any(OutStreamOptions.class))).thenReturn(mUnderStorageOutputStream);
OutStreamOptions options = OutStreamOptions.defaults(mClientContext).setBlockSizeBytes(BLOCK_LENGTH).setWriteType(WriteType.CACHE_THROUGH).setUfsPath(FILE_NAME.getPath());
mTestStream = createTestStream(FILE_NAME, options);
}
use of alluxio.client.block.stream.TestBlockOutStream in project alluxio by Alluxio.
the class ReplicateDefinitionTest method runTaskLocalBlockWorkerDifferentFileStatus.
@Test
public void runTaskLocalBlockWorkerDifferentFileStatus() throws Exception {
for (boolean persisted : new boolean[] { true, false }) {
for (boolean pinned : new boolean[] { true, false }) {
mTestStatus.getFileInfo().setPersisted(persisted).setMediumTypes(pinned ? Sets.newHashSet(Constants.MEDIUM_MEM) : Collections.emptySet());
byte[] input = BufferUtils.getIncreasingByteArray(0, (int) TEST_BLOCK_SIZE);
TestBlockInStream mockInStream = new TestBlockInStream(input, TEST_BLOCK_ID, input.length, false, BlockInStreamSource.NODE_LOCAL);
TestBlockOutStream mockOutStream = new TestBlockOutStream(ByteBuffer.allocate(MAX_BYTES), TEST_BLOCK_SIZE);
BlockWorkerInfo localBlockWorker = new BlockWorkerInfo(LOCAL_ADDRESS, TEST_BLOCK_SIZE, 0);
runTaskReplicateTestHelper(Lists.newArrayList(localBlockWorker), mockInStream, mockOutStream);
assertEquals(TEST_BLOCK_SIZE, mockInStream.getBytesRead());
if (!persisted || pinned) {
assertArrayEquals(String.format("input-output mismatched: pinned=%s, persisted=%s", pinned, persisted), input, mockOutStream.getWrittenData());
}
}
}
}
Aggregations