Watcher: Putting a watch now stores its state correctly

The active state was not serialized in the PutWatchRequest leading to
to always setting it to active, when a different node than the master
node was hit with a put watch request.

Closes elastic/elasticsearch#2490

Original commit: elastic/x-pack-elasticsearch@060c0fa35f
This commit is contained in:
Alexander Reelsen 2016-06-13 15:07:33 +02:00
parent aa292561c0
commit acc692bf68
2 changed files with 36 additions and 0 deletions

View File

@ -114,6 +114,7 @@ public class PutWatchRequest extends MasterNodeRequest<PutWatchRequest> {
super.readFrom(in);
id = in.readString();
source = in.readBytesReference();
active = in.readBoolean();
}
@Override
@ -121,6 +122,7 @@ public class PutWatchRequest extends MasterNodeRequest<PutWatchRequest> {
super.writeTo(out);
out.writeString(id);
out.writeBytesReference(source);
out.writeBoolean(active);
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.watcher.transport.action.put;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchRequest;
import static org.hamcrest.Matchers.is;
public class PutWatchSerializationTests extends ESTestCase {
// https://github.com/elastic/x-plugins/issues/2490
public void testPutWatchSerialization() throws Exception {
PutWatchRequest request = new PutWatchRequest();
request.setId(randomAsciiOfLength(10));
request.setActive(randomBoolean());
request.setSource(new BytesArray(randomAsciiOfLength(20)));
BytesStreamOutput streamOutput = new BytesStreamOutput();
request.writeTo(streamOutput);
PutWatchRequest readRequest = new PutWatchRequest();
readRequest.readFrom(streamOutput.bytes().streamInput());
assertThat(readRequest.isActive(), is(request.isActive()));
assertThat(readRequest.getId(), is(request.getId()));
assertThat(readRequest.getSource(), is(request.getSource()));
}
}