use of alluxio.grpc.BlockStoreLocationProto in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method registerLeaseExpired.
@Test
public void registerLeaseExpired() {
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();
// Prepare a lease
GetRegisterLeasePRequest leaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId).setBlockCount(blockIdList1.getBlockIdCount()).build();
Optional<RegisterLease> lease = mBlockMaster.tryAcquireRegisterLease(leaseRequest);
assertTrue(lease.isPresent());
// Sleep for a while so that the lease expires
SleepUtils.sleepMs(5000);
// The lease is recycled and taken away
GetRegisterLeasePRequest newLeaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId + 1).setBlockCount(blockIdList1.getBlockIdCount()).build();
Optional<RegisterLease> newLease = mBlockMaster.tryAcquireRegisterLease(newLeaseRequest);
assertTrue(newLease.isPresent());
RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
// Noop response observer
Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {
@Override
public void onNext(RegisterWorkerPResponse response) {
}
@Override
public void onError(Throwable t) {
errors.offer(t);
}
@Override
public void onCompleted() {
}
};
mHandler.registerWorker(request, noopResponseObserver);
assertEquals(1, errors.size());
Throwable t = errors.poll();
Assert.assertThat(t.getMessage(), containsString("does not have a lease or the lease has expired."));
mBlockMaster.releaseRegisterLease(workerId + 1);
}
use of alluxio.grpc.BlockStoreLocationProto in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method registerWithNoLeaseIsRejected.
@Test
public void registerWithNoLeaseIsRejected() {
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();
RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {
@Override
public void onNext(RegisterWorkerPResponse response) {
}
@Override
public void onError(Throwable t) {
errors.offer(t);
}
@Override
public void onCompleted() {
}
};
// The responseObserver should see an error
mHandler.registerWorker(request, noopResponseObserver);
assertEquals(1, errors.size());
Throwable t = errors.poll();
Assert.assertThat(t.getMessage(), containsString("does not have a lease or the lease has expired."));
}
use of alluxio.grpc.BlockStoreLocationProto in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method workerHeartbeatFailsOnDuplicateBlockLocation.
@Test
public void workerHeartbeatFailsOnDuplicateBlockLocation() 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();
BlockHeartbeatPRequest request = BlockHeartbeatPRequest.newBuilder().setWorkerId(workerId).addAddedBlocks(listEntry1).addAddedBlocks(listEntry2).build();
// Noop response observer
StreamObserver<BlockHeartbeatPResponse> noopResponseObserver = new StreamObserver<BlockHeartbeatPResponse>() {
@Override
public void onNext(BlockHeartbeatPResponse response) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
assertThrows(AssertionError.class, () -> {
mHandler.blockHeartbeat(request, noopResponseObserver);
});
}
use of alluxio.grpc.BlockStoreLocationProto 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);
}
use of alluxio.grpc.BlockStoreLocationProto in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method registerLeaseTurnedOff.
@Test
public void registerLeaseTurnedOff() throws Exception {
initServiceHandler(false);
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();
// No lease is acquired
RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {
@Override
public void onNext(RegisterWorkerPResponse response) {
}
@Override
public void onError(Throwable t) {
errors.offer(t);
}
@Override
public void onCompleted() {
}
};
mHandler.registerWorker(request, noopResponseObserver);
assertEquals(0, errors.size());
}
Aggregations