mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-23 10:20:33 +01:00
Use a "for each" strategy in profile migration methods
This commit is contained in:
@@ -5,21 +5,22 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.opentable.db.postgres.embedded.LiquibasePreparer;
|
||||
import com.opentable.db.postgres.junit5.EmbeddedPostgresExtension;
|
||||
import com.opentable.db.postgres.junit5.PreparedDbExtension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.jdbi.v3.core.result.ResultIterator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ProfilesPostgresTest extends ProfilesTest {
|
||||
|
||||
@@ -36,6 +37,8 @@ public class ProfilesPostgresTest extends ProfilesTest {
|
||||
new CircuitBreakerConfiguration());
|
||||
|
||||
profiles = new Profiles(faultTolerantDatabase);
|
||||
|
||||
faultTolerantDatabase.use(jdbi -> jdbi.useHandle(handle -> handle.createUpdate("DELETE FROM profiles").execute()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,9 +47,24 @@ public class ProfilesPostgresTest extends ProfilesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDeletedProfiles() {
|
||||
profiles.purgeDeletedProfiles();
|
||||
void testForEach() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
VersionedProfile profileOne = new VersionedProfile("123", "foo", "avatarLocation", null, null,
|
||||
null, "aDigest".getBytes());
|
||||
VersionedProfile profileTwo = new VersionedProfile("345", "bar", "baz", null, null, null, "boof".getBytes());
|
||||
|
||||
profiles.set(uuid, profileOne);
|
||||
profiles.set(uuid, profileTwo);
|
||||
|
||||
final Set<Pair<UUID, VersionedProfile>> retrievedProfiles = new HashSet<>();
|
||||
|
||||
profiles.forEach((u, profile) -> retrievedProfiles.add(new Pair<>(u, profile)), 1);
|
||||
|
||||
assertEquals(Set.of(new Pair<>(uuid, profileOne), new Pair<>(uuid, profileTwo)), retrievedProfiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEachDeletedProfiles() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
VersionedProfile profileOne = new VersionedProfile("123", "foo", "avatarLocation", null, null,
|
||||
null, "aDigest".getBytes());
|
||||
@@ -54,11 +72,12 @@ public class ProfilesPostgresTest extends ProfilesTest {
|
||||
|
||||
profiles.set(uuid, profileOne);
|
||||
profiles.set(UUID.randomUUID(), profileTwo);
|
||||
|
||||
profiles.deleteAll(uuid);
|
||||
|
||||
try (final ResultIterator<Pair<UUID, String>> resultIterator = profiles.getDeletedProfiles(10)) {
|
||||
assertEquals(List.of(new Pair<>(uuid, profileOne.getVersion())), ImmutableList.copyOf(resultIterator));
|
||||
}
|
||||
final List<Pair<UUID, String>> deletedProfiles = new ArrayList<>();
|
||||
|
||||
profiles.forEachDeletedProfile((u, version) -> deletedProfiles.add(new Pair<>(u, version)), 2);
|
||||
|
||||
assertEquals(List.of(new Pair<>(uuid, profileOne.getVersion())), deletedProfiles);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user