use of alluxio.grpc.GetRegisterLeasePRequest in project alluxio by Alluxio.
the class RegisterLeaseManagerTest method recycleExpiredLease.
@Test
public void recycleExpiredLease() {
// allocate two leases
GetRegisterLeasePRequest request1 = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER1_ID).setBlockCount(0).build();
Optional<RegisterLease> lease1 = mLeaseManager.tryAcquireLease(request1);
GetRegisterLeasePRequest request2 = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER2_ID).setBlockCount(0).build();
Optional<RegisterLease> lease2 = mLeaseManager.tryAcquireLease(request2);
assertTrue(lease1.isPresent());
assertTrue(lease2.isPresent());
assertTrue(mLeaseManager.hasLease(WORKER1_ID));
assertTrue(mLeaseManager.hasLease(WORKER2_ID));
// wait for expiration
SleepUtils.sleepMs(5000);
// allocate two more leases
GetRegisterLeasePRequest request3 = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER3_ID).setBlockCount(500_000).build();
Optional<RegisterLease> lease3 = mLeaseManager.tryAcquireLease(request3);
GetRegisterLeasePRequest request4 = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER4_ID).setBlockCount(100_000).build();
Optional<RegisterLease> lease4 = mLeaseManager.tryAcquireLease(request4);
// The 2 old leases should be recycled
assertFalse(mLeaseManager.hasLease(WORKER1_ID));
assertFalse(mLeaseManager.hasLease(WORKER2_ID));
assertTrue(lease3.isPresent());
assertTrue(lease4.isPresent());
assertTrue(mLeaseManager.hasLease(WORKER3_ID));
assertTrue(mLeaseManager.hasLease(WORKER4_ID));
// Acquiring one more lease before existing ones expire will be blocked
GetRegisterLeasePRequest shouldWait = GetRegisterLeasePRequest.newBuilder().setWorkerId(5L).setBlockCount(100_000).build();
Optional<RegisterLease> empty = mLeaseManager.tryAcquireLease(shouldWait);
assertFalse(empty.isPresent());
assertFalse(mLeaseManager.hasLease(5L));
}
use of alluxio.grpc.GetRegisterLeasePRequest in project alluxio by Alluxio.
the class RegisterLeaseManagerTest method findExistingLease.
@Test
public void findExistingLease() {
GetRegisterLeasePRequest request1 = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER1_ID).setBlockCount(0).build();
Optional<RegisterLease> lease1 = mLeaseManager.tryAcquireLease(request1);
assertTrue(lease1.isPresent());
assertTrue(mLeaseManager.hasLease(WORKER1_ID));
// Same worker requesting for an existing lease
Optional<RegisterLease> sameLease = mLeaseManager.tryAcquireLease(request1);
assertTrue(sameLease.isPresent());
assertTrue(mLeaseManager.hasLease(WORKER1_ID));
// The same lease is granted so there should be another vacancy
GetRegisterLeasePRequest request2 = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER2_ID).setBlockCount(0).build();
Optional<RegisterLease> lease2 = mLeaseManager.tryAcquireLease(request2);
assertTrue(lease2.isPresent());
assertTrue(mLeaseManager.hasLease(WORKER2_ID));
// The lease for worker 1 is not recycled
assertTrue(mLeaseManager.hasLease(WORKER1_ID));
// Now all token have been given out, new ones will have to wait
GetRegisterLeasePRequest shouldWait = GetRegisterLeasePRequest.newBuilder().setWorkerId(5L).setBlockCount(100_000).build();
Optional<RegisterLease> empty = mLeaseManager.tryAcquireLease(shouldWait);
assertFalse(empty.isPresent());
assertFalse(mLeaseManager.hasLease(5L));
}
use of alluxio.grpc.GetRegisterLeasePRequest in project alluxio by Alluxio.
the class RegisterLeaseManagerTest method acquireVerifyRelease.
@Test
public void acquireVerifyRelease() {
GetRegisterLeasePRequest request = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER1_ID).setBlockCount(0).build();
Optional<RegisterLease> lease = mLeaseManager.tryAcquireLease(request);
assertTrue(lease.isPresent());
assertTrue(mLeaseManager.hasLease(WORKER1_ID));
mLeaseManager.releaseLease(WORKER1_ID);
assertFalse(mLeaseManager.hasLease(WORKER1_ID));
}
use of alluxio.grpc.GetRegisterLeasePRequest in project alluxio by Alluxio.
the class JvmSpaceReviewerTest method reviewJvmUsage.
@Test
public void reviewJvmUsage() {
long usedBytes = 0L;
long maxBytes = 1000L;
// Mock the gauges
MetricRegistry mockRegistry = mock(MetricRegistry.class);
SortedMap<String, Gauge> heapGauges = new TreeMap<>();
Gauge<Long> usedSpaceGauge = mock(Gauge.class);
when(usedSpaceGauge.getValue()).thenReturn(usedBytes);
Gauge<Long> maxSpaceGauge = mock(Gauge.class);
when(maxSpaceGauge.getValue()).thenReturn(maxBytes);
heapGauges.put("heap.used", usedSpaceGauge);
heapGauges.put("heap.max", maxSpaceGauge);
when(mockRegistry.getGauges(any())).thenReturn(heapGauges);
Runtime mockRuntime = mock(Runtime.class);
// max - (total - free) = 1000L
when(mockRuntime.maxMemory()).thenReturn(1200L);
when(mockRuntime.freeMemory()).thenReturn(0L);
when(mockRuntime.totalMemory()).thenReturn(200L);
JvmSpaceReviewer reviewer = new JvmSpaceReviewer(mockRuntime);
// Determine how many blocks will be accepted
long maxBlocks = (maxBytes - usedBytes) / JvmSpaceReviewer.BLOCK_COUNT_MULTIPLIER;
GetRegisterLeasePRequest noBlocks = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER_ID).setBlockCount(0).build();
assertTrue(reviewer.reviewLeaseRequest(noBlocks));
GetRegisterLeasePRequest adequateBlocks = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER_ID).setBlockCount(maxBlocks).build();
assertTrue(reviewer.reviewLeaseRequest(adequateBlocks));
GetRegisterLeasePRequest tooManyBlocks = GetRegisterLeasePRequest.newBuilder().setWorkerId(WORKER_ID).setBlockCount(maxBlocks + 1).build();
assertFalse(reviewer.reviewLeaseRequest(tooManyBlocks));
}
use of alluxio.grpc.GetRegisterLeasePRequest 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);
}
Aggregations