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,11 +209,7 @@ 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()) {
|
|
||||||
final MockTransportService receiverTransportService =
|
|
||||||
(MockTransportService) getLeaderCluster().getInstance(TransportService.class, receiverNode.value.getName());
|
|
||||||
senderTransportService.addSendBehavior(receiverTransportService,
|
|
||||||
(connection, requestId, action, request, options) -> {
|
(connection, requestId, action, request, options) -> {
|
||||||
if (ClearCcrRestoreSessionAction.NAME.equals(action)) {
|
if (ClearCcrRestoreSessionAction.NAME.equals(action)) {
|
||||||
try {
|
try {
|
||||||
|
@ -226,8 +222,6 @@ public class CcrRetentionLeaseIT extends CcrIntegTestCase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final PlainActionFuture<RestoreInfo> future = PlainActionFuture.newFuture();
|
final PlainActionFuture<RestoreInfo> future = PlainActionFuture.newFuture();
|
||||||
restoreService.restoreSnapshot(restoreRequest, waitForRestore(clusterService, future));
|
restoreService.restoreSnapshot(restoreRequest, waitForRestore(clusterService, future));
|
||||||
|
|
||||||
|
@ -419,12 +413,7 @@ 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();
|
|
||||||
for (final ObjectCursor<DiscoveryNode> receiverNode : leaderClusterState.getState().nodes().getNodes().values()) {
|
|
||||||
final MockTransportService receiverTransportService =
|
|
||||||
(MockTransportService) getLeaderCluster().getInstance(TransportService.class, receiverNode.value.getName());
|
|
||||||
senderTransportService.addSendBehavior(receiverTransportService,
|
|
||||||
(connection, requestId, action, request, options) -> {
|
(connection, requestId, action, request, options) -> {
|
||||||
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
||||||
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
||||||
|
@ -460,7 +449,7 @@ public class CcrRetentionLeaseIT extends CcrIntegTestCase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pauseFollow(followerIndex);
|
pauseFollow(followerIndex);
|
||||||
|
@ -508,18 +497,13 @@ 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();
|
|
||||||
for (final ObjectCursor<DiscoveryNode> receiverNode : leaderClusterState.getState().nodes().getNodes().values()) {
|
|
||||||
final MockTransportService receiverTransportService =
|
|
||||||
(MockTransportService) getLeaderCluster().getInstance(TransportService.class, receiverNode.value.getName());
|
|
||||||
senderTransportService.addSendBehavior(receiverTransportService,
|
|
||||||
(connection, requestId, action, request, options) -> {
|
(connection, requestId, action, request, options) -> {
|
||||||
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
if (RetentionLeaseActions.Remove.ACTION_NAME.equals(action)) {
|
||||||
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
final RetentionLeaseActions.RemoveRequest removeRequest = (RetentionLeaseActions.RemoveRequest) request;
|
||||||
if (shardIds.contains(removeRequest.getShardId().id())) {
|
if (shardIds.contains(removeRequest.getShardId().id())) {
|
||||||
throw randomBoolean()
|
throw randomBoolean()
|
||||||
? new ConnectTransportException(receiverNode.value, "connection failed")
|
? new ConnectTransportException(connection.getNode(), "connection failed")
|
||||||
: new IndexShardClosedException(removeRequest.getShardId());
|
: new IndexShardClosedException(removeRequest.getShardId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -527,8 +511,6 @@ public class CcrRetentionLeaseIT extends CcrIntegTestCase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final ElasticsearchException e = expectThrows(
|
final ElasticsearchException e = expectThrows(
|
||||||
ElasticsearchException.class,
|
ElasticsearchException.class,
|
||||||
() -> followerClient().execute(UnfollowAction.INSTANCE, new UnfollowAction.Request(followerIndex)).actionGet());
|
() -> followerClient().execute(UnfollowAction.INSTANCE, new UnfollowAction.Request(followerIndex)).actionGet());
|
||||||
|
|
Loading…
Reference in New Issue