aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-utils/src/test
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-07-05 12:57:18 +0200
committerHarald Musum <musum@yahooinc.com>2023-07-05 12:57:18 +0200
commit15ae1073bbf3ff568b1184475848085bf4f4111a (patch)
treeb6726a222c7db89b11a8460f4f2c0baaee5c301e /clustercontroller-utils/src/test
parent16737570b30afbe3b8699daafdcc9b8de286e5b0 (diff)
Code cleanup, no functional changes
Diffstat (limited to 'clustercontroller-utils/src/test')
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java23
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java6
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java10
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java12
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyBackend.java10
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java41
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/test/TestTransport.java20
-rw-r--r--clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java2
8 files changed, 56 insertions, 68 deletions
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java
index 739b8d4bf15..fdb8d5922e7 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java
@@ -31,13 +31,13 @@ public class AsyncTest {
op.setResult("foo");
op.register(l4);
// Listener that is unregistered is not called
- assertEquals(false, l1.called);
+ assertFalse(l1.called);
// Listener that is registered is called
- assertEquals(true, l2.called);
+ assertTrue(l2.called);
// Multiple listeners supported
- assertEquals(true, l3.called);
+ assertTrue(l3.called);
// Listener called directly when registered after result is set
- assertEquals(true, l4.called);
+ assertTrue(l4.called);
}
@Test
@@ -53,14 +53,14 @@ public class AsyncTest {
op.setResult("foo");
op.setFailure(new Exception("bar"));
assertEquals("foo", op.getResult());
- assertEquals(true, op.isSuccess());
+ assertTrue(op.isSuccess());
}
{
AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test");
op.setFailure(new Exception("bar"));
op.setResult("foo");
assertNull(op.getResult());
- assertEquals(false, op.isSuccess());
+ assertFalse(op.isSuccess());
assertEquals("bar", op.getCause().getMessage());
}
}
@@ -70,7 +70,7 @@ public class AsyncTest {
AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test");
op.setFailure(new Exception("bar"), "foo");
assertEquals("foo", op.getResult());
- assertEquals(false, op.isSuccess());
+ assertFalse(op.isSuccess());
assertEquals("bar", op.getCause().getMessage());
}
@@ -81,7 +81,6 @@ public class AsyncTest {
super(op);
}
}
- ;
class Listener implements AsyncCallback<String> {
int calls = 0;
@@ -119,8 +118,8 @@ public class AsyncTest {
});
assertNull(deleteRequest.getProgress());
op.setResult("123");
- assertEquals(true, deleteRequest.isDone());
- assertEquals(true, deleteRequest.isSuccess());
+ assertTrue(deleteRequest.isDone());
+ assertTrue(deleteRequest.isSuccess());
assertEquals(Integer.valueOf(123), deleteRequest.getResult());
assertEquals("desc", deleteRequest.getDescription());
assertEquals("test", deleteRequest.getName());
@@ -142,9 +141,9 @@ public class AsyncTest {
}
};
op.setFailure(new Exception("foo"));
- assertEquals(true, deleteRequest.isDone());
+ assertTrue(deleteRequest.isDone());
assertEquals("foo", deleteRequest.getCause().getMessage());
- assertEquals(false, deleteRequest.isSuccess());
+ assertFalse(deleteRequest.isSuccess());
deleteRequest.getProgress();
}
}
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java
index 41328494f52..7a6ef91894f 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java
@@ -35,12 +35,12 @@ public class HttpRequestTest {
// - The HTTP operation type
try {
new HttpRequest().setPath("/foo").verifyComplete();
- assertTrue(false);
+ fail();
} catch (IllegalStateException e) {
}
try {
new HttpRequest().setHttpOperation(HttpRequest.HttpOp.GET).verifyComplete();
- assertTrue(false);
+ fail();
} catch (IllegalStateException e) {
}
new HttpRequest().setHttpOperation(HttpRequest.HttpOp.GET).setPath("/bar").verifyComplete();
@@ -126,7 +126,7 @@ public class HttpRequestTest {
@Test
void testNothingButGetCoverage() {
- assertEquals(false, new HttpRequest().equals(new Object()));
+ assertNotEquals(new HttpRequest(), new Object());
new HttpRequest().getHeaders();
new HttpRequest().setUrlOptions(new HttpRequest().getUrlOptions());
}
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java
index 3a08d735a4e..f4ef99ba40d 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java
@@ -4,15 +4,17 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class HttpResultTest {
@Test
void testSuccess() {
- assertEquals(false, new HttpResult().setHttpCode(199, "foo").isSuccess());
- assertEquals(true, new HttpResult().setHttpCode(200, "foo").isSuccess());
- assertEquals(true, new HttpResult().setHttpCode(299, "foo").isSuccess());
- assertEquals(false, new HttpResult().setHttpCode(300, "foo").isSuccess());
+ assertFalse(new HttpResult().setHttpCode(199, "foo").isSuccess());
+ assertTrue(new HttpResult().setHttpCode(200, "foo").isSuccess());
+ assertTrue(new HttpResult().setHttpCode(299, "foo").isSuccess());
+ assertFalse(new HttpResult().setHttpCode(300, "foo").isSuccess());
}
@Test
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java
index 52b632c6eb8..68fbab28b6b 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java
@@ -4,18 +4,18 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http.writer;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
public class HttpWriterTest {
- private static String defaultTitle = "My Title";
- private static String defaultHeader = "<html>\n"
+ private static final String defaultTitle = "My Title";
+ private static final String defaultHeader = "<html>\n"
+ " <head>\n"
+ " <title>My Title</title>\n"
+ " </head>\n"
+ " <body>\n"
+ " <h1>My Title</h1>\n";
- private static String defaultFooter = " </body>\n"
+ private static final String defaultFooter = " </body>\n"
+ "</html>\n";
@Test
@@ -60,12 +60,12 @@ public class HttpWriterTest {
HttpWriter writer = new HttpWriter().addTitle(defaultTitle);
writer.toString();
writer.write("foo");
- assertTrue(false);
+ fail();
} catch (IllegalStateException e) {
}
try {
new HttpWriter().write("foo").addTitle("bar");
- assertTrue(false);
+ fail();
} catch (IllegalStateException e) {
}
}
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyBackend.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyBackend.java
index b1ea3b99ac3..98b39dd0480 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyBackend.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/DummyBackend.java
@@ -6,26 +6,26 @@ import java.util.Map;
public class DummyBackend {
public static class Cluster {
- public String id;
- public Map<String, Node> nodes = new LinkedHashMap<>();
+ public final String id;
+ public final Map<String, Node> nodes = new LinkedHashMap<>();
public Cluster(String id) { this.id = id; }
public Cluster addNode(Node n) { nodes.put(n.id, n); n.clusterId = id; return this; }
}
public static class Node {
public String clusterId;
- public String id;
+ public final String id;
public int docCount = 0;
public String state = "up";
public String reason = "";
- public String group = "mygroup";
+ public final String group = "mygroup";
public Node(String id) { this.id = id; }
public Node setDocCount(int count) { docCount = count; return this; }
public Node setState(String state) { this.state = state; return this; }
}
- private Map<String, Cluster> clusters = new LinkedHashMap<>();
+ private final Map<String, Cluster> clusters = new LinkedHashMap<>();
public Map<String, Cluster> getClusters() { return clusters; }
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java
index 29e33b7906a..4e70e51505a 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
public class StateRestAPITest {
@@ -87,7 +88,7 @@ public class StateRestAPITest {
}
@Test
- void testTopLevelList() throws Exception {
+ void testTopLevelList() {
setupDummyStateApi();
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
assertEquals(200, result.getHttpReturnCode(), result.toString(true));
@@ -107,7 +108,7 @@ public class StateRestAPITest {
}
@Test
- void testClusterState() throws Exception {
+ void testClusterState() {
setupDummyStateApi();
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo"));
assertEquals(200, result.getHttpReturnCode(), result.toString(true));
@@ -127,7 +128,7 @@ public class StateRestAPITest {
}
@Test
- void testNodeState() throws Exception {
+ void testNodeState() {
setupDummyStateApi();
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3"));
assertEquals(200, result.getHttpReturnCode(), result.toString(true));
@@ -151,7 +152,7 @@ public class StateRestAPITest {
}
@Test
- void testRecursiveMode() throws Exception {
+ void testRecursiveMode() {
setupDummyStateApi();
{
JsonNode json = executeOkJsonRequest(
@@ -291,7 +292,7 @@ public class StateRestAPITest {
}
}
- private String retireAndExpectHttp200Response(Optional<String> responseWait) throws Exception {
+ private String retireAndExpectHttp200Response(Optional<String> responseWait) {
ObjectNode json = new ObjectNode(mapper.getNodeFactory());
json.putObject("state").putObject("current").put("state", "retired").put("reason", "No reason");
json.put("condition", "FORCE");
@@ -305,7 +306,7 @@ public class StateRestAPITest {
}
@Test
- void testSetNodeState() throws Exception {
+ void testSetNodeState() {
setupDummyStateApi();
{
ObjectNode json = new ObjectNode(mapper.getNodeFactory());
@@ -362,7 +363,7 @@ public class StateRestAPITest {
}
@Test
- void set_node_state_response_wait_type_is_propagated_to_handler() throws Exception {
+ void set_node_state_response_wait_type_is_propagated_to_handler() {
setupDummyStateApi();
{
String result = retireAndExpectHttp200Response(Optional.of("wait-until-cluster-acked"));
@@ -385,7 +386,7 @@ public class StateRestAPITest {
}
@Test
- void set_node_state_response_wait_type_is_cluster_acked_by_default() throws Exception {
+ void set_node_state_response_wait_type_is_cluster_acked_by_default() {
setupDummyStateApi();
String result = retireAndExpectHttp200Response(Optional.empty());
assertEquals("""
@@ -397,7 +398,7 @@ public class StateRestAPITest {
}
@Test
- void testMissingUnits() throws Exception {
+ void testMissingUnits() {
setupDummyStateApi();
{
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/unknown"));
@@ -416,7 +417,7 @@ public class StateRestAPITest {
}
@Test
- void testUnknownMaster() throws Exception {
+ void testUnknownMaster() {
setupDummyStateApi();
stateApi.induceException(new UnknownMasterException());
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
@@ -429,7 +430,7 @@ public class StateRestAPITest {
}
@Test
- void testOtherMaster() throws Exception {
+ void testOtherMaster() {
setupDummyStateApi();
{
stateApi.induceException(new OtherMasterException("example.com", 80));
@@ -454,7 +455,7 @@ public class StateRestAPITest {
}
@Test
- void testRuntimeException() throws Exception {
+ void testRuntimeException() {
setupDummyStateApi();
stateApi.induceException(new RuntimeException("Moahaha"));
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
@@ -466,7 +467,7 @@ public class StateRestAPITest {
}
@Test
- void testClientFailures() throws Exception {
+ void testClientFailures() {
setupDummyStateApi();
{
stateApi.induceException(new InvalidContentException("Foo bar"));
@@ -498,7 +499,7 @@ public class StateRestAPITest {
}
@Test
- void testInternalFailure() throws Exception {
+ void testInternalFailure() {
setupDummyStateApi();
{
stateApi.induceException(new InternalFailure("Foo"));
@@ -512,7 +513,7 @@ public class StateRestAPITest {
}
@Test
- void testInvalidRecursiveValues() throws Exception {
+ void testInvalidRecursiveValues() {
setupDummyStateApi();
{
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2").addUrlOption("recursive", "-5"));
@@ -533,7 +534,7 @@ public class StateRestAPITest {
}
@Test
- void testInvalidJsonInSetStateRequest() throws Exception {
+ void testInvalidJsonInSetStateRequest() {
setupDummyStateApi();
{
ObjectNode json = new ObjectNode(mapper.getNodeFactory());
@@ -596,7 +597,7 @@ public class StateRestAPITest {
}
}
- private String retireAndExpectHttp400Response(String condition, String responseWait) throws Exception {
+ private String retireAndExpectHttp400Response(String condition, String responseWait) {
ObjectNode json = new ObjectNode(mapper.getNodeFactory());
json.putObject("state").putObject("current").put("state", "retired").put("reason", "No reason");
json.put("condition", condition);
@@ -610,7 +611,7 @@ public class StateRestAPITest {
}
@Test
- void testInvalidPathPrefix() throws Exception {
+ void testInvalidPathPrefix() {
DummyBackend backend = new DummyBackend();
stateApi = new DummyStateApi(backend);
populateDummyBackend(backend);
@@ -618,13 +619,13 @@ public class StateRestAPITest {
RestApiHandler handler = new RestApiHandler(stateApi);
try {
handler.setDefaultPathPrefix("cluster/v2");
- assertTrue(false);
+ fail();
} catch (IllegalArgumentException e) {
}
}
@Test
- void deadline_exceeded_exception_returns_http_504_error() throws Exception {
+ void deadline_exceeded_exception_returns_http_504_error() {
setupDummyStateApi();
stateApi.induceException(new DeadlineExceededException("argh!"));
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/test/TestTransport.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/test/TestTransport.java
index 7a334ae3e34..f964ef8096f 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/test/TestTransport.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/test/TestTransport.java
@@ -25,8 +25,8 @@ public class TestTransport {
private static final Logger log = Logger.getLogger(TestTransport.class.getName());
private static class Handler {
- HttpRequestHandler handler;
- String pathPrefix;
+ final HttpRequestHandler handler;
+ final String pathPrefix;
Handler(HttpRequestHandler h, String prefix) { this.handler = h; this.pathPrefix = prefix; }
}
private static class Socket {
@@ -39,8 +39,7 @@ public class TestTransport {
}
@Override
public boolean equals(Object o) {
- if (!(o instanceof Socket)) return false;
- Socket other = (Socket) o;
+ if (!(o instanceof Socket other)) return false;
return (hostname.equals(other.hostname) && port == other.port);
}
@Override
@@ -171,17 +170,4 @@ public class TestTransport {
}
}
- public void removeServer(HttpRequestHandler server, String hostname, int port, String pathPrefix) {
- Socket socket = new Socket(hostname, port);
- synchronized (this) {
- List<Handler> shandlers = handlers.get(socket);
- if (shandlers == null) return;
- for (Handler h : shandlers) {
- if (h.handler == server && h.pathPrefix.equals(pathPrefix)) {
- shandlers.remove(h);
- }
- }
- }
- }
-
}
diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java
index 33164aaf53e..6805b1b014e 100644
--- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java
+++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java
@@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class MetricReporterTest {
static class MetricReporterMock implements MetricReporter {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
@Override
public void set(String s, Number number, Context context) {