mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 04:01:58 +01:00
Fix Server Startup
Add Container Test
This commit is contained in:
parent
954ff23667
commit
0a72a3c065
@ -151,6 +151,21 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
}
|
||||
Benchmark.stop("Enable", "Init Database");
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
|
||||
uiServer = new WebServer(this);
|
||||
registerWebAPIs(); // TODO Move to WebServer class
|
||||
uiServer.initServer();
|
||||
|
||||
if (!uiServer.isEnabled()) {
|
||||
Log.error("WebServer was not successfully initialized.");
|
||||
}
|
||||
|
||||
//TODO Re-Enable after DB ServerTable has been initialized properly.
|
||||
Benchmark.start("ServerInfo Registration");
|
||||
serverInfoManager = new ServerInfoManager(this);
|
||||
Benchmark.stop("Enable", "ServerInfo Registration");
|
||||
|
||||
Benchmark.start("Init DataCache");
|
||||
this.dataCache = new DataCache(this);
|
||||
Benchmark.stop("Enable", "Init DataCache");
|
||||
@ -174,21 +189,6 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
|
||||
Benchmark.stop("Enable", "Analysis refresh task registration");
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
|
||||
uiServer = new WebServer(this);
|
||||
registerWebAPIs(); // TODO Move to WebServer class
|
||||
uiServer.initServer();
|
||||
|
||||
if (!uiServer.isEnabled()) {
|
||||
Log.error("WebServer was not successfully initialized.");
|
||||
}
|
||||
|
||||
//TODO Re-Enable after DB ServerTable has been initialized properly.
|
||||
// Benchmark.start("ServerInfo Registration");
|
||||
// serverInfoManager = new ServerInfoManager(this);
|
||||
// Benchmark.stop("Enable", "ServerInfo Registration");
|
||||
|
||||
setupFilter(); // TODO Move to RegisterCommand Constructor
|
||||
|
||||
// Data view settings // TODO Rewrite. (TextUI removed & webserver might be running on bungee
|
||||
|
@ -60,7 +60,7 @@ public class ServerInfoManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDbInfo(UUID serverUUID) throws SQLException {
|
||||
private void updateDbInfo(UUID serverUUID) throws SQLException, IOException {
|
||||
Optional<Integer> serverID = serverTable.getServerID(serverUUID);
|
||||
if (!serverID.isPresent()) {
|
||||
registerServer(serverUUID);
|
||||
@ -76,21 +76,24 @@ public class ServerInfoManager {
|
||||
serverTable.saveCurrentServerInfo(serverInfo);
|
||||
}
|
||||
|
||||
private void registerServer() throws SQLException {
|
||||
private void registerServer() throws SQLException, IOException {
|
||||
registerServer(generateNewUUID(plugin.getServer()));
|
||||
}
|
||||
|
||||
private void registerServer(UUID serverUUID) throws SQLException {
|
||||
private void registerServer(UUID serverUUID) throws SQLException, IOException {
|
||||
String webAddress = plugin.getUiServer().getAccessAddress();
|
||||
String name = Settings.SERVER_NAME.toString();
|
||||
serverInfo = new ServerInfo(-1, serverUUID, name, webAddress);
|
||||
serverTable.saveCurrentServerInfo(serverInfo);
|
||||
Optional<Integer> serverID = serverTable.getServerID(serverUUID);
|
||||
if (serverID.isPresent()) {
|
||||
serverInfo.setId(serverID.get());
|
||||
} else {
|
||||
if (!serverID.isPresent()) {
|
||||
throw new IllegalStateException("Failed to Register Server (ID not found)");
|
||||
}
|
||||
|
||||
int id = serverID.get();
|
||||
serverInfo.setId(id);
|
||||
|
||||
serverInfoFile.saveInfo(serverInfo, new ServerInfo(id, serverUUID, name, webAddress));
|
||||
}
|
||||
|
||||
private UUID generateNewUUID(Server server) {
|
||||
|
@ -39,6 +39,7 @@ public class MySQLDB extends SQLDB {
|
||||
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
dataSource.setMaxTotal(-1);
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,13 @@ public class VersionTable extends Table {
|
||||
ResultSet set = null;
|
||||
try {
|
||||
if (usingMySQL) {
|
||||
statement = prepareStatement("SHOW TABLES LIKE " + tableName);
|
||||
statement = prepareStatement("SHOW TABLES LIKE ?");
|
||||
} else {
|
||||
statement = prepareStatement("SELECT tbl_name FROM sqlite_master WHERE tbl_name=?");
|
||||
statement.setString(1, tableName);
|
||||
}
|
||||
|
||||
statement.setString(1, tableName);
|
||||
|
||||
set = statement.executeQuery();
|
||||
|
||||
return set.next();
|
||||
|
@ -8,6 +8,7 @@ package test.java.main.java.com.djrapitops.plan.database;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.RandomData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -61,4 +62,15 @@ public class DBUtilsTest {
|
||||
assertEquals(946, result.get(2).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainers() {
|
||||
Object object = new Object();
|
||||
int id = RandomData.randomInt(1, 100);
|
||||
|
||||
Container<Object> container = new Container<>(object, id);
|
||||
|
||||
assertEquals(id, container.getId());
|
||||
assertEquals(object, container.getObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user