Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Oct 18, 2023
1 parent a19ea05 commit 8f6a6a0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ public void testTwoNodesSingleDoc() throws Exception {
.actionGet();
assertThat(health.isTimedOut(), equalTo(false));

refresh("test");

logger.info("--> verify 1 doc in the index");
for (int i = 0; i < 10; i++) {
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
Expand All @@ -331,6 +333,8 @@ public void testTwoNodesSingleDoc() throws Exception {
.actionGet();
assertThat(health.isTimedOut(), equalTo(false));

refresh("test");

logger.info("--> verify 1 doc in the index");
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST)
public class GetActionIT extends OpenSearchIntegTestCase {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void testUpdate() throws InterruptedException, ExecutionException {
.get();
assertEquals(2, update.getVersion());
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
refresh("test");
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");

// Upsert with RefreshPolicy.WAIT_UNTIL
Expand All @@ -125,6 +126,7 @@ public void testUpdate() throws InterruptedException, ExecutionException {
.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
.get();
assertEquals(1, update.getVersion());
refresh("test");
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get(), "2");

Expand All @@ -135,6 +137,7 @@ public void testUpdate() throws InterruptedException, ExecutionException {
.get();
assertEquals(2, update.getVersion());
assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
refresh("test");
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get());
}

Expand Down Expand Up @@ -176,6 +179,7 @@ public void testNoRefreshInterval() throws InterruptedException, ExecutionExcept
.execute();
while (false == index.isDone()) {
client().admin().indices().prepareRefresh("test").get();
refresh("test");
}
assertEquals(RestStatus.CREATED, index.get().status());
assertFalse("request shouldn't have forced a refresh", index.get().forcedRefresh());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ public void testPersistGlobalCheckpoint() throws Exception {
for (IndexService indexService : indicesService) {
for (IndexShard shard : indexService) {
final SeqNoStats seqNoStats = shard.seqNoStats();
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
assertThat(shard.getLastKnownGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
assertThat(shard.getLastSyncedGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
if((shard.isPrimaryMode() && shard.isRemoteTranslogEnabled() == true) || shard.isRemoteTranslogEnabled() == false) {
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
assertThat(shard.getLastKnownGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
assertThat(shard.getLastSyncedGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
}
}
}
}
Expand All @@ -277,7 +279,7 @@ public void testPersistLocalCheckpoint() {
.put("index.number_of_replicas", randomIntBetween(0, 1));
prepareCreate("test", indexSettings).get();
ensureGreen("test");
int numDocs = randomIntBetween(1, 20);
int numDocs = randomIntBetween(3, 10);
logger.info("numDocs {}", numDocs);
long maxSeqNo = 0;
for (int i = 0; i < numDocs; i++) {
Expand All @@ -288,9 +290,10 @@ public void testPersistLocalCheckpoint() {
for (IndexService indexService : indicesService) {
for (IndexShard shard : indexService) {
final SeqNoStats seqNoStats = shard.seqNoStats();
assertThat(maxSeqNo, equalTo(seqNoStats.getMaxSeqNo()));
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
;
if (shard.isRemoteTranslogEnabled() == false) {
assertThat(maxSeqNo, equalTo(seqNoStats.getMaxSeqNo()));
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testCreateSplitIndexWithSegmentReplicationBlocked() throws Exception

// block Segment Replication so that replicas never get the docs from primary
try (final Releasable ignored = blockReplication(List.of(discoveryNodes[0].getName()), latch)) {
final int docs = 500;
final int docs = 50;
for (int i = 0; i < docs; i++) {
client().prepareIndex("test").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", MediaTypeRegistry.JSON).get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public abstract class OpenSearchIntegTestCase extends OpenSearchTestCase {
* By default if no {@link ClusterScope} is configured this will hold a reference to the suite cluster.
*/
private static TestCluster currentCluster;
public static TestCluster remoteStoreNodeAttributeCluster;
private static RestClient restClient = null;

private static final Map<Class<?>, TestCluster> clusters = new IdentityHashMap<>();
Expand Down Expand Up @@ -2386,6 +2387,9 @@ public <T extends TransportRequest> TransportRequestHandler<T> interceptHandler(
* Returns path to a random directory that can be used to create a temporary file system repo
*/
public Path randomRepoPath() {
if (remoteStoreNodeAttributeCluster != null) {
return randomRepoPath(((InternalTestCluster) remoteStoreNodeAttributeCluster).getDefaultSettings());
}
if (currentCluster instanceof InternalTestCluster) {
return randomRepoPath(((InternalTestCluster) currentCluster).getDefaultSettings());
}
Expand Down

0 comments on commit 8f6a6a0

Please sign in to comment.