Attempts at fixing tests where "Another connection wrote to database"

This commit is contained in:
Rsl1122 2018-02-07 18:55:04 +02:00
parent 1945984fc4
commit 57f3a518a0
63 changed files with 194 additions and 117 deletions

View File

@ -80,7 +80,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
Log.info(Locale.get(Msg.ENABLED).toString());
} catch (Exception e) {
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
onDisable();
}
registerCommand("plan", new PlanCommand(this));

View File

@ -42,7 +42,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
Log.info(Locale.get(Msg.ENABLED).toString());
} catch (Exception e) {
Log.error("Plugin Failed to Initialize Correctly:");
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
registerCommand("planbungee", new PlanBungeeCommand(this));
}

View File

@ -65,13 +65,13 @@ public class ShutdownHook extends Thread {
} catch (IllegalStateException ignored) {
/* Database is not initialized */
} catch (DBInitException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
if (db != null) {
try {
db.close();
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
StaticHolder.unRegister(Plan.class);
@ -86,7 +86,7 @@ public class ShutdownHook extends Thread {
int messagesSent = entry.getValue();
db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent));
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}
@ -103,7 +103,7 @@ public class ShutdownHook extends Thread {
Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
db.save().session(uuid, session);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
activeSessions.clear();

View File

@ -61,7 +61,7 @@ public class AnalyzeCommand extends SubCommand {
} catch (DBException | WebException e) {
// TODO Exception handling
sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString());
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
});
return true;
@ -93,7 +93,7 @@ public class AnalyzeCommand extends SubCommand {
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
}
} catch (Exception e) {
Log.toLog(this.getClass().getName() + getName(), e);
Log.toLog(this.getClass() + getName(), e);
}
});
}

View File

@ -74,10 +74,10 @@ public class InspectCommand extends SubCommand {
}
new InspectCacheRequestProcessor(uuid, sender, playerName).queue();
} catch (FatalDBException ex) {
Log.toLog(this.getClass().getName(), ex);
Log.toLog(this.getClass(), ex);
sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage());
} catch (DBException ex) {
Log.toLog(this.getClass().getName(), ex);
Log.toLog(this.getClass(), ex);
sender.sendMessage(ChatColor.YELLOW + "Non-Fatal database exception occurred: " + ex.getMessage());
} finally {
this.cancel();

View File

@ -48,7 +48,7 @@ public class ListServersCommand extends SubCommand {
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
} catch (DBException e) {
sender.sendMessage("§cDatabase Exception occurred.");
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
return true;
}

View File

@ -82,7 +82,7 @@ public class QInspectCommand extends SubCommand {
sendMsgs(sender, playerProfile);
} catch (DBException ex) {
Log.toLog(this.getClass().getName(), ex);
Log.toLog(this.getClass(), ex);
} finally {
this.cancel();
}

View File

@ -125,7 +125,7 @@ public class RegisterCommand extends SubCommand {
sender.sendMessage(successMsg);
Log.info("Registered new user: " + userName + " Perm level: " + webUser.getPermLevel());
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
this.cancel();
}

View File

@ -33,7 +33,7 @@ public class ReloadCommand extends SubCommand {
try {
plugin.reloadPlugin(true);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
sender.sendMessage("§cSomething went wrong during reload of the plugin, a restart is recommended.");
}
sender.sendMessage(Locale.get(Msg.CMD_INFO_RELOAD_COMPLETE).toString());

View File

@ -72,7 +72,7 @@ public class ManageBackupCommand extends SubCommand {
ManageUtils.backup(args[0], database);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
} catch (Exception e) {
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
Log.toLog(this.getClass() + " " + getTaskName(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
} finally {
this.cancel();

View File

@ -70,7 +70,7 @@ public class ManageHotswapCommand extends SubCommand {
return true;
}
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
return true;
}

View File

@ -84,7 +84,7 @@ public class ManageMoveCommand extends SubCommand {
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), Database.getActive().getConfigName());
Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
} catch (Exception e) {
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
Log.toLog(this.getClass() + " " + getTaskName(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
} finally {
this.cancel();

View File

@ -90,7 +90,7 @@ public class ManageRemoveCommand extends SubCommand {
}
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, Database.getActive().getConfigName()));
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
} finally {
this.cancel();

View File

@ -92,7 +92,7 @@ public class ManageRestoreCommand extends SubCommand {
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
} catch (Exception e) {
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
Log.toLog(this.getClass() + " " + getTaskName(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
} finally {
this.cancel();

View File

@ -68,7 +68,7 @@ public class ManageSetupCommand extends SubCommand {
} catch (UnauthorizedServerException e) {
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
} catch (WebException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console");
}
return true;

View File

@ -48,7 +48,7 @@ public class WebCheckCommand extends SubCommand {
WebUser info = database.fetch().getWebUser(user);
sender.sendMessage(info.getName() + ": Permission level: " + info.getPermLevel());
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);
Log.toLog(this.getClass(), ex);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
} finally {
this.cancel();

View File

@ -47,7 +47,7 @@ public class WebDeleteCommand extends SubCommand {
database.remove().webUser(user);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_SUCCESS).parse());
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);
Log.toLog(this.getClass(), ex);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
} finally {
this.cancel();

View File

@ -48,7 +48,7 @@ public class WebListUsersCommand extends SubCommand {
}
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse());
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);
Log.toLog(this.getClass(), ex);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
} finally {
this.cancel();

View File

@ -39,7 +39,7 @@ public class HookHandler implements SubSystem {
try {
Bridge.hook(this);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
Log.error("Plan Plugin Bridge not included in the plugin jar.");
}
}
@ -73,7 +73,7 @@ public class HookHandler implements SubSystem {
additionalDataSources.add(dataSource);
}
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
Log.error("Attempting to register PluginDataSource caused an exception.");
}
}
@ -100,7 +100,7 @@ public class HookHandler implements SubSystem {
} catch (Exception e) {
String sourcePlugin = pluginData.getSourcePlugin();
Log.error("PluginData caused exception: " + sourcePlugin);
Log.toLog(this.getClass().getName() + " " + sourcePlugin, e);
Log.toLog(this.getClass() + " " + sourcePlugin, e);
}
}
return containers;

View File

@ -35,7 +35,7 @@ public class PluginsConfigSection {
section.sort();
section.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -77,7 +77,7 @@ public class DataCache extends SessionCache implements SubSystem {
uuids.put(entry.getValue(), entry.getKey());
}
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
@ -94,7 +94,7 @@ public class DataCache extends SessionCache implements SubSystem {
name = db.fetch().getPlayerName(uuid);
playerNames.put(uuid, name);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
name = "Error occurred";
}
}
@ -119,7 +119,7 @@ public class DataCache extends SessionCache implements SubSystem {
return nicknames.get(nicknames.size() - 1);
}
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
return cached;

View File

@ -68,7 +68,7 @@ public class SessionCache {
session.endSession(time);
Database.getActive().save().session(uuid, session);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
activeSessions.remove(uuid);

View File

@ -66,7 +66,7 @@ public abstract class DBSystem implements SubSystem {
db.close();
}
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -120,7 +120,7 @@ public abstract class SQLDB extends Database {
clean();
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
cancel();
}
@ -157,7 +157,7 @@ public abstract class SQLDB extends Database {
try {
new Version8TransferTable(db).alterTablesToV10();
} catch (DBInitException | SQLException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
@ -270,7 +270,7 @@ public abstract class SQLDB extends Database {
}
} catch (SQLException e) {
if (!e.getMessage().contains("cannot commit")) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
} finally {
returnToPool(connection);

View File

@ -10,10 +10,7 @@ import com.djrapitops.plugin.task.RunnableFactory;
import org.apache.commons.dbcp2.BasicDataSource;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
/**
* @author Rsl1122
@ -52,13 +49,14 @@ public class SQLiteDB extends SQLDB {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
return null; // Should never happen.
}
String dbFilePath = new File(PlanPlugin.getInstance().getDataFolder(), dbName + ".db").getAbsolutePath();
Connection newConnection = getConnectionFor(dbFilePath);
Log.debug("SQLite: Opened a new Connection");
newConnection.setAutoCommit(false);
return newConnection;
}
@ -80,22 +78,23 @@ public class SQLiteDB extends SQLDB {
@Override
public void run() {
Statement statement = null;
ResultSet resultSet = null;
try {
if (connection != null && !connection.isClosed()) {
statement = connection.createStatement();
statement.execute("/* ping */ SELECT 1");
resultSet = statement.executeQuery("/* ping */ SELECT 1");
}
} catch (SQLException e) {
Log.debug("Something went wrong during Ping task.");
try {
connection = getNewConnection(dbName);
} catch (SQLException e1) {
Log.toLog(this.getClass().getName(), e1);
Log.toLog(this.getClass(), e1);
Log.error("SQLite connection maintaining task had to be closed due to exception.");
this.cancel();
}
} finally {
MiscUtils.close(statement);
MiscUtils.close(statement, resultSet);
}
}
}).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);

View File

@ -9,8 +9,8 @@ import com.djrapitops.plugin.utilities.Verify;
import com.google.common.base.Objects;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author Rsl1122
@ -24,8 +24,8 @@ public abstract class Table {
/**
* Constructor.
*
* @param name Name of the table in the db.
* @param db Database to use.
* @param name Name of the table in the db.
* @param db Database to use.
*/
public Table(String name, SQLDB db) {
this.tableName = name;
@ -71,19 +71,12 @@ public abstract class Table {
* @throws SQLException DB error
*/
protected boolean execute(String statementString) throws SQLException {
Statement statement = null;
Connection connection = null;
try {
connection = getConnection();
statement = connection.createStatement();
boolean b = statement.execute(statementString);
// Log.debug("Execute: " + statementString);
commit(connection);
return b;
} finally {
close(statement);
db.returnToPool(connection);
}
return execute(new ExecStatement(statementString) {
@Override
public void prepare(PreparedStatement statement) {
/* No preparations necessary */
}
});
}
/**
@ -176,9 +169,11 @@ public abstract class Table {
Connection connection = null;
try {
connection = getConnection();
updatedSomething = statement.execute(connection.prepareStatement(statement.getSql()));
commit(connection);
try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) {
updatedSomething = statement.execute(preparedStatement);
}
} finally {
commit(connection);
db.returnToPool(connection);
}
return updatedSomething;
@ -188,9 +183,11 @@ public abstract class Table {
Connection connection = null;
try {
connection = getConnection();
statement.executeBatch(connection.prepareStatement(statement.getSql()));
commit(connection);
try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) {
statement.executeBatch(preparedStatement);
}
} finally {
commit(connection);
db.returnToPool(connection);
}
}
@ -199,7 +196,9 @@ public abstract class Table {
Connection connection = null;
try {
connection = getConnection();
return statement.executeQuery(connection.prepareStatement(statement.getSql()));
try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) {
return statement.executeQuery(preparedStatement);
}
} finally {
db.returnToPool(connection);
}

View File

@ -96,7 +96,7 @@ public abstract class InfoSystem implements SubSystem {
/* Ignored */
} catch (WebException e) {
// TODO Exception handling
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -46,7 +46,7 @@ public class BukkitConnectionSystem extends ConnectionSystem {
bukkitServers = database.fetch().getBukkitServers();
latestServerMapRefresh = MiscUtils.getTime();
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -37,7 +37,7 @@ public class BungeeConnectionSystem extends ConnectionSystem {
bukkitServers = Database.getActive().fetch().getBukkitServers();
latestServerMapRefresh = MiscUtils.getTime();
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -143,7 +143,7 @@ public class ConnectionOut {
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
if (Settings.DEV_MODE.isTrue()) {
Log.warn("THIS ERROR IS ONLY LOGGED IN DEV MODE:");
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
ConnectionLog.logConnectionTo(toServer, infoRequest, -1);
throw new ConnectionFailException("Connection failed to address: " + address, e);

View File

@ -98,7 +98,7 @@ public abstract class ConnectionSystem implements SubSystem {
} catch (UnsupportedTransferDatabaseException e) {
/* Do nothing */
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
return Optional.empty();
}

View File

@ -111,7 +111,7 @@ public class BukkitServerInfo extends ServerInfo {
return Optional.of(bungeeInfo.get().getWebAddress());
}
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
return Optional.empty();
}

View File

@ -153,7 +153,7 @@ public class UserImportRefiner {
result = uuidFetcher.call().entrySet().parallelStream()
.collect(Collectors.toMap(entry -> entry.getValue().toString(), Map.Entry::getKey));
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
return;
}

View File

@ -67,7 +67,7 @@ public abstract class Importer {
try {
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
Thread.currentThread().interrupt();
}
@ -108,7 +108,7 @@ public abstract class Importer {
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
Benchmark.stop(insertDataIntoDatabaseBenchmarkName);
@ -189,7 +189,7 @@ public abstract class Importer {
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
Benchmark.stop(insertDataIntoDatabaseBenchmarkName);
@ -242,7 +242,7 @@ public abstract class Importer {
try {
execute();
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
});

View File

@ -24,7 +24,7 @@ public class CommandProcessor extends ObjectProcessor<String> {
try {
Database.getActive().save().commandUsed(object);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -48,7 +48,7 @@ public class TPSInsertProcessor extends ObjectProcessor<List<TPS>> {
try {
Database.getActive().save().insertTPSforThisServer(tps);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -44,7 +44,7 @@ public class InspectCacheRequestProcessor extends PlayerProcessor {
// TODO Test if this is appropriate
sender.sendMessage("§c" + e.getMessage());
} catch (WebException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -21,7 +21,7 @@ public class NetworkPageUpdateProcessor implements Processor {
try {
InfoSystem.getInstance().updateNetworkPage();
} catch (WebException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -35,7 +35,7 @@ public class BanAndOpProcessor extends PlayerProcessor {
save.banStatus(uuid, banned);
save.opStatus(uuid, opped);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -36,7 +36,7 @@ public class BungeePlayerRegisterProcessor extends PlayerProcessor {
}
database.save().registerNewUser(uuid, registered, name);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -34,7 +34,7 @@ public class FirstLeaveProcessor extends PlayerProcessor {
try {
Database.getActive().save().action(uuid, leaveAction);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
SessionCache.getInstance().endFirstSessionActionTracking(uuid);
}

View File

@ -35,7 +35,7 @@ public class IPUpdateProcessor extends PlayerProcessor {
try {
Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time));
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -26,7 +26,7 @@ public class KickProcessor extends PlayerProcessor {
try {
Database.getActive().save().playerWasKicked(uuid);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -54,7 +54,7 @@ public class NameProcessor extends PlayerProcessor {
database.save().playerDisplayName(uuid, displayName);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
dataCache.updateNames(uuid, playerName, displayName);
@ -76,7 +76,7 @@ public class NameProcessor extends PlayerProcessor {
try {
Database.getActive().save().action(uuid, action);
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
});
}

View File

@ -56,7 +56,7 @@ public class RegisterProcessor extends PlayerProcessor {
SessionCache.getInstance().markFirstSession(uuid);
db.save().action(uuid, new Action(time, Actions.FIRST_SESSION, "Online: " + playersOnline + " Players"));
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
Processor.queueMany(afterProcess);
}

View File

@ -88,7 +88,7 @@ public class ServerSpecificSettings {
}
config.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -59,7 +59,7 @@ public class WorldAliasSettings {
try {
aliasSect.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
});
}

View File

@ -74,7 +74,7 @@ public class Locale {
loadFromResource("locale_" + locale + ".txt");
}
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
Benchmark.stop("Enable", "Initializing locale");
}
@ -316,7 +316,7 @@ public class Locale {
Log.error("Could not find file inside the jar: " + fileName);
Log.info("Using Locale: Default (EN)");
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
Log.info("Using Locale: Default (EN)");
}
}

View File

@ -31,10 +31,6 @@ public class NetworkSettings {
private static final String SPLIT = ";;SETTING;;";
private static final String VAL_SPLIT = ";;VALUE;;";
private NetworkSettings() {
/* Hides Constructor */
}
public static void loadSettingsFromDB() {
if (Check.isBungeeAvailable()) {
return;
@ -69,7 +65,7 @@ public class NetworkSettings {
});
}
private void loadFromDatabase() throws DBException, UnsupportedTransferDatabaseException {
public void loadFromDatabase() throws DBException, UnsupportedTransferDatabaseException {
Optional<String> encodedConfigSettings = Database.getActive().transfer().getEncodedConfigSettings();
if (!encodedConfigSettings.isPresent()) {
@ -78,7 +74,6 @@ public class NetworkSettings {
}
String configSettings = Base64Util.decode(encodedConfigSettings.get());
Map<String, String> pathValueMap = getPathsAndValues(configSettings);
ServerSpecificSettings.updateSettings(pathValueMap);
@ -110,7 +105,7 @@ public class NetworkSettings {
return pathValueMap;
}
private void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException {
public void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException {
Map<String, Object> configValues = getConfigValues();
StringBuilder transferBuilder = new StringBuilder();

View File

@ -80,7 +80,7 @@ public class ResponseHandler extends TreePageHandler {
return new InternalErrorResponse(request.getTarget(), e);
}
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
return new InternalErrorResponse(request.getTarget(), e);
}
}

View File

@ -114,7 +114,7 @@ public class WebServer implements SubSystem {
Log.info(Locale.get(Msg.ENABLE_WEBSERVER_INFO).parse(server.getAddress().getPort()) + " (" + getAccessAddress() + ")");
} catch (IllegalArgumentException | IllegalStateException | IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
enabled = false;
}
}
@ -164,16 +164,16 @@ public class WebServer implements SubSystem {
startSuccessful = true;
} catch (KeyManagementException | NoSuchAlgorithmException e) {
Log.error("WebServer: SSL Context Initialization Failed.");
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} catch (FileNotFoundException e) {
Log.infoColor("§eWebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
Log.info("No Certificate -> Using Http server for Visualization.");
} catch (IOException e) {
Log.error("WebServer: " + e);
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {
Log.error("WebServer: SSL Certificate loading Failed.");
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
return startSuccessful;
}

View File

@ -58,7 +58,7 @@ public class PlayerPageHandler extends PageHandler {
return notFound("Player has not played on this server.");
}
} catch (DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
throw new InternalErrorException("Analysis", e);
} catch (NoServersException e) {
ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> new NotFoundResponse(e.getMessage()));

View File

@ -29,7 +29,7 @@ public class ErrorResponse extends Response {
try {
setContent(Theme.replaceColors(FileUtil.getStringFromResource("web/error.html")));
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -122,7 +122,7 @@ public class DebugPageResponse extends ErrorResponse {
try {
content.append(" schema v").append(((SQLDB) database).getVersion());
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
@ -165,7 +165,7 @@ public class DebugPageResponse extends ErrorResponse {
content.append("&#96;&#96;&#96;</pre>");
}
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
@ -210,7 +210,7 @@ public class DebugPageResponse extends ErrorResponse {
}
content.append("</pre>");
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}

View File

@ -49,7 +49,7 @@ public class PlayersPageResponse extends Response {
replace.put("version", plugin.getVersion());
super.setContent(Theme.replaceColors(StrSubstitutor.replace(FileUtil.getStringFromResource("web/players.html"), replace)));
} catch (DBException | IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
setContent(new InternalErrorResponse("/players", e).getContent());
}
}

View File

@ -132,7 +132,7 @@ public class Analysis {
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin());
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
Benchmark.stop("Analysis", "Analysis: Source " + source.getSourcePlugin());
}

View File

@ -37,7 +37,7 @@ public class AnalysisExport extends SpecificExport {
exportAvailableServerPage(serverUUID, serverName);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
try {
this.cancel();

View File

@ -71,7 +71,7 @@ public class HtmlExport extends SpecificExport {
exportAvailablePlayers();
exportPlayersPage();
} catch (IOException | DBException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
try {
this.cancel();
@ -149,7 +149,7 @@ public class HtmlExport extends SpecificExport {
outputFolder.mkdirs();
export(new File(outputFolder, "demo.js"), lines);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
@ -174,7 +174,7 @@ public class HtmlExport extends SpecificExport {
try {
copyFromJar(resource);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
}
}
}

View File

@ -37,7 +37,7 @@ public class PlayerExport extends SpecificExport {
exportAvailablePlayerPage(uuid, name);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
Log.toLog(this.getClass(), e);
} finally {
try {
this.cancel();

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.Base64Util;
import com.djrapitops.plan.utilities.ManageUtils;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.analysis.MathUtils;
@ -846,7 +847,6 @@ public class SQLiteTest {
}
@Test
@Ignore
public void testRegisterProcessorRegisterException() throws SQLException {
assertFalse(db.getUsersTable().isRegistered(playerUUID));
assertFalse(db.getUserInfoTable().isRegistered(playerUUID));
@ -871,4 +871,16 @@ public class SQLiteTest {
public void testWorldTableGetWorldNamesNoException() throws SQLException {
Set<String> worldNames = db.getWorldTable().getWorldNames();
}
@Test
public void testSettingTransfer() throws SQLException {
String testString = RandomData.randomString(100);
TransferTable transferTable = db.getTransferTable();
transferTable.storeConfigSettings(Base64Util.encode(testString));
Optional<String> configSettings = transferTable.getConfigSettings();
assertTrue(configSettings.isPresent());
assertEquals(testString, Base64Util.decode(configSettings.get()));
}
}

View File

@ -0,0 +1,70 @@
package com.djrapitops.plan.system.settings.network;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.connection.UnsupportedTransferDatabaseException;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import utilities.Teardown;
import utilities.TestConstants;
import utilities.TestErrorManager;
import utilities.mocks.SystemMockUtil;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
public class NetworkSettingsTest {
@ClassRule
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
private static SQLDB db;
@BeforeClass
public static void setUpClass() throws Exception {
Teardown.resetSettingsTempValues();
StaticHolder.saveInstance(NetworkSettingsTest.class, Plan.class);
db = new SQLiteDB();
SystemMockUtil.setUp(temporaryFolder.getRoot())
.enableConfigSystem()
.enableDatabaseSystem(db)
.enableServerInfoSystem();
Log.setErrorManager(new TestErrorManager());
Log.setDebugMode("console");
Settings.DEV_MODE.setTemporaryValue(true);
}
@AfterClass
public static void tearDownClass() {
if (db != null) {
db.close();
}
Teardown.resetSettingsTempValues();
}
@Before
public void setUp() throws DBException, SQLException {
db.remove().everything();
ServerTable serverTable = db.getServerTable();
serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20));
assertEquals(ServerInfo.getServerUUID(), TestConstants.SERVER_UUID);
}
@Test
public void testTransfer() throws DBException, UnsupportedTransferDatabaseException {
NetworkSettings networkSettings = new NetworkSettings();
networkSettings.placeToDatabase();
networkSettings.loadFromDatabase();
}
}

View File

@ -15,6 +15,6 @@ public class TestErrorManager extends ErrorManager {
@Override
public void toLog(String s, Throwable throwable, Class aClass) {
throw new IllegalStateException(throwable);
throw new RuntimeException("Error During Test.", throwable);
}
}

View File

@ -9,6 +9,7 @@ import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.BukkitSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plugin.StaticHolder;
import java.io.File;
@ -22,6 +23,7 @@ public class SystemMockUtil {
private BukkitSystem bukkitSystem;
public static SystemMockUtil setUp(File dataFolder) throws Exception {
StaticHolder.saveInstance(SystemMockUtil.class, Plan.class);
return new SystemMockUtil().initializeBukkitSystem(dataFolder);
}