Skip to content

Commit f8de0fc

Browse files
CR: Add tests
1 parent 92209a3 commit f8de0fc

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

server/src/test/java/org/elasticsearch/action/admin/cluster/bootstrap/TransportGetDiscoveredNodesActionTests.java

+51
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.junit.BeforeClass;
5252

5353
import java.io.IOException;
54+
import java.util.Arrays;
5455
import java.util.Random;
5556
import java.util.concurrent.CountDownLatch;
5657
import java.util.concurrent.TimeUnit;
@@ -65,6 +66,7 @@
6566
import static org.hamcrest.Matchers.equalTo;
6667
import static org.hamcrest.Matchers.instanceOf;
6768
import static org.hamcrest.Matchers.startsWith;
69+
import static org.hamcrest.core.Is.is;
6870
import static org.mockito.Mockito.mock;
6971
import static org.mockito.Mockito.verifyZeroInteractions;
7072

@@ -289,6 +291,55 @@ public void handleException(TransportException exp) {
289291

290292
assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));
291293
}
294+
295+
{
296+
final CountDownLatch countDownLatch = new CountDownLatch(1);
297+
final GetDiscoveredNodesRequest getDiscoveredNodesRequest = new GetDiscoveredNodesRequest();
298+
getDiscoveredNodesRequest.setRequiredNodes(
299+
Arrays.asList(localNode.getAddress().toString(), otherNode.getAddress().toString())
300+
);
301+
getDiscoveredNodesRequest.setTimeout(TimeValue.ZERO);
302+
transportService.sendRequest(localNode, GetDiscoveredNodesAction.NAME, getDiscoveredNodesRequest, new ResponseHandler() {
303+
@Override
304+
public void handleResponse(GetDiscoveredNodesResponse response) {
305+
assertThat(response.getNodes(), containsInAnyOrder(localNode, otherNode));
306+
countDownLatch.countDown();
307+
}
308+
309+
@Override
310+
public void handleException(TransportException exp) {
311+
throw new AssertionError("should not be called", exp);
312+
}
313+
});
314+
315+
assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));
316+
}
317+
318+
{
319+
final CountDownLatch countDownLatch = new CountDownLatch(1);
320+
final GetDiscoveredNodesRequest getDiscoveredNodesRequest = new GetDiscoveredNodesRequest();
321+
getDiscoveredNodesRequest.setRequiredNodes(
322+
Arrays.asList(localNode.getAddress().toString(), localNode.getName())
323+
);
324+
getDiscoveredNodesRequest.setTimeout(TimeValue.ZERO);
325+
transportService.sendRequest(localNode, GetDiscoveredNodesAction.NAME, getDiscoveredNodesRequest, new ResponseHandler() {
326+
@Override
327+
public void handleResponse(GetDiscoveredNodesResponse response) {
328+
throw new AssertionError("should not be called");
329+
}
330+
331+
@Override
332+
public void handleException(TransportException exp) {
333+
Throwable t = exp.getRootCause();
334+
assertThat(t, instanceOf(IllegalArgumentException.class));
335+
assertThat(t.getMessage(), is("Node [" + localNode + "] matched both a name as well as an address entry" +
336+
" in the nodes list specified in setting [cluster.initial_master_nodes]."));
337+
countDownLatch.countDown();
338+
}
339+
});
340+
341+
assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));
342+
}
292343
}
293344

294345
private abstract class ResponseHandler implements TransportResponseHandler<GetDiscoveredNodesResponse> {

0 commit comments

Comments
 (0)