Fix tests

This commit is contained in:
Fuzzlemann 2017-08-23 22:30:19 +02:00
parent 8b9acc3382
commit 238a547181
19 changed files with 54 additions and 54 deletions

View File

@ -343,6 +343,7 @@ public abstract class Database {
public UserInfoTable getUserInfoTable() { public UserInfoTable getUserInfoTable() {
return userInfoTable; return userInfoTable;
} }
public BasicDataSource getDataSource() { public BasicDataSource getDataSource() {
return dataSource; return dataSource;
} }

View File

@ -233,12 +233,6 @@ public abstract class SQLDB extends Database {
try { try {
Benchmark.start("Remove Account"); Benchmark.start("Remove Account");
Log.debug("Database", "Removing Account: " + uuid); Log.debug("Database", "Removing Account: " + uuid);
try {
setupDatabase();
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
return false;
}
for (Table t : getAllTablesInRemoveOrder()) { for (Table t : getAllTablesInRemoveOrder()) {
if (!(t instanceof UserIDTable)) { if (!(t instanceof UserIDTable)) {

View File

@ -80,8 +80,9 @@ public class ActionsTable extends UserIDTable {
statement.setLong(4, action.getDate()); statement.setLong(4, action.getDate());
statement.setString(5, action.getAdditionalInfo()); statement.setString(5, action.getAdditionalInfo());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -157,8 +157,8 @@ public class CommandUseTable extends Table {
} }
statement.executeBatch(); statement.executeBatch();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }
@ -187,8 +187,8 @@ public class CommandUseTable extends Table {
} }
statement.executeBatch(); statement.executeBatch();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -103,8 +103,9 @@ public class IPsTable extends UserIDTable {
statement.setString(2, ip); statement.setString(2, ip);
statement.setString(3, geolocation); statement.setString(3, geolocation);
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -64,17 +64,14 @@ public class KillsTable extends UserIDTable {
" OR " + columnVictimUserID + " = " + usersTable.statementSelectID); " OR " + columnVictimUserID + " = " + usersTable.statementSelectID);
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex); Log.toLog(this.getClass().getName(), ex);
return false; return false;
} finally { } finally {
try {
endTransaction(statement);
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
close(statement); close(statement);
} }
} }
@ -106,9 +103,10 @@ public class KillsTable extends UserIDTable {
statement.setString(5, weapon); statement.setString(5, weapon);
statement.addBatch(); statement.addBatch();
} }
statement.executeBatch(); statement.executeBatch();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }
@ -128,7 +126,10 @@ public class KillsTable extends UserIDTable {
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID + " JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID +
" WHERE " + columnKillerUserID + "=" + usersTable.statementSelectID); " WHERE " + columnKillerUserID + "=" + usersTable.statementSelectID);
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
set = statement.executeQuery(); set = statement.executeQuery();
commit(statement.getConnection());
while (set.next()) { while (set.next()) {
long sessionID = set.getLong(columnSessionID); long sessionID = set.getLong(columnSessionID);
Session session = sessions.get(sessionID); Session session = sessions.get(sessionID);
@ -142,7 +143,6 @@ public class KillsTable extends UserIDTable {
session.getPlayerKills().add(new KillData(victim, weapon, date)); session.getPlayerKills().add(new KillData(victim, weapon, date));
} }
} finally { } finally {
endTransaction(statement);
close(set, statement); close(set, statement);
} }
} }

View File

@ -152,9 +152,10 @@ public class NicknamesTable extends UserIDTable {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, Plan.getServerUUID().toString()); statement.setString(2, Plan.getServerUUID().toString());
statement.setString(3, displayName); statement.setString(3, displayName);
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -47,18 +47,14 @@ public class SecurityTable extends Table {
try { try {
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUser + "=?)"); statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUser + "=?)");
statement.setString(1, user); statement.setString(1, user);
statement.execute(); statement.execute();
commit(statement.getConnection());
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex); Log.toLog(this.getClass().getName(), ex);
return false; return false;
} finally { } finally {
try {
endTransaction(statement);
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
close(statement); close(statement);
} }
} }

View File

@ -65,7 +65,6 @@ public class ServerTable extends Table {
} else { } else {
updateServerInfo(info); updateServerInfo(info);
} }
} }
private void updateServerInfo(ServerInfo info) throws SQLException { private void updateServerInfo(ServerInfo info) throws SQLException {
@ -85,8 +84,9 @@ public class ServerTable extends Table {
statement.setBoolean(4, true); statement.setBoolean(4, true);
statement.setInt(5, info.getId()); statement.setInt(5, info.getId());
statement.executeUpdate(); statement.executeUpdate();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }
@ -116,8 +116,9 @@ public class ServerTable extends Table {
statement.setString(3, webAddress); statement.setString(3, webAddress);
statement.setBoolean(4, true); statement.setBoolean(4, true);
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -74,6 +74,7 @@ public class SessionsTable extends UserIDTable {
if (sessionID == -1) { if (sessionID == -1) {
throw new IllegalStateException("Session was not Saved!"); throw new IllegalStateException("Session was not Saved!");
} }
db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getWorldTimes()); db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getWorldTimes());
db.getKillsTable().savePlayerKills(uuid, sessionID, session.getPlayerKills()); db.getKillsTable().savePlayerKills(uuid, sessionID, session.getPlayerKills());
} }
@ -107,11 +108,11 @@ public class SessionsTable extends UserIDTable {
statement.setLong(3, session.getSessionEnd()); statement.setLong(3, session.getSessionEnd());
statement.setInt(4, session.getDeaths()); statement.setInt(4, session.getDeaths());
statement.setInt(5, session.getMobKills()); statement.setInt(5, session.getMobKills());
statement.setString(6, Plan.getServerUUID().toString()); statement.setString(6, Plan.getServerUUID().toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -117,7 +117,9 @@ public class TPSTable extends Table {
statement.setLong(6, tps.getUsedMemory()); statement.setLong(6, tps.getUsedMemory());
statement.setDouble(7, tps.getEntityCount()); statement.setDouble(7, tps.getEntityCount());
statement.setDouble(8, tps.getChunksLoaded()); statement.setDouble(8, tps.getChunksLoaded());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
close(statement); close(statement);
} }
@ -133,9 +135,10 @@ public class TPSTable extends Table {
// More than 2 Months ago. // More than 2 Months ago.
long fiveWeeks = TimeAmount.MONTH.ms() * 2L; long fiveWeeks = TimeAmount.MONTH.ms() * 2L;
statement.setLong(1, MiscUtils.getTime() - fiveWeeks); statement.setLong(1, MiscUtils.getTime() - fiveWeeks);
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -29,17 +29,14 @@ public abstract class UserIDTable extends Table {
statement = prepareStatement("DELETE FROM " + tableName + statement = prepareStatement("DELETE FROM " + tableName +
" WHERE (" + columnUserID + "=" + usersTable.statementSelectID + ")"); " WHERE (" + columnUserID + "=" + usersTable.statementSelectID + ")");
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
Log.toLog(this.getClass().getName(), ex); Log.toLog(this.getClass().getName(), ex);
return false; return false;
} finally { } finally {
try {
endTransaction(statement);
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
close(statement); close(statement);
} }
} }

View File

@ -70,7 +70,9 @@ public class UserInfoTable extends UserIDTable {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setLong(2, registered); statement.setLong(2, registered);
statement.setString(3, Plan.getServerUUID().toString()); statement.setString(3, Plan.getServerUUID().toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
close(statement); close(statement);
} }
@ -100,7 +102,9 @@ public class UserInfoTable extends UserIDTable {
statement.setBoolean(1, opped); statement.setBoolean(1, opped);
statement.setBoolean(2, banned); statement.setBoolean(2, banned);
statement.setString(3, uuid.toString()); statement.setString(3, uuid.toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
close(statement); close(statement);
} }

View File

@ -1,7 +1,6 @@
package main.java.com.djrapitops.plan.database.tables; package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.database.sql.*; import main.java.com.djrapitops.plan.database.sql.*;
@ -79,16 +78,13 @@ public class UsersTable extends UserIDTable {
try { try {
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUUID + "=?)"); statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUUID + "=?)");
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
return true; return true;
} catch (SQLException ex) { } catch (SQLException ex) {
return false; return false;
} finally { } finally {
try {
endTransaction(statement);
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
close(statement); close(statement);
} }
} }
@ -167,9 +163,10 @@ public class UsersTable extends UserIDTable {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setLong(2, registered); statement.setLong(2, registered);
statement.setString(3, name); statement.setString(3, name);
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }
@ -198,9 +195,10 @@ public class UsersTable extends UserIDTable {
.toString()); .toString());
statement.setString(1, name); statement.setString(1, name);
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }
@ -231,9 +229,10 @@ public class UsersTable extends UserIDTable {
+ columnTimesKicked + "=" + columnTimesKicked + "+ 1" + + columnTimesKicked + "=" + columnTimesKicked + "+ 1" +
" WHERE " + columnUUID + "=?"); " WHERE " + columnUUID + "=?");
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.execute(); statement.execute();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -64,6 +64,7 @@ public class VersionTable extends Table {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = prepareStatement("INSERT INTO " + tableName + " (version) VALUES (" + version + ")"); statement = prepareStatement("INSERT INTO " + tableName + " (version) VALUES (" + version + ")");
statement.executeUpdate(); statement.executeUpdate();
commit(statement.getConnection()); commit(statement.getConnection());
} finally { } finally {

View File

@ -101,8 +101,8 @@ public class WorldTable extends Table {
} }
statement.executeBatch(); statement.executeBatch();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -98,8 +98,8 @@ public class WorldTimesTable extends UserIDTable {
} }
statement.executeBatch(); statement.executeBatch();
commit(statement.getConnection());
} finally { } finally {
endTransaction(statement);
close(statement); close(statement);
} }
} }

View File

@ -58,14 +58,9 @@ public class DatabaseTest {
public void setUp() throws Exception { public void setUp() throws Exception {
TestInit t = TestInit.init(); TestInit t = TestInit.init();
plan = t.getPlanMock(); plan = t.getPlanMock();
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) { db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
@Override
public void startConnectionPingTask() {
}
};
db.init(); db.init();
db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, t.getServerUUID(), "ServerName", "")); db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", ""));
File f = new File(plan.getDataFolder(), "Errors.txt"); File f = new File(plan.getDataFolder(), "Errors.txt");
rows = FileUtil.lines(f).size(); rows = FileUtil.lines(f).size();
@ -344,6 +339,7 @@ public class DatabaseTest {
saveTwoWorlds(); saveTwoWorlds();
saveUserOne(); saveUserOne();
saveUserTwo(); saveUserTwo();
Session session = new Session(12345L, "", ""); Session session = new Session(12345L, "", "");
session.endSession(22345L); session.endSession(22345L);
session.setWorldTimes(createWorldTimes()); session.setWorldTimes(createWorldTimes());
@ -501,8 +497,13 @@ public class DatabaseTest {
assertTrue(usersTable.isRegistered(uuid)); assertTrue(usersTable.isRegistered(uuid));
System.out.println("0 " + uuid);
System.out.println("1 " + db.getUsersTable().getSavedUUIDs());
db.removeAccount(uuid); db.removeAccount(uuid);
System.out.println("2 " + db.getUsersTable().getSavedUUIDs());
assertFalse(usersTable.isRegistered(uuid)); assertFalse(usersTable.isRegistered(uuid));
assertFalse(userInfoTable.isRegistered(uuid)); assertFalse(userInfoTable.isRegistered(uuid));
assertTrue(nicknamesTable.getNicknames(uuid).isEmpty()); assertTrue(nicknamesTable.getNicknames(uuid).isEmpty());

View File

@ -24,7 +24,6 @@ import org.powermock.api.mockito.PowerMockito;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger; import java.util.logging.Logger;