This commit is contained in:
Lee 2024-04-18 16:28:09 +01:00
parent 3ac4bfe2ee
commit 046df7fd1f
18 changed files with 22 additions and 35 deletions

@ -174,7 +174,6 @@
<groupId>de.flapdoodle.embed</groupId> <groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo.spring3x</artifactId> <artifactId>de.flapdoodle.embed.mongo.spring3x</artifactId>
<version>4.12.6</version> <version>4.12.6</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

@ -1,10 +1,8 @@
package xyz.mcutils.backend.config; package xyz.mcutils.backend.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
@Configuration @Configuration
@EnableMongoRepositories(basePackages = "xyz.mcutils.backend.repository.mongo") @EnableMongoRepositories(basePackages = "xyz.mcutils.backend.repository.mongo")
public class MongoConfig { public class MongoConfig { }
}

@ -1,9 +1,6 @@
package xyz.mcutils.backend.repository.mongo; 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.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.service.metric.Metric; import xyz.mcutils.backend.service.metric.Metric;
/** /**
@ -11,4 +8,4 @@ import xyz.mcutils.backend.service.metric.Metric;
* *
* @author Braydon * @author Braydon
*/ */
public interface MetricsRepository extends CrudRepository<Metric<?>, String> { } public interface MetricsRepository extends MongoRepository<Metric<?>, String> { }

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis; package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedEndpointStatus; import xyz.mcutils.backend.model.cache.CachedEndpointStatus;
/** /**

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis; package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedMinecraftServer; import xyz.mcutils.backend.model.cache.CachedMinecraftServer;
/** /**

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis; package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedPlayer; import xyz.mcutils.backend.model.cache.CachedPlayer;
import java.util.UUID; import java.util.UUID;

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis; package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedPlayerName; import xyz.mcutils.backend.model.cache.CachedPlayerName;
/** /**

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis; package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedPlayerSkinPart; import xyz.mcutils.backend.model.cache.CachedPlayerSkinPart;
/** /**

@ -7,6 +7,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import xyz.mcutils.backend.common.Timer; import xyz.mcutils.backend.common.Timer;
import xyz.mcutils.backend.config.Config;
import xyz.mcutils.backend.repository.mongo.MetricsRepository; import xyz.mcutils.backend.repository.mongo.MetricsRepository;
import xyz.mcutils.backend.service.metric.Metric; import xyz.mcutils.backend.service.metric.Metric;
import xyz.mcutils.backend.service.metric.metrics.*; import xyz.mcutils.backend.service.metric.metrics.*;
@ -55,6 +56,7 @@ public class MetricService {
collectorEnabled.put(metric, metric.isCollector()); collectorEnabled.put(metric, metric.isCollector());
} }
if (Config.INSTANCE.isProduction()) {
// Load the metrics from Redis // Load the metrics from Redis
loadMetrics(); loadMetrics();
@ -67,6 +69,7 @@ public class MetricService {
writeToInflux(); writeToInflux();
}, saveInterval, saveInterval); }, saveInterval, saveInterval);
} }
}
/** /**
* Register a metric. * Register a metric.

@ -9,7 +9,6 @@ import lombok.ToString;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient; import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import xyz.mcutils.backend.service.MetricService;
@AllArgsConstructor @AllArgsConstructor
@Getter @Setter @ToString @Getter @Setter @ToString

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics; package xyz.mcutils.backend.service.metric.metrics;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.IntegerMetric; import xyz.mcutils.backend.service.metric.impl.IntegerMetric;
import xyz.mcutils.backend.websocket.MetricsWebSocketHandler; import xyz.mcutils.backend.websocket.MetricsWebSocketHandler;

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics; package xyz.mcutils.backend.service.metric.metrics;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.IntegerMetric; import xyz.mcutils.backend.service.metric.impl.IntegerMetric;
import java.util.ArrayList; import java.util.ArrayList;

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics; package xyz.mcutils.backend.service.metric.metrics;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.IntegerMetric; import xyz.mcutils.backend.service.metric.impl.IntegerMetric;
import java.util.ArrayList; import java.util.ArrayList;

@ -1,7 +1,6 @@
package xyz.mcutils.backend.service.metric.metrics.process; package xyz.mcutils.backend.service.metric.metrics.process;
import com.sun.management.OperatingSystemMXBean; import com.sun.management.OperatingSystemMXBean;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.DoubleMetric; import xyz.mcutils.backend.service.metric.impl.DoubleMetric;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics.process; package xyz.mcutils.backend.service.metric.metrics.process;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.MapMetric; import xyz.mcutils.backend.service.metric.impl.MapMetric;
public class MemoryMetric extends MapMetric<String, Long> { public class MemoryMetric extends MapMetric<String, Long> {

@ -4,8 +4,6 @@ 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;

@ -1,7 +1,10 @@
package xyz.mcutils.backend.test.tests; package xyz.mcutils.backend.test.tests;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
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;
@ -15,6 +18,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(classes = { TestRedisConfig.class }) @SpringBootTest(classes = { TestRedisConfig.class })
@AutoConfigureMockMvc @AutoConfigureMockMvc
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class PlayerControllerTests { class PlayerControllerTests {
private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";

@ -1,7 +1,10 @@
package xyz.mcutils.backend.test.tests; package xyz.mcutils.backend.test.tests;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
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;
@ -14,6 +17,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(classes = { TestRedisConfig.class }) @SpringBootTest(classes = { TestRedisConfig.class })
@AutoConfigureMockMvc @AutoConfigureMockMvc
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class ServerControllerTests { class ServerControllerTests {
private final String testServer = "play.hypixel.net"; private final String testServer = "play.hypixel.net";