mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-26 18:11:29 +01:00
Fixes Clearing of the data, the pool itself
This commit is contained in:
parent
82da226edb
commit
654ff26fb6
@ -34,6 +34,7 @@ public abstract class SQLDB extends Database {
|
||||
this.supportsModification = supportsModification;
|
||||
usingMySQL = getName().equals("MySQL");
|
||||
|
||||
serverTable = new ServerTable(this, usingMySQL);
|
||||
usersTable = new UsersTable(this, usingMySQL);
|
||||
sessionsTable = new SessionsTable(this, usingMySQL);
|
||||
killsTable = new KillsTable(this, usingMySQL);
|
||||
@ -45,7 +46,6 @@ public abstract class SQLDB extends Database {
|
||||
securityTable = new SecurityTable(this, usingMySQL);
|
||||
worldTable = new WorldTable(this, usingMySQL);
|
||||
worldTimesTable = new WorldTimesTable(this, usingMySQL);
|
||||
serverTable = new ServerTable(this, usingMySQL);
|
||||
|
||||
setupDataSource();
|
||||
}
|
||||
@ -67,11 +67,9 @@ public abstract class SQLDB extends Database {
|
||||
String benchName = "Init " + getConfigName();
|
||||
Benchmark.start(benchName);
|
||||
try {
|
||||
System.out.println("SETUP DATABASES");
|
||||
if (!setupDatabases()) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("CLEAN DATABASES");
|
||||
clean();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
@ -126,10 +124,8 @@ public abstract class SQLDB extends Database {
|
||||
* @return true if successful.
|
||||
*/
|
||||
private boolean createTables() {
|
||||
System.out.println("Create Tables");
|
||||
Benchmark.start("Create tables");
|
||||
for (Table table : getAllTables()) {
|
||||
System.out.println("Create Table " + table.getTableName());
|
||||
if (!table.createTable()) {
|
||||
Log.error("Failed to create table: " + table.getTableName());
|
||||
return false;
|
||||
|
@ -38,12 +38,14 @@ public class SQLiteDB extends SQLDB {
|
||||
public void setupDataSource() {
|
||||
dataSource = new BasicDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:sqlite:" + new File(plugin.getDataFolder(), dbName + ".db").getAbsolutePath());
|
||||
String filePath = new File(plugin.getDataFolder(), dbName + ".db").getAbsolutePath();
|
||||
dataSource.setUrl("jdbc:sqlite:" + filePath);
|
||||
|
||||
dataSource.setEnableAutoCommitOnReturn(false);
|
||||
dataSource.setDefaultAutoCommit(false);
|
||||
|
||||
dataSource.setConnectionInitSqls(Collections.singletonList("PRAGMA JOURNAL_MODE=WAL"));
|
||||
dataSource.setMaxTotal(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,6 @@ public class SessionsTable extends UserIDTable {
|
||||
.foreignKey(columnServerID, serverTableName, serverTableID)
|
||||
.primaryKey(usingMySQL, columnSessionID)
|
||||
.toString();
|
||||
System.out.println(sql);
|
||||
execute(sql);
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
|
@ -29,14 +29,12 @@ public class WorldTimesTest {
|
||||
public void setUp() throws Exception {
|
||||
test = new WorldTimes(worldOne, gms[0]);
|
||||
time = test.getGMTimes(worldOne).getLastStateChange();
|
||||
System.out.println(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldChange() {
|
||||
long changeTime = time + 1000L;
|
||||
test.updateState(worldTwo, gms[0], changeTime);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
}
|
||||
@ -45,7 +43,6 @@ public class WorldTimesTest {
|
||||
public void testGMChange() {
|
||||
long changeTime = time + 1000L;
|
||||
test.updateState(worldOne, gms[0], changeTime);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
}
|
||||
@ -55,11 +52,9 @@ public class WorldTimesTest {
|
||||
long changeTime = time + 1000L;
|
||||
long changeTime2 = changeTime + 1000L;
|
||||
test.updateState(worldTwo, gms[2], changeTime);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
test.updateState(worldOne, gms[1], changeTime2);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
assertEquals(1000L, test.getGMTimes(worldTwo).getTime(gms[2]));
|
||||
@ -98,7 +93,6 @@ public class WorldTimesTest {
|
||||
|
||||
long time1 = test.getWorldPlaytime(worldOne);
|
||||
long time2 = test.getWorldPlaytime(worldTwo);
|
||||
System.out.println(test);
|
||||
|
||||
// Tests World time calculation.
|
||||
assertEquals(amount * 50, time1 + time2);
|
||||
@ -156,13 +150,10 @@ public class WorldTimesTest {
|
||||
|
||||
// No change should occur.
|
||||
test.updateState(worldOne, "ADVENTURE", time + 5000L);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
test.updateState(worldTwo, "CREATIVE", time + 5000L);
|
||||
System.out.println(test);
|
||||
test.updateState(worldOne, "ADVENTURE", time + 6000L);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
|
||||
|
@ -20,7 +20,6 @@ import test.java.utils.TestInit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -70,11 +69,9 @@ public class DatabaseCommitTest {
|
||||
public void testNoExceptionWhenCommitEmpty() throws SQLException {
|
||||
db.init();
|
||||
|
||||
Connection con = db.getConnection();
|
||||
|
||||
db.commit(con);
|
||||
db.commit(con);
|
||||
db.commit(con);
|
||||
db.commit(db.getConnection());
|
||||
db.commit(db.getConnection());
|
||||
db.commit(db.getConnection());
|
||||
}
|
||||
|
||||
@Ignore("//TODO")
|
||||
|
@ -136,7 +136,7 @@ public class DatabaseTest {
|
||||
@Ignore("")
|
||||
@Test // TODO Rewrite
|
||||
public void testRemoveAll() throws SQLException {
|
||||
//db.init();
|
||||
db.init();
|
||||
//UserData data = MockUtils.mockUser();
|
||||
//db.saveUserData(data);
|
||||
HashMap<String, Integer> c = new HashMap<>();
|
||||
@ -157,7 +157,7 @@ public class DatabaseTest {
|
||||
@Ignore("//TODO")
|
||||
@Test
|
||||
public void testSaveCommandUse() throws SQLException {
|
||||
//db.init();
|
||||
db.init();
|
||||
HashMap<String, Integer> c = new HashMap<>();
|
||||
c.put("/plan", 1);
|
||||
c.put("/tp", 4);
|
||||
@ -211,7 +211,7 @@ public class DatabaseTest {
|
||||
|
||||
@Test
|
||||
public void testTPSSaving() throws SQLException {
|
||||
//db.init();
|
||||
db.init();
|
||||
TPSTable tpsTable = db.getTpsTable();
|
||||
List<TPS> expected = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
|
47
Plan/test/test/java/utils/DBTestSuite.java
Normal file
47
Plan/test/test/java/utils/DBTestSuite.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package test.java.utils;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import test.java.main.java.com.djrapitops.plan.database.DatabaseCommitTest;
|
||||
import test.java.main.java.com.djrapitops.plan.database.DatabaseTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({DatabaseCommitTest.class, DatabaseTest.class})
|
||||
public class DBTestSuite {
|
||||
@BeforeClass
|
||||
public static void setUp() throws IOException {
|
||||
clean(true);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void tearDown() throws IOException {
|
||||
clean(false);
|
||||
}
|
||||
|
||||
private static void clean(boolean dbOnly) throws IOException {
|
||||
File testFolder = TestInit.getTestFolder();
|
||||
|
||||
if (!testFolder.exists() || !testFolder.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (File f : testFolder.listFiles()) {
|
||||
if (dbOnly && !f.getName().endsWith(".db")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,6 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
@ -63,17 +62,11 @@ public class TestInit {
|
||||
|
||||
public static TestInit init() throws Exception {
|
||||
TestInit t = new TestInit();
|
||||
t.setUp(true);
|
||||
t.setUp();
|
||||
return t;
|
||||
}
|
||||
|
||||
public static TestInit init(boolean clearOnStart) throws Exception {
|
||||
TestInit t = new TestInit();
|
||||
t.setUp(clearOnStart);
|
||||
return t;
|
||||
}
|
||||
|
||||
private void setUp(boolean clearOnStart) throws Exception {
|
||||
private void setUp() throws Exception {
|
||||
planMock = PowerMockito.mock(Plan.class);
|
||||
StaticHolder.setInstance(Plan.class, planMock);
|
||||
StaticHolder.setInstance(planMock.getClass(), planMock);
|
||||
@ -82,9 +75,6 @@ public class TestInit {
|
||||
when(planMock.getConfig()).thenReturn(config);
|
||||
|
||||
File testFolder = getTestFolder();
|
||||
/*if (clearOnStart) {
|
||||
clean(testFolder);
|
||||
}*/
|
||||
when(planMock.getDataFolder()).thenReturn(testFolder);
|
||||
|
||||
// Html Files
|
||||
@ -172,24 +162,12 @@ public class TestInit {
|
||||
};
|
||||
}
|
||||
|
||||
private static File getTestFolder() {
|
||||
static File getTestFolder() {
|
||||
File testFolder = new File("temporaryTestFolder");
|
||||
testFolder.mkdir();
|
||||
return testFolder;
|
||||
}
|
||||
|
||||
public static void clean() throws IOException {
|
||||
clean(getTestFolder());
|
||||
}
|
||||
|
||||
public static void clean(File testFolder) throws IOException {
|
||||
if (testFolder.exists() && testFolder.isDirectory()) {
|
||||
for (File f : testFolder.listFiles()) {
|
||||
Files.deleteIfExists(f.toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Server mockServer() {
|
||||
Server mockServer = PowerMockito.mock(Server.class);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user