tajoWorkerResourceManager.stop();
}
@Test
public void testDiskResource() throws Exception {
TajoWorkerResourceManager tajoWorkerResourceManager = initResourceManager(false);
final float minDiskSlots = 1.0f;
final float maxDiskSlots = 2.0f;
int memoryMB = 256;
QueryId queryId = QueryIdFactory.newQueryId(queryIdTime, 3);
ExecutionBlockId ebId = QueryIdFactory.newExecutionBlockId(queryId);
WorkerResourceAllocationRequest request = WorkerResourceAllocationRequest.newBuilder()
.setResourceRequestPriority(ResourceRequestPriority.DISK)
.setNumContainers(60)
.setExecutionBlockId(ebId.getProto())
.setMaxDiskSlotPerContainer(maxDiskSlots)
.setMinDiskSlotPerContainer(minDiskSlots)
.setMinMemoryMBPerContainer(memoryMB)
.setMaxMemoryMBPerContainer(memoryMB)
.build();
final CountDownLatch barrier = new CountDownLatch(1);
final List<YarnProtos.ContainerIdProto> containerIds = new ArrayList<YarnProtos.ContainerIdProto>();
RpcCallback<WorkerResourceAllocationResponse> callBack = new RpcCallback<WorkerResourceAllocationResponse>() {
@Override
public void run(WorkerResourceAllocationResponse response) {
TestTajoResourceManager.this.response = response;
barrier.countDown();
}
};
tajoWorkerResourceManager.allocateWorkerResources(request, callBack);
assertTrue(barrier.await(3, TimeUnit.SECONDS));
for(WorkerAllocatedResource eachResource: response.getWorkerAllocatedResourceList()) {
assertTrue("AllocatedDiskSlot:" + eachResource.getAllocatedDiskSlots(),
eachResource.getAllocatedDiskSlots() >= minDiskSlots &&
eachResource.getAllocatedDiskSlots() <= maxDiskSlots);
containerIds.add(eachResource.getContainerId());
}
// assert after callback
int totalUsedDisks = 0;
for(WorkerResource eachWorker: tajoWorkerResourceManager.getWorkers().values()) {
//each worker allocated 3 container (2 disk slot = 2, 1 disk slot = 1)
assertEquals(0, eachWorker.getAvailableDiskSlots(), 0);
assertEquals(5.0f, eachWorker.getUsedDiskSlots(), 0);
assertEquals(256 * 3, eachWorker.getUsedMemoryMB());
totalUsedDisks += eachWorker.getUsedDiskSlots();
}
assertEquals(workerDiskSlots * numWorkers, totalUsedDisks, 0);
assertEquals(numWorkers * 3, response.getWorkerAllocatedResourceList().size());
for(YarnProtos.ContainerIdProto eachContainerId: containerIds) {
tajoWorkerResourceManager.releaseWorkerResource(ebId, eachContainerId);
}
for(WorkerResource eachWorker: tajoWorkerResourceManager.getWorkers().values()) {
assertEquals(workerMemoryMB, eachWorker.getAvailableMemoryMB());
assertEquals(0, eachWorker.getUsedMemoryMB());
assertEquals(workerDiskSlots, eachWorker.getAvailableDiskSlots(), 0);
assertEquals(0.0f, eachWorker.getUsedDiskSlots(), 0);
}
tajoWorkerResourceManager.stop();
}