use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class ExtensionsDatabaseTest method extensionPlayerValuesCanBeQueriedAsTableData.
@Test
default void extensionPlayerValuesCanBeQueriedAsTableData() {
extensionPlayerValuesAreStored();
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
// Store a session to check against issue https://github.com/plan-player-analytics/Plan/issues/1039
ActiveSession session = new ActiveSession(playerUUID, serverUUID(), 32345L, worlds[0], "SURVIVAL");
session.getExtraData().put(WorldTimes.class, RandomData.randomWorldTimes(worlds));
execute(DataStoreQueries.storeSession(session.toFinishedSession(42345L)));
Map<UUID, ExtensionTabData> result = db().query(new ExtensionServerTableDataQuery(serverUUID(), 50));
assertEquals(1, result.size());
ExtensionTabData playerData = result.get(playerUUID);
assertNotNull(playerData);
OptionalAssert.equals("5", playerData.getNumber("value").map(data -> data.getFormattedValue(Object::toString)));
OptionalAssert.equals("No", playerData.getBoolean("boolVal").map(ExtensionBooleanData::getFormattedValue));
OptionalAssert.equals("0.5", playerData.getDouble("doubleVal").map(data -> data.getFormattedValue(Object::toString)));
OptionalAssert.equals("0.5", playerData.getPercentage("percentageVal").map(data -> data.getFormattedValue(Object::toString)));
OptionalAssert.equals("Something", playerData.getString("stringVal").map(ExtensionStringData::getFormattedValue));
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class DatabaseTest method registerDateIsMinimized.
@Test
default void registerDateIsMinimized() {
executeTransactions(new PlayerServerRegisterTransaction(playerUUID, () -> 1000, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME), new Transaction() {
@Override
protected void performOperations() {
execute("UPDATE " + UserInfoTable.TABLE_NAME + " SET " + UserInfoTable.REGISTERED + "=0" + WHERE + UserInfoTable.USER_UUID + "='" + playerUUID + "'");
}
});
// Check test assumptions
Map<UUID, Long> registerDates = db().query(UserInfoQueries.fetchRegisterDates(0L, System.currentTimeMillis(), serverUUID()));
assertEquals(0L, registerDates.get(playerUUID));
Optional<BaseUser> baseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
assertEquals(1000L, baseUser.isPresent() ? baseUser.get().getRegistered() : null);
RegisterDateMinimizationPatch testedPatch = new RegisterDateMinimizationPatch();
executeTransactions(testedPatch);
// Test expected result
Optional<BaseUser> updatedBaseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
assertEquals(0L, updatedBaseUser.isPresent() ? updatedBaseUser.get().getRegistered() : null);
assertTrue(testedPatch.isApplied());
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class DatabaseTest method playerContainerSupportsAllPlayerKeys.
@Test
default void playerContainerSupportsAllPlayerKeys() throws IllegalAccessException {
saveUserOne();
saveUserTwo();
saveTwoWorlds();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
execute(DataStoreQueries.storeSession(session));
db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
saveGeoInfo(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()));
assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), RandomData.randomIntDateObjects()));
PlayerContainer playerContainer = db().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
// Active sessions are added after fetching
playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomUnfinishedSession(serverUUID(), worlds, playerUUID));
List<String> unsupported = new ArrayList<>();
List<Key> keys = FieldFetcher.getPublicStaticFields(PlayerKeys.class, Key.class);
for (Key<?> key : keys) {
if (!playerContainer.supports(key)) {
unsupported.add(key.getKeyName());
}
}
assertTrue(unsupported.isEmpty(), () -> "Some keys are not supported by PlayerContainer: PlayerKeys." + unsupported.toString());
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class TestData method createSessionsForPlayer.
private static List<FinishedSession> createSessionsForPlayer(UUID uuid) {
List<FinishedSession> sessions = new ArrayList<>();
String[] gms = GMTimes.getGMKeyArray();
ActiveSession sessionOne = new ActiveSession(uuid, serverUUID, playerFirstJoin, serverWorldNames[0], gms[0]);
UUID otherUUID = uuid.equals(playerUUID) ? player2UUID : playerUUID;
sessionOne.addPlayerKill(TestData.getPlayerKill(uuid, otherUUID, serverUUID, "Iron Sword", 1234750L));
sessionOne.addPlayerKill(TestData.getPlayerKill(uuid, otherUUID, serverUUID, "Gold Sword", 1234800L));
// Length 500ms
sessions.add(sessionOne.toFinishedSession(1235000L));
ActiveSession sessionTwo = new ActiveSession(uuid, server2UUID, playerSecondJoin, server2WorldNames[0], gms[1]);
// Length 100s
sessionTwo.changeState(server2WorldNames[1], gms[0], 334000L);
// Length 200s
sessions.add(sessionTwo.toFinishedSession(434000L));
return sessions;
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class SessionQueriesTest method worldTimesAreSavedWithAllSessionSave.
@Test
default void worldTimesAreSavedWithAllSessionSave() {
prepareForSessionSave();
WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
session.getExtraData().put(WorldTimes.class, worldTimes);
List<FinishedSession> sessions = Collections.singletonList(session);
db().executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
}
});
Map<ServerUUID, WorldTimes> saved = db().query(WorldTimesQueries.fetchPlayerWorldTimesOnServers(playerUUID));
WorldTimes savedWorldTimes = saved.get(serverUUID());
assertEquals(worldTimes, savedWorldTimes);
}
Aggregations