Simplify mocking in CCR retention lease tests
This commit simplifies the use of transport mocking in the CCR retention lease integration tests. Instead of adding a send rule between nodes, we add a default send rule. This greatly simplifies the code here, and speeds the test up a little bit too.
This commit is contained in:
parent
c7516b03b6
commit
feb25c71a0
|
@ -209,23 +209,17 @@ public class CcrRetentionLeaseIT extends CcrIntegTestCase {
|
||||||
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
|
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
|
||||||
final MockTransportService senderTransportService =
|
final MockTransportService senderTransportService =
|
||||||
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
|
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
|
||||||
final ClusterStateResponse leaderClusterState = leaderClient().admin().cluster().prepareState().clear().setNodes(true).get();
|
senderTransportService.addSendBehavior(
|
||||||
for (final ObjectCursor<DiscoveryNode> receiverNode : leaderClusterState.getState().nodes().getNodes().values()) {
|
(connection, requestId, action, request, options) -> {
|
||||||
final MockTransportService receiverTransportService =
|
if (ClearCcrRestoreSessionAction.NAME.equals(action)) {
|
||||||
(MockTransportService) getLeaderCluster().getInstance(TransportService.class, receiverNode.value.getName());
|
try {
|
||||||
senderTransportService.addSendBehavior(receiverTransportService,
|
latch.await();
|
||||||
(connection, requestId, action, request, options) -> {
|
} catch (final InterruptedException e) {
|
||||||
if (ClearCcrRestoreSessionAction.NAME.equals(action)) {
|
fail(e.toString());
|
||||||
try {
|
|
||||||
latch.await();
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
fail(e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
connection.sendRequest(requestId, action, request, options);
|
}
|
||||||
});
|
connection.sendRequest(requestId, action, request, options);
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlainActionFuture<RestoreInfo> future = PlainActionFuture.newFuture();
|
final PlainActionFuture<RestoreInfo> future = PlainActionFuture.newFuture();
|
||||||
|
@ -419,50 +413,45 @@ public class CcrRetentionLeaseIT extends CcrIntegTestCase {
|
||||||
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
|
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
|
||||||
final MockTransportService senderTransportService =
|
final MockTransportService senderTransportService =
|
||||||
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
|
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
|
||||||
final ClusterStateResponse leaderClusterState =
|
senderTransportService.addSendBehavior(
|
||||||
leaderClient().admin().cluster().prepareState().clear().setNodes(true).get();
|
(connection, requestId, action, request, options) -> {
|
||||||
for (final ObjectCursor<DiscoveryNode> receiverNode : leaderClusterState.getState().nodes().getNodes().values()) {
|
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
||||||
final MockTransportService receiverTransportService =
|
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
||||||
(MockTransportService) getLeaderCluster().getInstance(TransportService.class, receiverNode.value.getName());
|
if (shardIds.contains(removeRequest.getShardId().id())) {
|
||||||
senderTransportService.addSendBehavior(receiverTransportService,
|
final String primaryShardNodeId =
|
||||||
(connection, requestId, action, request, options) -> {
|
getLeaderCluster()
|
||||||
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
.clusterService()
|
||||||
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
.state()
|
||||||
if (shardIds.contains(removeRequest.getShardId().id())) {
|
.routingTable()
|
||||||
final String primaryShardNodeId =
|
.index(leaderIndex)
|
||||||
getLeaderCluster()
|
.shard(removeRequest.getShardId().id())
|
||||||
.clusterService()
|
.primaryShard()
|
||||||
.state()
|
.currentNodeId();
|
||||||
.routingTable()
|
final String primaryShardNodeName =
|
||||||
.index(leaderIndex)
|
getLeaderCluster().clusterService().state().nodes().get(primaryShardNodeId).getName();
|
||||||
.shard(removeRequest.getShardId().id())
|
final IndexShard primary =
|
||||||
.primaryShard()
|
getLeaderCluster()
|
||||||
.currentNodeId();
|
.getInstance(IndicesService.class, primaryShardNodeName)
|
||||||
final String primaryShardNodeName =
|
.getShardOrNull(removeRequest.getShardId());
|
||||||
getLeaderCluster().clusterService().state().nodes().get(primaryShardNodeId).getName();
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
final IndexShard primary =
|
primary.removeRetentionLease(
|
||||||
getLeaderCluster()
|
retentionLeaseId,
|
||||||
.getInstance(IndicesService.class, primaryShardNodeName)
|
ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString())));
|
||||||
.getShardOrNull(removeRequest.getShardId());
|
try {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
latch.await();
|
||||||
primary.removeRetentionLease(
|
} catch (final InterruptedException e) {
|
||||||
retentionLeaseId,
|
Thread.currentThread().interrupt();
|
||||||
ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString())));
|
fail(e.toString());
|
||||||
try {
|
|
||||||
latch.await();
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
fail(e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connection.sendRequest(requestId, action, request, options);
|
}
|
||||||
});
|
connection.sendRequest(requestId, action, request, options);
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pauseFollow(followerIndex);
|
pauseFollow(followerIndex);
|
||||||
followerClient().admin().indices().close(new CloseIndexRequest(followerIndex)).actionGet();
|
followerClient().admin().indices().close(new CloseIndexRequest(followerIndex)).actionGet();
|
||||||
assertAcked(followerClient().execute(UnfollowAction.INSTANCE, new UnfollowAction.Request(followerIndex)).actionGet());
|
assertAcked(followerClient().execute(UnfollowAction.INSTANCE, new UnfollowAction.Request(followerIndex)).actionGet());
|
||||||
|
@ -508,25 +497,18 @@ public class CcrRetentionLeaseIT extends CcrIntegTestCase {
|
||||||
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
|
for (final ObjectCursor<DiscoveryNode> senderNode : followerClusterState.getState().nodes().getNodes().values()) {
|
||||||
final MockTransportService senderTransportService =
|
final MockTransportService senderTransportService =
|
||||||
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
|
(MockTransportService) getFollowerCluster().getInstance(TransportService.class, senderNode.value.getName());
|
||||||
final ClusterStateResponse leaderClusterState =
|
senderTransportService.addSendBehavior(
|
||||||
leaderClient().admin().cluster().prepareState().clear().setNodes(true).get();
|
(connection, requestId, action, request, options) -> {
|
||||||
for (final ObjectCursor<DiscoveryNode> receiverNode : leaderClusterState.getState().nodes().getNodes().values()) {
|
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
||||||
final MockTransportService receiverTransportService =
|
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
||||||
(MockTransportService) getLeaderCluster().getInstance(TransportService.class, receiverNode.value.getName());
|
if (shardIds.contains(removeRequest.getShardId().id())) {
|
||||||
senderTransportService.addSendBehavior(receiverTransportService,
|
throw randomBoolean()
|
||||||
(connection, requestId, action, request, options) -> {
|
? new ConnectTransportException(connection.getNode(), "connection failed")
|
||||||
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
: new IndexShardClosedException(removeRequest.getShardId());
|
||||||
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
|
||||||
if (shardIds.contains(removeRequest.getShardId().id())) {
|
|
||||||
throw randomBoolean()
|
|
||||||
? new ConnectTransportException(receiverNode.value, "connection failed")
|
|
||||||
: new IndexShardClosedException(removeRequest.getShardId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
connection.sendRequest(requestId, action, request, options);
|
}
|
||||||
});
|
connection.sendRequest(requestId, action, request, options);
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final ElasticsearchException e = expectThrows(
|
final ElasticsearchException e = expectThrows(
|
||||||
|
|
Loading…
Reference in New Issue