Skip to content

Commit

Permalink
fix: corrected automated offboarding log message
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkAtra committed Nov 17, 2024
1 parent 5924b48 commit 76d0b12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ class ServerService(
}

val sevenDaysAgo = Instant.now().minus(7, ChronoUnit.DAYS)
val serverIds = inactiveServers.map { server ->
if (server.lastUpdated.isBefore(sevenDaysAgo)) {
serverRepository.removeServer(server.id)
val serverIds = inactiveServers.mapNotNull { server ->
when (server.lastUpdated.isBefore(sevenDaysAgo)) {
true -> {
serverRepository.removeServer(server.id)
server.id
}

false -> null
}
server.id
}

logger.info("Successfully removed ${serverIds.count()} servers with no active feature: $serverIds")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import de.darkatra.vrising.discord.persistence.model.ServerTestUtils.DISCORD_SER
import de.darkatra.vrising.discord.persistence.model.ServerTestUtils.HOST_NAME
import de.darkatra.vrising.discord.persistence.model.ServerTestUtils.QUERY_PORT
import de.darkatra.vrising.discord.persistence.model.Version
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledInNativeImage
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito
import org.mockito.kotlin.given
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.springframework.boot.test.system.CapturedOutput
import org.springframework.boot.test.system.OutputCaptureExtension
import java.time.Instant
import java.time.temporal.ChronoUnit

@DisabledInNativeImage
@ExtendWith(OutputCaptureExtension::class)
class ServerServiceTest {

private val serverRepository = Mockito.mock(ServerRepository::class.java)
Expand All @@ -30,7 +35,7 @@ class ServerServiceTest {
private val serverService = ServerService(serverRepository, statusMonitorService, playerActivityFeedService, pvpKillFeedService)

@Test
fun shouldOffboardInactiveServers() {
fun shouldOffboardInactiveServers(capturedOutput: CapturedOutput) {

val servers = listOf(
// should not be offboarded
Expand Down Expand Up @@ -70,5 +75,7 @@ class ServerServiceTest {

verify(serverRepository).removeServer("offboard-me-pls")
verify(serverRepository, never()).removeServer("do-not-offboard")

assertThat(capturedOutput.out).contains("Successfully removed 1 servers with no active feature: [offboard-me-pls]")
}
}

0 comments on commit 76d0b12

Please sign in to comment.