Fix PTCMDT#testMinVersionSerialization

This commit fixes an issue with
PersistentTasksCustomMetaDataTests#testMinVersionSerialization. There
were two problems here:
 - some versions do not have future compatible version (e.g., betas)
 - the feature logic was incorrect
This commit is contained in:
Jason Tedor 2018-06-03 21:35:01 -04:00
parent a7ceefe93f
commit 5667b08aaa
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
1 changed files with 11 additions and 5 deletions

View File

@ -53,12 +53,14 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import static org.elasticsearch.cluster.metadata.MetaData.CONTEXT_MODE_GATEWAY; import static org.elasticsearch.cluster.metadata.MetaData.CONTEXT_MODE_GATEWAY;
import static org.elasticsearch.cluster.metadata.MetaData.CONTEXT_MODE_SNAPSHOT; import static org.elasticsearch.cluster.metadata.MetaData.CONTEXT_MODE_SNAPSHOT;
import static org.elasticsearch.persistent.PersistentTasksExecutor.NO_NODE_FOUND; import static org.elasticsearch.persistent.PersistentTasksExecutor.NO_NODE_FOUND;
import static org.elasticsearch.test.VersionUtils.allReleasedVersions;
import static org.elasticsearch.test.VersionUtils.compatibleFutureVersion; import static org.elasticsearch.test.VersionUtils.compatibleFutureVersion;
import static org.elasticsearch.test.VersionUtils.getFirstVersion; import static org.elasticsearch.test.VersionUtils.getFirstVersion;
import static org.elasticsearch.test.VersionUtils.getPreviousVersion; import static org.elasticsearch.test.VersionUtils.getPreviousVersion;
@ -247,8 +249,10 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ
public void testMinVersionSerialization() throws IOException { public void testMinVersionSerialization() throws IOException {
PersistentTasksCustomMetaData.Builder tasks = PersistentTasksCustomMetaData.builder(); PersistentTasksCustomMetaData.Builder tasks = PersistentTasksCustomMetaData.builder();
Version minVersion = getFirstVersion(); Version minVersion = allReleasedVersions().stream().filter(Version::isRelease).findFirst().orElseThrow(NoSuchElementException::new);
System.out.println(minVersion);
final Version streamVersion = randomVersionBetween(random(), minVersion, getPreviousVersion(Version.CURRENT)); final Version streamVersion = randomVersionBetween(random(), minVersion, getPreviousVersion(Version.CURRENT));
System.out.println(streamVersion);
tasks.addTask("test_compatible_version", TestPersistentTasksExecutor.NAME, tasks.addTask("test_compatible_version", TestPersistentTasksExecutor.NAME,
new TestParams(null, randomVersionBetween(random(), minVersion, streamVersion), new TestParams(null, randomVersionBetween(random(), minVersion, streamVersion),
randomBoolean() ? Optional.empty() : Optional.of("test")), randomBoolean() ? Optional.empty() : Optional.of("test")),
@ -260,12 +264,14 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ
final BytesStreamOutput out = new BytesStreamOutput(); final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(streamVersion); out.setVersion(streamVersion);
Set<String> features = new HashSet<>(); Set<String> features = new HashSet<>();
if (randomBoolean()) { final boolean transportClient = randomBoolean();
features.add("test"); if (transportClient) {
}
if (randomBoolean()) {
features.add(TransportClient.TRANSPORT_CLIENT_FEATURE); features.add(TransportClient.TRANSPORT_CLIENT_FEATURE);
} }
// if a transport client, then it must have the feature otherwise we add the feature randomly
if (transportClient || randomBoolean()) {
features.add("test");
}
out.setFeatures(features); out.setFeatures(features);
tasks.build().writeTo(out); tasks.build().writeTo(out);