commit
378b9354da
|
@ -23,15 +23,102 @@ class CompletableFutureTimeoutUnitTest {
|
||||||
private WireMockServer wireMockServer;
|
private WireMockServer wireMockServer;
|
||||||
private ScheduledExecutorService executorService;
|
private ScheduledExecutorService executorService;
|
||||||
private static final int DEFAULT_TIMEOUT = 1000; //1 seconds
|
private static final int DEFAULT_TIMEOUT = 1000; //1 seconds
|
||||||
private static final String DEFAULT_PRODUCT = "default_product";
|
private static final String DEFAULT_PRODUCT = """
|
||||||
private static final String PRODUCT_OFFERS = "product_offers";
|
{
|
||||||
|
"products": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"title": "iPhone X",
|
||||||
|
"description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...",
|
||||||
|
"price": 899,
|
||||||
|
"discountPercentage": 0.0,
|
||||||
|
"rating": 4.44,
|
||||||
|
"stock": 34,
|
||||||
|
"brand": "Apple",
|
||||||
|
"category": "smartphones"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"title": "Samsung Universe 9",
|
||||||
|
"description": "Samsung's new variant which goes beyond Galaxy to the Universe",
|
||||||
|
"price": 1249,
|
||||||
|
"discountPercentage": 0.0,
|
||||||
|
"rating": 4.09,
|
||||||
|
"stock": 36,
|
||||||
|
"brand": "Samsung",
|
||||||
|
"category": "smartphones"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total": 2
|
||||||
|
}""";
|
||||||
|
private static final String PRODUCT_OFFERS = """
|
||||||
|
{
|
||||||
|
"products": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"title": "iPhone 9",
|
||||||
|
"description": "An apple mobile which is nothing like apple",
|
||||||
|
"price": 549,
|
||||||
|
"discountPercentage": 12.96,
|
||||||
|
"rating": 4.69,
|
||||||
|
"stock": 94,
|
||||||
|
"brand": "Apple",
|
||||||
|
"category": "smartphones"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"title": "iPhone X",
|
||||||
|
"description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...",
|
||||||
|
"price": 899,
|
||||||
|
"discountPercentage": 17.94,
|
||||||
|
"rating": 4.44,
|
||||||
|
"stock": 34,
|
||||||
|
"brand": "Apple",
|
||||||
|
"category": "smartphones"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"title": "Samsung Universe 9",
|
||||||
|
"description": "Samsung's new variant which goes beyond Galaxy to the Universe",
|
||||||
|
"price": 1249,
|
||||||
|
"discountPercentage": 15.46,
|
||||||
|
"rating": 4.09,
|
||||||
|
"stock": 36,
|
||||||
|
"brand": "Samsung",
|
||||||
|
"category": "smartphones"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"title": "OPPOF19",
|
||||||
|
"description": "OPPO F19 is officially announced on April 2021.",
|
||||||
|
"price": 280,
|
||||||
|
"discountPercentage": 17.91,
|
||||||
|
"rating": 4.3,
|
||||||
|
"stock": 123,
|
||||||
|
"brand": "OPPO",
|
||||||
|
"category": "smartphones"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"title": "Huawei P30",
|
||||||
|
"description": "Huawei’s re-badged P30 Pro New Edition was officially unveiled yesterday in Germany and now the device has made its way to the UK.",
|
||||||
|
"price": 499,
|
||||||
|
"discountPercentage": 10.58,
|
||||||
|
"rating": 4.09,
|
||||||
|
"stock": 32,
|
||||||
|
"brand": "Huawei",
|
||||||
|
"category": "smartphones"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total": 5
|
||||||
|
}""";
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
void setUp() {
|
void setUp() {
|
||||||
wireMockServer = new WireMockServer(8080);
|
wireMockServer = new WireMockServer(8080);
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
WireMock.configureFor("localhost", 8080);
|
WireMock.configureFor("localhost", 8080);
|
||||||
|
System.out.println(PRODUCT_OFFERS);
|
||||||
stubFor(get(urlEqualTo("/api/dummy"))
|
stubFor(get(urlEqualTo("/api/dummy"))
|
||||||
.willReturn(aResponse()
|
.willReturn(aResponse()
|
||||||
.withFixedDelay(5000) // must be > DEFAULT_TIMEOUT for a timeout to occur.
|
.withFixedDelay(5000) // must be > DEFAULT_TIMEOUT for a timeout to occur.
|
||||||
|
@ -40,7 +127,6 @@ class CompletableFutureTimeoutUnitTest {
|
||||||
executorService = Executors.newScheduledThreadPool(1);
|
executorService = Executors.newScheduledThreadPool(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
void tearDown() {
|
void tearDown() {
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
|
|
Loading…
Reference in New Issue