|
19 | 19 |
|
20 | 20 | package org.elasticsearch.client.ccr;
|
21 | 21 |
|
| 22 | +import org.elasticsearch.action.support.ActiveShardCount; |
| 23 | +import org.elasticsearch.client.AbstractRequestTestCase; |
22 | 24 | import org.elasticsearch.common.unit.ByteSizeValue;
|
23 | 25 | import org.elasticsearch.common.unit.TimeValue;
|
24 |
| -import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
25 |
| -import org.elasticsearch.common.xcontent.ObjectParser; |
26 | 26 | import org.elasticsearch.common.xcontent.XContentParser;
|
27 |
| -import org.elasticsearch.test.AbstractXContentTestCase; |
| 27 | +import org.elasticsearch.xpack.core.ccr.action.FollowParameters; |
| 28 | +import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; |
28 | 29 |
|
29 | 30 | import java.io.IOException;
|
30 | 31 |
|
31 |
| -public class PutFollowRequestTests extends AbstractXContentTestCase<PutFollowRequest> { |
| 32 | +import static org.hamcrest.Matchers.equalTo; |
32 | 33 |
|
33 |
| - private static final ConstructingObjectParser<PutFollowRequest, Void> PARSER = new ConstructingObjectParser<>("test_parser", |
34 |
| - true, (args) -> new PutFollowRequest((String) args[0], (String) args[1], "followerIndex")); |
35 |
| - |
36 |
| - static { |
37 |
| - PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.REMOTE_CLUSTER_FIELD); |
38 |
| - PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.LEADER_INDEX_FIELD); |
39 |
| - PARSER.declareInt(PutFollowRequest::setMaxReadRequestOperationCount, PutFollowRequest.MAX_READ_REQUEST_OPERATION_COUNT); |
40 |
| - PARSER.declareField( |
41 |
| - PutFollowRequest::setMaxReadRequestSize, |
42 |
| - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), PutFollowRequest.MAX_READ_REQUEST_SIZE.getPreferredName()), |
43 |
| - PutFollowRequest.MAX_READ_REQUEST_SIZE, |
44 |
| - ObjectParser.ValueType.STRING); |
45 |
| - PARSER.declareInt(PutFollowRequest::setMaxOutstandingReadRequests, PutFollowRequest.MAX_OUTSTANDING_READ_REQUESTS); |
46 |
| - PARSER.declareInt(PutFollowRequest::setMaxWriteRequestOperationCount, PutFollowRequest.MAX_WRITE_REQUEST_OPERATION_COUNT); |
47 |
| - PARSER.declareField( |
48 |
| - PutFollowRequest::setMaxWriteRequestSize, |
49 |
| - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), PutFollowRequest.MAX_WRITE_REQUEST_SIZE.getPreferredName()), |
50 |
| - PutFollowRequest.MAX_WRITE_REQUEST_SIZE, |
51 |
| - ObjectParser.ValueType.STRING); |
52 |
| - PARSER.declareInt(PutFollowRequest::setMaxOutstandingWriteRequests, PutFollowRequest.MAX_OUTSTANDING_WRITE_REQUESTS); |
53 |
| - PARSER.declareInt(PutFollowRequest::setMaxWriteBufferCount, PutFollowRequest.MAX_WRITE_BUFFER_COUNT); |
54 |
| - PARSER.declareField( |
55 |
| - PutFollowRequest::setMaxWriteBufferSize, |
56 |
| - (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), PutFollowRequest.MAX_WRITE_BUFFER_SIZE.getPreferredName()), |
57 |
| - PutFollowRequest.MAX_WRITE_BUFFER_SIZE, |
58 |
| - ObjectParser.ValueType.STRING); |
59 |
| - PARSER.declareField( |
60 |
| - PutFollowRequest::setMaxRetryDelay, |
61 |
| - (p, c) -> TimeValue.parseTimeValue(p.text(), PutFollowRequest.MAX_RETRY_DELAY_FIELD.getPreferredName()), |
62 |
| - PutFollowRequest.MAX_RETRY_DELAY_FIELD, |
63 |
| - ObjectParser.ValueType.STRING); |
64 |
| - PARSER.declareField( |
65 |
| - PutFollowRequest::setReadPollTimeout, |
66 |
| - (p, c) -> TimeValue.parseTimeValue(p.text(), PutFollowRequest.READ_POLL_TIMEOUT.getPreferredName()), |
67 |
| - PutFollowRequest.READ_POLL_TIMEOUT, |
68 |
| - ObjectParser.ValueType.STRING); |
69 |
| - } |
70 |
| - |
71 |
| - @Override |
72 |
| - protected PutFollowRequest doParseInstance(XContentParser parser) throws IOException { |
73 |
| - return PARSER.apply(parser, null); |
74 |
| - } |
75 |
| - |
76 |
| - @Override |
77 |
| - protected boolean supportsUnknownFields() { |
78 |
| - return false; |
79 |
| - } |
| 34 | +public class PutFollowRequestTests extends AbstractRequestTestCase<PutFollowRequest, PutFollowAction.Request> { |
80 | 35 |
|
81 | 36 | @Override
|
82 |
| - protected PutFollowRequest createTestInstance() { |
| 37 | + protected PutFollowRequest createClientTestInstance() { |
83 | 38 | PutFollowRequest putFollowRequest =
|
84 | 39 | new PutFollowRequest(randomAlphaOfLength(4), randomAlphaOfLength(4), "followerIndex");
|
85 | 40 | if (randomBoolean()) {
|
@@ -115,4 +70,30 @@ protected PutFollowRequest createTestInstance() {
|
115 | 70 | return putFollowRequest;
|
116 | 71 | }
|
117 | 72 |
|
| 73 | + @Override |
| 74 | + protected PutFollowAction.Request doParseToServerInstance(XContentParser parser) throws IOException { |
| 75 | + return PutFollowAction.Request.fromXContent(parser, "followerIndex", ActiveShardCount.DEFAULT); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + protected void assertInstances(PutFollowAction.Request serverInstance, PutFollowRequest clientTestInstance) { |
| 80 | + assertThat(serverInstance.getRemoteCluster(), equalTo(clientTestInstance.getRemoteCluster())); |
| 81 | + assertThat(serverInstance.getLeaderIndex(), equalTo(clientTestInstance.getLeaderIndex())); |
| 82 | + assertThat(serverInstance.getFollowerIndex(), equalTo(clientTestInstance.getFollowerIndex())); |
| 83 | + assertFollowConfig(serverInstance.getParameters(), clientTestInstance); |
| 84 | + } |
| 85 | + |
| 86 | + static void assertFollowConfig(FollowParameters serverParameters, FollowConfig clientConfig) { |
| 87 | + assertThat(serverParameters.getMaxReadRequestOperationCount(), equalTo(clientConfig.getMaxReadRequestOperationCount())); |
| 88 | + assertThat(serverParameters.getMaxWriteRequestOperationCount(), equalTo(clientConfig.getMaxWriteRequestOperationCount())); |
| 89 | + assertThat(serverParameters.getMaxOutstandingReadRequests(), equalTo(clientConfig.getMaxOutstandingReadRequests())); |
| 90 | + assertThat(serverParameters.getMaxOutstandingWriteRequests(), equalTo(clientConfig.getMaxOutstandingWriteRequests())); |
| 91 | + assertThat(serverParameters.getMaxReadRequestSize(), equalTo(clientConfig.getMaxReadRequestSize())); |
| 92 | + assertThat(serverParameters.getMaxWriteRequestSize(), equalTo(clientConfig.getMaxWriteRequestSize())); |
| 93 | + assertThat(serverParameters.getMaxWriteBufferCount(), equalTo(clientConfig.getMaxWriteBufferCount())); |
| 94 | + assertThat(serverParameters.getMaxWriteBufferSize(), equalTo(clientConfig.getMaxWriteBufferSize())); |
| 95 | + assertThat(serverParameters.getMaxRetryDelay(), equalTo(clientConfig.getMaxRetryDelay())); |
| 96 | + assertThat(serverParameters.getReadPollTimeout(), equalTo(clientConfig.getReadPollTimeout())); |
| 97 | + } |
| 98 | + |
118 | 99 | }
|
0 commit comments