This commit is contained in:
Lee 2024-04-18 15:47:05 +01:00
parent f037f3f9e7
commit 3ac4bfe2ee
19 changed files with 31 additions and 67 deletions

@ -2,6 +2,7 @@ package xyz.mcutils.backend.repository.mongo;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.service.metric.Metric; import xyz.mcutils.backend.service.metric.Metric;
@ -10,6 +11,4 @@ import xyz.mcutils.backend.service.metric.Metric;
* *
* @author Braydon * @author Braydon
*/ */
@EnableMongoRepositories public interface MetricsRepository extends CrudRepository<Metric<?>, String> { }
@Repository
public interface MetricsRepository extends MongoRepository<Metric<?>, String> { }

@ -10,6 +10,4 @@ import xyz.mcutils.backend.model.cache.CachedEndpointStatus;
* *
* @author Braydon * @author Braydon
*/ */
@EnableRedisRepositories
@Repository
public interface EndpointStatusRepository extends CrudRepository<CachedEndpointStatus, String> { } public interface EndpointStatusRepository extends CrudRepository<CachedEndpointStatus, String> { }

@ -10,6 +10,4 @@ import xyz.mcutils.backend.model.cache.CachedMinecraftServer;
* *
* @author Braydon * @author Braydon
*/ */
@EnableRedisRepositories
@Repository
public interface MinecraftServerCacheRepository extends CrudRepository<CachedMinecraftServer, String> { } public interface MinecraftServerCacheRepository extends CrudRepository<CachedMinecraftServer, String> { }

@ -12,6 +12,4 @@ import java.util.UUID;
* *
* @author Braydon * @author Braydon
*/ */
@EnableRedisRepositories
@Repository
public interface PlayerCacheRepository extends CrudRepository<CachedPlayer, UUID> { } public interface PlayerCacheRepository extends CrudRepository<CachedPlayer, UUID> { }

@ -14,6 +14,4 @@ import xyz.mcutils.backend.model.cache.CachedPlayerName;
* *
* @author Braydon * @author Braydon
*/ */
@EnableRedisRepositories
@Repository
public interface PlayerNameCacheRepository extends CrudRepository<CachedPlayerName, String> { } public interface PlayerNameCacheRepository extends CrudRepository<CachedPlayerName, String> { }

@ -12,6 +12,4 @@ import xyz.mcutils.backend.model.cache.CachedPlayerSkinPart;
* player skin part by it's id. * player skin part by it's id.
* </p> * </p>
*/ */
@EnableRedisRepositories
@Repository
public interface PlayerSkinPartCacheRepository extends CrudRepository<CachedPlayerSkinPart, String> { } public interface PlayerSkinPartCacheRepository extends CrudRepository<CachedPlayerSkinPart, String> { }

@ -131,7 +131,7 @@ public class MetricService {
List<Point> points = new ArrayList<>(); List<Point> points = new ArrayList<>();
for (Metric<?> metric : metrics.values()) { for (Metric<?> metric : metrics.values()) {
if (metric.isCollector()) { if (metric.isCollector()) {
metric.collect(this); metric.collect();
} }
Point point = metric.toPoint(); Point point = metric.toPoint();
if (point != null) { if (point != null) {

@ -35,7 +35,7 @@ public abstract class Metric<T> {
/** /**
* Collects the metric. * Collects the metric.
*/ */
public void collect(MetricService metricService) {} public void collect() {}
/** /**
* Gets this point as a {@link Point}. * Gets this point as a {@link Point}.

@ -16,7 +16,7 @@ public class ConnectedSocketsMetric extends IntegerMetric {
} }
@Override @Override
public void collect(MetricService metricService) { public void collect() {
setValue(MetricsWebSocketHandler.SESSIONS.size()); setValue(MetricsWebSocketHandler.SESSIONS.size());
} }
} }

@ -31,7 +31,7 @@ public class UniquePlayerLookupsMetric extends IntegerMetric {
} }
@Override @Override
public void collect(MetricService metricService) { public void collect() {
setValue(uniqueLookups.size()); setValue(uniqueLookups.size());
} }
} }

@ -31,7 +31,7 @@ public class UniqueServerLookupsMetric extends IntegerMetric {
} }
@Override @Override
public void collect(MetricService metricService) { public void collect() {
setValue(uniqueLookups.size()); setValue(uniqueLookups.size());
} }
} }

@ -22,7 +22,7 @@ public class CpuUsageMetric extends DoubleMetric {
} }
@Override @Override
public void collect(MetricService metricService) { public void collect() {
this.setValue(OS_BEAN.getProcessCpuLoad() * 100); this.setValue(OS_BEAN.getProcessCpuLoad() * 100);
} }
} }

@ -15,7 +15,7 @@ public class MemoryMetric extends MapMetric<String, Long> {
} }
@Override @Override
public void collect(MetricService metricService) { public void collect() {
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
this.getValue().put("total", runtime.maxMemory()); this.getValue().put("total", runtime.maxMemory());

@ -20,7 +20,8 @@ spring:
# MongoDB - This is used for general data storage # MongoDB - This is used for general data storage
mongodb: mongodb:
uri: mongodb://localhost:27017 uri: mongodb://localhost:27017
database: database database: test
port: 27017
# Disable default metrics # Disable default metrics
management: management:
@ -41,4 +42,10 @@ influx:
org: org org: org
bucket: bucket bucket: bucket
de:
flapdoodle:
mongodb:
embedded:
version: 7.0.8
public-url: http://localhost public-url: http://localhost

@ -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 { }

@ -1,9 +1,11 @@
package cc.fascinated.config; package xyz.mcutils.backend.test.config;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.boot.test.context.TestConfiguration; 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 redis.embedded.RedisServer;
import java.io.IOException; import java.io.IOException;
@ -16,7 +18,8 @@ import java.io.IOException;
*/ */
@TestConfiguration @TestConfiguration
public class TestRedisConfig { public class TestRedisConfig {
@NonNull private final RedisServer server; @NonNull
private final RedisServer server;
public TestRedisConfig() throws IOException { public TestRedisConfig() throws IOException {
server = new RedisServer(); // Construct the mock server server = new RedisServer(); // Construct the mock server

@ -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.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; 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.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@AutoConfigureMockMvc
@SpringBootTest(classes = { TestRedisConfig.class }) @SpringBootTest(classes = { TestRedisConfig.class })
@DataMongoTest() @AutoConfigureMockMvc
@ExtendWith(SpringExtension.class)
class MojangControllerTests { class MojangControllerTests {
@Autowired @Autowired

@ -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.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; 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.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import xyz.mcutils.backend.config.TestMongoConfig;
import xyz.mcutils.backend.model.skin.ISkinPart; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@AutoConfigureMockMvc
@SpringBootTest(classes = { TestRedisConfig.class }) @SpringBootTest(classes = { TestRedisConfig.class })
@DataMongoTest() @AutoConfigureMockMvc
@ExtendWith(SpringExtension.class)
class PlayerControllerTests { class PlayerControllerTests {
private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";

@ -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.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; 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.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@AutoConfigureMockMvc
@SpringBootTest(classes = { TestRedisConfig.class }) @SpringBootTest(classes = { TestRedisConfig.class })
@DataMongoTest() @AutoConfigureMockMvc
@ExtendWith(SpringExtension.class)
class ServerControllerTests { class ServerControllerTests {
private final String testServer = "play.hypixel.net"; private final String testServer = "play.hypixel.net";