Skip to content

Commit

Permalink
Reduce the number of cluster start/stops for Metadata end to end tests
Browse files Browse the repository at this point in the history
After recently reviewing metadata migration end to end test cases I
noticed there was 56 different tests, this was a large increase, taking
nearly 20 minutes of runtime.  Reviewing the parameters of the tests
I'm running evuaulate and then immediately following migrate, this
should reduce the test cases by nearly half and increase of coverag
using http and snapshot sources.

I have tweaked how we use templates moving back to the logic of
legacy templates for ES 6.X and using both index and index compontent
templates for future ES versions, which should be another 30%
redunction.

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Dec 9, 2024
1 parent fc62f57 commit ad90bda
Showing 1 changed file with 20 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opensearch.migrations;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand All @@ -28,7 +27,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import org.opensearch.migrations.VersionMatchers;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -48,39 +47,28 @@ class EndToEndTest {

private static Stream<Arguments> scenarios() {
return SupportedClusters.sources().stream()
.flatMap(sourceCluster -> {
// Determine applicable template types based on source version
List<TemplateType> templateTypes = Stream.concat(
Stream.of(TemplateType.Legacy),
(sourceCluster.getVersion().getMajor() >= 7
? Stream.of(TemplateType.Index, TemplateType.IndexAndComponent)
: Stream.empty()))
.collect(Collectors.toList());

return SupportedClusters.targets().stream()
.flatMap(targetCluster -> templateTypes.stream().flatMap(templateType -> {
// Generate arguments for both HTTP and SnapshotImage transfer mediums
Stream<Arguments> httpArgs = Arrays.stream(MetadataCommands.values())
.map(command -> Arguments.of(sourceCluster, targetCluster, TransferMedium.Http, command, templateType));

Stream<Arguments> snapshotArgs = Stream.of(
Arguments.of(sourceCluster, targetCluster, TransferMedium.SnapshotImage, MetadataCommands.MIGRATE, templateType)
);

return Stream.concat(httpArgs, snapshotArgs);
}));
});
.flatMap(sourceCluster ->
SupportedClusters.targets().stream()
.flatMap(targetCluster ->
Stream.concat(
Stream.of(Arguments.of(sourceCluster, targetCluster, TransferMedium.Http)),
Stream.of(Arguments.of(sourceCluster, targetCluster, TransferMedium.SnapshotImage))
)
)
);
}

@ParameterizedTest(name = "From version {0} to version {1}, Command {2}, Medium of transfer {3}, and Template Type {4}")
@ParameterizedTest(name = "From version {0} to version {1}, Command {2}")
@MethodSource(value = "scenarios")
void metadataCommand(ContainerVersion sourceVersion, ContainerVersion targetVersion, TransferMedium medium,
MetadataCommands command, TemplateType templateType) {
void metadataCommand(ContainerVersion sourceVersion, ContainerVersion targetVersion, TransferMedium medium) {
var templateType = VersionMatchers.isES_6_X.test(sourceVersion.getVersion())
? TemplateType.Legacy : TemplateType.IndexAndComponent;
try (
final var sourceCluster = new SearchClusterContainer(sourceVersion);
final var targetCluster = new SearchClusterContainer(targetVersion)
) {
metadataCommandOnClusters(sourceCluster, targetCluster, medium, command, templateType);
metadataCommandOnClusters(sourceCluster, targetCluster, medium, MetadataCommands.EVALUATE, templateType);
metadataCommandOnClusters(sourceCluster, targetCluster, medium, MetadataCommands.MIGRATE, templateType);
}
}

Expand All @@ -91,7 +79,6 @@ private enum TransferMedium {

private enum TemplateType {
Legacy,
Index,
IndexAndComponent
}

Expand All @@ -114,9 +101,8 @@ private void metadataCommandOnClusters(
var sourceClusterOperations = new ClusterOperations(sourceCluster.getUrl());
if (templateType == TemplateType.Legacy) {
sourceClusterOperations.createLegacyTemplate(testData.indexTemplateName, "blog*");
} else if (templateType == TemplateType.Index) {
sourceClusterOperations.createIndexTemplate(testData.indexTemplateName, "author", "blog*");
} else if (templateType == TemplateType.IndexAndComponent) {
sourceClusterOperations.createIndexTemplate(testData.indexTemplateName, "author", "blog*");
sourceClusterOperations.createComponentTemplate(testData.compoTemplateName, testData.indexTemplateName, "author", "blog*");
}

Expand Down Expand Up @@ -262,13 +248,11 @@ private void verifyTargetCluster(
if (templateType.equals(TemplateType.Legacy)) {
res = targetClusterOperations.get("/_template/" + testData.indexTemplateName);
assertThat(res.getValue(), res.getKey(), verifyResponseCode);
} else if(templateType.equals(TemplateType.Index) || templateType.equals(TemplateType.IndexAndComponent)) {
} else if(templateType.equals(TemplateType.IndexAndComponent)) {
res = targetClusterOperations.get("/_index_template/" + testData.indexTemplateName);
assertThat(res.getValue(), res.getKey(), verifyResponseCode);
if (templateType.equals(TemplateType.IndexAndComponent)) {
var verifyBodyHasComponentTemplate = containsString("composed_of\":[\"" + testData.compoTemplateName + "\"]");
assertThat(res.getValue(), expectUpdatesOnTarget ? verifyBodyHasComponentTemplate : not(verifyBodyHasComponentTemplate));
}
var verifyBodyHasComponentTemplate = containsString("composed_of\":[\"" + testData.compoTemplateName + "\"]");
assertThat(res.getValue(), expectUpdatesOnTarget ? verifyBodyHasComponentTemplate : not(verifyBodyHasComponentTemplate));
}
}
}

0 comments on commit ad90bda

Please sign in to comment.