diff --git a/microservices-self-registration/contextservice/pom.xml b/microservices-self-registration/contextservice/pom.xml
index ea6d105bd..71f61fcf6 100644
--- a/microservices-self-registration/contextservice/pom.xml
+++ b/microservices-self-registration/contextservice/pom.xml
@@ -67,6 +67,26 @@
org.apache.maven.plugins
maven-compiler-plugin
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+ 2.44.4
+
+
+
+ check
+ apply
+
+
+
+
+
+
+ 1.17.0
+
+
+
+
diff --git a/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/ContextserviceApplication.java b/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/ContextserviceApplication.java
index eb22d094f..01335dcc2 100644
--- a/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/ContextserviceApplication.java
+++ b/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/ContextserviceApplication.java
@@ -10,8 +10,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients
public class ContextserviceApplication {
- public static void main(String[] args) {
- SpringApplication.run(ContextserviceApplication.class, args);
- }
-
+ public static void main(String[] args) {
+ SpringApplication.run(ContextserviceApplication.class, args);
+ }
}
diff --git a/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java b/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java
index 0226fc50e..554ab2e83 100644
--- a/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java
+++ b/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java
@@ -7,7 +7,6 @@ import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
-
@Component("myCustomHealthCheck")
public class MyCustomHealthCheck implements HealthIndicator {
@@ -33,7 +32,9 @@ public class MyCustomHealthCheck implements HealthIndicator {
public Health health() {
if (isHealthy) {
log.info("Health check successful, service is UP");
- return Health.up().withDetail("message", "Service is running and scheduled checks are OK").build();
+ return Health.up()
+ .withDetail("message", "Service is running and scheduled checks are OK")
+ .build();
} else {
log.warn("Health check failed, service is DOWN");
return Health.down().withDetail("error", "Scheduled health checks failed").build();
diff --git a/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/controller/ContextController.java b/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/controller/ContextController.java
index 5ad8969e0..3b5febb80 100644
--- a/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/controller/ContextController.java
+++ b/microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/controller/ContextController.java
@@ -13,7 +13,8 @@ public class ContextController {
private final String userRegion;
@Autowired
- public ContextController(GreetingServiceClient greetingServiceClient, @Value("${user.region}") String userRegion) {
+ public ContextController(
+ GreetingServiceClient greetingServiceClient, @Value("${user.region}") String userRegion) {
this.greetingServiceClient = greetingServiceClient;
this.userRegion = userRegion;
}
@@ -21,6 +22,6 @@ public class ContextController {
@GetMapping("/context")
public String getContext() {
String greeting = greetingServiceClient.getGreeting();
- return "The Greeting Service says: "+greeting+" from "+userRegion;
+ return "The Greeting Service says: " + greeting + " from " + userRegion;
}
}
diff --git a/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java b/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java
index f11da867c..8fba01f0c 100644
--- a/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java
+++ b/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java
@@ -7,7 +7,6 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
-
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
@@ -21,29 +20,31 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@Import(TestConfig.class)
class ContextControllerTest {
- @Autowired
- private MockMvc mockMvc;
+ @Autowired private MockMvc mockMvc;
- @MockitoBean
- private GreetingServiceClient greetingServiceClient;
+ @MockitoBean private GreetingServiceClient greetingServiceClient;
@Value("${user.region}")
private String userRegion;
@Test
- void shouldReturnContextGreeting() throws Exception{
+ void shouldReturnContextGreeting() throws Exception {
Mockito.when(greetingServiceClient.getGreeting()).thenReturn("Mocked Hello");
- mockMvc.perform(MockMvcRequestBuilders.get("/context")
- .accept(MediaType.TEXT_PLAIN))
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/context").accept(MediaType.TEXT_PLAIN))
.andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.content().string("The Greeting Service says: Mocked Hello from Chennai, Tamil Nadu, India"));
+ .andExpect(
+ MockMvcResultMatchers.content()
+ .string("The Greeting Service says: Mocked Hello from Chennai, Tamil Nadu, India"));
}
@Test
void shouldReturnContextServiceHealthStatusUp() throws Exception {
- mockMvc.perform(MockMvcRequestBuilders.get("/actuator/health"))
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/actuator/health"))
.andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"status\":\"UP\"")));
+ .andExpect(
+ MockMvcResultMatchers.content().string(Matchers.containsString("\"status\":\"UP\"")));
}
}
diff --git a/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextserviceApplicationTests.java b/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextserviceApplicationTests.java
index a5d5c869c..aa789ad92 100644
--- a/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextserviceApplicationTests.java
+++ b/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextserviceApplicationTests.java
@@ -6,12 +6,13 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ContextserviceApplicationTests {
- @Test
- void contextLoads() {
- // This is a basic integration test that checks if the Spring Application Context loads successfully.
+ @Test
+ void contextLoads() {
+ // This is a basic integration test that checks if the Spring Application Context loads
+ // successfully.
// If the context loads without any exceptions, the test is considered passing.
// It is often left empty as the act of loading the context is the primary verification.
- // You can add specific assertions here if you want to verify the presence or state of certain beans.
- }
-
+ // You can add specific assertions here if you want to verify the presence or state of certain
+ // beans.
+ }
}
diff --git a/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java b/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java
index 129209469..d771a1eed 100644
--- a/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java
+++ b/microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java
@@ -1,10 +1,11 @@
package com.learning.contextservice;
+import static org.junit.jupiter.api.Assertions.*;
+
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.Health;
-import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.boot.actuate.health.Status;
-import static org.junit.jupiter.api.Assertions.*;
+import org.springframework.test.util.ReflectionTestUtils;
class MyCustomHealthCheckTest {
@@ -16,7 +17,8 @@ class MyCustomHealthCheckTest {
Health health = healthCheck.health();
assertEquals(Status.UP, health.getStatus());
assertTrue(health.getDetails().containsKey("message"));
- assertEquals("Service is running and scheduled checks are OK", health.getDetails().get("message"));
+ assertEquals(
+ "Service is running and scheduled checks are OK", health.getDetails().get("message"));
}
@Test
@@ -29,5 +31,4 @@ class MyCustomHealthCheckTest {
assertTrue(health.getDetails().containsKey("error"));
assertEquals("Scheduled health checks failed", health.getDetails().get("error"));
}
-
-}
\ No newline at end of file
+}
diff --git a/microservices-self-registration/eurekaserver/pom.xml b/microservices-self-registration/eurekaserver/pom.xml
index b1a4b26cf..fac49a1e4 100644
--- a/microservices-self-registration/eurekaserver/pom.xml
+++ b/microservices-self-registration/eurekaserver/pom.xml
@@ -49,6 +49,26 @@
org.apache.maven.plugins
maven-compiler-plugin
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+ 2.44.4
+
+
+
+ check
+ apply
+
+
+
+
+
+
+ 1.17.0
+
+
+
+
diff --git a/microservices-self-registration/eurekaserver/src/main/java/com/learning/eurekaserver/EurekaserverApplication.java b/microservices-self-registration/eurekaserver/src/main/java/com/learning/eurekaserver/EurekaserverApplication.java
index 80b3d904f..80b888f59 100644
--- a/microservices-self-registration/eurekaserver/src/main/java/com/learning/eurekaserver/EurekaserverApplication.java
+++ b/microservices-self-registration/eurekaserver/src/main/java/com/learning/eurekaserver/EurekaserverApplication.java
@@ -8,8 +8,7 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
public class EurekaserverApplication {
- public static void main(String[] args) {
- SpringApplication.run(EurekaserverApplication.class, args);
- }
-
+ public static void main(String[] args) {
+ SpringApplication.run(EurekaserverApplication.class, args);
+ }
}
diff --git a/microservices-self-registration/eurekaserver/src/test/java/com/learning/eurekaserver/EurekaserverApplicationTests.java b/microservices-self-registration/eurekaserver/src/test/java/com/learning/eurekaserver/EurekaserverApplicationTests.java
index b5150fefa..4f8468882 100644
--- a/microservices-self-registration/eurekaserver/src/test/java/com/learning/eurekaserver/EurekaserverApplicationTests.java
+++ b/microservices-self-registration/eurekaserver/src/test/java/com/learning/eurekaserver/EurekaserverApplicationTests.java
@@ -6,12 +6,13 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class EurekaserverApplicationTests {
- @Test
- void contextLoads() {
- // This is a basic integration test that checks if the Spring Application Context loads successfully.
+ @Test
+ void contextLoads() {
+ // This is a basic integration test that checks if the Spring Application Context loads
+ // successfully.
// If the context loads without any exceptions, the test is considered passing.
// It is often left empty as the act of loading the context is the primary verification.
- // You can add specific assertions here if you want to verify the presence or state of certain beans.
- }
-
+ // You can add specific assertions here if you want to verify the presence or state of certain
+ // beans.
+ }
}
diff --git a/microservices-self-registration/greetingservice/pom.xml b/microservices-self-registration/greetingservice/pom.xml
index 45988a145..36221db34 100644
--- a/microservices-self-registration/greetingservice/pom.xml
+++ b/microservices-self-registration/greetingservice/pom.xml
@@ -63,6 +63,26 @@
org.apache.maven.plugins
maven-compiler-plugin
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+ 2.44.4
+
+
+
+ check
+ apply
+
+
+
+
+
+
+ 1.17.0
+
+
+
+
diff --git a/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/GreetingserviceApplication.java b/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/GreetingserviceApplication.java
index 7a549a084..93b3d3041 100644
--- a/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/GreetingserviceApplication.java
+++ b/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/GreetingserviceApplication.java
@@ -10,8 +10,7 @@ import org.springframework.context.annotation.ComponentScan;
@ComponentScan("com.learning.greetingservice.controller")
public class GreetingserviceApplication {
- public static void main(String[] args) {
- SpringApplication.run(GreetingserviceApplication.class, args);
- }
-
+ public static void main(String[] args) {
+ SpringApplication.run(GreetingserviceApplication.class, args);
+ }
}
diff --git a/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/MyCustomHealthCheck.java b/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/MyCustomHealthCheck.java
index 218a4ad00..639a402fc 100644
--- a/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/MyCustomHealthCheck.java
+++ b/microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/MyCustomHealthCheck.java
@@ -32,7 +32,9 @@ public class MyCustomHealthCheck implements HealthIndicator {
public Health health() {
if (isHealthy) {
log.info("Health check successful, service is UP");
- return Health.up().withDetail("message", "Service is running and scheduled checks are OK").build();
+ return Health.up()
+ .withDetail("message", "Service is running and scheduled checks are OK")
+ .build();
} else {
log.warn("Health check failed, service is DOWN");
return Health.down().withDetail("error", "Scheduled health checks failed").build();
diff --git a/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/GreetingserviceApplicationTests.java b/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/GreetingserviceApplicationTests.java
index 945898278..0f00c8ab4 100644
--- a/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/GreetingserviceApplicationTests.java
+++ b/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/GreetingserviceApplicationTests.java
@@ -6,12 +6,13 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class GreetingserviceApplicationTests {
- @Test
- void contextLoads() {
- // This is a basic integration test that checks if the Spring Application Context loads successfully.
+ @Test
+ void contextLoads() {
+ // This is a basic integration test that checks if the Spring Application Context loads
+ // successfully.
// If the context loads without any exceptions, the test is considered passing.
// It is often left empty as the act of loading the context is the primary verification.
- // You can add specific assertions here if you want to verify the presence or state of certain beans.
- }
-
+ // You can add specific assertions here if you want to verify the presence or state of certain
+ // beans.
+ }
}
diff --git a/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/MyCustomHealthCheckTest.java b/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/MyCustomHealthCheckTest.java
index 8ba8b2a30..6e67f875c 100644
--- a/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/MyCustomHealthCheckTest.java
+++ b/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/MyCustomHealthCheckTest.java
@@ -1,10 +1,11 @@
package com.learning.greetingservice;
+import static org.junit.jupiter.api.Assertions.*;
+
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.Health;
-import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.boot.actuate.health.Status;
-import static org.junit.jupiter.api.Assertions.*;
+import org.springframework.test.util.ReflectionTestUtils;
class MyCustomHealthCheckTest {
@@ -16,7 +17,7 @@ class MyCustomHealthCheckTest {
Health health = healthCheck.health();
assertEquals(Status.UP, health.getStatus());
assertTrue(health.getDetails().containsKey("message"));
- assertEquals("Service is running and scheduled checks are OK", health.getDetails().get("message"));
+ assertEquals(
+ "Service is running and scheduled checks are OK", health.getDetails().get("message"));
}
-
-}
\ No newline at end of file
+}
diff --git a/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/controller/GreetingControllerTest.java b/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/controller/GreetingControllerTest.java
index 5ae98c8b6..22fa8ecf3 100644
--- a/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/controller/GreetingControllerTest.java
+++ b/microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/controller/GreetingControllerTest.java
@@ -16,21 +16,23 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@ActiveProfiles("test")
class GreetingControllerTest {
- @Autowired
- private MockMvc mockMvc;
+ @Autowired private MockMvc mockMvc;
@Test
- void shouldReturnGreeting() throws Exception{
- mockMvc.perform(MockMvcRequestBuilders.get("/greeting")
- .accept(MediaType.TEXT_PLAIN))
+ void shouldReturnGreeting() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/greeting").accept(MediaType.TEXT_PLAIN))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("Hello"));
}
@Test
- void shouldReturnHealthStatusUp() throws Exception{
- mockMvc.perform(MockMvcRequestBuilders.get("/actuator/health"))
+ void shouldReturnHealthStatusUp() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/actuator/health"))
.andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.content().string(org.hamcrest.Matchers.containsString("\"status\":\"UP\"")));
+ .andExpect(
+ MockMvcResultMatchers.content()
+ .string(org.hamcrest.Matchers.containsString("\"status\":\"UP\"")));
}
}
diff --git a/rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/TokenBucketRateLimiter.java b/rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/TokenBucketRateLimiter.java
index e13b966a2..ded1396f1 100644
--- a/rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/TokenBucketRateLimiter.java
+++ b/rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/TokenBucketRateLimiter.java
@@ -4,10 +4,8 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
- * Token Bucket rate limiter implementation. Allows requests to proceed as long
- * as there are tokens
- * available in the bucket. Tokens are added at a fixed interval up to a defined
- * capacity.
+ * Token Bucket rate limiter implementation. Allows requests to proceed as long as there are tokens
+ * available in the bucket. Tokens are added at a fixed interval up to a defined capacity.
*/
public class TokenBucketRateLimiter implements RateLimiter {
private final int capacity;
@@ -22,10 +20,10 @@ public class TokenBucketRateLimiter implements RateLimiter {
/**
* Constructor with custom refill interval.
*
- * @param capacity token bucket capacity
- * @param refillRate token refill rate
+ * @param capacity token bucket capacity
+ * @param refillRate token refill rate
* @param refillInterval refill interval value
- * @param timeUnit refill interval time unit
+ * @param timeUnit refill interval time unit
*/
public TokenBucketRateLimiter(
int capacity, int refillRate, long refillInterval, TimeUnit timeUnit) {
@@ -53,10 +51,7 @@ public class TokenBucketRateLimiter implements RateLimiter {
buckets.forEach((k, b) -> b.refill(refillRate));
}
- /**
- * Inner class that represents the bucket holding tokens for each
- * service-operation.
- */
+ /** Inner class that represents the bucket holding tokens for each service-operation. */
private static class TokenBucket {
private final int capacity;
private final AtomicInteger tokens;
@@ -69,10 +64,8 @@ public class TokenBucketRateLimiter implements RateLimiter {
boolean tryConsume() {
while (true) {
int current = tokens.get();
- if (current <= 0)
- return false;
- if (tokens.compareAndSet(current, current - 1))
- return true;
+ if (current <= 0) return false;
+ if (tokens.compareAndSet(current, current - 1)) return true;
}
}