Skip to content

Commit 981884a

Browse files
committed
Merge branch '6.x' into ccr-6.x
* 6.x: Revert "Silence IndexUpgradeIT test failures. (#30430)" [DOCS] Remove references to changelog and to highlights Revert "Mute ML upgrade test (#30458)" [ML] Fix BWC version for backport of #30125 [Docs] Improve section detailing translog usage (#30573) [Tests] Relax allowed delta in extended_stats aggregation (#30569) Fail if reading from closed KeyStoreWrapper (#30394) [ML] Reverse engineer Grok patterns from categorization results (#30125) Derive max composite buffers from max content len Update build file due to doc file rename SQL: Extract SQL request and response classes (#30457) Remove the changelog (#30593) Revert "Add deprecation warning for default shards (#30587)" Silence IndexUpgradeIT test failures. (#30430) Add deprecation warning for default shards (#30587) [DOCS] Adds 6.4.0 release highlight pages [DOCS] Adds release highlight pages (#30590) Docs: Document how to rebuild analyzers (#30498) [DOCS] Fixes title capitalization in security content LLRest: Add equals and hashcode tests for Request (#30584) [DOCS] Fix realm setting names (#30499) [DOCS] Fix path info for various security files (#30502) Docs: document precision limitations of geo_bounding_box (#30540) Fix non existing javadocs link in RestClientTests Auto-expand replicas only after failing nodes (#30553)
2 parents 1325c25 + 513e297 commit 981884a

File tree

136 files changed

+2276
-6455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+2276
-6455
lines changed

client/rest/src/test/java/org/elasticsearch/client/RequestTests.java

+101-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626

2727
import org.apache.http.Header;
2828
import org.apache.http.HttpEntity;
29+
import org.apache.http.entity.ByteArrayEntity;
2930
import org.apache.http.entity.ContentType;
3031
import org.apache.http.entity.StringEntity;
3132
import org.apache.http.message.BasicHeader;
3233
import org.apache.http.nio.entity.NStringEntity;
34+
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory;
3335

3436
import static org.junit.Assert.assertArrayEquals;
3537
import static org.junit.Assert.assertEquals;
38+
import static org.junit.Assert.assertNotEquals;
3639
import static org.junit.Assert.assertNull;
3740
import static org.junit.Assert.fail;
3841

@@ -151,6 +154,103 @@ public void testSetHeaders() {
151154
assertArrayEquals(headers, request.getHeaders());
152155
}
153156

154-
// TODO equals and hashcode
157+
public void testEqualsAndHashCode() {
158+
Request request = randomRequest();
159+
assertEquals(request, request);
155160

161+
Request copy = copy(request);
162+
assertEquals(request, copy);
163+
assertEquals(copy, request);
164+
assertEquals(request.hashCode(), copy.hashCode());
165+
166+
Request mutant = mutate(request);
167+
assertNotEquals(request, mutant);
168+
assertNotEquals(mutant, request);
169+
}
170+
171+
private Request randomRequest() {
172+
Request request = new Request(
173+
randomFrom(new String[] {"GET", "PUT", "DELETE", "POST", "HEAD", "OPTIONS"}),
174+
randomAsciiAlphanumOfLength(5));
175+
176+
int parameterCount = between(0, 5);
177+
for (int i = 0; i < parameterCount; i++) {
178+
request.addParameter(randomAsciiAlphanumOfLength(i), randomAsciiLettersOfLength(3));
179+
}
180+
181+
if (randomBoolean()) {
182+
if (randomBoolean()) {
183+
request.setJsonEntity(randomAsciiAlphanumOfLength(10));
184+
} else {
185+
request.setEntity(randomFrom(new HttpEntity[] {
186+
new StringEntity(randomAsciiAlphanumOfLength(10), ContentType.APPLICATION_JSON),
187+
new NStringEntity(randomAsciiAlphanumOfLength(10), ContentType.APPLICATION_JSON),
188+
new ByteArrayEntity(randomBytesOfLength(40), ContentType.APPLICATION_JSON)
189+
}));
190+
}
191+
}
192+
193+
if (randomBoolean()) {
194+
int headerCount = between(1, 5);
195+
Header[] headers = new Header[headerCount];
196+
for (int i = 0; i < headerCount; i++) {
197+
headers[i] = new BasicHeader(randomAsciiAlphanumOfLength(3), randomAsciiAlphanumOfLength(3));
198+
}
199+
request.setHeaders(headers);
200+
}
201+
202+
if (randomBoolean()) {
203+
request.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(1));
204+
}
205+
206+
return request;
207+
}
208+
209+
private Request copy(Request request) {
210+
Request copy = new Request(request.getMethod(), request.getEndpoint());
211+
copyMutables(request, copy);
212+
return copy;
213+
}
214+
215+
private Request mutate(Request request) {
216+
if (randomBoolean()) {
217+
// Mutate request or method but keep everything else constant
218+
Request mutant = randomBoolean()
219+
? new Request(request.getMethod() + "m", request.getEndpoint())
220+
: new Request(request.getMethod(), request.getEndpoint() + "m");
221+
copyMutables(request, mutant);
222+
return mutant;
223+
}
224+
Request mutant = copy(request);
225+
int mutationType = between(0, 3);
226+
switch (mutationType) {
227+
case 0:
228+
mutant.addParameter(randomAsciiAlphanumOfLength(mutant.getParameters().size() + 4), "extra");
229+
return mutant;
230+
case 1:
231+
mutant.setJsonEntity("mutant"); // randomRequest can't produce this value
232+
return mutant;
233+
case 2:
234+
if (mutant.getHeaders().length > 0) {
235+
mutant.setHeaders(new Header[0]);
236+
} else {
237+
mutant.setHeaders(new BasicHeader("extra", "m"));
238+
}
239+
return mutant;
240+
case 3:
241+
mutant.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(5));
242+
return mutant;
243+
default:
244+
throw new UnsupportedOperationException("Unknown mutation type [" + mutationType + "]");
245+
}
246+
}
247+
248+
private void copyMutables(Request from, Request to) {
249+
for (Map.Entry<String, String> param : from.getParameters().entrySet()) {
250+
to.addParameter(param.getKey(), param.getValue());
251+
}
252+
to.setEntity(from.getEntity());
253+
to.setHeaders(from.getHeaders());
254+
to.setHttpAsyncResponseConsumerFactory(from.getHttpAsyncResponseConsumerFactory());
255+
}
156256
}

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void onFailure(Exception exception) {
9696
}
9797

9898
/**
99-
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests#testSetParameters()}.
99+
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests#testAddParameters()}.
100100
*/
101101
@Deprecated
102102
public void testPerformOldStyleAsyncWithNullParams() throws Exception {

0 commit comments

Comments
 (0)