Search in sources :

Example 1 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamLocal.

@Test
public void getInStreamLocal() throws Exception {
    WorkerNetAddress remote = new WorkerNetAddress().setHost("remote");
    WorkerNetAddress local = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
    // Mock away gRPC usage.
    OpenLocalBlockResponse response = OpenLocalBlockResponse.newBuilder().setPath("/tmp").build();
    when(mWorkerClient.openLocalBlock(any(StreamObserver.class))).thenAnswer(invocation -> {
        mResponseObserver = invocation.getArgument(0, StreamObserver.class);
        return mStreamObserver;
    });
    doAnswer(invocation -> {
        mResponseObserver.onNext(response);
        mResponseObserver.onCompleted();
        return null;
    }).when(mStreamObserver).onNext(any(OpenLocalBlockRequest.class));
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays.asList(new BlockLocation().setWorkerAddress(remote), new BlockLocation().setWorkerAddress(local)));
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info);
    assertEquals(local, mBlockStore.getInStream(BLOCK_ID, new InStreamOptions(new URIStatus(new FileInfo().setBlockIds(Lists.newArrayList(BLOCK_ID))), sConf)).getAddress());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) FileInfo(alluxio.wire.FileInfo) OpenLocalBlockResponse(alluxio.grpc.OpenLocalBlockResponse) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) OpenLocalBlockRequest(alluxio.grpc.OpenLocalBlockRequest) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamInAlluxioWhenCreateStreamIsFailed.

@Test
public void getInStreamInAlluxioWhenCreateStreamIsFailed() throws Exception {
    int workerCount = 5;
    boolean persisted = false;
    int[] blockLocations = new int[] { 2, 3, 4 };
    Map<Integer, Long> failedWorkers = ImmutableMap.of(0, 3L, 1, 1L, 3, 2L);
    int expectedWorker = 2;
    WorkerNetAddress[] workers = new WorkerNetAddress[workerCount];
    for (int i = 0; i < workers.length - 1; i++) {
        workers[i] = new WorkerNetAddress().setHost(String.format("worker-%d", i));
    }
    workers[workers.length - 1] = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
    when(mContext.acquireBlockWorkerClient(WORKER_NET_ADDRESS_LOCAL)).thenThrow(new UnavailableException("failed to connect to " + WORKER_NET_ADDRESS_LOCAL.getHost()));
    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(persisted).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 = null;
    int i = 2;
    while (i-- > 0) {
        try {
            inStream = mBlockStore.getInStream(BLOCK_ID, options, failedWorkerAddresses);
        } catch (Exception e) {
        // do nothing
        }
    }
    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) UnavailableException(alluxio.exception.status.UnavailableException) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) 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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamMissingBlock.

@Test
public void getInStreamMissingBlock() throws Exception {
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(false).setBlockIds(Collections.singletonList(0L)));
    InStreamOptions options = new InStreamOptions(dummyStatus, FileSystemOptions.openFileDefaults(sConf), sConf);
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
    Exception e = assertThrows(UnavailableException.class, () -> mBlockStore.getInStream(BLOCK_ID, options).getAddress());
    assertTrue(e.getMessage().contains("unavailable in both Alluxio and UFS"));
}
Also used : FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) URIStatus(alluxio.client.file.URIStatus) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamProcessLocal.

@Test
public void getInStreamProcessLocal() throws Exception {
    WorkerNetAddress remote = new WorkerNetAddress().setHost("remote");
    WorkerNetAddress local = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays.asList(new BlockLocation().setWorkerAddress(remote), new BlockLocation().setWorkerAddress(local)));
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info);
    when(mContext.hasProcessLocalWorker()).thenReturn(true);
    BlockWorker blockWorker = Mockito.mock(BlockWorker.class);
    when(mContext.getProcessLocalWorker()).thenReturn(blockWorker);
    BlockInStream stream = mBlockStore.getInStream(BLOCK_ID, new InStreamOptions(new URIStatus(new FileInfo().setBlockIds(Lists.newArrayList(BLOCK_ID))), sConf));
    assertEquals(local, stream.getAddress());
    assertEquals(BlockWorkerDataReader.Factory.class.getName(), stream.getDataReaderFactory().getClass().getName());
}
Also used : BlockInStream(alluxio.client.block.stream.BlockInStream) FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) BlockWorker(alluxio.worker.block.BlockWorker) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions 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)

Aggregations

InStreamOptions (alluxio.client.file.options.InStreamOptions)36 Test (org.junit.Test)26 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)23 BlockInfo (alluxio.wire.BlockInfo)22 URIStatus (alluxio.client.file.URIStatus)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 WorkerNetAddress (alluxio.wire.WorkerNetAddress)18 FileBlockInfo (alluxio.wire.FileBlockInfo)17 FileInfo (alluxio.wire.FileInfo)16 BlockInStream (alluxio.client.block.stream.BlockInStream)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)7 FileSystemContext (alluxio.client.file.FileSystemContext)7 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)7 IOException (java.io.IOException)7 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)6 BlockLocation (alluxio.wire.BlockLocation)6 Before (org.junit.Before)6 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)5 BlockWorkerDataReader (alluxio.client.block.stream.BlockWorkerDataReader)5