Split ActivityIndexQueries to own Test class

This commit is contained in:
Rsl1122 2020-03-11 15:12:01 +02:00 committed by Risto Lahtela
parent ea209aceb3
commit 952cac1fbf
5 changed files with 105 additions and 64 deletions

View File

@ -26,7 +26,6 @@ import com.djrapitops.plan.delivery.domain.keys.Key;
import com.djrapitops.plan.delivery.domain.keys.PlayerKeys;
import com.djrapitops.plan.delivery.domain.keys.ServerKeys;
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
import com.djrapitops.plan.delivery.domain.mutators.ActivityIndex;
import com.djrapitops.plan.delivery.domain.mutators.SessionsMutator;
import com.djrapitops.plan.gathering.domain.*;
import com.djrapitops.plan.identification.Server;
@ -35,7 +34,6 @@ import com.djrapitops.plan.settings.config.Config;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.storage.database.queries.*;
import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries;
import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries;
import com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery;
import com.djrapitops.plan.storage.database.queries.objects.*;
@ -988,16 +986,6 @@ public interface DatabaseTest extends DatabaseTestPreparer {
assertEquals(expected, result);
}
@Test
default void activityIndexCoalesceSanityCheck() {
sessionsAreStoredWithAllData();
Map<String, Integer> groupings = db().query(
ActivityIndexQueries.fetchActivityIndexGroupingsOn(System.currentTimeMillis(), serverUUID(), TimeUnit.HOURS.toMillis(2L))
);
Map<String, Integer> expected = Collections.singletonMap(ActivityIndex.getDefaultGroups()[4], 1); // Inactive
assertEquals(expected, groupings);
}
@Test
default void serverGeolocationsAreCountedAppropriately() {
UUID firstUuid = UUID.randomUUID();
@ -1153,46 +1141,6 @@ public interface DatabaseTest extends DatabaseTestPreparer {
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 registerDateIsMinimized() {
executeTransactions(
@ -1220,15 +1168,6 @@ public interface DatabaseTest extends DatabaseTestPreparer {
assertTrue(testedPatch.hasBeenApplied());
}
@Test
default void activeTurnedInactiveQueryHasAllParametersSet() {
Integer result = db().query(ActivityIndexQueries.countRegularPlayersTurnedInactive(
0, System.currentTimeMillis(), serverUUID(),
TimeUnit.HOURS.toMillis(2L)
));
assertNotNull(result);
}
@Test
default void serverTablePlayersQueryQueriesAtLeastOnePlayer() {
sessionsAreStoredWithAllData();

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.storage.database;
import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueriesTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
@ -37,7 +38,9 @@ import java.util.UUID;
* @see ExtensionsDatabaseTest
*/
@ExtendWith(MockitoExtension.class)
public class H2Test implements DatabaseTest, ExtensionsDatabaseTest {
public class H2Test implements DatabaseTest,
ExtensionsDatabaseTest,
ActivityIndexQueriesTest {
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.storage.database;
import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueriesTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
@ -43,7 +44,9 @@ import java.util.UUID;
* @see utilities.CIProperties for assumed MySQL setup.
*/
@ExtendWith(MockitoExtension.class)
class MySQLTest implements DatabaseTest, ExtensionsDatabaseTest {
class MySQLTest implements DatabaseTest,
ExtensionsDatabaseTest,
ActivityIndexQueriesTest {
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.storage.database;
import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueriesTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
@ -37,7 +38,9 @@ import java.util.UUID;
* @see ExtensionsDatabaseTest
*/
@ExtendWith(MockitoExtension.class)
public class SQLiteTest implements DatabaseTest, ExtensionsDatabaseTest {
public class SQLiteTest implements DatabaseTest,
ExtensionsDatabaseTest,
ActivityIndexQueriesTest {
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);

View File

@ -0,0 +1,93 @@
package com.djrapitops.plan.storage.database.queries.analysis;
import com.djrapitops.plan.delivery.domain.TablePlayer;
import com.djrapitops.plan.delivery.domain.mutators.ActivityIndex;
import com.djrapitops.plan.gathering.domain.Session;
import com.djrapitops.plan.storage.database.DatabaseTestPreparer;
import com.djrapitops.plan.storage.database.queries.DataStoreQueries;
import com.djrapitops.plan.storage.database.queries.objects.NetworkTablePlayersQuery;
import com.djrapitops.plan.storage.database.queries.objects.ServerTablePlayersQuery;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction;
import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction;
import org.junit.jupiter.api.Test;
import utilities.TestConstants;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
public interface ActivityIndexQueriesTest extends DatabaseTestPreparer {
default void storeSessions() {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> 1000L, TestConstants.PLAYER_ONE_NAME, serverUUID()));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
Session session = new Session(playerUUID, serverUUID(), 12345L, worlds[0], "SURVIVAL");
session.endSession(22345L);
execute(DataStoreQueries.storeSession(session));
}
@Test
default void activityIndexCoalesceSanityCheck() {
storeSessions();
Map<String, Integer> groupings = db().query(
ActivityIndexQueries.fetchActivityIndexGroupingsOn(System.currentTimeMillis(), serverUUID(), TimeUnit.HOURS.toMillis(2L))
);
Map<String, Integer> expected = Collections.singletonMap(ActivityIndex.getDefaultGroups()[4], 1); // Inactive
assertEquals(expected, groupings);
}
@Test
default void activityIndexCalculationsMatch() {
storeSessions();
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() {
storeSessions();
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 activeTurnedInactiveQueryHasAllParametersSet() {
Integer result = db().query(ActivityIndexQueries.countRegularPlayersTurnedInactive(
0, System.currentTimeMillis(), serverUUID(),
TimeUnit.HOURS.toMillis(2L)
));
assertNotNull(result);
}
}