Use task builder instead of creating persistent tasks directly.

This commit is contained in:
Martijn van Groningen 2017-04-12 16:02:48 +02:00
parent abd9ae399c
commit 4771965931
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
2 changed files with 9 additions and 6 deletions

View File

@ -499,7 +499,6 @@ public final class PersistentTasksCustomMetaData extends AbstractNamedDiffable<M
return lastAllocationId;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("last_allocation_id", lastAllocationId);
@ -524,10 +523,10 @@ public final class PersistentTasksCustomMetaData extends AbstractNamedDiffable<M
private long lastAllocationId;
private boolean changed;
public Builder() {
private Builder() {
}
public Builder(PersistentTasksCustomMetaData tasksInProgress) {
private Builder(PersistentTasksCustomMetaData tasksInProgress) {
if (tasksInProgress != null) {
tasks.putAll(tasksInProgress.tasks);
lastAllocationId = tasksInProgress.lastAllocationId;
@ -536,6 +535,10 @@ public final class PersistentTasksCustomMetaData extends AbstractNamedDiffable<M
}
}
public long getLastAllocationId() {
return lastAllocationId;
}
private Builder setLastAllocationId(long currentId) {
this.lastAllocationId = currentId;
return this;

View File

@ -87,7 +87,7 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ
@Override
protected Custom makeTestChanges(Custom testInstance) {
Builder builder = new Builder((PersistentTasksCustomMetaData) testInstance);
Builder builder = PersistentTasksCustomMetaData.builder((PersistentTasksCustomMetaData) testInstance);
switch (randomInt(3)) {
case 0:
addRandomTask(builder);
@ -209,9 +209,9 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ
for (int i = 0; i < randomIntBetween(10, 100); i++) {
final Builder builder;
if (randomBoolean()) {
builder = new Builder();
builder = PersistentTasksCustomMetaData.builder();
} else {
builder = new Builder(persistentTasks);
builder = PersistentTasksCustomMetaData.builder(persistentTasks);
}
boolean changed = false;
for (int j = 0; j < randomIntBetween(1, 10); j++) {