From 4ab46c7fcb51d28b06d8e8f23561ba13510062b6 Mon Sep 17 00:00:00 2001 From: Christian Cygnus Date: Fri, 25 May 2018 22:26:35 -0500 Subject: [PATCH 1/2] #643 Fix flaky tests for throttling pattern --- .../java/com/iluwatar/throttling/B2BServiceTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java b/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java index 18dee50a0..8a57f19df 100644 --- a/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java +++ b/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java @@ -22,29 +22,27 @@ */ package com.iluwatar.throttling; -import com.iluwatar.throttling.timer.ThrottleTimerImpl; import com.iluwatar.throttling.timer.Throttler; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * B2BServiceTest class to test the B2BService */ public class B2BServiceTest { - @Disabled @Test public void dummyCustomerApiTest() { Tenant tenant = new Tenant("testTenant", 2); - Throttler timer = new ThrottleTimerImpl(100); + // In order to assure that throttling limits will not be reset, we use an empty throttling implementation + Throttler timer = () -> {}; B2BService service = new B2BService(timer); for (int i = 0; i < 5; i++) { service.dummyCustomerApi(tenant); } long counter = CallsCount.getCount(tenant.getName()); - assertTrue(counter == 2, "Counter limit must be reached"); + assertEquals(2, counter, "Counter limit must be reached"); } } From f3e1cd3a1de6ca6257ced28ada04cea3258c741e Mon Sep 17 00:00:00 2001 From: Christian Cygnus Date: Fri, 25 May 2018 22:47:23 -0500 Subject: [PATCH 2/2] Fix checkstyle --- .../src/test/java/com/iluwatar/throttling/B2BServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java b/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java index 8a57f19df..7e98fb67a 100644 --- a/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java +++ b/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java @@ -36,7 +36,7 @@ public class B2BServiceTest { public void dummyCustomerApiTest() { Tenant tenant = new Tenant("testTenant", 2); // In order to assure that throttling limits will not be reset, we use an empty throttling implementation - Throttler timer = () -> {}; + Throttler timer = () -> { }; B2BService service = new B2BService(timer); for (int i = 0; i < 5; i++) {