use of alluxio.wire.RegisterLease in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method registerWorkerFailsOnDuplicateBlockLocation.
@Test
public void registerWorkerFailsOnDuplicateBlockLocation() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Prepare LocationBlockIdListEntry objects
BlockStoreLocation loc = new BlockStoreLocation("MEM", 0);
BlockStoreLocationProto locationProto = BlockStoreLocationProto.newBuilder().setTierAlias(loc.tierAlias()).setMediumType(loc.mediumType()).build();
BlockIdList blockIdList1 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(1L, 2L)).build();
LocationBlockIdListEntry listEntry1 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList1).build();
BlockIdList blockIdList2 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(3L, 4L)).build();
LocationBlockIdListEntry listEntry2 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList2).build();
// Prepare a lease
GetRegisterLeasePRequest leaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId).setBlockCount(blockIdList1.getBlockIdCount() + blockIdList2.getBlockIdCount()).build();
Optional<RegisterLease> lease = mBlockMaster.tryAcquireRegisterLease(leaseRequest);
assertTrue(lease.isPresent());
// The request is not deduplicated
RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).addCurrentBlocks(listEntry2).build();
// Noop response observer
StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {
@Override
public void onNext(RegisterWorkerPResponse response) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
assertThrows(AssertionError.class, () -> {
mHandler.registerWorker(request, noopResponseObserver);
});
mBlockMaster.releaseRegisterLease(workerId);
}
Aggregations