|
81 | 81 |
|
82 | 82 | import static java.util.Collections.emptyMap; |
83 | 83 | import static java.util.Collections.emptySet; |
| 84 | +import static org.hamcrest.Matchers.equalTo; |
84 | 85 | import static org.hamcrest.Matchers.instanceOf; |
| 86 | +import static org.hamcrest.Matchers.iterableWithSize; |
| 87 | +import static org.hamcrest.Matchers.not; |
| 88 | +import static org.hamcrest.Matchers.notNullValue; |
85 | 89 | import static org.hamcrest.Matchers.startsWith; |
86 | 90 |
|
87 | 91 | public class RemoteClusterConnectionTests extends ESTestCase { |
@@ -305,6 +309,63 @@ public void testConnectWithIncompatibleTransports() throws Exception { |
305 | 309 | } |
306 | 310 | } |
307 | 311 |
|
| 312 | + public void testRemoteConnectionVersionMatchesTransportConnectionVersion() throws Exception { |
| 313 | + List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>(); |
| 314 | + final Version previousVersion = VersionUtils.getPreviousVersion(); |
| 315 | + try (MockTransportService seedTransport = startTransport("seed_node", knownNodes, previousVersion); |
| 316 | + MockTransportService discoverableTransport = startTransport("discoverable_node", knownNodes, Version.CURRENT)) { |
| 317 | + |
| 318 | + DiscoveryNode seedNode = seedTransport.getLocalDiscoNode(); |
| 319 | + assertThat(seedNode, notNullValue()); |
| 320 | + knownNodes.add(seedNode); |
| 321 | + |
| 322 | + DiscoveryNode oldVersionNode = discoverableTransport.getLocalDiscoNode(); |
| 323 | + assertThat(oldVersionNode, notNullValue()); |
| 324 | + knownNodes.add(oldVersionNode); |
| 325 | + |
| 326 | + assertThat(seedNode.getVersion(), not(equalTo(oldVersionNode.getVersion()))); |
| 327 | + try (MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) { |
| 328 | + final Transport.Connection seedConnection = new Transport.Connection() { |
| 329 | + @Override |
| 330 | + public DiscoveryNode getNode() { |
| 331 | + return seedNode; |
| 332 | + } |
| 333 | + |
| 334 | + @Override |
| 335 | + public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) |
| 336 | + throws IOException, TransportException { |
| 337 | + // no-op |
| 338 | + } |
| 339 | + |
| 340 | + @Override |
| 341 | + public void close() throws IOException { |
| 342 | + // no-op |
| 343 | + } |
| 344 | + }; |
| 345 | + service.addDelegate(seedNode.getAddress(), new MockTransportService.DelegateTransport(service.getOriginalTransport()) { |
| 346 | + @Override |
| 347 | + public Connection getConnection(DiscoveryNode node) { |
| 348 | + if (node == seedNode) { |
| 349 | + return seedConnection; |
| 350 | + } |
| 351 | + return super.getConnection(node); |
| 352 | + } |
| 353 | + }); |
| 354 | + service.start(); |
| 355 | + service.acceptIncomingRequests(); |
| 356 | + try (RemoteClusterConnection connection = new RemoteClusterConnection(Settings.EMPTY, "test-cluster", |
| 357 | + Arrays.asList(seedNode), service, Integer.MAX_VALUE, n -> true)) { |
| 358 | + connection.addConnectedNode(seedNode); |
| 359 | + for (DiscoveryNode node : knownNodes) { |
| 360 | + final Transport.Connection transportConnection = connection.getConnection(node); |
| 361 | + assertThat(transportConnection.getVersion(), equalTo(previousVersion)); |
| 362 | + } |
| 363 | + assertThat(knownNodes, iterableWithSize(2)); |
| 364 | + } |
| 365 | + } |
| 366 | + } |
| 367 | + } |
| 368 | + |
308 | 369 | @SuppressForbidden(reason = "calls getLocalHost here but it's fine in this case") |
309 | 370 | public void testSlowNodeCanBeCanceled() throws IOException, InterruptedException { |
310 | 371 | try (ServerSocket socket = new MockServerSocket()) { |
|
0 commit comments