[Update] no need to be public
This commit is contained in:
		
							parent
							
								
									e9536ff0c4
								
							
						
					
					
						commit
						05f4487d63
					
				| @ -14,14 +14,15 @@ import java.util.concurrent.*; | |||||||
| import static com.github.tomakehurst.wiremock.client.WireMock.*; | import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | import static org.junit.jupiter.api.Assertions.assertEquals; | ||||||
| import static org.junit.jupiter.api.Assertions.assertThrows; | import static org.junit.jupiter.api.Assertions.assertThrows; | ||||||
| public class CompletableFutureTimeoutUnitTest { | 
 | ||||||
|  | class CompletableFutureTimeoutUnitTest { | ||||||
|     private static WireMockServer wireMockServer; |     private static WireMockServer wireMockServer; | ||||||
|     private static ScheduledExecutorService executorService; |     private static ScheduledExecutorService executorService; | ||||||
|     private static final int DEFAULT_TIMEOUT = 1000; //1 seconds |     private static final int DEFAULT_TIMEOUT = 1000; //1 seconds | ||||||
|     private static final int TIMEOUT_STATUS_CODE = 408; //0.5 seconds |     private static final int TIMEOUT_STATUS_CODE = 408; //0.5 seconds | ||||||
| 
 | 
 | ||||||
|     @BeforeAll |     @BeforeAll | ||||||
|     public static void setUp() { |     static void setUp() { | ||||||
|         wireMockServer = new WireMockServer(8080); |         wireMockServer = new WireMockServer(8080); | ||||||
|         wireMockServer.start(); |         wireMockServer.start(); | ||||||
|         WireMock.configureFor("localhost", 8080); |         WireMock.configureFor("localhost", 8080); | ||||||
| @ -36,7 +37,7 @@ public class CompletableFutureTimeoutUnitTest { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @AfterAll |     @AfterAll | ||||||
|     public static void tearDown() { |     static void tearDown() { | ||||||
|         executorService.shutdown(); |         executorService.shutdown(); | ||||||
|         wireMockServer.stop(); |         wireMockServer.stop(); | ||||||
|     } |     } | ||||||
| @ -58,14 +59,14 @@ public class CompletableFutureTimeoutUnitTest { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenorTimeout_thenGetThrow() { |     void whenorTimeout_thenGetThrow() { | ||||||
|         CompletableFuture<Integer> completableFuture = createDummyRequest() |         CompletableFuture<Integer> completableFuture = createDummyRequest() | ||||||
|                 .orTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); |                 .orTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); | ||||||
|         assertThrows(ExecutionException.class, completableFuture::get); |         assertThrows(ExecutionException.class, completableFuture::get); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whencompleteOnTimeout_thenReturnValue() throws ExecutionException, InterruptedException { |     void whencompleteOnTimeout_thenReturnValue() throws ExecutionException, InterruptedException { | ||||||
|         CompletableFuture<Integer> completableFuture = createDummyRequest() |         CompletableFuture<Integer> completableFuture = createDummyRequest() | ||||||
|                 .completeOnTimeout(TIMEOUT_STATUS_CODE, DEFAULT_TIMEOUT, |                 .completeOnTimeout(TIMEOUT_STATUS_CODE, DEFAULT_TIMEOUT, | ||||||
|                         TimeUnit.MILLISECONDS); |                         TimeUnit.MILLISECONDS); | ||||||
| @ -73,7 +74,7 @@ public class CompletableFutureTimeoutUnitTest { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whencompleteExceptionally_thenGetThrow() { |     void whencompleteExceptionally_thenGetThrow() { | ||||||
|         CompletableFuture<Integer> completableFuture = createDummyRequest(); |         CompletableFuture<Integer> completableFuture = createDummyRequest(); | ||||||
|         executorService.schedule(() -> completableFuture |         executorService.schedule(() -> completableFuture | ||||||
|                 .completeExceptionally(new TimeoutException("Timeout occurred")), DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); |                 .completeExceptionally(new TimeoutException("Timeout occurred")), DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user