diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/Ping.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/Ping.java index 2aaba6b2a..795deeac3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/Ping.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/Ping.java @@ -67,4 +67,14 @@ public class Ping extends DateObj { public int hashCode() { return Objects.hash(serverUUID, average, min, max); } + + @Override + public String toString() { + return "Ping{" + + "serverUUID=" + serverUUID + + ", average=" + average + + ", min=" + min + + ", max=" + max + + '}'; + } } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java index 796500e89..ed581b4f7 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java @@ -80,19 +80,13 @@ public interface DatabaseTest extends DatabaseTestPreparer { @Test default void testTPSSaving() { - Random r = new Random(); - - List expected = new ArrayList<>(); - - for (int i = 0; i < RandomData.randomInt(1, 5); i++) { - expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), r.nextDouble(), r.nextLong(), r.nextInt(), r.nextInt(), r.nextLong())); - } + List expected = RandomData.randomTPS(); for (TPS tps : expected) { execute(DataStoreQueries.storeTPS(serverUUID(), tps)); } - commitTest(); + forcePersistenceCheck(); assertEquals(expected, db().query(TPSQueries.fetchTPSDataOfServer(serverUUID()))); } @@ -106,20 +100,6 @@ public interface DatabaseTest extends DatabaseTestPreparer { db().executeTransaction(new PlayerRegisterTransaction(player2UUID, () -> 123456789L, "Test")); } - @Test - default void geoInformationIsStored() { - saveUserOne(); - - long time = System.currentTimeMillis(); - - GeoInfo expected = new GeoInfo("TestLocation", time); - saveGeoInfo(playerUUID, expected); - commitTest(); - - List result = db().query(GeoInfoQueries.fetchAllGeoInformation()).get(playerUUID); - assertEquals(Collections.singletonList(expected), result); - } - @Test default void testNicknamesTable() { saveUserOne(); @@ -127,7 +107,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { Nickname expected = new Nickname("TestNickname", System.currentTimeMillis(), serverUUID()); db().executeTransaction(new NicknameStoreTransaction(playerUUID, expected, (uuid, name) -> false /* Not cached */)); db().executeTransaction(new NicknameStoreTransaction(playerUUID, expected, (uuid, name) -> true /* Cached */)); - commitTest(); + forcePersistenceCheck(); List nicknames = db().query(NicknameQueries.fetchNicknameDataOfPlayer(playerUUID)); assertEquals(1, nicknames.size()); @@ -138,7 +118,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { default void webUserIsRegistered() { WebUser expected = new WebUser(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0); db().executeTransaction(new RegisterWebUserTransaction(expected)); - commitTest(); + forcePersistenceCheck(); Optional found = db().query(WebUserQueries.fetchWebUser(TestConstants.PLAYER_ONE_NAME)); assertTrue(found.isPresent()); @@ -163,7 +143,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { String[] expected = {"Test", "Test2", "Test3"}; saveWorlds(expected); - commitTest(); + forcePersistenceCheck(); Collection result = db().query(LargeFetchQueries.fetchAllWorldNames()).get(serverUUID()); assertEquals(new HashSet<>(Arrays.asList(expected)), result); @@ -223,7 +203,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { execute(DataStoreQueries.storeSession(session)); - commitTest(); + forcePersistenceCheck(); Map> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)); assertTrue(sessions.containsKey(serverUUID())); @@ -250,7 +230,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { execute(DataStoreQueries.storeSession(session)); - commitTest(); + forcePersistenceCheck(); Map> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)); List savedSessions = sessions.get(serverUUID()); @@ -317,7 +297,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { // Updates the name db().executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> 0, "NewName")); - commitTest(); + forcePersistenceCheck(); assertFalse(db().query(UserIdentifierQueries.fetchPlayerUUIDOf(TestConstants.PLAYER_ONE_NAME)).isPresent()); @@ -334,7 +314,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { for (int i = 0; i < random + 1; i++) { db().executeTransaction(new KickStoreTransaction(playerUUID)); } - commitTest(); + forcePersistenceCheck(); OptionalAssert.equals(random + 2, db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID)).map(BaseUser::getTimesKicked)); } @@ -447,7 +427,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { session.setPlayerKills(createKills()); execute(DataStoreQueries.storeSession(session)); - commitTest(); + forcePersistenceCheck(); Map> sessions = db().query(SessionQueries.fetchSessionsOfServer(serverUUID())); @@ -521,7 +501,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { session.setPlayerKills(expected); execute(DataStoreQueries.storeSession(session)); - commitTest(); + forcePersistenceCheck(); Map> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)); List savedSessions = sessions.get(serverUUID()); @@ -986,81 +966,6 @@ public interface DatabaseTest extends DatabaseTestPreparer { assertEquals(expected, result); } - @Test - default void serverGeolocationsAreCountedAppropriately() { - UUID firstUuid = UUID.randomUUID(); - UUID secondUuid = UUID.randomUUID(); - UUID thirdUuid = UUID.randomUUID(); - UUID fourthUuid = UUID.randomUUID(); - UUID fifthUuid = UUID.randomUUID(); - UUID sixthUuid = UUID.randomUUID(); - - Database database = db(); - - database.executeTransaction(new PlayerServerRegisterTransaction(firstUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(secondUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(thirdUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(fourthUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(fifthUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(sixthUuid, () -> 0L, "", serverUUID())); - - saveGeoInfo(firstUuid, new GeoInfo("Norway", 0)); - saveGeoInfo(firstUuid, new GeoInfo("Finland", 5)); - saveGeoInfo(secondUuid, new GeoInfo("Sweden", 0)); - saveGeoInfo(thirdUuid, new GeoInfo("Denmark", 0)); - saveGeoInfo(fourthUuid, new GeoInfo("Denmark", 0)); - saveGeoInfo(fifthUuid, new GeoInfo("Not Known", 0)); - saveGeoInfo(sixthUuid, new GeoInfo("Local Machine", 0)); - - Map got = database.query(GeoInfoQueries.serverGeolocationCounts(serverUUID())); - - Map expected = new HashMap<>(); - // first user has a more recent connection from Finland so their country should be counted as Finland. - expected.put("Finland", 1); - expected.put("Sweden", 1); - expected.put("Not Known", 1); - expected.put("Local Machine", 1); - expected.put("Denmark", 2); - - assertEquals(expected, got); - } - - @Test - default void networkGeolocationsAreCountedAppropriately() { - UUID firstUuid = UUID.randomUUID(); - UUID secondUuid = UUID.randomUUID(); - UUID thirdUuid = UUID.randomUUID(); - UUID fourthUuid = UUID.randomUUID(); - UUID fifthUuid = UUID.randomUUID(); - UUID sixthUuid = UUID.randomUUID(); - - Database db = db(); - db.executeTransaction(new PlayerRegisterTransaction(firstUuid, () -> 0L, "")); - db.executeTransaction(new PlayerRegisterTransaction(secondUuid, () -> 0L, "")); - db.executeTransaction(new PlayerRegisterTransaction(thirdUuid, () -> 0L, "")); - - saveGeoInfo(firstUuid, new GeoInfo("Norway", 0)); - saveGeoInfo(firstUuid, new GeoInfo("Finland", 5)); - saveGeoInfo(secondUuid, new GeoInfo("Sweden", 0)); - saveGeoInfo(thirdUuid, new GeoInfo("Denmark", 0)); - saveGeoInfo(fourthUuid, new GeoInfo("Denmark", 0)); - saveGeoInfo(fifthUuid, new GeoInfo("Not Known", 0)); - saveGeoInfo(sixthUuid, new GeoInfo("Local Machine", 0)); - - Map got = db.query(GeoInfoQueries.networkGeolocationCounts()); - - Map expected = new HashMap<>(); - // first user has a more recent connection from Finland so their country should be counted as Finland. - expected.put("Finland", 1); - expected.put("Sweden", 1); - expected.put("Not Known", 1); - expected.put("Local Machine", 1); - expected.put("Denmark", 2); - - assertEquals(expected, got); - } - - @Test default void bungeeInformationIsStored() { Optional bungeeInfo = db().query(ServerQueries.fetchProxyServerInformation()); @@ -1070,7 +975,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { Server bungeeCord = new Server(-1, bungeeUUID, "BungeeCord", "Random:1234", 20); db().executeTransaction(new StoreServerInformationTransaction(bungeeCord)); - commitTest(); + forcePersistenceCheck(); bungeeCord.setId(2); @@ -1092,55 +997,6 @@ public interface DatabaseTest extends DatabaseTestPreparer { assertEquals(1, serverInformation.values().stream().filter(Server::isProxy).count()); } - @Test - default void pingIsGroupedByGeolocationAppropriately() { - UUID firstUuid = UUID.randomUUID(); - UUID secondUuid = UUID.randomUUID(); - UUID thirdUuid = UUID.randomUUID(); - UUID fourthUuid = UUID.randomUUID(); - UUID fifthUuid = UUID.randomUUID(); - UUID sixthUuid = UUID.randomUUID(); - - Database database = db(); - - database.executeTransaction(new PlayerServerRegisterTransaction(firstUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(secondUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(thirdUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(fourthUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(fifthUuid, () -> 0L, "", serverUUID())); - database.executeTransaction(new PlayerServerRegisterTransaction(sixthUuid, () -> 0L, "", serverUUID())); - - saveGeoInfo(firstUuid, new GeoInfo("Norway", 0)); - saveGeoInfo(firstUuid, new GeoInfo("Finland", 5)); - saveGeoInfo(secondUuid, new GeoInfo("Sweden", 0)); - saveGeoInfo(thirdUuid, new GeoInfo("Denmark", 0)); - saveGeoInfo(fourthUuid, new GeoInfo("Denmark", 0)); - saveGeoInfo(fifthUuid, new GeoInfo("Not Known", 0)); - saveGeoInfo(sixthUuid, new GeoInfo("Local Machine", 0)); - - long time = System.currentTimeMillis(); - List> ping = Collections.singletonList(new DateObj<>(time, 5)); - database.executeTransaction(new PingStoreTransaction(firstUuid, serverUUID(), ping)); - database.executeTransaction(new PingStoreTransaction(secondUuid, serverUUID(), ping)); - database.executeTransaction(new PingStoreTransaction(thirdUuid, serverUUID(), ping)); - database.executeTransaction(new PingStoreTransaction(fourthUuid, serverUUID(), ping)); - database.executeTransaction(new PingStoreTransaction(fifthUuid, serverUUID(), ping)); - database.executeTransaction(new PingStoreTransaction(sixthUuid, serverUUID(), ping)); - - Map got = database.query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID())); - - Map expected = new HashMap<>(); - // first user has a more recent connection from Finland so their country should be counted as Finland. - Ping expectedPing = new Ping(time, serverUUID(), 5, 5, 5); - expected.put("Finland", expectedPing); - expected.put("Sweden", expectedPing); - expected.put("Not Known", expectedPing); - expected.put("Local Machine", expectedPing); - expected.put("Denmark", expectedPing); - - assertEquals(expected, got); - } - @Test default void registerDateIsMinimized() { executeTransactions( diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTestPreparer.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTestPreparer.java index f52da93d7..f0256acf9 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTestPreparer.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTestPreparer.java @@ -76,7 +76,7 @@ public interface DatabaseTestPreparer { }); } - default void commitTest() { + default void forcePersistenceCheck() { db().close(); db().init(); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/H2Test.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/H2Test.java index b17fe5fb2..6f434d0d6 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/H2Test.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/H2Test.java @@ -17,7 +17,8 @@ package com.djrapitops.plan.storage.database; import com.djrapitops.plan.PlanSystem; -import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueriesTest; +import com.djrapitops.plan.storage.database.queries.ActivityIndexQueriesTest; +import com.djrapitops.plan.storage.database.queries.GeolocationQueriesTest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.extension.ExtendWith; @@ -40,7 +41,8 @@ import java.util.UUID; @ExtendWith(MockitoExtension.class) public class H2Test implements DatabaseTest, ExtensionsDatabaseTest, - ActivityIndexQueriesTest { + ActivityIndexQueriesTest, + GeolocationQueriesTest { private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/MySQLTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/MySQLTest.java index c60c91110..cd4ce91eb 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/MySQLTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/MySQLTest.java @@ -17,7 +17,8 @@ package com.djrapitops.plan.storage.database; import com.djrapitops.plan.PlanSystem; -import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueriesTest; +import com.djrapitops.plan.storage.database.queries.ActivityIndexQueriesTest; +import com.djrapitops.plan.storage.database.queries.GeolocationQueriesTest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; @@ -35,7 +36,7 @@ import java.util.UUID; /** * Tests for MySQL database. *

- * These settings assume CI environment with MySQL service running. + * The setup assumes CI environment with MySQL service running. * 'MYSQL_DB' database should be created before the test. * * @author Rsl1122 @@ -46,7 +47,8 @@ import java.util.UUID; @ExtendWith(MockitoExtension.class) class MySQLTest implements DatabaseTest, ExtensionsDatabaseTest, - ActivityIndexQueriesTest { + ActivityIndexQueriesTest, + GeolocationQueriesTest { private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/SQLiteTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/SQLiteTest.java index 47cbe62ef..c93c0097c 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/SQLiteTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/SQLiteTest.java @@ -17,7 +17,8 @@ package com.djrapitops.plan.storage.database; import com.djrapitops.plan.PlanSystem; -import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueriesTest; +import com.djrapitops.plan.storage.database.queries.ActivityIndexQueriesTest; +import com.djrapitops.plan.storage.database.queries.GeolocationQueriesTest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.extension.ExtendWith; @@ -40,7 +41,8 @@ import java.util.UUID; @ExtendWith(MockitoExtension.class) public class SQLiteTest implements DatabaseTest, ExtensionsDatabaseTest, - ActivityIndexQueriesTest { + ActivityIndexQueriesTest, + GeolocationQueriesTest { private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/ActivityIndexQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java similarity index 96% rename from Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/ActivityIndexQueriesTest.java rename to Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java index 9c3e47a14..26c4fdba8 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/ActivityIndexQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java @@ -1,10 +1,10 @@ -package com.djrapitops.plan.storage.database.queries.analysis; +package com.djrapitops.plan.storage.database.queries; import com.djrapitops.plan.delivery.domain.TablePlayer; import com.djrapitops.plan.delivery.domain.mutators.ActivityIndex; import com.djrapitops.plan.gathering.domain.Session; import com.djrapitops.plan.storage.database.DatabaseTestPreparer; -import com.djrapitops.plan.storage.database.queries.DataStoreQueries; +import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries; import com.djrapitops.plan.storage.database.queries.objects.NetworkTablePlayersQuery; import com.djrapitops.plan.storage.database.queries.objects.ServerTablePlayersQuery; import com.djrapitops.plan.storage.database.queries.objects.SessionQueries; diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java new file mode 100644 index 000000000..0c934b81a --- /dev/null +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java @@ -0,0 +1,125 @@ +package com.djrapitops.plan.storage.database.queries; + +import com.djrapitops.plan.delivery.domain.DateObj; +import com.djrapitops.plan.gathering.domain.GeoInfo; +import com.djrapitops.plan.gathering.domain.Ping; +import com.djrapitops.plan.storage.database.Database; +import com.djrapitops.plan.storage.database.DatabaseTestPreparer; +import com.djrapitops.plan.storage.database.queries.objects.GeoInfoQueries; +import com.djrapitops.plan.storage.database.queries.objects.PingQueries; +import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction; +import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction; +import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction; +import org.junit.jupiter.api.Test; +import utilities.RandomData; +import utilities.TestConstants; + +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public interface GeolocationQueriesTest extends DatabaseTestPreparer { + + @Test + default void geoInformationIsStored() { + db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> 1000L, TestConstants.PLAYER_ONE_NAME, serverUUID())); + + List expected = RandomData.randomGeoInfo(); + for (GeoInfo geoInfo : expected) { + save(playerUUID, geoInfo); + } + + forcePersistenceCheck(); + + List result = db().query(GeoInfoQueries.fetchAllGeoInformation()).get(playerUUID); + assertEquals(expected, result); + } + + default void save(UUID uuid, GeoInfo info) { + db().executeTransaction(new GeoInfoStoreTransaction(uuid, info)); + } + + @Test + default void serverGeolocationsAreCountedAppropriately() { + storeSpecificGeolocations(); + + Map got = db().query(GeoInfoQueries.serverGeolocationCounts(serverUUID())); + + Map expected = new HashMap<>(); + // first user has a more recent connection from Finland so their country should be counted as Finland. + expected.put("Finland", 1); + expected.put("Sweden", 1); + expected.put("Not Known", 1); + expected.put("Local Machine", 1); + expected.put("Denmark", 2); + + assertEquals(expected, got); + } + + @Test + default void networkGeolocationsAreCountedAppropriately() { + storeSpecificGeolocations(); + + Map got = db().query(GeoInfoQueries.networkGeolocationCounts()); + + Map expected = new HashMap<>(); + // first user has a more recent connection from Finland so their country should be counted as Finland. + expected.put("Finland", 1); + expected.put("Sweden", 1); + expected.put("Not Known", 1); + expected.put("Local Machine", 1); + expected.put("Denmark", 2); + + assertEquals(expected, got); + } + + default UUID[] storeSpecificGeolocations() { + UUID firstUuid = UUID.randomUUID(); + UUID secondUuid = UUID.randomUUID(); + UUID thirdUuid = UUID.randomUUID(); + UUID fourthUuid = UUID.randomUUID(); + UUID fifthUuid = UUID.randomUUID(); + UUID sixthUuid = UUID.randomUUID(); + UUID[] uuids = {firstUuid, secondUuid, thirdUuid, fourthUuid, fifthUuid, sixthUuid}; + + Database db = db(); + for (UUID uuid : uuids) { + db.executeTransaction(new PlayerServerRegisterTransaction(uuid, () -> 0L, "", serverUUID())); + } + + save(firstUuid, new GeoInfo("Norway", 0)); + save(firstUuid, new GeoInfo("Finland", 5)); + save(secondUuid, new GeoInfo("Sweden", 0)); + save(thirdUuid, new GeoInfo("Denmark", 0)); + save(fourthUuid, new GeoInfo("Denmark", 0)); + save(fifthUuid, new GeoInfo("Not Known", 0)); + save(sixthUuid, new GeoInfo("Local Machine", 0)); + return uuids; + } + + @Test + default void pingIsGroupedByGeolocationAppropriately() { + UUID[] uuids = storeSpecificGeolocations(); + + Database db = db(); + + long time = System.currentTimeMillis(); + List> ping = Collections.singletonList(new DateObj<>(time, 5)); + for (UUID uuid : uuids) { + db.executeTransaction(new PingStoreTransaction(uuid, serverUUID(), ping)); + } + + Map got = db.query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID())); + + Map expected = new HashMap<>(); + // first user has a more recent connection from Finland so their country should be counted as Finland. + Ping expectedPing = new Ping(time, serverUUID(), 5, 5, 5); + expected.put("Finland", expectedPing); + expected.put("Sweden", expectedPing); + expected.put("Not Known", expectedPing); + expected.put("Local Machine", expectedPing); + expected.put("Denmark", expectedPing); + + assertEquals(expected, got); + } +} \ No newline at end of file diff --git a/Plan/common/src/test/java/utilities/RandomData.java b/Plan/common/src/test/java/utilities/RandomData.java index a135b7f64..3fe94e433 100644 --- a/Plan/common/src/test/java/utilities/RandomData.java +++ b/Plan/common/src/test/java/utilities/RandomData.java @@ -56,7 +56,7 @@ public class RandomData { public static List randomTPS() { List test = new ArrayList<>(); - for (int i = 0; i < 20; i++) { + for (int i = 0; i < randomInt(5, 100); i++) { int randInt = r.nextInt(); long randLong = Math.abs(r.nextLong()); test.add(new TPS(randLong, randLong, randInt, randLong, randLong, randInt, randInt, randLong));