use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class SearchRequestTests method testRandomVersionSerialization.
public void testRandomVersionSerialization() throws IOException {
SearchRequest searchRequest = createSearchRequest();
Version version = VersionUtils.randomVersion(random());
SearchRequest deserializedRequest = copyWriteable(searchRequest, namedWriteableRegistry, SearchRequest::new, version);
if (version.before(LegacyESVersion.V_7_0_0)) {
assertTrue(deserializedRequest.isCcsMinimizeRoundtrips());
} else {
assertEquals(searchRequest.isCcsMinimizeRoundtrips(), deserializedRequest.isCcsMinimizeRoundtrips());
}
assertEquals(searchRequest.getLocalClusterAlias(), deserializedRequest.getLocalClusterAlias());
assertEquals(searchRequest.getAbsoluteStartMillis(), deserializedRequest.getAbsoluteStartMillis());
assertEquals(searchRequest.isFinalReduce(), deserializedRequest.isFinalReduce());
if (version.onOrAfter(Version.V_1_1_0)) {
assertEquals(searchRequest.getCancelAfterTimeInterval(), deserializedRequest.getCancelAfterTimeInterval());
} else {
assertNull(deserializedRequest.getCancelAfterTimeInterval());
}
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class SearchContextIdTests method testEncode.
public void testEncode() {
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Arrays.asList(new NamedWriteableRegistry.Entry(QueryBuilder.class, TermQueryBuilder.NAME, TermQueryBuilder::new), new NamedWriteableRegistry.Entry(QueryBuilder.class, MatchAllQueryBuilder.NAME, MatchAllQueryBuilder::new), new NamedWriteableRegistry.Entry(QueryBuilder.class, IdsQueryBuilder.NAME, IdsQueryBuilder::new)));
final AtomicArray<SearchPhaseResult> queryResults = TransportSearchHelperTests.generateQueryResults();
final Version version = Version.CURRENT;
final Map<String, AliasFilter> aliasFilters = new HashMap<>();
for (SearchPhaseResult result : queryResults.asList()) {
final AliasFilter aliasFilter;
if (randomBoolean()) {
aliasFilter = new AliasFilter(randomQueryBuilder());
} else if (randomBoolean()) {
aliasFilter = new AliasFilter(randomQueryBuilder(), "alias-" + between(1, 10));
} else {
aliasFilter = AliasFilter.EMPTY;
}
if (randomBoolean()) {
aliasFilters.put(result.getSearchShardTarget().getShardId().getIndex().getUUID(), aliasFilter);
}
}
final String id = SearchContextId.encode(queryResults.asList(), aliasFilters, version);
final SearchContextId context = SearchContextId.decode(namedWriteableRegistry, id);
assertThat(context.shards().keySet(), hasSize(3));
assertThat(context.aliasFilter(), equalTo(aliasFilters));
SearchContextIdForNode node1 = context.shards().get(new ShardId("idx", "uuid1", 2));
assertThat(node1.getClusterAlias(), equalTo("cluster_x"));
assertThat(node1.getNode(), equalTo("node_1"));
assertThat(node1.getSearchContextId().getId(), equalTo(1L));
assertThat(node1.getSearchContextId().getSessionId(), equalTo("a"));
SearchContextIdForNode node2 = context.shards().get(new ShardId("idy", "uuid2", 42));
assertThat(node2.getClusterAlias(), equalTo("cluster_y"));
assertThat(node2.getNode(), equalTo("node_2"));
assertThat(node2.getSearchContextId().getId(), equalTo(12L));
assertThat(node2.getSearchContextId().getSessionId(), equalTo("b"));
SearchContextIdForNode node3 = context.shards().get(new ShardId("idy", "uuid2", 43));
assertThat(node3.getClusterAlias(), nullValue());
assertThat(node3.getNode(), equalTo("node_3"));
assertThat(node3.getSearchContextId().getId(), equalTo(42L));
assertThat(node3.getSearchContextId().getSessionId(), equalTo("c"));
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class ClusterSerializationTests method testSnapshotDeletionsInProgressSerialization.
public void testSnapshotDeletionsInProgressSerialization() throws Exception {
boolean includeRestore = randomBoolean();
ClusterState.Builder builder = ClusterState.builder(ClusterState.EMPTY_STATE).putCustom(SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress.of(Collections.singletonList(new SnapshotDeletionsInProgress.Entry(Collections.singletonList(new SnapshotId("snap1", UUIDs.randomBase64UUID())), "repo1", randomNonNegativeLong(), randomNonNegativeLong(), SnapshotDeletionsInProgress.State.STARTED))));
if (includeRestore) {
builder.putCustom(RestoreInProgress.TYPE, new RestoreInProgress.Builder().add(new RestoreInProgress.Entry(UUIDs.randomBase64UUID(), new Snapshot("repo2", new SnapshotId("snap2", UUIDs.randomBase64UUID())), RestoreInProgress.State.STARTED, Collections.singletonList("index_name"), ImmutableOpenMap.of())).build());
}
ClusterState clusterState = builder.incrementVersion().build();
Diff<ClusterState> diffs = clusterState.diff(ClusterState.EMPTY_STATE);
// serialize with current version
BytesStreamOutput outStream = new BytesStreamOutput();
Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
outStream.setVersion(version);
diffs.writeTo(outStream);
StreamInput inStream = outStream.bytes().streamInput();
inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
inStream.setVersion(version);
Diff<ClusterState> serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
ClusterState stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), notNullValue());
// remove the custom and try serializing again
clusterState = ClusterState.builder(clusterState).removeCustom(SnapshotDeletionsInProgress.TYPE).incrementVersion().build();
outStream = new BytesStreamOutput();
outStream.setVersion(version);
diffs.writeTo(outStream);
inStream = outStream.bytes().streamInput();
inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
inStream.setVersion(version);
serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
stateAfterDiffs = serializedDiffs.apply(stateAfterDiffs);
assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), notNullValue());
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class ClusterSerializationTests method testCustomSerialization.
public void testCustomSerialization() throws Exception {
ClusterState.Builder builder = ClusterState.builder(ClusterState.EMPTY_STATE).putCustom(TestCustomOne.TYPE, new TestCustomOne("test_custom_one")).putCustom(TestCustomTwo.TYPE, new TestCustomTwo(10));
ClusterState clusterState = builder.incrementVersion().build();
Diff<ClusterState> diffs = clusterState.diff(ClusterState.EMPTY_STATE);
// Add the new customs to named writeables
final List<NamedWriteableRegistry.Entry> entries = ClusterModule.getNamedWriteables();
entries.add(new NamedWriteableRegistry.Entry(ClusterState.Custom.class, TestCustomOne.TYPE, TestCustomOne::new));
entries.add(new NamedWriteableRegistry.Entry(NamedDiff.class, TestCustomOne.TYPE, TestCustomOne::readDiffFrom));
entries.add(new NamedWriteableRegistry.Entry(ClusterState.Custom.class, TestCustomTwo.TYPE, TestCustomTwo::new));
entries.add(new NamedWriteableRegistry.Entry(NamedDiff.class, TestCustomTwo.TYPE, TestCustomTwo::readDiffFrom));
// serialize with current version
BytesStreamOutput outStream = new BytesStreamOutput();
Version version = Version.CURRENT;
outStream.setVersion(version);
diffs.writeTo(outStream);
StreamInput inStream = outStream.bytes().streamInput();
inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(entries));
inStream.setVersion(version);
Diff<ClusterState> serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
ClusterState stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
// Current version - Both the customs are non null
assertThat(stateAfterDiffs.custom(TestCustomOne.TYPE), notNullValue());
assertThat(stateAfterDiffs.custom(TestCustomTwo.TYPE), notNullValue());
// serialize with minimum compatibile version
outStream = new BytesStreamOutput();
version = Version.CURRENT.minimumCompatibilityVersion();
outStream.setVersion(version);
diffs.writeTo(outStream);
inStream = outStream.bytes().streamInput();
inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(entries));
inStream.setVersion(version);
serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
// Old version - TestCustomOne is null and TestCustomTwo is not null
assertThat(stateAfterDiffs.custom(TestCustomOne.TYPE), nullValue());
assertThat(stateAfterDiffs.custom(TestCustomTwo.TYPE), notNullValue());
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class VersionsTests method testLuceneVersionOnUnknownVersions.
public void testLuceneVersionOnUnknownVersions() {
// between two known versions, should use the lucene version of the previous version
Version version = LegacyESVersion.fromString("7.10.50");
assertEquals(VersionUtils.getPreviousVersion(Version.fromString("7.10.3")).luceneVersion, version.luceneVersion);
// too old version, major should be the oldest supported lucene version minus 1
version = LegacyESVersion.fromString("5.2.1");
assertEquals(VersionUtils.getFirstVersion().luceneVersion.major - 1, version.luceneVersion.major);
// future version, should be the same version as today
version = Version.fromString("2.77.1");
assertEquals(Version.CURRENT.luceneVersion, version.luceneVersion);
}
Aggregations