Search in sources :

Example 46 with WorkerNetAddress

use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamUfsMockLocaltion.

@Test
public void getInStreamUfsMockLocaltion() throws Exception {
    try (Closeable c = new ConfigurationRule(PropertyKey.USER_UFS_BLOCK_READ_LOCATION_POLICY, MockBlockLocationPolicy.class.getTypeName(), sConf).toResource()) {
        WorkerNetAddress worker1 = new WorkerNetAddress().setHost("worker1");
        WorkerNetAddress worker2 = new WorkerNetAddress().setHost("worker2");
        BlockInfo info = new BlockInfo().setBlockId(0);
        URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
        OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().build();
        InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf);
        ((MockBlockLocationPolicy) options.getUfsReadLocationPolicy()).setHosts(Arrays.asList(worker1, worker2));
        when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
        when(mContext.getCachedWorkers()).thenReturn(Lists.newArrayList(new BlockWorkerInfo(worker1, -1, -1), new BlockWorkerInfo(worker2, -1, -1)));
        // Location policy chooses worker1 first.
        assertEquals(worker1, mBlockStore.getInStream(BLOCK_ID, options).getAddress());
        // Location policy chooses worker2 second.
        assertEquals(worker2, mBlockStore.getInStream(BLOCK_ID, options).getAddress());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) Closeable(java.io.Closeable) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) ConfigurationRule(alluxio.ConfigurationRule) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with WorkerNetAddress

use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method testGetInStreamFallback.

private void testGetInStreamFallback(int workerCount, boolean isPersisted, int[] blockLocations, Map<Integer, Long> failedWorkers, int expectedWorker) throws Exception {
    WorkerNetAddress[] workers = new WorkerNetAddress[workerCount];
    Arrays.setAll(workers, i -> new WorkerNetAddress().setHost(String.format("worker-%d", i)));
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays.stream(blockLocations).mapToObj(x -> new BlockLocation().setWorkerAddress(workers[x])).collect(Collectors.toList()));
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(isPersisted).setBlockIds(Collections.singletonList(BLOCK_ID)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
    BlockLocationPolicy mockPolicy = mock(BlockLocationPolicy.class);
    when(mockPolicy.getWorker(any())).thenAnswer(arg -> arg.getArgument(0, GetWorkerOptions.class).getBlockWorkerInfos().iterator().next().getNetAddress());
    InStreamOptions options = new InStreamOptions(dummyStatus, FileSystemOptions.openFileDefaults(sConf), sConf);
    options.setUfsReadLocationPolicy(mockPolicy);
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info);
    when(mContext.getCachedWorkers()).thenReturn(Arrays.stream(workers).map(x -> new BlockWorkerInfo(x, -1, -1)).collect((Collectors.toList())));
    Map<WorkerNetAddress, Long> failedWorkerAddresses = failedWorkers.entrySet().stream().map(x -> new AbstractMap.SimpleImmutableEntry<>(workers[x.getKey()], x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    BlockInStream inStream = mBlockStore.getInStream(BLOCK_ID, options, failedWorkerAddresses);
    assertEquals(workers[expectedWorker], inStream.getAddress());
}
Also used : Arrays(java.util.Arrays) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) BlockInfo(alluxio.wire.BlockInfo) GrpcDataReader(alluxio.client.block.stream.GrpcDataReader) NoopClosableResource(alluxio.client.block.stream.NoopClosableResource) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) StreamObserver(io.grpc.stub.StreamObserver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) PreconditionMessage(alluxio.exception.PreconditionMessage) ClientContext(alluxio.ClientContext) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) List(java.util.List) DummyCloseableResource(alluxio.resource.DummyCloseableResource) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) Mockito.any(org.mockito.Mockito.any) WriteType(alluxio.client.WriteType) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) UnavailableException(alluxio.exception.status.UnavailableException) BlockWorker(alluxio.worker.block.BlockWorker) Assert.assertThrows(org.junit.Assert.assertThrows) WorkerNetAddress(alluxio.wire.WorkerNetAddress) RunWith(org.junit.runner.RunWith) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) BlockOutStream(alluxio.client.block.stream.BlockOutStream) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ConfigurationRule(alluxio.ConfigurationRule) OpenLocalBlockResponse(alluxio.grpc.OpenLocalBlockResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) CreateLocalBlockResponse(alluxio.grpc.CreateLocalBlockResponse) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) PowerMockito(org.powermock.api.mockito.PowerMockito) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) BlockInStream(alluxio.client.block.stream.BlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) ExceptionMessage(alluxio.exception.ExceptionMessage) Assert.assertTrue(org.junit.Assert.assertTrue) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) File(java.io.File) OpenLocalBlockRequest(alluxio.grpc.OpenLocalBlockRequest) BlockLocation(alluxio.wire.BlockLocation) Mockito(org.mockito.Mockito) URIStatus(alluxio.client.file.URIStatus) AbstractMap(java.util.AbstractMap) FileSystemContext(alluxio.client.file.FileSystemContext) FileInfo(alluxio.wire.FileInfo) Closeable(java.io.Closeable) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemOptions(alluxio.util.FileSystemOptions) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockInStream(alluxio.client.block.stream.BlockInStream) FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap)

Example 48 with WorkerNetAddress

use of alluxio.wire.WorkerNetAddress 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 49 with WorkerNetAddress

use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.

the class BlockInStreamTest method createShortCircuit.

@Test
public void createShortCircuit() throws Exception {
    WorkerNetAddress dataSource = new WorkerNetAddress();
    BlockInStream.BlockInStreamSource dataSourceType = BlockInStream.BlockInStreamSource.NODE_LOCAL;
    BlockInStream stream = BlockInStream.create(mMockContext, mInfo, dataSource, dataSourceType, mOptions);
    assertEquals(LocalFileDataReader.Factory.class.getName(), stream.getDataReaderFactory().getClass().getName());
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with WorkerNetAddress

use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.

the class BufferCachingGrpcDataReaderTest method before.

@Before
public void before() throws Exception {
    WorkerNetAddress address = new WorkerNetAddress();
    BlockWorkerClient client = Mockito.mock(BlockWorkerClient.class);
    GrpcBlockingStream<ReadRequest, ReadResponse> unusedStream = new GrpcBlockingStream<>(client::readBlock, 5, "test message");
    ReadRequest readRequest = ReadRequest.newBuilder().setOffset(0).setLength(BLOCK_SIZE).setChunkSize(CHUNK_SIZE).setBlockId(1L).build();
    mDataReader = new TestBufferCachingGrpcDataReader(address, new NoopClosableResource<>(client), TIMEOUT, readRequest, unusedStream, CHUNK_SIZE, BLOCK_SIZE);
}
Also used : ReadResponse(alluxio.grpc.ReadResponse) WorkerNetAddress(alluxio.wire.WorkerNetAddress) ReadRequest(alluxio.grpc.ReadRequest) Before(org.junit.Before)

Aggregations

WorkerNetAddress (alluxio.wire.WorkerNetAddress)117 Test (org.junit.Test)63 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)43 ArrayList (java.util.ArrayList)38 BlockInfo (alluxio.wire.BlockInfo)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 URIStatus (alluxio.client.file.URIStatus)22 IOException (java.io.IOException)21 AlluxioURI (alluxio.AlluxioURI)20 FileBlockInfo (alluxio.wire.FileBlockInfo)20 InStreamOptions (alluxio.client.file.options.InStreamOptions)19 FileInfo (alluxio.wire.FileInfo)16 GetWorkerOptions (alluxio.client.block.policy.options.GetWorkerOptions)15 List (java.util.List)14 FileSystemContext (alluxio.client.file.FileSystemContext)12 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)12 BlockLocation (alluxio.wire.BlockLocation)12 BlockInStream (alluxio.client.block.stream.BlockInStream)11 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)11 Before (org.junit.Before)11