flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
/**
	 * Tests that cache entries are cleaned up when their TTL has expired upon
	 * calling {@link ExecutionGraphCache#cleanup()}.
	 */
Tests that cache entries are cleaned up when their TTL has expired upon
calling  ExecutionGraphCache#cleanup().
Tests that cache entries are cleaned up when their TTL has expired upon calling ExecutionGraphCache#cleanup () .
@Test
	public void testCacheEntryCleanup() throws Exception {
		final Time timeout = Time.milliseconds(100L);
		final Time timeToLive = Time.milliseconds(1L);
		final JobID jobId1 = new JobID();
		final JobID jobId2 = new JobID();
		final AccessExecutionGraph accessExecutionGraph1 = mock(AccessExecutionGraph.class);
		final AccessExecutionGraph accessExecutionGraph2 = mock(AccessExecutionGraph.class);
		final JobManagerGateway jobManagerGateway = mock(JobManagerGateway.class);
		when(jobManagerGateway.requestJob(eq(jobId1), any(Time.class))).thenReturn(CompletableFuture.completedFuture(accessExecutionGraph1));
		when(jobManagerGateway.requestJob(eq(jobId2), any(Time.class))).thenReturn(CompletableFuture.completedFuture(accessExecutionGraph2));
		try (ExecutionGraphCache executionGraphCache = new ExecutionGraphCache(timeout, timeToLive)) {
			CompletableFuture<AccessExecutionGraph> executionGraph1Future = executionGraphCache.getExecutionGraph(jobId1, jobManagerGateway);
			CompletableFuture<AccessExecutionGraph> executionGraph2Future = executionGraphCache.getExecutionGraph(jobId2, jobManagerGateway);
			assertEquals(accessExecutionGraph1, executionGraph1Future.get());
			assertEquals(accessExecutionGraph2, executionGraph2Future.get());
			verify(jobManagerGateway, times(1)).requestJob(eq(jobId1), any(Time.class));
			verify(jobManagerGateway, times(1)).requestJob(eq(jobId2), any(Time.class));
			Thread.sleep(timeToLive.toMilliseconds());
			executionGraphCache.cleanup();
			assertTrue(executionGraphCache.size() == 0);
		}
	}
@ Test public void testCacheEntryCleanup ( ) throws Exception { final Time timeout = Time . milliseconds ( 100L ) ; final Time timeToLive = Time . milliseconds ( 1L ) ; final JobID jobId1 = new JobID ( ) ; final JobID jobId2 = new JobID ( ) ; final AccessExecutionGraph accessExecutionGraph1 = mock ( AccessExecutionGraph . class ) ; final AccessExecutionGraph accessExecutionGraph2 = mock ( AccessExecutionGraph . class ) ; final JobManagerGateway jobManagerGateway = mock ( JobManagerGateway . class ) ; when ( jobManagerGateway . requestJob ( eq ( jobId1 ) , any ( Time . class ) ) ) . thenReturn ( CompletableFuture . completedFuture ( accessExecutionGraph1 ) ) ; when ( jobManagerGateway . requestJob ( eq ( jobId2 ) , any ( Time . class ) ) ) . thenReturn ( CompletableFuture . completedFuture ( accessExecutionGraph2 ) ) ; try ( ExecutionGraphCache executionGraphCache = new ExecutionGraphCache ( timeout , timeToLive ) ) { CompletableFuture < AccessExecutionGraph > executionGraph1Future = executionGraphCache . getExecutionGraph ( jobId1 , jobManagerGateway ) ; CompletableFuture < AccessExecutionGraph > executionGraph2Future = executionGraphCache . getExecutionGraph ( jobId2 , jobManagerGateway ) ; assertEquals ( accessExecutionGraph1 , executionGraph1Future . get ( ) ) ; assertEquals ( accessExecutionGraph2 , executionGraph2Future . get ( ) ) ; verify ( jobManagerGateway , times ( 1 ) ) . requestJob ( eq ( jobId1 ) , any ( Time . class ) ) ; verify ( jobManagerGateway , times ( 1 ) ) . requestJob ( eq ( jobId2 ) , any ( Time . class ) ) ; Thread . sleep ( timeToLive . toMilliseconds ( ) ) ; executionGraphCache . cleanup ( ) ; assertTrue ( executionGraphCache . size ( ) == 0 ) ; } }
Tests that cache entries are cleaned up when their TTL has expired upon
 calling {@link ExecutionGraphCache#cleanup()}.
Tests that cache entries are cleaned up when their TTL has expired upon calling { @link ExecutionGraphCache#cleanup () } .