Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Partition
Commits
a5102043
Commit
a5102043
authored
May 05, 2021
by
Mingyang Zhu
Browse files
customized readiness check to make sure cache layer is ready before serving traffic
parent
009ea359
Changes
2
Hide whitespace changes
Inline
Side-by-side
partition-core/src/main/java/org/opengroup/osdu/partition/api/HealthCheck.java
View file @
a5102043
...
...
@@ -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"
);
}
}
partition-core/src/test/java/org/opengroup/osdu/partition/api/HealthCheckTest.java
View file @
a5102043
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment