flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request #4937: [FLINK-6434] [runtime] cancel slot allocation if r...
Date Thu, 02 Nov 2017 17:25:25 GMT
Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4937#discussion_r148602423
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/instance/SlotPoolRpcTest.java
---
    @@ -99,4 +108,129 @@ public void testSlotAllocationNoResourceManager() throws Exception
{
     			fail("wrong exception: " + e);
     		}
     	}
    +
    +	@Test
    +	public void testCancelSlotAllocation() throws Exception {
    +		final JobID jid = new JobID();
    +
    +		final SlotPool pool = new SlotPool(
    +				rpcService, jid,
    +				SystemClock.getInstance(),
    +				Time.days(1), Time.days(1),
    +				Time.seconds(3) // this is the timeout for the request tested here
    +		);
    +		pool.start(JobMasterId.generate(), "foobar");
    +		SlotPoolGateway slotPoolGateway = pool.getSelfGateway(SlotPoolGateway.class);
    +
    +		// 1. test the pending request is in waitingResourceManagerRequests
    +		AllocationID allocationID = new AllocationID();
    +		CompletableFuture<SimpleSlot> future = slotPoolGateway.allocateSlot(allocationID,
DEFAULT_TESTING_PROFILE, null, Time.seconds(1));
    +
    +		try {
    +			future.get(2, TimeUnit.SECONDS);
    +			fail("We expected a AskTimeoutException.");
    +		}
    +		catch (ExecutionException e) {
    +			assertEquals(AskTimeoutException.class, e.getCause().getClass());
    +		}
    +		catch (Exception e) {
    +			fail("wrong exception: " + e);
    +		}
    +
    +		assertEquals(1, pool.getNumOfWaitingForResourceRequests());
    +
    +		pool.cancelSlotAllocation(allocationID);
    +		assertEquals(0, pool.getNumOfWaitingForResourceRequests());
    --- End diff --
    
    I think the test could look the following:
    
    ```
    slotPoolGateway.allocateSlot();
    CompletableFuture<Integer> numberPendingRequestsFuture = slotPoolGateway.requestNumberPendingRequests();
    assertEquals(1, numberPendingRequestsFuture.get());
    slotPoolGateway.cancelAllocation();
    CompletableFuture<Integer> numberPendingRequestsFuture = slotPoolGateway.requestNumberPendingRequests();
    assertEquals(0, numberPendingRequestsFuture.get());
    ```


---

Mime
View raw message