Commit a5102043 authored by Mingyang Zhu's avatar Mingyang Zhu
Browse files

customized readiness check to make sure cache layer is ready before serving traffic

parent 009ea359
......@@ -16,7 +16,10 @@ package org.opengroup.osdu.partition.api;
import java.util.Collections;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -29,6 +32,9 @@ public class HealthCheck {
@Autowired
private AuditLogger auditLogger;
@Autowired
@Qualifier("partitionServiceCache")
private IPartitionServiceCache<String, PartitionInfo> dummyCache;
@GetMapping("/liveness_check")
public ResponseEntity<String> livenessCheck() {
......@@ -39,6 +45,14 @@ public class HealthCheck {
@GetMapping("/readiness_check")
public ResponseEntity<String> readinessCheck() {
customReadinessCheckList();
return new ResponseEntity<>("Partition service is ready", HttpStatus.OK);
}
/**
* Cache layer must be ready before the pod can serve the traffic
*/
private void customReadinessCheckList() {
dummyCache.get("dummy-key");
}
}
......@@ -15,6 +15,8 @@
package org.opengroup.osdu.partition.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -22,6 +24,8 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import org.springframework.http.HttpStatus;
@RunWith(MockitoJUnitRunner.class)
......@@ -29,6 +33,8 @@ public class HealthCheckTest {
@Mock
private AuditLogger auditLogger;
@Mock
private IPartitionServiceCache<String, PartitionInfo> dummyCache;
@InjectMocks
private HealthCheck sut;
......@@ -41,5 +47,6 @@ public class HealthCheckTest {
@Test
public void should_returnHttp200_when_checkReadiness() {
assertEquals(HttpStatus.OK, this.sut.readinessCheck().getStatusCode());
verify(dummyCache).get(any());
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment