Skip to content

Commit

Permalink
Merge pull request #80 from Onlineberatung/OB-4497-add-actuator-healt…
Browse files Browse the repository at this point in the history
…check

chore: add actuator healtcheck endpoints
  • Loading branch information
tkuzynow authored Apr 17, 2023
2 parents b6ecc89 + 3a7fcdf commit 95d66c3
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
<version>${spring-security.version}</version>
</dependency>

<!-- Spring actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down Expand Up @@ -162,6 +169,12 @@
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -198,6 +211,17 @@
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public synchronized void addUser(WebSocketUserSession webSocketUserSession) {
this.subscribedUsers.add(webSocketUserSession);
}

public synchronized void clearAllSessions() {
this.subscribedUsers.clear();
}

/**
* Removes the user session if a session with given id exists.
*
Expand Down Expand Up @@ -66,4 +70,5 @@ public synchronized List<WebSocketUserSession> retrieveAllUsers() {
return new LinkedList<>(this.subscribedUsers);
}


}
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ live.event.retry.amount=5
live.event.minimum.seconds.before.retry=1

logging.level.root=WARN

management.endpoint.health.enabled=true
management.endpoint.health.show-details=never
management.endpoints.web.exposure.include=health
management.health.probes.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -51,6 +52,11 @@ class LiveServiceApplicationIT extends StompClientIntegrationTest {
@Autowired
private MockMvc mockMvc;

@BeforeEach
void setup() {
socketUserRegistry.clearAllSessions();
}

@Test
void connectToSocket_Should_connect_When_accessTokenIsValid() throws Exception {
var stompSession = performConnect(FIRST_VALID_USER);
Expand Down Expand Up @@ -96,6 +102,7 @@ void connectToSocket_Should_registerExpectedUser_When_accessTokenIsValid() throw
@Test
void subscribe_Should_subscribeUser() throws Exception {
var stompSession = performConnect(FIRST_VALID_USER);

final Subscription subscription = performSubscribe(stompSession);


Expand Down Expand Up @@ -188,7 +195,7 @@ void sendLiveEvent_Should_sendVideoDenyRequestMessageEventToUser_When_userIsSubs
.andExpect(status().isOk());

await()
.atMost(15, SECONDS)
.atMost(25, SECONDS)
.until(receivedMessages::size, is(1));
var resultMessage = receivedMessages.iterator().next();
assertThat(resultMessage, notNullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public abstract class StompClientIntegrationTest extends AbstractJUnit4SpringContextTests {

protected static final String SUBSCRIPTION_ENDPOINT = "/user/events";
protected static final int MESSAGE_TIMEOUT = 5;
protected static final int MESSAGE_TIMEOUT = 10;
protected static final String FIRST_VALID_USER = "firstValidUser";
static final String SECOND_VALID_USER = "secondValidUser";
static final String THIRD_VALID_USER = "thirdValidUser";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.caritas.cob.liveservice.api.controller;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.hamcrest.Matchers.is;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import de.caritas.cob.liveservice.LiveServiceApplication;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@SpringBootTest(classes = LiveServiceApplication.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@AutoConfigureMockMvc(addFilters = false)
class ActuatorControllerIT {

@Autowired private WebApplicationContext context;

private MockMvc mockMvc;

@BeforeEach
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();
}

@Test
void getHealtcheck_Should_returnHealtcheck() throws Exception {
mockMvc
.perform(get("/actuator/health").contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("status", is("UP")));
}

@Test
void getActuatorEndpoints_Should_returnNotFound_When_ActuatorEndpointsNotExposed() throws Exception {
mockMvc
.perform(get("/actuator/env").contentType(APPLICATION_JSON))
.andExpect(status().isNotFound());

mockMvc
.perform(get("/actuator/beans").contentType(APPLICATION_JSON))
.andExpect(status().isNotFound());
}
}

0 comments on commit 95d66c3

Please sign in to comment.