// Tests that space will be allocated when possible @Test public void requestSpaceTest() throws Exception { final long blockId1 = 12345L; final long blockId2 = 12346L; final int chunkSize = (int) WORKER_CAPACITY_BYTES / 10; mBlockWorkerServiceHandler.requestBlockLocation(SESSION_ID, blockId1, chunkSize); boolean result = mBlockWorkerServiceHandler.requestSpace(SESSION_ID, blockId1, chunkSize); // Initial request and first additional request should succeed Assert.assertTrue(result); result = mBlockWorkerServiceHandler.requestSpace(SESSION_ID, blockId1, WORKER_CAPACITY_BYTES); // Impossible request should fail Assert.assertFalse(result); // Request for space on a nonexistent block should fail Assert.assertFalse(mBlockWorkerServiceHandler.requestSpace(SESSION_ID, blockId2, chunkSize)); // Request for impossible initial space should fail Exception exception = null; try { mBlockWorkerServiceHandler.requestBlockLocation( SESSION_ID, blockId2, WORKER_CAPACITY_BYTES + 1); } catch (AlluxioTException e) { exception = e; } Assert.assertNotNull(exception); }
// Tests that multiple users cannot request a combined space greater than worker space @Test public void totalOverCapacityRequestSpaceTest() throws Exception { final int chunkSize = (int) WORKER_CAPACITY_BYTES / 2; final long userId1 = SESSION_ID; final long userId2 = SESSION_ID + 1; final long blockId1 = 12345L; final long blockId2 = 23456L; String filePath1 = mBlockWorkerServiceHandler.requestBlockLocation(userId1, blockId1, chunkSize); String filePath2 = mBlockWorkerServiceHandler.requestBlockLocation(userId2, blockId2, chunkSize); // Initial requests should succeed Assert.assertTrue(filePath1 != null); Assert.assertTrue(filePath2 != null); // Additional requests for space should fail Assert.assertFalse(mBlockWorkerServiceHandler.requestSpace(userId1, blockId1, chunkSize)); Assert.assertFalse(mBlockWorkerServiceHandler.requestSpace(userId2, blockId2, chunkSize)); }