Skip to content

Commit ec293c0

Browse files
committed
low level client tests to junit 5
1 parent 0554611 commit ec293c0

27 files changed

+295
-166
lines changed

java-client/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@ dependencies {
278278
// https://github.com/mockito/mockito
279279
testImplementation("org.mockito","mockito-core","5.12.0")
280280

281-
// Apache-2.0
282-
// https://github.com/randomizedtesting/randomizedtesting
283-
testImplementation("com.carrotsearch.randomizedtesting","randomizedtesting-runner","2.8.1")
284-
285281
// Apache-2.0
286282
// https://github.com/elastic/mocksocket
287283
testImplementation("org.elasticsearch","mocksocket","1.2")

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/BasicAsyncResponseConsumerTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.hc.core5.http.nio.ContentDecoder;
2929
import org.apache.hc.core5.http.protocol.HttpContext;
3030
import org.junit.Assert;
31+
import org.junit.jupiter.api.Test;
3132

3233
import java.nio.ByteBuffer;
3334

@@ -38,6 +39,7 @@ public class BasicAsyncResponseConsumerTests extends RestClientTestCase {
3839
// maximum buffer that this test ends up allocating is 50MB
3940
private static final int MAX_TEST_BUFFER_SIZE = 50 * 1024 * 1024;
4041

42+
@Test
4143
public void testResponseProcessing() throws Exception {
4244
ContentDecoder contentDecoder = mock(ContentDecoder.class);
4345
HttpContext httpContext = mock(HttpContext.class);
@@ -55,6 +57,7 @@ public void testResponseProcessing() throws Exception {
5557
consumer.consume(ByteBuffer.wrap("test".getBytes()));
5658
}
5759

60+
@Test
5861
public void testBufferLimit() throws Exception {
5962
HttpContext httpContext = mock(HttpContext.class);
6063

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/ClientsGraalVMThreadsFilter.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/DeadHostStateTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package co.elastic.clients.transport.rest5_client.low_level;
2121

22+
import org.junit.jupiter.api.Test;
23+
2224
import java.util.concurrent.TimeUnit;
2325
import java.util.concurrent.atomic.AtomicLong;
2426

@@ -36,13 +38,15 @@ public class DeadHostStateTests extends RestClientTestCase {
3638
private static long[] EXPECTED_TIMEOUTS_SECONDS = new long[]{60, 84, 120, 169, 240, 339, 480, 678, 960,
3739
1357, 1800};
3840

41+
@Test
3942
public void testInitialDeadHostStateDefaultTimeSupplier() {
4043
DeadHostState deadHostState = new DeadHostState(DeadHostState.DEFAULT_TIME_SUPPLIER);
4144
long currentTime = System.nanoTime();
4245
assertThat(deadHostState.getDeadUntilNanos(), greaterThanOrEqualTo(currentTime));
4346
assertThat(deadHostState.getFailedAttempts(), equalTo(1));
4447
}
4548

49+
@Test
4650
public void testDeadHostStateFromPreviousDefaultTimeSupplier() {
4751
DeadHostState previous = new DeadHostState(DeadHostState.DEFAULT_TIME_SUPPLIER);
4852
int iters = randomIntBetween(5, 30);
@@ -54,6 +58,7 @@ public void testDeadHostStateFromPreviousDefaultTimeSupplier() {
5458
}
5559
}
5660

61+
@Test
5762
public void testCompareToTimeSupplier() {
5863
int numObjects = randomIntBetween(EXPECTED_TIMEOUTS_SECONDS.length, 30);
5964
DeadHostState[] deadHostStates = new DeadHostState[numObjects];
@@ -77,6 +82,7 @@ public void testCompareToTimeSupplier() {
7782
}
7883
}
7984

85+
@Test
8086
public void testCompareToDifferingTimeSupplier() {
8187
try {
8288
new DeadHostState(DeadHostState.DEFAULT_TIME_SUPPLIER).compareTo(new DeadHostState(() -> 0L));
@@ -90,6 +96,7 @@ public void testCompareToDifferingTimeSupplier() {
9096
}
9197
}
9298

99+
@Test
93100
public void testShallBeRetried() {
94101
final AtomicLong time = new AtomicLong(0);
95102
DeadHostState deadHostState = null;
@@ -112,6 +119,7 @@ public void testShallBeRetried() {
112119
}
113120
}
114121

122+
@Test
115123
public void testDeadHostStateTimeouts() {
116124
DeadHostState previous = new DeadHostState(() -> 0L);
117125
for (long expectedTimeoutsSecond : EXPECTED_TIMEOUTS_SECONDS) {

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/FailureTrackingResponseListenerTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.hc.core5.http.ProtocolVersion;
2424
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
2525
import org.apache.hc.core5.http.message.RequestLine;
26+
import org.junit.jupiter.api.Test;
2627

2728
import java.util.concurrent.atomic.AtomicReference;
2829

@@ -33,6 +34,7 @@
3334

3435
public class FailureTrackingResponseListenerTests extends RestClientTestCase {
3536

37+
@Test
3638
public void testOnSuccess() {
3739
MockResponseListener responseListener = new MockResponseListener();
3840
Rest5Client.FailureTrackingResponseListener listener =
@@ -44,6 +46,7 @@ public void testOnSuccess() {
4446
assertNull(responseListener.lastException.get());
4547
}
4648

49+
@Test
4750
public void testOnFailure() {
4851
MockResponseListener responseListener = new MockResponseListener();
4952
Rest5Client.FailureTrackingResponseListener listener =

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/HasAttributeNodeSelectorTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package co.elastic.clients.transport.rest5_client.low_level;
2121

2222
import org.apache.hc.core5.http.HttpHost;
23+
import org.junit.jupiter.api.Test;
2324

2425
import java.util.ArrayList;
2526
import java.util.Arrays;
@@ -34,6 +35,8 @@
3435
import static org.junit.Assert.assertEquals;
3536

3637
public class HasAttributeNodeSelectorTests extends RestClientTestCase {
38+
39+
@Test
3740
public void testHasAttribute() {
3841
Node hasAttributeValue = dummyNode(singletonMap("attr", singletonList("val")));
3942
Node hasAttributeButNotValue = dummyNode(singletonMap("attr", singletonList("notval")));

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/NodeSelectorTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@
2020
package co.elastic.clients.transport.rest5_client.low_level;
2121

2222
import org.apache.hc.core5.http.HttpHost;
23+
import org.junit.jupiter.api.Test;
2324

2425
import java.util.ArrayList;
2526
import java.util.Collections;
2627
import java.util.List;
28+
import java.util.Random;
2729
import java.util.Set;
2830
import java.util.TreeSet;
2931

3032
import static org.junit.Assert.assertEquals;
3133

3234
public class NodeSelectorTests extends RestClientTestCase {
35+
36+
@Test
3337
public void testAny() {
3438
List<Node> nodes = new ArrayList<>();
35-
int size = between(2, 5);
39+
int size = randomIntBetween(2, 5);
3640
for (int i = 0; i < size; i++) {
3741
nodes.add(dummyNode(randomBoolean(), randomBoolean(), randomBoolean()));
3842
}
@@ -41,6 +45,7 @@ public void testAny() {
4145
assertEquals(expected, nodes);
4246
}
4347

48+
@Test
4449
public void testNotMasterOnly() {
4550
Node masterOnly = dummyNode(true, false, false);
4651
Node all = dummyNode(true, true, true);
@@ -67,7 +72,7 @@ public void testNotMasterOnly() {
6772
nodes.add(dataWarm);
6873
nodes.add(dataCold);
6974
nodes.add(dataFrozen);
70-
Collections.shuffle(nodes, getRandom());
75+
Collections.shuffle(nodes, new Random());
7176
List<Node> expected = new ArrayList<>(nodes);
7277
expected.remove(masterOnly);
7378
NodeSelector.SKIP_DEDICATED_MASTERS.select(nodes);

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/NodeTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package co.elastic.clients.transport.rest5_client.low_level;
2121

2222
import org.apache.hc.core5.http.HttpHost;
23+
import org.junit.jupiter.api.Test;
2324

2425
import java.util.Arrays;
2526
import java.util.Collections;
@@ -37,6 +38,8 @@
3738
import static org.junit.Assert.assertTrue;
3839

3940
public class NodeTests extends RestClientTestCase {
41+
42+
@Test
4043
public void testToString() {
4144
Map<String, List<String>> attributes = new HashMap<>();
4245
attributes.put("foo", singletonList("bar"));
@@ -72,6 +75,7 @@ public void testToString() {
7275
);
7376
}
7477

78+
@Test
7579
public void testEqualsAndHashCode() {
7680
HttpHost host = new HttpHost(randomAsciiAlphanumOfLength(5));
7781
Node node = new Node(
@@ -148,6 +152,7 @@ public void testEqualsAndHashCode() {
148152
);
149153
}
150154

155+
@Test
151156
public void testDataRole() {
152157
Node.Roles roles = new Node.Roles(new TreeSet<>(Arrays.asList("data_hot")));
153158
assertTrue(roles.hasDataHotRole());

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/PreferHasAttributeNodeSelectorTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package co.elastic.clients.transport.rest5_client.low_level;
2121

2222
import org.apache.hc.core5.http.HttpHost;
23+
import org.junit.jupiter.api.Test;
2324

2425
import java.util.ArrayList;
2526
import java.util.Arrays;
@@ -34,6 +35,8 @@
3435
import static org.junit.Assert.assertEquals;
3536

3637
public class PreferHasAttributeNodeSelectorTests extends RestClientTestCase {
38+
39+
@Test
3740
public void testFoundPreferHasAttribute() {
3841
Node hasAttributeValue = dummyNode(singletonMap("attr", singletonList("val")));
3942
Node hasAttributeButNotValue = dummyNode(singletonMap("attr", singletonList("notval")));
@@ -51,6 +54,7 @@ public void testFoundPreferHasAttribute() {
5154
assertEquals(expected, nodes);
5255
}
5356

57+
@Test
5458
public void testNotFoundPreferHasAttribute() {
5559
Node notHasAttribute = dummyNode(singletonMap("notattr", singletonList("val")));
5660
List<Node> nodes = new ArrayList<>();

java-client/src/test/java/co/elastic/clients/transport/rest5_client/low_level/RequestLoggerTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hc.core5.http.io.entity.StringEntity;
4040
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
4141
import org.apache.hc.core5.http.message.BasicHeader;
42+
import org.junit.jupiter.api.Test;
4243

4344
import java.io.ByteArrayInputStream;
4445
import java.io.IOException;
@@ -53,6 +54,8 @@
5354
import static org.junit.Assert.assertThat;
5455

5556
public class RequestLoggerTests extends RestClientTestCase {
57+
58+
@Test
5659
public void testTraceRequest() throws IOException, URISyntaxException, ParseException {
5760
HttpHost host = new HttpHost(randomBoolean() ? "http" : "https", "localhost", 9200);
5861
String expectedEndpoint = "/index/type/_api";
@@ -104,6 +107,7 @@ public void testTraceRequest() throws IOException, URISyntaxException, ParseExce
104107
}
105108
}
106109

110+
@Test
107111
public void testTraceResponse() throws IOException, ParseException {
108112
int statusCode = randomIntBetween(200, 599);
109113
String reasonPhrase = "REASON";
@@ -115,7 +119,7 @@ public void testTraceResponse() throws IOException, ParseException {
115119
expected += "\n# header" + i + ": value";
116120
}
117121
expected += "\n#";
118-
boolean hasBody = getRandom().nextBoolean();
122+
boolean hasBody = randomBoolean();
119123
String responseBody = "{\n \"field\": \"value\"\n}";
120124
if (hasBody) {
121125
expected += "\n# {";
@@ -152,6 +156,7 @@ public void testTraceResponse() throws IOException, ParseException {
152156
}
153157
}
154158

159+
@Test
155160
public void testResponseWarnings() throws Exception {
156161
HttpHost host = new HttpHost("localhost", 9200);
157162
HttpUriRequest request = randomHttpRequest(new URI("/index/type/_api"));

0 commit comments

Comments
 (0)