Tests against Activity index calculation mismatch

This commit is contained in:
Rsl1122 2019-10-19 14:09:29 +03:00
parent d17a962505
commit 194bbe9850
2 changed files with 48 additions and 0 deletions

View File

@ -48,6 +48,14 @@ public class ServerTablePlayersQuery implements Query<List<TablePlayer>> {
private final long activeMsThreshold;
private final int xMostRecentPlayers;
/**
* Create a new query.
*
* @param serverUUID UUID of the Plan server.
* @param date Date used for Activity Index calculation
* @param activeMsThreshold Playtime threshold for Activity Index calculation
* @param xMostRecentPlayers Limit query size
*/
public ServerTablePlayersQuery(UUID serverUUID, long date, long activeMsThreshold, int xMostRecentPlayers) {
this.serverUUID = serverUUID;
this.date = date;

View File

@ -1153,6 +1153,46 @@ public interface DatabaseTest {
assertEquals(expected, got);
}
@Test
default void activityIndexCalculationsMatch() {
sessionsAreStoredWithAllData();
long date = System.currentTimeMillis();
long playtimeThreshold = TimeUnit.HOURS.toMillis(5L);
List<Session> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID))
.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
ActivityIndex javaCalculation = new ActivityIndex(sessions, date, playtimeThreshold);
List<TablePlayer> players = db().query(new ServerTablePlayersQuery(serverUUID(), date, playtimeThreshold, 5));
Optional<TablePlayer> found = players.stream().filter(tp -> playerUUID.equals(tp.getPlayerUUID())).findFirst();
assertTrue(found.isPresent());
Optional<ActivityIndex> currentActivityIndex = found.get().getCurrentActivityIndex();
assertTrue(currentActivityIndex.isPresent());
assertEquals(javaCalculation.getValue(), currentActivityIndex.get().getValue(), 0.001);
}
@Test
default void networkActivityIndexCalculationsMatch() {
sessionsAreStoredWithAllData();
long date = System.currentTimeMillis();
long playtimeThreshold = TimeUnit.HOURS.toMillis(5L);
List<Session> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID))
.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
ActivityIndex javaCalculation = new ActivityIndex(sessions, date, playtimeThreshold);
List<TablePlayer> players = db().query(new NetworkTablePlayersQuery(date, playtimeThreshold, 5));
Optional<TablePlayer> found = players.stream().filter(tp -> playerUUID.equals(tp.getPlayerUUID())).findFirst();
assertTrue(found.isPresent());
Optional<ActivityIndex> currentActivityIndex = found.get().getCurrentActivityIndex();
assertTrue(currentActivityIndex.isPresent());
assertEquals(javaCalculation.getValue(), currentActivityIndex.get().getValue(), 0.001);
}
@Test
default void extensionPlayerValuesAreStored() {
ExtensionServiceImplementation extensionService = (ExtensionServiceImplementation) system().getExtensionService();