mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-29 19:41:35 +01:00
Attempt to catch #956 with tests
This commit is contained in:
parent
8a13f1d792
commit
4215939deb
@ -76,4 +76,14 @@ public class BaseUser {
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid, name, registered, timesKicked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseUser{" +
|
||||
uuid +
|
||||
", '" + name + '\'' +
|
||||
", +" + registered +
|
||||
", kick:" + timesKicked +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import com.djrapitops.plan.db.access.queries.objects.WorldTimesQueries;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -65,7 +66,7 @@ public class ServerContainerQuery implements Query<ServerContainer> {
|
||||
container.putRawData(ServerKeys.SERVER_UUID, serverUUID);
|
||||
container.putRawData(ServerKeys.NAME, serverInfo.get().getName());
|
||||
container.putCachingSupplier(ServerKeys.PLAYERS, () -> db.query(new ServerPlayerContainersQuery(serverUUID)));
|
||||
container.putSupplier(ServerKeys.PLAYER_COUNT, () -> container.getUnsafe(ServerKeys.PLAYERS).size());
|
||||
container.putSupplier(ServerKeys.PLAYER_COUNT, () -> container.getValue(ServerKeys.PLAYERS).map(Collection::size).orElse(0));
|
||||
|
||||
container.putCachingSupplier(ServerKeys.TPS, () -> db.query(TPSQueries.fetchTPSDataOfServer(serverUUID)));
|
||||
container.putCachingSupplier(ServerKeys.PING, () -> PlayersMutator.forContainer(container).pings());
|
||||
|
@ -32,7 +32,9 @@ import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.queries.*;
|
||||
import com.djrapitops.plan.db.access.queries.containers.AllPlayerContainersQuery;
|
||||
import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
|
||||
import com.djrapitops.plan.db.access.queries.containers.ServerPlayerContainersQuery;
|
||||
import com.djrapitops.plan.db.access.queries.objects.*;
|
||||
import com.djrapitops.plan.db.access.transactions.BackupCopyTransaction;
|
||||
import com.djrapitops.plan.db.access.transactions.StoreConfigTransaction;
|
||||
@ -60,10 +62,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.rules.Timeout;
|
||||
import rules.ComponentMocker;
|
||||
import rules.PluginComponentMocker;
|
||||
import utilities.FieldFetcher;
|
||||
import utilities.OptionalAssert;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestConstants;
|
||||
import utilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
@ -1020,4 +1019,54 @@ public abstract class CommonDBTest {
|
||||
Map<UUID, Integer> result = db.query(ServerAggregateQueries.serverUserCounts());
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseUserQueryDoesNotReturnDuplicatePlayers() {
|
||||
db.executeTransaction(TestData.storeServers());
|
||||
db.executeTransaction(TestData.storePlayerOneData());
|
||||
db.executeTransaction(TestData.storePlayerTwoData());
|
||||
|
||||
Collection<BaseUser> expected = Arrays.asList(TestData.getPlayerBaseUser(), TestData.getPlayer2BaseUser());
|
||||
Collection<BaseUser> result = db.query(BaseUserQueries.fetchServerBaseUsers(TestConstants.SERVER_UUID));
|
||||
|
||||
assertEquals(expected, result);
|
||||
|
||||
result = db.query(BaseUserQueries.fetchServerBaseUsers(TestConstants.SERVER_TWO_UUID));
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverPlayerContainersQueryDoesNotReturnDuplicatePlayers() {
|
||||
db.executeTransaction(TestData.storeServers());
|
||||
db.executeTransaction(TestData.storePlayerOneData());
|
||||
db.executeTransaction(TestData.storePlayerTwoData());
|
||||
|
||||
List<UUID> expected = Arrays.asList(playerUUID, player2UUID);
|
||||
Collections.sort(expected);
|
||||
|
||||
Collection<UUID> result = db.query(new ServerPlayerContainersQuery(TestConstants.SERVER_UUID))
|
||||
.stream().map(player -> player.getUnsafe(PlayerKeys.UUID))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allPlayerContainersQueryDoesNotReturnDuplicatePlayers() {
|
||||
db.executeTransaction(TestData.storeServers());
|
||||
db.executeTransaction(TestData.storePlayerOneData());
|
||||
db.executeTransaction(TestData.storePlayerTwoData());
|
||||
|
||||
List<UUID> expected = Arrays.asList(playerUUID, player2UUID);
|
||||
Collections.sort(expected);
|
||||
|
||||
Collection<UUID> result = db.query(new AllPlayerContainersQuery())
|
||||
.stream().map(player -> player.getUnsafe(PlayerKeys.UUID))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package utilities;
|
||||
|
||||
import com.djrapitops.plan.data.container.BaseUser;
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
@ -174,4 +175,12 @@ public class TestData {
|
||||
public static List<GeoInfo> getPlayerGeoInfo() {
|
||||
return playerGeoInfo;
|
||||
}
|
||||
|
||||
public static BaseUser getPlayerBaseUser() {
|
||||
return new BaseUser(playerUUID, playerName, playerFirstJoin, 0);
|
||||
}
|
||||
|
||||
public static BaseUser getPlayer2BaseUser() {
|
||||
return new BaseUser(player2UUID, player2Name, playerFirstJoin, 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user