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();
}
}
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();
}
}
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();
}
}
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());
}
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));
}
});
}
Aggregations