/** * Randomly create a BlockInfo object. * * @return the created BlockInfo object */ public static BlockInfo createRandom() { BlockInfo result = new BlockInfo(); Random random = new Random(); long blockId = random.nextLong(); long length = random.nextLong(); List<BlockLocation> locations = new ArrayList<>(); long numLocations = random.nextInt(10); for (int i = 0; i < numLocations; i++) { locations.add(BlockLocationTest.createRandom()); } result.setBlockId(blockId); result.setLength(length); result.setLocations(locations); return result; } }
/** * Converts a proto type to a wire type. * * @param blockPInfo the proto type to convert * @return the converted wire type */ public static BlockInfo fromProto(alluxio.grpc.BlockInfo blockPInfo) { BlockInfo blockInfo = new BlockInfo(); blockInfo.setBlockId(blockPInfo.getBlockId()); blockInfo.setLength(blockPInfo.getLength()); blockInfo.setLocations(map(GrpcUtils::fromProto, blockPInfo.getLocationsList())); return blockInfo; }
new BlockInfo().setBlockId(blockId).setLength(block.getLength()).setLocations(locations));
@Test public void getBlockInfo() throws Exception { // Create a worker with a block. long worker1 = mBlockMaster.getWorkerId(NET_ADDRESS_1); long blockId = 1L; long blockLength = 20L; mBlockMaster.workerRegister(worker1, Arrays.asList("MEM"), ImmutableMap.of("MEM", 100L), ImmutableMap.of("MEM", 0L), NO_BLOCKS_ON_TIERS, RegisterWorkerPOptions.getDefaultInstance()); mBlockMaster.commitBlock(worker1, 50L, "MEM", blockId, blockLength); BlockLocation blockLocation = new BlockLocation() .setTierAlias("MEM") .setWorkerAddress(NET_ADDRESS_1) .setWorkerId(worker1); BlockInfo expectedBlockInfo = new BlockInfo() .setBlockId(1L) .setLength(20L) .setLocations(ImmutableList.of(blockLocation)); assertEquals(expectedBlockInfo, mBlockMaster.getBlockInfo(blockId)); }
/** * Creates a new instance of {@link BlockInfo} from a thrift representation. * * @param blockInfo the thrift representation of a block information * @return the instance */ public static BlockInfo fromThrift(alluxio.thrift.BlockInfo blockInfo) { return new BlockInfo() .setBlockId(blockInfo.getBlockId()) .setLength(blockInfo.getLength()) .setLocations(map(BlockLocation::fromThrift, blockInfo.getLocations())); }
.setLength(masterBlockInfo.getLength()).setLocations(locations);