Fixed error in serverPreferencePieValuesAreCorrect test

This commit is contained in:
Risto Lahtela 2021-02-02 14:01:16 +02:00
parent 25e98ef7b5
commit ae4fb0c98e
3 changed files with 23 additions and 11 deletions

View File

@ -746,12 +746,12 @@ public class SessionQueries {
String sql = SELECT + String sql = SELECT +
"SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime," + "SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime," +
"s." + ServerTable.SERVER_ID + ',' + "s." + ServerTable.SERVER_ID + ',' +
ServerTable.NAME + "s." + ServerTable.NAME +
FROM + SessionsTable.TABLE_NAME + FROM + SessionsTable.TABLE_NAME +
INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.SERVER_UUID + '=' + SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID + INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.SERVER_UUID + '=' + SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID +
WHERE + SessionsTable.SESSION_END + ">=?" + WHERE + SessionsTable.SESSION_END + ">=?" +
AND + SessionsTable.SESSION_START + "<=?" + AND + SessionsTable.SESSION_START + "<=?" +
GROUP_BY + ServerTable.NAME; GROUP_BY + "s." + ServerTable.SERVER_ID;
return new QueryStatement<Map<String, Long>>(sql, 100) { return new QueryStatement<Map<String, Long>>(sql, 100) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {

View File

@ -25,6 +25,7 @@ import com.djrapitops.plan.storage.database.transactions.Transaction;
import utilities.TestConstants; import utilities.TestConstants;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException;
public interface DatabaseTestPreparer { public interface DatabaseTestPreparer {
@ -57,17 +58,25 @@ public interface DatabaseTestPreparer {
} }
default void execute(Executable executable) { default void execute(Executable executable) {
db().executeTransaction(new Transaction() { try {
@Override db().executeTransaction(new Transaction() {
protected void performOperations() { @Override
execute(executable); protected void performOperations() {
} execute(executable);
}); }
}).get();
} catch (InterruptedException | ExecutionException e) {
throw new AssertionError(e);
}
} }
default void executeTransactions(Transaction... transactions) { default void executeTransactions(Transaction... transactions) {
for (Transaction transaction : transactions) { for (Transaction transaction : transactions) {
db().executeTransaction(transaction); try {
db().executeTransaction(transaction).get();
} catch (InterruptedException | ExecutionException e) {
throw new AssertionError(e);
}
} }
} }

View File

@ -328,11 +328,14 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
@Test @Test
default void serverPreferencePieValuesAreCorrect() { default void serverPreferencePieValuesAreCorrect() {
prepareForSessionSave(); prepareForSessionSave();
List<Session> server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
UUID serverTwoUuid = TestConstants.SERVER_TWO_UUID; UUID serverTwoUuid = TestConstants.SERVER_TWO_UUID;
executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, ""))); executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "")));
List<Session> server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID); db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[1]));
List<Session> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID); List<Session> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);
server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
server2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session))); server2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
Map<String, Long> expected = Maps.builder(String.class, Long.class) Map<String, Long> expected = Maps.builder(String.class, Long.class)