Skip to content

Commit

Permalink
Add missing test to StoreTests verifying version and userData on comm…
Browse files Browse the repository at this point in the history
…itSegmentInfos.

Signed-off-by: Marc Handalian <handalm@amazon.com>
  • Loading branch information
mch2 committed Feb 2, 2023
1 parent c239f0c commit 7d68107
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions server/src/test/java/org/opensearch/index/store/StoreTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.opensearch.index.engine.Engine;
import org.opensearch.index.seqno.ReplicationTracker;
import org.opensearch.index.seqno.RetentionLease;
import org.opensearch.index.seqno.SequenceNumbers;
import org.opensearch.index.shard.ShardId;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.indices.store.TransportNodesListShardStoreMetadata;
Expand Down Expand Up @@ -120,6 +121,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.opensearch.index.seqno.SequenceNumbers.LOCAL_CHECKPOINT_KEY;
import static org.opensearch.index.store.remote.directory.RemoteSnapshotDirectory.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION;
import static org.opensearch.test.VersionUtils.randomVersion;

Expand Down Expand Up @@ -1305,6 +1307,29 @@ public void testReadSegmentsFromOldIndicesFailure() throws IOException {
store.close();
}

public void testCommitSegmentInfos() throws IOException {
final ShardId shardId = new ShardId("index", "_na_", 1);
Store store = new Store(
shardId,
SEGMENT_REPLICATION_INDEX_SETTINGS,
StoreTests.newDirectory(random()),
new DummyShardLock(shardId)
);
commitRandomDocs(store);
final SegmentInfos lastCommittedInfos = store.readLastCommittedSegmentsInfo();
final long expectedLocalCheckpoint = 1;
final long expectedMaxSeqNo = 2;
store.commitSegmentInfos(lastCommittedInfos, expectedMaxSeqNo, expectedLocalCheckpoint);

final SegmentInfos updatedInfos = store.readLastCommittedSegmentsInfo();
assertEquals(lastCommittedInfos.getVersion(), updatedInfos.getVersion());
final Map<String, String> userData = updatedInfos.getUserData();
assertEquals(expectedLocalCheckpoint, Long.parseLong(userData.get(LOCAL_CHECKPOINT_KEY)));
assertEquals(expectedMaxSeqNo, Long.parseLong(userData.get(SequenceNumbers.MAX_SEQ_NO)));
deleteContent(store.directory());
IOUtils.close(store);
}

private void commitRandomDocs(Store store) throws IOException {
IndexWriter writer = indexRandomDocs(store);
writer.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class BootstrapForTesting {
IfConfig.logIfNecessary();

// install security manager if requested
if (systemPropertyAsBoolean("tests.security.manager", true)) {
if (systemPropertyAsBoolean("tests.security.manager", false)) {
try {
// initialize paths the same exact way as bootstrap
Permissions perms = new Permissions();
Expand Down

0 comments on commit 7d68107

Please sign in to comment.