use of alluxio.exception.status.UnavailableException 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());
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class AlluxioFileInStreamTest method readBufferRetry.
@Test
public void readBufferRetry() throws Exception {
TestBlockInStream workingStream = mInStreams.get(0);
TestBlockInStream brokenStream = mock(TestBlockInStream.class);
when(mBlockStore.getInStream(any(BlockInfo.class), any(InStreamOptions.class), any())).thenReturn(brokenStream).thenReturn(workingStream);
when(brokenStream.read(any(ByteBuffer.class), anyInt(), anyInt())).thenThrow(new UnavailableException("test exception"));
when(brokenStream.getPos()).thenReturn(BLOCK_LENGTH / 2);
mTestStream.seek(BLOCK_LENGTH / 2);
byte[] b = new byte[(int) BLOCK_LENGTH * 2];
mTestStream.read(b, 0, b.length);
doReturn(0).when(brokenStream).read(any(ByteBuffer.class), anyInt(), anyInt());
verify(brokenStream, times(1)).read(any(ByteBuffer.class), anyInt(), anyInt());
assertArrayEquals(BufferUtils.getIncreasingByteArray((int) BLOCK_LENGTH / 2, (int) BLOCK_LENGTH * 2), b);
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class AlluxioFileInStreamTest method failGetInStream.
/**
* Tests that {@link IOException}s thrown by the {@link AlluxioBlockStore} are properly
* propagated.
*/
@Test
public void failGetInStream() throws IOException {
when(mBlockStore.getInStream(any(BlockInfo.class), any(InStreamOptions.class), any())).thenThrow(new UnavailableException("test exception"));
try {
mTestStream.read();
fail("block store should throw exception");
} catch (IOException e) {
assertEquals("test exception", e.getMessage());
}
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class ClientMasterSync method loadConf.
/**
* Loads configuration.
*
* @return true if successfully loaded configuration
*/
private boolean loadConf() {
try {
InetSocketAddress masterAddr = mInquireClient.getPrimaryRpcAddress();
mContext.loadConf(masterAddr, true, false);
} catch (UnavailableException e) {
SAMPLING_LOG.error("Failed to get master address during initialization", e);
return false;
} catch (AlluxioStatusException ae) {
SAMPLING_LOG.error("Failed to load configuration from meta master during initialization", ae);
return false;
}
return true;
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class RetryHandlingMetricsMasterClient method heartbeat.
@Override
public void heartbeat(final List<ClientMetrics> metrics) throws IOException {
connect();
try {
MetricsHeartbeatPRequest.Builder request = MetricsHeartbeatPRequest.newBuilder();
request.setOptions(MetricsHeartbeatPOptions.newBuilder().addAllClientMetrics(metrics).build());
mClient.metricsHeartbeat(request.build());
} catch (io.grpc.StatusRuntimeException e) {
disconnect();
throw new UnavailableException(e);
}
}
Aggregations