Search in sources :

Example 1 with TestBlockOutStream

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);
}
Also used : TestBlockOutStream(alluxio.client.block.stream.TestBlockOutStream) TestBlockInStream(alluxio.client.block.stream.TestBlockInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with TestBlockOutStream

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);
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) GetStatusPOptions(alluxio.grpc.GetStatusPOptions) TestUnderFileSystemFileOutStream(alluxio.client.block.stream.TestUnderFileSystemFileOutStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) FileInfo(alluxio.wire.FileInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WorkerNetAddress(alluxio.wire.WorkerNetAddress) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) TestBlockOutStream(alluxio.client.block.stream.TestBlockOutStream) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) AlluxioURI(alluxio.AlluxioURI) Before(org.junit.Before)

Example 3 with TestBlockOutStream

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());
            }
        }
    }
}
Also used : BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) TestBlockOutStream(alluxio.client.block.stream.TestBlockOutStream) TestBlockInStream(alluxio.client.block.stream.TestBlockInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TestBlockOutStream (alluxio.client.block.stream.TestBlockOutStream)3 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)2 TestBlockInStream (alluxio.client.block.stream.TestBlockInStream)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AlluxioURI (alluxio.AlluxioURI)1 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 TestUnderFileSystemFileOutStream (alluxio.client.block.stream.TestUnderFileSystemFileOutStream)1 OutStreamOptions (alluxio.client.file.options.OutStreamOptions)1 GetStatusPOptions (alluxio.grpc.GetStatusPOptions)1 FileInfo (alluxio.wire.FileInfo)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Before (org.junit.Before)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1