Skip to content

Commit

Permalink
missed await caused problems
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Mierzwa <[email protected]>
  • Loading branch information
MaciejMierzwa committed Dec 12, 2023
1 parent 6730a0e commit 971d26a
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.google.common.base.Stopwatch;
Expand Down Expand Up @@ -1690,7 +1692,7 @@ public void shouldCreateSnapshot_positive() throws IOException {
);
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "PutRepositoryRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "CreateSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertAtLeast(snapshotGetCount, grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
}

@Test
Expand Down Expand Up @@ -1742,7 +1744,7 @@ public void shouldDeleteSnapshot_positive() throws IOException {
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "PutRepositoryRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "CreateSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "DeleteSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertExactly(snapshotGetCount, grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
}

@Test
Expand Down Expand Up @@ -1775,13 +1777,14 @@ public void shouldDeleteSnapshot_negative() throws IOException {
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "PutRepositoryRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "CreateSnapshotRequest"));
auditLogsRule.assertExactlyOne(missingPrivilege(LIMITED_READ_USER, "DeleteSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertExactly(snapshotGetCount, grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
}

@Test
public void shouldRestoreSnapshot_positive() throws IOException {
final String snapshotName = "restore-snapshot-positive";
long snapshotGetCount;
AtomicInteger restoredCount = new AtomicInteger();
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(LIMITED_WRITE_USER)) {
SnapshotSteps steps = new SnapshotSteps(restHighLevelClient);
// 1. create some documents
Expand Down Expand Up @@ -1821,8 +1824,12 @@ public void shouldRestoreSnapshot_positive() throws IOException {
CountRequest countRequest = new CountRequest(RESTORED_SONG_INDEX_NAME);
Awaitility.await()
.ignoreExceptions()
.pollInterval(100, TimeUnit.MILLISECONDS)
.alias("Index contains proper number of documents restored from snapshot.")
.until(() -> restHighLevelClient.count(countRequest, DEFAULT).getCount() == 2);
.until(() -> {
restoredCount.incrementAndGet();
return restHighLevelClient.count(countRequest, DEFAULT).getCount() == 2;
});

// 8. verify that document are present in restored index
assertThat(
Expand All @@ -1846,7 +1853,10 @@ public void shouldRestoreSnapshot_positive() throws IOException {
"/_snapshot/test-snapshot-repository/restore-snapshot-positive/_restore"
)
);
auditLogsRule.assertExactlyOne(userAuthenticated(LIMITED_WRITE_USER).withRestRequest(POST, "/restored_write_song_index/_count"));
auditLogsRule.assertExactly(
restoredCount.get(),
userAuthenticated(LIMITED_WRITE_USER).withRestRequest(POST, "/restored_write_song_index/_count")
);
auditLogsRule.assertExactly(2, userAuthenticated(LIMITED_WRITE_USER).withRestRequest(POST, "/_bulk"));
auditLogsRule.assertExactly(
snapshotGetCount,
Expand All @@ -1856,8 +1866,8 @@ public void shouldRestoreSnapshot_positive() throws IOException {
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "CreateSnapshotRequest"));
auditLogsRule.assertExactly(2, grantedPrivilege(LIMITED_WRITE_USER, "BulkRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "RestoreSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "SearchRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertExactly(restoredCount.get(), grantedPrivilege(LIMITED_WRITE_USER, "SearchRequest"));
auditLogsRule.assertExactly(snapshotGetCount, grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertAtLeastTransportMessages(2, grantedPrivilege(LIMITED_WRITE_USER, "PutMappingRequest"));
}

Expand Down Expand Up @@ -1921,7 +1931,7 @@ public void shouldRestoreSnapshot_failureForbiddenIndex() throws IOException {
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "PutRepositoryRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "CreateSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "BulkRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertExactly(snapshotGetCount, grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertAtLeastTransportMessages(1, auditPredicate(INDEX_EVENT).withEffectiveUser(LIMITED_WRITE_USER));
auditLogsRule.assertExactlyScanAll(1, missingPrivilege(LIMITED_WRITE_USER, "RestoreSnapshotRequest"));
auditLogsRule.assertAtLeastTransportMessages(2, grantedPrivilege(LIMITED_WRITE_USER, "PutMappingRequest"));
Expand Down Expand Up @@ -1988,7 +1998,7 @@ public void shouldRestoreSnapshot_failureOperationForbidden() throws IOException
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "CreateSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "BulkRequest"));
auditLogsRule.assertExactlyScanAll(1, missingPrivilege(LIMITED_READ_USER, "RestoreSnapshotRequest"));
auditLogsRule.assertExactlyOne(grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertExactly(snapshotGetCount, grantedPrivilege(LIMITED_WRITE_USER, "GetSnapshotsRequest"));
auditLogsRule.assertAtLeastTransportMessages(2, grantedPrivilege(LIMITED_WRITE_USER, "PutMappingRequest"));
}

Expand Down

0 comments on commit 971d26a

Please sign in to comment.