Update test to handle read-then-write in ContactDiscoveryWriter.
This commit is contained in:
parent
b080a5db4d
commit
2059bb5ef8
|
@ -27,6 +27,9 @@ public class ContactDiscoveryWriter extends AccountDatabaseCrawlerListener {
|
||||||
throws AccountDatabaseCrawlerRestartException {
|
throws AccountDatabaseCrawlerRestartException {
|
||||||
for (Account account : chunkAccounts) {
|
for (Account account : chunkAccounts) {
|
||||||
if (account.isCanonicallyDiscoverable() != account.shouldBeVisibleInDirectory()) {
|
if (account.isCanonicallyDiscoverable() != account.shouldBeVisibleInDirectory()) {
|
||||||
|
// It’s less than ideal, but crawler listeners currently must not call update()
|
||||||
|
// with the accounts from the chunk, because updates cause the account instance to become stale. Instead, they
|
||||||
|
// must get a new copy, which they are free to update.
|
||||||
accounts.get(account.getUuid()).ifPresent(accounts::update);
|
accounts.get(account.getUuid()).ifPresent(accounts::update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
|
||||||
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
||||||
import org.whispersystems.textsecuregcm.util.AttributeValues;
|
import org.whispersystems.textsecuregcm.util.AttributeValues;
|
||||||
|
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||||
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
|
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
|
||||||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
|
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
|
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
|
||||||
|
@ -46,6 +47,7 @@ import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.GetItemResponse;
|
import software.amazon.awssdk.services.dynamodb.model.GetItemResponse;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
|
import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.KeyType;
|
import software.amazon.awssdk.services.dynamodb.model.KeyType;
|
||||||
|
import software.amazon.awssdk.services.dynamodb.model.ReturnValue;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
|
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
|
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
|
||||||
import software.amazon.awssdk.services.dynamodb.model.ScanResponse;
|
import software.amazon.awssdk.services.dynamodb.model.ScanResponse;
|
||||||
|
@ -532,11 +534,26 @@ class AccountsDynamoDbTest {
|
||||||
ContactDiscoveryWriter writer = new ContactDiscoveryWriter(accountsDynamoDb);
|
ContactDiscoveryWriter writer = new ContactDiscoveryWriter(accountsDynamoDb);
|
||||||
account.setCanonicallyDiscoverable(false);
|
account.setCanonicallyDiscoverable(false);
|
||||||
writer.onCrawlChunk(null, List.of(account));
|
writer.onCrawlChunk(null, List.of(account));
|
||||||
|
account.setVersion(1);
|
||||||
verifyStoredState("+14151112222", account.getUuid(), account, true);
|
verifyStoredState("+14151112222", account.getUuid(), account, true);
|
||||||
account.setCanonicallyDiscoverable(true);
|
|
||||||
account.setDiscoverableByPhoneNumber(false);
|
// Make the stored "C" column not match reality.
|
||||||
writer.onCrawlChunk(null, List.of(account));
|
final UpdateItemRequest updateItemRequest = UpdateItemRequest.builder()
|
||||||
|
.tableName(ACCOUNTS_TABLE_NAME)
|
||||||
|
.key(Map.of(AccountsDynamoDb.KEY_ACCOUNT_UUID, AttributeValues.fromUUID(account.getUuid())))
|
||||||
|
.updateExpression("SET #cds = :cds")
|
||||||
|
.expressionAttributeNames(Map.of("#cds", AccountsDynamoDb.ATTR_CANONICALLY_DISCOVERABLE))
|
||||||
|
.expressionAttributeValues(Map.of(
|
||||||
|
":cds", AttributeValues.fromBool(false)))
|
||||||
|
.build();
|
||||||
|
dynamoDbExtension.getDynamoDbClient().updateItem(updateItemRequest);
|
||||||
verifyStoredState("+14151112222", account.getUuid(), account, false);
|
verifyStoredState("+14151112222", account.getUuid(), account, false);
|
||||||
|
|
||||||
|
// Crawl again and make sure update happened
|
||||||
|
account.setCanonicallyDiscoverable(false);
|
||||||
|
writer.onCrawlChunk(null, List.of(account));
|
||||||
|
account.setVersion(2);
|
||||||
|
verifyStoredState("+14151112222", account.getUuid(), account, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Device generateDevice(long id) {
|
private Device generateDevice(long id) {
|
||||||
|
|
Loading…
Reference in New Issue