mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Fix tests
This commit is contained in:
parent
8b9acc3382
commit
238a547181
@ -343,6 +343,7 @@ public abstract class Database {
|
||||
public UserInfoTable getUserInfoTable() {
|
||||
return userInfoTable;
|
||||
}
|
||||
|
||||
public BasicDataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
@ -233,12 +233,6 @@ public abstract class SQLDB extends Database {
|
||||
try {
|
||||
Benchmark.start("Remove Account");
|
||||
Log.debug("Database", "Removing Account: " + uuid);
|
||||
try {
|
||||
setupDatabase();
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Table t : getAllTablesInRemoveOrder()) {
|
||||
if (!(t instanceof UserIDTable)) {
|
||||
|
@ -80,8 +80,9 @@ public class ActionsTable extends UserIDTable {
|
||||
statement.setLong(4, action.getDate());
|
||||
statement.setString(5, action.getAdditionalInfo());
|
||||
statement.execute();
|
||||
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ public class CommandUseTable extends Table {
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -187,8 +187,8 @@ public class CommandUseTable extends Table {
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,9 @@ public class IPsTable extends UserIDTable {
|
||||
statement.setString(2, ip);
|
||||
statement.setString(3, geolocation);
|
||||
statement.execute();
|
||||
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -64,17 +64,14 @@ public class KillsTable extends UserIDTable {
|
||||
" OR " + columnVictimUserID + " = " + usersTable.statementSelectID);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, uuid.toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
endTransaction(statement);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -106,9 +103,10 @@ public class KillsTable extends UserIDTable {
|
||||
statement.setString(5, weapon);
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -128,7 +126,10 @@ public class KillsTable extends UserIDTable {
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID +
|
||||
" WHERE " + columnKillerUserID + "=" + usersTable.statementSelectID);
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
set = statement.executeQuery();
|
||||
commit(statement.getConnection());
|
||||
|
||||
while (set.next()) {
|
||||
long sessionID = set.getLong(columnSessionID);
|
||||
Session session = sessions.get(sessionID);
|
||||
@ -142,7 +143,6 @@ public class KillsTable extends UserIDTable {
|
||||
session.getPlayerKills().add(new KillData(victim, weapon, date));
|
||||
}
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
@ -152,9 +152,10 @@ public class NicknamesTable extends UserIDTable {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, Plan.getServerUUID().toString());
|
||||
statement.setString(3, displayName);
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -47,18 +47,14 @@ public class SecurityTable extends Table {
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUser + "=?)");
|
||||
statement.setString(1, user);
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
endTransaction(statement);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ public class ServerTable extends Table {
|
||||
} else {
|
||||
updateServerInfo(info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateServerInfo(ServerInfo info) throws SQLException {
|
||||
@ -85,8 +84,9 @@ public class ServerTable extends Table {
|
||||
statement.setBoolean(4, true);
|
||||
statement.setInt(5, info.getId());
|
||||
statement.executeUpdate();
|
||||
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -116,8 +116,9 @@ public class ServerTable extends Table {
|
||||
statement.setString(3, webAddress);
|
||||
statement.setBoolean(4, true);
|
||||
statement.execute();
|
||||
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ public class SessionsTable extends UserIDTable {
|
||||
if (sessionID == -1) {
|
||||
throw new IllegalStateException("Session was not Saved!");
|
||||
}
|
||||
|
||||
db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getWorldTimes());
|
||||
db.getKillsTable().savePlayerKills(uuid, sessionID, session.getPlayerKills());
|
||||
}
|
||||
@ -107,11 +108,11 @@ public class SessionsTable extends UserIDTable {
|
||||
statement.setLong(3, session.getSessionEnd());
|
||||
statement.setInt(4, session.getDeaths());
|
||||
statement.setInt(5, session.getMobKills());
|
||||
|
||||
statement.setString(6, Plan.getServerUUID().toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,9 @@ public class TPSTable extends Table {
|
||||
statement.setLong(6, tps.getUsedMemory());
|
||||
statement.setDouble(7, tps.getEntityCount());
|
||||
statement.setDouble(8, tps.getChunksLoaded());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
@ -133,9 +135,10 @@ public class TPSTable extends Table {
|
||||
// More than 2 Months ago.
|
||||
long fiveWeeks = TimeAmount.MONTH.ms() * 2L;
|
||||
statement.setLong(1, MiscUtils.getTime() - fiveWeeks);
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -29,17 +29,14 @@ public abstract class UserIDTable extends Table {
|
||||
statement = prepareStatement("DELETE FROM " + tableName +
|
||||
" WHERE (" + columnUserID + "=" + usersTable.statementSelectID + ")");
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
endTransaction(statement);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,9 @@ public class UserInfoTable extends UserIDTable {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setLong(2, registered);
|
||||
statement.setString(3, Plan.getServerUUID().toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
@ -100,7 +102,9 @@ public class UserInfoTable extends UserIDTable {
|
||||
statement.setBoolean(1, opped);
|
||||
statement.setBoolean(2, banned);
|
||||
statement.setString(3, uuid.toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
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.sql.*;
|
||||
|
||||
@ -79,16 +78,13 @@ public class UsersTable extends UserIDTable {
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUUID + "=?)");
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
endTransaction(statement);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -167,9 +163,10 @@ public class UsersTable extends UserIDTable {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setLong(2, registered);
|
||||
statement.setString(3, name);
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -198,9 +195,10 @@ public class UsersTable extends UserIDTable {
|
||||
.toString());
|
||||
statement.setString(1, name);
|
||||
statement.setString(2, uuid.toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
@ -231,9 +229,10 @@ public class UsersTable extends UserIDTable {
|
||||
+ columnTimesKicked + "=" + columnTimesKicked + "+ 1" +
|
||||
" WHERE " + columnUUID + "=?");
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
statement.execute();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ public class VersionTable extends Table {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " (version) VALUES (" + version + ")");
|
||||
|
||||
statement.executeUpdate();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
|
@ -101,8 +101,8 @@ public class WorldTable extends Table {
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ public class WorldTimesTable extends UserIDTable {
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
@ -58,14 +58,9 @@ public class DatabaseTest {
|
||||
public void setUp() throws Exception {
|
||||
TestInit t = TestInit.init();
|
||||
plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask() {
|
||||
|
||||
}
|
||||
};
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
|
||||
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");
|
||||
rows = FileUtil.lines(f).size();
|
||||
|
||||
@ -344,6 +339,7 @@ public class DatabaseTest {
|
||||
saveTwoWorlds();
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
Session session = new Session(12345L, "", "");
|
||||
session.endSession(22345L);
|
||||
session.setWorldTimes(createWorldTimes());
|
||||
@ -501,8 +497,13 @@ public class DatabaseTest {
|
||||
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
|
||||
System.out.println("0 " + uuid);
|
||||
System.out.println("1 " + db.getUsersTable().getSavedUUIDs());
|
||||
|
||||
db.removeAccount(uuid);
|
||||
|
||||
System.out.println("2 " + db.getUsersTable().getSavedUUIDs());
|
||||
|
||||
assertFalse(usersTable.isRegistered(uuid));
|
||||
assertFalse(userInfoTable.isRegistered(uuid));
|
||||
assertTrue(nicknamesTable.getNicknames(uuid).isEmpty());
|
||||
|
@ -24,7 +24,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.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user