From 3ac4bfe2ee4d1133715936de5cb863b505a4d3e0 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 18 Apr 2024 15:47:05 +0100 Subject: [PATCH] maybe --- .../repository/mongo/MetricsRepository.java | 5 ++--- .../redis/EndpointStatusRepository.java | 2 -- .../redis/MinecraftServerCacheRepository.java | 2 -- .../repository/redis/PlayerCacheRepository.java | 2 -- .../redis/PlayerNameCacheRepository.java | 2 -- .../redis/PlayerSkinPartCacheRepository.java | 2 -- .../mcutils/backend/service/MetricService.java | 2 +- .../mcutils/backend/service/metric/Metric.java | 2 +- .../metric/metrics/ConnectedSocketsMetric.java | 2 +- .../metrics/UniquePlayerLookupsMetric.java | 2 +- .../metrics/UniqueServerLookupsMetric.java | 2 +- .../metric/metrics/process/CpuUsageMetric.java | 2 +- .../metric/metrics/process/MemoryMetric.java | 2 +- src/main/resources/application.yml | 9 ++++++++- .../mcutils/backend/config/TestMongoConfig.java | 17 ----------------- .../{ => test}/config/TestRedisConfig.java | 7 +++++-- .../{ => test}/tests/MojangControllerTests.java | 12 +++--------- .../{ => test}/tests/PlayerControllerTests.java | 12 +++--------- .../{ => test}/tests/ServerControllerTests.java | 12 +++--------- 19 files changed, 31 insertions(+), 67 deletions(-) delete mode 100644 src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java rename src/test/java/xyz/mcutils/backend/{ => test}/config/TestRedisConfig.java (78%) rename src/test/java/xyz/mcutils/backend/{ => test}/tests/MojangControllerTests.java (67%) rename src/test/java/xyz/mcutils/backend/{ => test}/tests/PlayerControllerTests.java (88%) rename src/test/java/xyz/mcutils/backend/{ => test}/tests/ServerControllerTests.java (83%) diff --git a/src/main/java/xyz/mcutils/backend/repository/mongo/MetricsRepository.java b/src/main/java/xyz/mcutils/backend/repository/mongo/MetricsRepository.java index 7b142a0..bbada47 100644 --- a/src/main/java/xyz/mcutils/backend/repository/mongo/MetricsRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/mongo/MetricsRepository.java @@ -2,6 +2,7 @@ package xyz.mcutils.backend.repository.mongo; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import xyz.mcutils.backend.service.metric.Metric; @@ -10,6 +11,4 @@ import xyz.mcutils.backend.service.metric.Metric; * * @author Braydon */ -@EnableMongoRepositories -@Repository -public interface MetricsRepository extends MongoRepository, String> { } \ No newline at end of file +public interface MetricsRepository extends CrudRepository, String> { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/repository/redis/EndpointStatusRepository.java b/src/main/java/xyz/mcutils/backend/repository/redis/EndpointStatusRepository.java index 57c86e0..c84d25b 100644 --- a/src/main/java/xyz/mcutils/backend/repository/redis/EndpointStatusRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/redis/EndpointStatusRepository.java @@ -10,6 +10,4 @@ import xyz.mcutils.backend.model.cache.CachedEndpointStatus; * * @author Braydon */ -@EnableRedisRepositories -@Repository public interface EndpointStatusRepository extends CrudRepository { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/repository/redis/MinecraftServerCacheRepository.java b/src/main/java/xyz/mcutils/backend/repository/redis/MinecraftServerCacheRepository.java index 2eff856..fb4cbec 100644 --- a/src/main/java/xyz/mcutils/backend/repository/redis/MinecraftServerCacheRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/redis/MinecraftServerCacheRepository.java @@ -10,6 +10,4 @@ import xyz.mcutils.backend.model.cache.CachedMinecraftServer; * * @author Braydon */ -@EnableRedisRepositories -@Repository public interface MinecraftServerCacheRepository extends CrudRepository { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/repository/redis/PlayerCacheRepository.java b/src/main/java/xyz/mcutils/backend/repository/redis/PlayerCacheRepository.java index e3a996c..17d4377 100644 --- a/src/main/java/xyz/mcutils/backend/repository/redis/PlayerCacheRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/redis/PlayerCacheRepository.java @@ -12,6 +12,4 @@ import java.util.UUID; * * @author Braydon */ -@EnableRedisRepositories -@Repository public interface PlayerCacheRepository extends CrudRepository { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/repository/redis/PlayerNameCacheRepository.java b/src/main/java/xyz/mcutils/backend/repository/redis/PlayerNameCacheRepository.java index cf93dcb..26c66b4 100644 --- a/src/main/java/xyz/mcutils/backend/repository/redis/PlayerNameCacheRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/redis/PlayerNameCacheRepository.java @@ -14,6 +14,4 @@ import xyz.mcutils.backend.model.cache.CachedPlayerName; * * @author Braydon */ -@EnableRedisRepositories -@Repository public interface PlayerNameCacheRepository extends CrudRepository { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/repository/redis/PlayerSkinPartCacheRepository.java b/src/main/java/xyz/mcutils/backend/repository/redis/PlayerSkinPartCacheRepository.java index 0efbefa..da4560d 100644 --- a/src/main/java/xyz/mcutils/backend/repository/redis/PlayerSkinPartCacheRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/redis/PlayerSkinPartCacheRepository.java @@ -12,6 +12,4 @@ import xyz.mcutils.backend.model.cache.CachedPlayerSkinPart; * player skin part by it's id. *

*/ -@EnableRedisRepositories -@Repository public interface PlayerSkinPartCacheRepository extends CrudRepository { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/service/MetricService.java b/src/main/java/xyz/mcutils/backend/service/MetricService.java index d5c6ed6..464496d 100644 --- a/src/main/java/xyz/mcutils/backend/service/MetricService.java +++ b/src/main/java/xyz/mcutils/backend/service/MetricService.java @@ -131,7 +131,7 @@ public class MetricService { List points = new ArrayList<>(); for (Metric metric : metrics.values()) { if (metric.isCollector()) { - metric.collect(this); + metric.collect(); } Point point = metric.toPoint(); if (point != null) { diff --git a/src/main/java/xyz/mcutils/backend/service/metric/Metric.java b/src/main/java/xyz/mcutils/backend/service/metric/Metric.java index 1b4129f..c36c37b 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/Metric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/Metric.java @@ -35,7 +35,7 @@ public abstract class Metric { /** * Collects the metric. */ - public void collect(MetricService metricService) {} + public void collect() {} /** * Gets this point as a {@link Point}. diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/ConnectedSocketsMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/ConnectedSocketsMetric.java index 3626c20..632db1a 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/ConnectedSocketsMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/ConnectedSocketsMetric.java @@ -16,7 +16,7 @@ public class ConnectedSocketsMetric extends IntegerMetric { } @Override - public void collect(MetricService metricService) { + public void collect() { setValue(MetricsWebSocketHandler.SESSIONS.size()); } } diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java index 4096321..2c92ae6 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java @@ -31,7 +31,7 @@ public class UniquePlayerLookupsMetric extends IntegerMetric { } @Override - public void collect(MetricService metricService) { + public void collect() { setValue(uniqueLookups.size()); } } diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java index e1be045..e5a3a9c 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java @@ -31,7 +31,7 @@ public class UniqueServerLookupsMetric extends IntegerMetric { } @Override - public void collect(MetricService metricService) { + public void collect() { setValue(uniqueLookups.size()); } } diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/CpuUsageMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/CpuUsageMetric.java index 771df7c..616127e 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/CpuUsageMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/CpuUsageMetric.java @@ -22,7 +22,7 @@ public class CpuUsageMetric extends DoubleMetric { } @Override - public void collect(MetricService metricService) { + public void collect() { this.setValue(OS_BEAN.getProcessCpuLoad() * 100); } } diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/MemoryMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/MemoryMetric.java index 4d98e21..5eed6e6 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/MemoryMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/process/MemoryMetric.java @@ -15,7 +15,7 @@ public class MemoryMetric extends MapMetric { } @Override - public void collect(MetricService metricService) { + public void collect() { Runtime runtime = Runtime.getRuntime(); this.getValue().put("total", runtime.maxMemory()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0c49791..f8e822c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,7 +20,8 @@ spring: # MongoDB - This is used for general data storage mongodb: uri: mongodb://localhost:27017 - database: database + database: test + port: 27017 # Disable default metrics management: @@ -41,4 +42,10 @@ influx: org: org bucket: bucket +de: + flapdoodle: + mongodb: + embedded: + version: 7.0.8 + public-url: http://localhost \ No newline at end of file diff --git a/src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java b/src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java deleted file mode 100644 index d5a0e06..0000000 --- a/src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package xyz.mcutils.backend.config; - -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -/** - * Test configuration for - * a mock Redis server. - * - * @author Braydon - */ -@TestConfiguration -@DataMongoTest() -@ExtendWith(SpringExtension.class) -public class TestMongoConfig { } \ No newline at end of file diff --git a/src/test/java/xyz/mcutils/backend/config/TestRedisConfig.java b/src/test/java/xyz/mcutils/backend/test/config/TestRedisConfig.java similarity index 78% rename from src/test/java/xyz/mcutils/backend/config/TestRedisConfig.java rename to src/test/java/xyz/mcutils/backend/test/config/TestRedisConfig.java index 2a408bf..a3bba95 100644 --- a/src/test/java/xyz/mcutils/backend/config/TestRedisConfig.java +++ b/src/test/java/xyz/mcutils/backend/test/config/TestRedisConfig.java @@ -1,9 +1,11 @@ -package cc.fascinated.config; +package xyz.mcutils.backend.test.config; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import lombok.NonNull; import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; import redis.embedded.RedisServer; import java.io.IOException; @@ -16,7 +18,8 @@ import java.io.IOException; */ @TestConfiguration public class TestRedisConfig { - @NonNull private final RedisServer server; + @NonNull + private final RedisServer server; public TestRedisConfig() throws IOException { server = new RedisServer(); // Construct the mock server diff --git a/src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java b/src/test/java/xyz/mcutils/backend/test/tests/MojangControllerTests.java similarity index 67% rename from src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java rename to src/test/java/xyz/mcutils/backend/test/tests/MojangControllerTests.java index b5780e0..a1d75d9 100644 --- a/src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java +++ b/src/test/java/xyz/mcutils/backend/test/tests/MojangControllerTests.java @@ -1,24 +1,18 @@ -package xyz.mcutils.backend.tests; +package xyz.mcutils.backend.test.tests; -import cc.fascinated.config.TestRedisConfig; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import xyz.mcutils.backend.config.TestMongoConfig; +import xyz.mcutils.backend.test.config.TestRedisConfig; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +@SpringBootTest(classes = { TestRedisConfig.class }) @AutoConfigureMockMvc -@SpringBootTest(classes = {TestRedisConfig.class}) -@DataMongoTest() -@ExtendWith(SpringExtension.class) class MojangControllerTests { @Autowired diff --git a/src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java b/src/test/java/xyz/mcutils/backend/test/tests/PlayerControllerTests.java similarity index 88% rename from src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java rename to src/test/java/xyz/mcutils/backend/test/tests/PlayerControllerTests.java index 3aacc98..93bcc8c 100644 --- a/src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java +++ b/src/test/java/xyz/mcutils/backend/test/tests/PlayerControllerTests.java @@ -1,26 +1,20 @@ -package xyz.mcutils.backend.tests; +package xyz.mcutils.backend.test.tests; -import cc.fascinated.config.TestRedisConfig; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import xyz.mcutils.backend.config.TestMongoConfig; import xyz.mcutils.backend.model.skin.ISkinPart; +import xyz.mcutils.backend.test.config.TestRedisConfig; 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; +@SpringBootTest(classes = { TestRedisConfig.class }) @AutoConfigureMockMvc -@SpringBootTest(classes = {TestRedisConfig.class}) -@DataMongoTest() -@ExtendWith(SpringExtension.class) class PlayerControllerTests { private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; diff --git a/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java b/src/test/java/xyz/mcutils/backend/test/tests/ServerControllerTests.java similarity index 83% rename from src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java rename to src/test/java/xyz/mcutils/backend/test/tests/ServerControllerTests.java index 977f202..27cd0bc 100644 --- a/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java +++ b/src/test/java/xyz/mcutils/backend/test/tests/ServerControllerTests.java @@ -1,25 +1,19 @@ -package xyz.mcutils.backend.tests; +package xyz.mcutils.backend.test.tests; -import cc.fascinated.config.TestRedisConfig; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import xyz.mcutils.backend.config.TestMongoConfig; +import xyz.mcutils.backend.test.config.TestRedisConfig; 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; +@SpringBootTest(classes = { TestRedisConfig.class }) @AutoConfigureMockMvc -@SpringBootTest(classes = {TestRedisConfig.class}) -@DataMongoTest() -@ExtendWith(SpringExtension.class) class ServerControllerTests { private final String testServer = "play.hypixel.net";