More test changes
This commit is contained in:
parent
a9703d4a56
commit
75704510e1
|
@ -144,30 +144,30 @@ public class IndexLifecycleMetadata implements MetaData.Custom {
|
|||
public static class IndexLifecycleMetadataDiff implements NamedDiff<MetaData.Custom> {
|
||||
|
||||
final Diff<Map<String, LifecyclePolicy>> policies;
|
||||
final Long pollInterval;
|
||||
final Long pollIntervalDiff;
|
||||
|
||||
IndexLifecycleMetadataDiff(IndexLifecycleMetadata before, IndexLifecycleMetadata after) {
|
||||
this.policies = DiffableUtils.diff(before.policies, after.policies, DiffableUtils.getStringKeySerializer());
|
||||
this.pollInterval = after.pollInterval;
|
||||
this.pollIntervalDiff = after.pollInterval - before.pollInterval;
|
||||
}
|
||||
|
||||
public IndexLifecycleMetadataDiff(StreamInput in) throws IOException {
|
||||
this.policies = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), LifecyclePolicy::new,
|
||||
IndexLifecycleMetadataDiff::readLifecyclePolicyDiffFrom);
|
||||
this.pollInterval = in.readVLong();
|
||||
this.pollIntervalDiff = in.readZLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaData.Custom apply(MetaData.Custom part) {
|
||||
TreeMap<String, LifecyclePolicy> newPolicies = new TreeMap<>(policies.apply(((IndexLifecycleMetadata) part).policies));
|
||||
long pollInterval = ((IndexLifecycleMetadata) part).pollInterval;
|
||||
long pollInterval = ((IndexLifecycleMetadata) part).pollInterval + pollIntervalDiff;
|
||||
return new IndexLifecycleMetadata(newPolicies, pollInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
policies.writeTo(out);
|
||||
out.writeVLong(pollInterval);
|
||||
out.writeZLong(pollIntervalDiff);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -170,7 +170,8 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy> implement
|
|||
return false;
|
||||
}
|
||||
LifecyclePolicy other = (LifecyclePolicy) obj;
|
||||
return Objects.equals(name, other.name) && Objects.equals(phases, other.phases);
|
||||
return Objects.equals(name, other.name) &&
|
||||
Objects.equals(phases, other.phases);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -74,6 +74,10 @@ public class GetLifecycleAction
|
|||
this.policy = policy;
|
||||
}
|
||||
|
||||
public LifecyclePolicy getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
policy.toXContent(builder, params);
|
||||
|
|
|
@ -5,23 +5,28 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.cluster.Diff;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractSerializingTestCase;
|
||||
import org.elasticsearch.test.AbstractDiffableSerializationTestCase;
|
||||
import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata.IndexLifecycleMetadataDiff;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class IndexLifecycleMetadataTests extends AbstractSerializingTestCase<IndexLifecycleMetadata> {
|
||||
public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTestCase<MetaData.Custom> {
|
||||
|
||||
private NamedXContentRegistry registry;
|
||||
|
||||
|
@ -65,7 +70,7 @@ public class IndexLifecycleMetadataTests extends AbstractSerializingTestCase<Ind
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Reader<IndexLifecycleMetadata> instanceReader() {
|
||||
protected Reader<MetaData.Custom> instanceReader() {
|
||||
return IndexLifecycleMetadata::new;
|
||||
}
|
||||
|
||||
|
@ -74,4 +79,34 @@ public class IndexLifecycleMetadataTests extends AbstractSerializingTestCase<Ind
|
|||
Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetaData.Custom mutateInstance(MetaData.Custom instance) {
|
||||
IndexLifecycleMetadata metadata = (IndexLifecycleMetadata) instance;
|
||||
SortedMap<String, LifecyclePolicy> policies = metadata.getPolicies();
|
||||
long pollInterval = metadata.getPollInterval();
|
||||
switch (between(0, 1)) {
|
||||
case 0:
|
||||
pollInterval = pollInterval + randomIntBetween(1, 1000);
|
||||
break;
|
||||
case 1:
|
||||
policies = new TreeMap<>(policies);
|
||||
String policyName = randomAlphaOfLength(10);
|
||||
policies.put(policyName, new LifecyclePolicy(policyName, Collections.emptyList()));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
return new IndexLifecycleMetadata(policies, pollInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Custom makeTestChanges(Custom testInstance) {
|
||||
return mutateInstance(testInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Reader<Diff<Custom>> diffReader() {
|
||||
return IndexLifecycleMetadataDiff::new;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.junit.Before;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecyclePolicy> {
|
||||
|
@ -69,4 +70,23 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
|
|||
Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LifecyclePolicy mutateInstance(LifecyclePolicy instance) throws IOException {
|
||||
String name = instance.getName();
|
||||
List<Phase> phases = instance.getPhases();
|
||||
switch (between(0, 1)) {
|
||||
case 0:
|
||||
name = name + randomAlphaOfLengthBetween(1, 5);
|
||||
break;
|
||||
case 1:
|
||||
phases = new ArrayList<>(phases);
|
||||
phases.add(new Phase(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueSeconds(randomIntBetween(1, 1000)),
|
||||
Collections.emptyList()));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
return new LifecyclePolicy(name, phases);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,4 +60,26 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
|
|||
.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Phase mutateInstance(Phase instance) throws IOException {
|
||||
String name = instance.getName();
|
||||
TimeValue after = instance.getAfter();
|
||||
List<LifecycleAction> actions = instance.getActions();
|
||||
switch (between(0, 2)) {
|
||||
case 0:
|
||||
name = name + randomAlphaOfLengthBetween(1, 5);
|
||||
break;
|
||||
case 1:
|
||||
after = TimeValue.timeValueSeconds(after.getSeconds() + randomIntBetween(1, 1000));
|
||||
break;
|
||||
case 2:
|
||||
actions = new ArrayList<>(actions);
|
||||
actions.add(new DeleteAction());
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
return new Phase(name, after, actions);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.indexlifecycle.action;
|
||||
|
||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils.MutateFunction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.action.DeleteLifecycleAction.Request;
|
||||
|
||||
public class DeleteLifecycleRequestTests extends AbstractStreamableTestCase<DeleteLifecycleAction.Request> {
|
||||
|
@ -20,4 +21,9 @@ public class DeleteLifecycleRequestTests extends AbstractStreamableTestCase<Dele
|
|||
return new Request();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutateFunction<Request> getMutateFunction() {
|
||||
return resp -> new Request(resp.getPolicyName() + randomAlphaOfLengthBetween(1, 10));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.indexlifecycle.action;
|
||||
|
||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils.MutateFunction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.action.DeleteLifecycleAction.Response;
|
||||
|
||||
public class DeleteLifecycleResponseTests extends AbstractStreamableTestCase<DeleteLifecycleAction.Response> {
|
||||
|
@ -20,4 +21,9 @@ public class DeleteLifecycleResponseTests extends AbstractStreamableTestCase<Del
|
|||
return new Response();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutateFunction<Response> getMutateFunction() {
|
||||
return resp -> new Response(resp.isAcknowledged() == false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.indexlifecycle.action;
|
||||
|
||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils.MutateFunction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.action.GetLifecycleAction.Request;
|
||||
|
||||
public class GetLifecycleRequestTests extends AbstractStreamableTestCase<GetLifecycleAction.Request> {
|
||||
|
@ -20,4 +21,9 @@ public class GetLifecycleRequestTests extends AbstractStreamableTestCase<GetLife
|
|||
return new Request();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutateFunction<Request> getMutateFunction() {
|
||||
return resp -> new Request(resp.getPolicyName() + randomAlphaOfLengthBetween(1, 10));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.indexlifecycle.action;
|
|||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils.MutateFunction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.DeleteAction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.LifecycleAction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy;
|
||||
|
@ -17,6 +18,7 @@ import org.junit.Before;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GetLifecycleResponseTests extends AbstractStreamableTestCase<GetLifecycleAction.Response> {
|
||||
|
@ -54,4 +56,26 @@ public class GetLifecycleResponseTests extends AbstractStreamableTestCase<GetLif
|
|||
Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutateFunction<Response> getMutateFunction() {
|
||||
return resp -> {
|
||||
LifecyclePolicy policy = resp.getPolicy();
|
||||
String name = policy.getName();
|
||||
List<Phase> phases = policy.getPhases();
|
||||
switch (between(0, 1)) {
|
||||
case 0:
|
||||
name = name + randomAlphaOfLengthBetween(1, 5);
|
||||
break;
|
||||
case 1:
|
||||
phases = new ArrayList<>(phases);
|
||||
phases.add(new Phase(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueSeconds(randomIntBetween(1, 1000)),
|
||||
Collections.emptyList()));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
return new Response(new LifecyclePolicy(name, phases));
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils.MutateFunction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.DeleteAction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.LifecycleAction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy;
|
||||
|
@ -20,6 +21,7 @@ import org.junit.Before;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase<PutLifecycleAction.Request> {
|
||||
|
@ -70,4 +72,26 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutateFunction<Request> getMutateFunction() {
|
||||
return resp -> {
|
||||
LifecyclePolicy policy = resp.getPolicy();
|
||||
String name = policy.getName();
|
||||
List<Phase> phases = policy.getPhases();
|
||||
switch (between(0, 1)) {
|
||||
case 0:
|
||||
name = name + randomAlphaOfLengthBetween(1, 5);
|
||||
break;
|
||||
case 1:
|
||||
phases = new ArrayList<>(phases);
|
||||
phases.add(new Phase(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueSeconds(randomIntBetween(1, 1000)),
|
||||
Collections.emptyList()));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
return new Request(new LifecyclePolicy(name, phases));
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.indexlifecycle.action;
|
||||
|
||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils.MutateFunction;
|
||||
import org.elasticsearch.xpack.indexlifecycle.action.PutLifecycleAction.Response;
|
||||
|
||||
public class PutLifecycleResponseTests extends AbstractStreamableTestCase<PutLifecycleAction.Response> {
|
||||
|
@ -20,4 +21,9 @@ public class PutLifecycleResponseTests extends AbstractStreamableTestCase<PutLif
|
|||
return new Response();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutateFunction<Response> getMutateFunction() {
|
||||
return resp -> new Response(resp.isAcknowledged() == false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue