|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.client.ccr; |
| 21 | + |
| 22 | +import org.elasticsearch.common.unit.ByteSizeValue; |
| 23 | +import org.elasticsearch.common.unit.TimeValue; |
| 24 | +import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
| 25 | +import org.elasticsearch.common.xcontent.ObjectParser; |
| 26 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 27 | +import org.elasticsearch.test.AbstractXContentTestCase; |
| 28 | + |
| 29 | +import java.io.IOException; |
| 30 | +import java.util.Arrays; |
| 31 | +import java.util.List; |
| 32 | + |
| 33 | +public class PutAutoFollowPatternRequestTests extends AbstractXContentTestCase<PutAutoFollowPatternRequest> { |
| 34 | + |
| 35 | + @SuppressWarnings("unchecked") |
| 36 | + private static final ConstructingObjectParser<PutAutoFollowPatternRequest, Void> PARSER = new ConstructingObjectParser<>("test_parser", |
| 37 | + true, (args) -> new PutAutoFollowPatternRequest("name", (String) args[0], (List<String>) args[1])); |
| 38 | + |
| 39 | + static { |
| 40 | + PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.REMOTE_CLUSTER_FIELD); |
| 41 | + PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), PutAutoFollowPatternRequest.LEADER_PATTERNS_FIELD); |
| 42 | + PARSER.declareString(PutAutoFollowPatternRequest::setFollowIndexNamePattern, PutAutoFollowPatternRequest.FOLLOW_PATTERN_FIELD); |
| 43 | + PARSER.declareInt(PutAutoFollowPatternRequest::setMaxReadRequestOperationCount, FollowConfig.MAX_READ_REQUEST_OPERATION_COUNT); |
| 44 | + PARSER.declareField( |
| 45 | + PutAutoFollowPatternRequest::setMaxReadRequestSize, |
| 46 | + (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), FollowConfig.MAX_READ_REQUEST_SIZE.getPreferredName()), |
| 47 | + PutFollowRequest.MAX_READ_REQUEST_SIZE, |
| 48 | + ObjectParser.ValueType.STRING); |
| 49 | + PARSER.declareInt(PutAutoFollowPatternRequest::setMaxOutstandingReadRequests, FollowConfig.MAX_OUTSTANDING_READ_REQUESTS); |
| 50 | + PARSER.declareInt(PutAutoFollowPatternRequest::setMaxWriteRequestOperationCount, FollowConfig.MAX_WRITE_REQUEST_OPERATION_COUNT); |
| 51 | + PARSER.declareField( |
| 52 | + PutAutoFollowPatternRequest::setMaxWriteRequestSize, |
| 53 | + (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), FollowConfig.MAX_WRITE_REQUEST_SIZE.getPreferredName()), |
| 54 | + PutFollowRequest.MAX_WRITE_REQUEST_SIZE, |
| 55 | + ObjectParser.ValueType.STRING); |
| 56 | + PARSER.declareInt(PutAutoFollowPatternRequest::setMaxOutstandingWriteRequests, FollowConfig.MAX_OUTSTANDING_WRITE_REQUESTS); |
| 57 | + PARSER.declareInt(PutAutoFollowPatternRequest::setMaxWriteBufferCount, FollowConfig.MAX_WRITE_BUFFER_COUNT); |
| 58 | + PARSER.declareField( |
| 59 | + PutAutoFollowPatternRequest::setMaxWriteBufferSize, |
| 60 | + (p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), FollowConfig.MAX_WRITE_BUFFER_SIZE.getPreferredName()), |
| 61 | + PutFollowRequest.MAX_WRITE_BUFFER_SIZE, |
| 62 | + ObjectParser.ValueType.STRING); |
| 63 | + PARSER.declareField( |
| 64 | + PutAutoFollowPatternRequest::setMaxRetryDelay, |
| 65 | + (p, c) -> TimeValue.parseTimeValue(p.text(), FollowConfig.MAX_RETRY_DELAY_FIELD.getPreferredName()), |
| 66 | + PutFollowRequest.MAX_RETRY_DELAY_FIELD, |
| 67 | + ObjectParser.ValueType.STRING); |
| 68 | + PARSER.declareField( |
| 69 | + PutAutoFollowPatternRequest::setReadPollTimeout, |
| 70 | + (p, c) -> TimeValue.parseTimeValue(p.text(), FollowConfig.READ_POLL_TIMEOUT.getPreferredName()), |
| 71 | + PutFollowRequest.READ_POLL_TIMEOUT, |
| 72 | + ObjectParser.ValueType.STRING); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + protected PutAutoFollowPatternRequest doParseInstance(XContentParser parser) throws IOException { |
| 77 | + return PARSER.apply(parser, null); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + protected boolean supportsUnknownFields() { |
| 82 | + return true; |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + protected PutAutoFollowPatternRequest createTestInstance() { |
| 87 | + // Name isn't serialized, because it specified in url path, so no need to randomly generate it here. |
| 88 | + PutAutoFollowPatternRequest putAutoFollowPatternRequest = new PutAutoFollowPatternRequest("name", |
| 89 | + randomAlphaOfLength(4), Arrays.asList(generateRandomStringArray(4, 4, false))); |
| 90 | + if (randomBoolean()) { |
| 91 | + putAutoFollowPatternRequest.setFollowIndexNamePattern(randomAlphaOfLength(4)); |
| 92 | + } |
| 93 | + if (randomBoolean()) { |
| 94 | + putAutoFollowPatternRequest.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE)); |
| 95 | + } |
| 96 | + if (randomBoolean()) { |
| 97 | + putAutoFollowPatternRequest.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE)); |
| 98 | + } |
| 99 | + if (randomBoolean()) { |
| 100 | + putAutoFollowPatternRequest.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); |
| 101 | + } |
| 102 | + if (randomBoolean()) { |
| 103 | + putAutoFollowPatternRequest.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong())); |
| 104 | + } |
| 105 | + if (randomBoolean()) { |
| 106 | + putAutoFollowPatternRequest.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE)); |
| 107 | + } |
| 108 | + if (randomBoolean()) { |
| 109 | + putAutoFollowPatternRequest.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong())); |
| 110 | + } |
| 111 | + if (randomBoolean()) { |
| 112 | + putAutoFollowPatternRequest.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE)); |
| 113 | + } |
| 114 | + if (randomBoolean()) { |
| 115 | + putAutoFollowPatternRequest.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong())); |
| 116 | + } |
| 117 | + if (randomBoolean()) { |
| 118 | + putAutoFollowPatternRequest.setMaxRetryDelay(new TimeValue(randomNonNegativeLong())); |
| 119 | + } |
| 120 | + if (randomBoolean()) { |
| 121 | + putAutoFollowPatternRequest.setReadPollTimeout(new TimeValue(randomNonNegativeLong())); |
| 122 | + } |
| 123 | + return putAutoFollowPatternRequest; |
| 124 | + } |
| 125 | + |
| 126 | +} |
0 commit comments