Search in sources :

Example 96 with ServerUUID

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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 97 with ServerUUID

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());
}
Also used : BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Test(org.junit.jupiter.api.Test)

Example 98 with ServerUUID

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());
}
Also used : SELECT(com.djrapitops.plan.storage.database.sql.building.Sql.SELECT) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) UserInfoTable(com.djrapitops.plan.storage.database.sql.tables.UserInfoTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) Disabled(org.junit.jupiter.api.Disabled) utilities(utilities) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) com.djrapitops.plan.storage.database.queries(com.djrapitops.plan.storage.database.queries) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ContainerFetchQueries(com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WHERE(com.djrapitops.plan.storage.database.sql.building.Sql.WHERE) ServerPlayerContainersQuery(com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery) QuerySvc(com.djrapitops.plan.query.QuerySvc) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Key(com.djrapitops.plan.delivery.domain.keys.Key) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) Assertions(org.junit.jupiter.api.Assertions) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Config(com.djrapitops.plan.settings.config.Config) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) Key(com.djrapitops.plan.delivery.domain.keys.Key) Test(org.junit.jupiter.api.Test)

Example 99 with ServerUUID

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;
}
Also used : ArrayList(java.util.ArrayList) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID)

Example 100 with ServerUUID

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);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ServerUUID (com.djrapitops.plan.identification.ServerUUID)105 UUID (java.util.UUID)26 ResultSet (java.sql.ResultSet)23 PreparedStatement (java.sql.PreparedStatement)21 Database (com.djrapitops.plan.storage.database.Database)17 Test (org.junit.jupiter.api.Test)17 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)14 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)12 Nickname (com.djrapitops.plan.delivery.domain.Nickname)11 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)11 Server (com.djrapitops.plan.identification.Server)11 HashMap (java.util.HashMap)11 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)9 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)9 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)9 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)9 Lists (com.djrapitops.plan.utilities.java.Lists)9 CallEvents (com.djrapitops.plan.extension.CallEvents)8 List (java.util.List)8 Map (java.util.Map)8