mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Fixed test fail caused by transaction isolation
Since each transaction is isolated, any inserts done in the transaction do not affect the queries in the transaction. Since TestData had both PlayerRegisterTransaction and PlayerServerRegisterTransaction (extends former) the tests failed as query for plan_users register status returned false even though the previously executed statement inserted the user.
This commit is contained in:
parent
4215939deb
commit
248e662414
@ -1020,11 +1020,17 @@ public abstract class CommonDBTest {
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
private void executeTransactions(Transaction... transactions) {
|
||||
for (Transaction transaction : transactions) {
|
||||
db.executeTransaction(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseUserQueryDoesNotReturnDuplicatePlayers() {
|
||||
db.executeTransaction(TestData.storeServers());
|
||||
db.executeTransaction(TestData.storePlayerOneData());
|
||||
db.executeTransaction(TestData.storePlayerTwoData());
|
||||
executeTransactions(TestData.storePlayerOneData());
|
||||
executeTransactions(TestData.storePlayerTwoData());
|
||||
|
||||
Collection<BaseUser> expected = Arrays.asList(TestData.getPlayerBaseUser(), TestData.getPlayer2BaseUser());
|
||||
Collection<BaseUser> result = db.query(BaseUserQueries.fetchServerBaseUsers(TestConstants.SERVER_UUID));
|
||||
@ -1039,8 +1045,8 @@ public abstract class CommonDBTest {
|
||||
@Test
|
||||
public void serverPlayerContainersQueryDoesNotReturnDuplicatePlayers() {
|
||||
db.executeTransaction(TestData.storeServers());
|
||||
db.executeTransaction(TestData.storePlayerOneData());
|
||||
db.executeTransaction(TestData.storePlayerTwoData());
|
||||
executeTransactions(TestData.storePlayerOneData());
|
||||
executeTransactions(TestData.storePlayerTwoData());
|
||||
|
||||
List<UUID> expected = Arrays.asList(playerUUID, player2UUID);
|
||||
Collections.sort(expected);
|
||||
@ -1056,8 +1062,8 @@ public abstract class CommonDBTest {
|
||||
@Test
|
||||
public void allPlayerContainersQueryDoesNotReturnDuplicatePlayers() {
|
||||
db.executeTransaction(TestData.storeServers());
|
||||
db.executeTransaction(TestData.storePlayerOneData());
|
||||
db.executeTransaction(TestData.storePlayerTwoData());
|
||||
executeTransactions(TestData.storePlayerOneData());
|
||||
executeTransactions(TestData.storePlayerTwoData());
|
||||
|
||||
List<UUID> expected = Arrays.asList(playerUUID, player2UUID);
|
||||
Collections.sort(expected);
|
||||
|
@ -118,41 +118,45 @@ public class TestData {
|
||||
};
|
||||
}
|
||||
|
||||
public static Transaction storePlayerOneData() {
|
||||
return new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new PlayerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName));
|
||||
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName, serverUUID));
|
||||
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerSecondJoin, playerName, server2UUID));
|
||||
public static Transaction[] storePlayerOneData() {
|
||||
return new Transaction[]{
|
||||
new PlayerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName),
|
||||
new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerFirstJoin, playerName, serverUUID));
|
||||
executeOther(new PlayerServerRegisterTransaction(playerUUID, () -> playerSecondJoin, playerName, server2UUID));
|
||||
|
||||
for (GeoInfo geoInfo : playerGeoInfo) {
|
||||
executeOther(new GeoInfoStoreTransaction(playerUUID, geoInfo));
|
||||
}
|
||||
for (GeoInfo geoInfo : playerGeoInfo) {
|
||||
executeOther(new GeoInfoStoreTransaction(playerUUID, geoInfo));
|
||||
}
|
||||
|
||||
for (Session session : playerSessions) {
|
||||
executeOther(new SessionEndTransaction(session));
|
||||
for (Session session : playerSessions) {
|
||||
executeOther(new SessionEndTransaction(session));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Transaction storePlayerTwoData() {
|
||||
return new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new PlayerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name));
|
||||
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name, serverUUID));
|
||||
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerSecondJoin, player2Name, server2UUID));
|
||||
public static Transaction[] storePlayerTwoData() {
|
||||
return new Transaction[]{
|
||||
new PlayerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name),
|
||||
new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerFirstJoin, player2Name, serverUUID));
|
||||
executeOther(new PlayerServerRegisterTransaction(player2UUID, () -> playerSecondJoin, player2Name, server2UUID));
|
||||
|
||||
for (GeoInfo geoInfo : playerGeoInfo) {
|
||||
executeOther(new GeoInfoStoreTransaction(player2UUID, geoInfo));
|
||||
}
|
||||
for (GeoInfo geoInfo : playerGeoInfo) {
|
||||
executeOther(new GeoInfoStoreTransaction(player2UUID, geoInfo));
|
||||
}
|
||||
|
||||
for (Session session : player2Sessions) {
|
||||
executeOther(new SessionEndTransaction(session));
|
||||
for (Session session : player2Sessions) {
|
||||
executeOther(new SessionEndTransaction(session));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user