Search in sources :

Example 11 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class PageFactory method inspectPluginTabs.

public PlayerPluginTab inspectPluginTabs(UUID playerUUID) {
    Database database = dbSystem.get().getDatabase();
    Map<ServerUUID, List<ExtensionData>> extensionPlayerData = database.query(new ExtensionPlayerDataQuery(playerUUID));
    if (extensionPlayerData.isEmpty()) {
        return new PlayerPluginTab("", Collections.emptyList(), formatters.get());
    }
    List<PlayerPluginTab> playerPluginTabs = new ArrayList<>();
    for (Map.Entry<ServerUUID, Server> entry : database.query(ServerQueries.fetchPlanServerInformation()).entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        String serverName = entry.getValue().getIdentifiableName();
        List<ExtensionData> ofServer = extensionPlayerData.get(serverUUID);
        if (ofServer == null) {
            continue;
        }
        playerPluginTabs.add(new PlayerPluginTab(serverName, ofServer, formatters.get()));
    }
    StringBuilder navs = new StringBuilder();
    StringBuilder tabs = new StringBuilder();
    playerPluginTabs.stream().sorted().forEach(tab -> {
        navs.append(tab.getNav());
        tabs.append(tab.getTab());
    });
    return new PlayerPluginTab(navs.toString(), tabs.toString());
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Database(com.djrapitops.plan.storage.database.Database)

Example 12 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class MySQLTest method setUp.

@BeforeEach
void setUp() {
    TestErrorLogger.throwErrors(true);
    db().executeTransaction(new RemoveEverythingTransaction());
    db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), TestConstants.SERVER_NAME, "", TestConstants.VERSION)));
    assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}
Also used : Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class SQLiteTest method setUp.

@BeforeEach
void setUp() {
    TestErrorLogger.throwErrors(true);
    db().executeTransaction(new Patch() {

        @Override
        public boolean hasBeenApplied() {
            return false;
        }

        @Override
        public void applyPatch() {
            dropTable("plan_world_times");
            dropTable("plan_kills");
            dropTable("plan_sessions");
            dropTable("plan_worlds");
            dropTable("plan_users");
        }
    });
    db().executeTransaction(new CreateTablesTransaction());
    db().executeTransaction(new RemoveEverythingTransaction());
    db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), "ServerName", "", TestConstants.VERSION)));
    assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}
Also used : Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class ShutdownSaveTest method storeNecessaryInformation.

private void storeNecessaryInformation() throws Exception {
    database.executeTransaction(new RemoveEverythingTransaction());
    ServerUUID serverUUID = TestConstants.SERVER_UUID;
    UUID playerUUID = TestConstants.PLAYER_ONE_UUID;
    String worldName = TestConstants.WORLD_ONE_NAME;
    database.executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID, "-", "", TestConstants.VERSION)));
    database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> 0L, TestConstants.PLAYER_ONE_NAME));
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, worldName)).get();
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) 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) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID)

Example 15 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class ServerFileLoaderTest method runParallelLoadsAndSaves.

@Test
void runParallelLoadsAndSaves() throws InterruptedException {
    ExecutorService executorService = new ScheduledThreadPoolExecutor(6);
    AtomicInteger runs = new AtomicInteger(1);
    int expected = 1000;
    AtomicInteger fails = new AtomicInteger(0);
    try {
        for (int i = 0; i < expected; i++) {
            executorService.submit(() -> {
                try {
                    Optional<Server> load = underTest.load(null);
                    if (load.isPresent()) {
                        underTest.save(load.get());
                    } else {
                        System.out.println("Failure " + fails.incrementAndGet());
                    }
                } finally {
                    runs.incrementAndGet();
                }
            });
        }
        Awaitility.await().atMost(2, TimeUnit.MINUTES).until(() -> runs.get() >= expected);
    } finally {
        executorService.shutdown();
        if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
            executorService.shutdownNow();
        }
    }
    assertEquals(0, fails.get());
}
Also used : Server(com.djrapitops.plan.identification.Server) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.jupiter.api.Test)

Aggregations

Server (com.djrapitops.plan.identification.Server)28 ServerUUID (com.djrapitops.plan.identification.ServerUUID)11 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)9 Test (org.junit.jupiter.api.Test)7 PreparedStatement (java.sql.PreparedStatement)6 Database (com.djrapitops.plan.storage.database.Database)5 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)5 ResultSet (java.sql.ResultSet)5 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)3 EnableException (com.djrapitops.plan.exceptions.EnableException)3 ServerInfo (com.djrapitops.plan.identification.ServerInfo)3 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 DBSystem (com.djrapitops.plan.storage.database.DBSystem)3 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)3 SetServerAsUninstalledTransaction (com.djrapitops.plan.storage.database.transactions.commands.SetServerAsUninstalledTransaction)3 User (com.djrapitops.plan.delivery.domain.auth.User)2 ExtensionPlayerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery)2 Locale (com.djrapitops.plan.settings.locale.Locale)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2