mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-01 14:07:54 +01:00
Test case against ShutdownSave doing the bad save in #1424
- Rules out ShutdownSave code from the cause of the bug.
This commit is contained in:
parent
b7e1261597
commit
95cd4acb7d
@ -111,7 +111,7 @@ public abstract class ServerShutdownSave {
|
||||
return saveSessions(activeSessions, database);
|
||||
}
|
||||
|
||||
private void prepareSessionsForStorage(Map<UUID, Session> activeSessions, long now) {
|
||||
void prepareSessionsForStorage(Map<UUID, Session> activeSessions, long now) {
|
||||
for (Session session : activeSessions.values()) {
|
||||
Optional<Long> end = session.getValue(SessionKeys.END);
|
||||
if (!end.isPresent()) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
||||
import com.djrapitops.plan.gathering.cache.SessionCache;
|
||||
import com.djrapitops.plan.gathering.domain.GMTimes;
|
||||
import com.djrapitops.plan.gathering.domain.Session;
|
||||
@ -36,16 +37,17 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestConstants;
|
||||
import utilities.dagger.DaggerPlanPluginComponent;
|
||||
import utilities.dagger.PlanPluginComponent;
|
||||
import utilities.mocks.PlanPluginMocker;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -151,4 +153,21 @@ class ShutdownSaveTest {
|
||||
|
||||
sessionCache.cacheSession(playerUUID, session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endedSessionsHaveSameEndTime() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
UUID playerUUID = UUID.randomUUID();
|
||||
Session session = RandomData.randomUnfinishedSession(
|
||||
TestConstants.SERVER_UUID, new String[]{"w1", "w2"}, playerUUID
|
||||
);
|
||||
sessionCache.cacheSession(playerUUID, session);
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
|
||||
underTest.prepareSessionsForStorage(activeSessions, endTime);
|
||||
for (Session session : activeSessions.values()) {
|
||||
assertEquals(endTime, session.getUnsafe(SessionKeys.END), () -> "One of the sessions had differing end time");
|
||||
}
|
||||
}
|
||||
}
|
@ -114,6 +114,19 @@ public class RandomData {
|
||||
return session;
|
||||
}
|
||||
|
||||
public static List<Session> randomUnfinishedSessions(UUID serverUUID, String[] worlds, UUID... uuids) {
|
||||
return pickMultiple(randomInt(5, 50), () -> randomUnfinishedSession(serverUUID, worlds, uuids));
|
||||
}
|
||||
|
||||
public static Session randomUnfinishedSession(UUID serverUUID, String[] worlds, UUID... uuids) {
|
||||
Session session = new Session(uuids[0], serverUUID, RandomData.randomTime(), pickAtRandom(worlds), randomGameMode());
|
||||
session.setWorldTimes(RandomData.randomWorldTimes(worlds));
|
||||
if (uuids.length >= 2) {
|
||||
session.setPlayerKills(RandomData.randomKills(pickAtRandom(Arrays.copyOfRange(uuids, 1, uuids.length))));
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
public static List<Point> randomPoints() {
|
||||
List<Point> test = new ArrayList<>();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user