Search in sources :

Example 1 with SQLiteDB

use of com.djrapitops.plan.storage.database.SQLiteDB in project Plan by plan-player-analytics.

the class VelocitySystemTest method velocityEnables.

@Test
void velocityEnables(@TempDir Path temp) throws Exception {
    PlanSystem velocitySystem = new VelocityMockComponent(temp).getPlanSystem();
    try {
        PlanConfig config = velocitySystem.getConfigSystem().getConfig();
        config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
        config.set(ProxySettings.IP, "8.8.8.8");
        DBSystem dbSystem = velocitySystem.getDatabaseSystem();
        SQLiteDB db = dbSystem.getSqLiteFactory().usingDefaultFile();
        db.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
        dbSystem.setActiveDatabase(db);
        velocitySystem.enable();
        assertTrue(velocitySystem.isEnabled());
    } finally {
        velocitySystem.disable();
    }
}
Also used : VelocityMockComponent(utilities.mocks.VelocityMockComponent) DBSystem(com.djrapitops.plan.storage.database.DBSystem) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Test(org.junit.jupiter.api.Test)

Example 2 with SQLiteDB

use of com.djrapitops.plan.storage.database.SQLiteDB in project Plan by plan-player-analytics.

the class BungeeSystemTest method bungeeEnables.

@Test
void bungeeEnables() throws Exception {
    PlanSystem bungeeSystem = component.getPlanSystem();
    try {
        PlanConfig config = bungeeSystem.getConfigSystem().getConfig();
        config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
        config.set(ProxySettings.IP, "8.8.8.8");
        DBSystem dbSystem = bungeeSystem.getDatabaseSystem();
        SQLiteDB db = dbSystem.getSqLiteFactory().usingDefaultFile();
        db.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
        dbSystem.setActiveDatabase(db);
        bungeeSystem.enable();
        assertTrue(bungeeSystem.isEnabled());
    } finally {
        bungeeSystem.disable();
    }
}
Also used : DBSystem(com.djrapitops.plan.storage.database.DBSystem) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Test(org.junit.jupiter.api.Test)

Example 3 with SQLiteDB

use of com.djrapitops.plan.storage.database.SQLiteDB in project Plan by plan-player-analytics.

the class DatabaseBackupTest method testBackupAndRestoreSQLite.

@Test
default void testBackupAndRestoreSQLite() throws Exception {
    File tempFile = Files.createTempFile(system().getPlanFiles().getDataFolder().toPath(), "backup-", ".db").toFile();
    tempFile.deleteOnExit();
    SQLiteDB backup = dbSystem().getSqLiteFactory().usingFile(tempFile);
    backup.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
    try {
        backup.init();
        saveDataForBackup();
        backup.executeTransaction(new BackupCopyTransaction(db(), backup));
        assertQueryResultIsEqual(db(), backup, BaseUserQueries.fetchAllBaseUsers());
        assertQueryResultIsEqual(db(), backup, UserInfoQueries.fetchAllUserInformation());
        assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData());
        assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation());
        assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions());
        assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames());
        assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData());
        assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation());
        assertQueryResultIsEqual(db(), backup, WebUserQueries.fetchAllUsers());
    } finally {
        backup.close();
    }
}
Also used : SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) BackupCopyTransaction(com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with SQLiteDB

use of com.djrapitops.plan.storage.database.SQLiteDB in project Plan by plan-player-analytics.

the class BungeeSystemTest method bungeeDoesNotEnableWithDefaultIP.

@Test
void bungeeDoesNotEnableWithDefaultIP() {
    EnableException thrown = assertThrows(EnableException.class, () -> {
        PlanSystem bungeeSystem = component.getPlanSystem();
        try {
            PlanConfig config = bungeeSystem.getConfigSystem().getConfig();
            config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
            config.set(ProxySettings.IP, "0.0.0.0");
            DBSystem dbSystem = bungeeSystem.getDatabaseSystem();
            SQLiteDB db = dbSystem.getSqLiteFactory().usingDefaultFile();
            db.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
            dbSystem.setActiveDatabase(db);
            // Throws EnableException
            bungeeSystem.enable();
        } finally {
            bungeeSystem.disable();
        }
    });
    assertEquals("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.", thrown.getMessage());
}
Also used : DBSystem(com.djrapitops.plan.storage.database.DBSystem) EnableException(com.djrapitops.plan.exceptions.EnableException) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Test(org.junit.jupiter.api.Test)

Example 5 with SQLiteDB

use of com.djrapitops.plan.storage.database.SQLiteDB in project Plan by plan-player-analytics.

the class DatabaseCommands method onRestore.

public void onRestore(String mainCommand, CMDSender sender, Arguments arguments) {
    String backupDbName = arguments.get(0).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 1, "<" + locale.getString(HelpLang.ARG_BACKUP_FILE) + ">")));
    boolean containsDBFileExtension = backupDbName.endsWith(".db");
    File backupDBFile = files.getFileFromPluginFolder(backupDbName + (containsDBFileExtension ? "" : ".db"));
    if (!backupDBFile.exists()) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
    }
    String dbName = arguments.get(1).orElse(dbSystem.getDatabase().getType().getName()).toLowerCase();
    if (!DBType.exists(dbName)) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_INCORRECT_DB, dbName));
    }
    Database toDB = dbSystem.getActiveDatabaseByName(dbName);
    // Check against restoring from database.db as it is active database
    if (backupDbName.contains("database") && toDB instanceof SQLiteDB) {
        throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_SAME_DB));
    }
    if (toDB.getState() != Database.State.OPEN)
        toDB.init();
    if (sender.supportsChatEvents()) {
        sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_OVERWRITE_DB, toDB.getType().getName(), backupDBFile.toPath().toString())).newLine().addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover(locale.getString(CommandLang.CONFIRM_ACCEPT)).addPart(" ").addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover(locale.getString(CommandLang.CONFIRM_DENY)).send();
    } else {
        sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_OVERWRITE_DB, toDB.getType().getName(), backupDBFile.toPath().toString())).newLine().addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§a/" + mainCommand + " accept").addPart(" ").addPart("§c/" + mainCommand + " cancel").send();
    }
    confirmation.confirm(sender, choice -> {
        if (Boolean.TRUE.equals(choice)) {
            performRestore(sender, backupDBFile, toDB);
        } else {
            sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED_DATA));
        }
    });
}
Also used : SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) Database(com.djrapitops.plan.storage.database.Database) File(java.io.File)

Aggregations

SQLiteDB (com.djrapitops.plan.storage.database.SQLiteDB)6 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)4 Test (org.junit.jupiter.api.Test)4 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 DBSystem (com.djrapitops.plan.storage.database.DBSystem)3 BackupCopyTransaction (com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction)2 File (java.io.File)2 EnableException (com.djrapitops.plan.exceptions.EnableException)1 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1 Database (com.djrapitops.plan.storage.database.Database)1 ExecutionException (java.util.concurrent.ExecutionException)1 VelocityMockComponent (utilities.mocks.VelocityMockComponent)1