use of org.opensearch.transport.TestTransportChannel in project OpenSearch by opensearch-project.
the class NodeJoinTests method handleFollowerCheckFrom.
private void handleFollowerCheckFrom(DiscoveryNode node, long term) throws Exception {
final RequestHandlerRegistry<FollowersChecker.FollowerCheckRequest> followerCheckHandler = transport.getRequestHandlers().getHandler(FollowersChecker.FOLLOWER_CHECK_ACTION_NAME);
final TestTransportChannel channel = new TestTransportChannel(new ActionListener<TransportResponse>() {
@Override
public void onResponse(TransportResponse transportResponse) {
}
@Override
public void onFailure(Exception e) {
fail();
}
});
followerCheckHandler.processMessageReceived(new FollowersChecker.FollowerCheckRequest(term, node), channel);
// Will throw exception if failed
deterministicTaskQueue.runAllRunnableTasks();
assertFalse(isLocalNodeElectedMaster());
assertThat(coordinator.getMode(), equalTo(Coordinator.Mode.FOLLOWER));
}
use of org.opensearch.transport.TestTransportChannel in project OpenSearch by opensearch-project.
the class TransportBroadcastByNodeActionTests method testOperationExecution.
public void testOperationExecution() throws Exception {
ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[] { TEST_INDEX });
Set<ShardRouting> shards = new HashSet<>();
String nodeId = shardIt.iterator().next().currentNodeId();
for (ShardRouting shard : shardIt) {
if (nodeId.equals(shard.currentNodeId())) {
shards.add(shard);
}
}
final TransportBroadcastByNodeAction.BroadcastByNodeTransportRequestHandler handler = action.new BroadcastByNodeTransportRequestHandler();
final PlainActionFuture<TransportResponse> future = PlainActionFuture.newFuture();
TestTransportChannel channel = new TestTransportChannel(future);
handler.messageReceived(action.new NodeRequest(nodeId, new Request(), new ArrayList<>(shards)), channel, null);
// check the operation was executed only on the expected shards
assertEquals(shards, action.getResults().keySet());
TransportResponse response = future.actionGet();
assertTrue(response instanceof TransportBroadcastByNodeAction.NodeResponse);
TransportBroadcastByNodeAction.NodeResponse nodeResponse = (TransportBroadcastByNodeAction.NodeResponse) response;
// check the operation was executed on the correct node
assertEquals("node id", nodeId, nodeResponse.getNodeId());
int successfulShards = 0;
int failedShards = 0;
for (Object result : action.getResults().values()) {
if (!(result instanceof OpenSearchException)) {
successfulShards++;
} else {
failedShards++;
}
}
// check the operation results
assertEquals("successful shards", successfulShards, nodeResponse.getSuccessfulShards());
assertEquals("total shards", action.getResults().size(), nodeResponse.getTotalShards());
assertEquals("failed shards", failedShards, nodeResponse.getExceptions().size());
List<BroadcastShardOperationFailedException> exceptions = nodeResponse.getExceptions();
for (BroadcastShardOperationFailedException exception : exceptions) {
assertThat(exception.getMessage(), is("operation indices:admin/test failed"));
assertThat(exception, hasToString(containsString("operation failed")));
}
}
use of org.opensearch.transport.TestTransportChannel in project OpenSearch by opensearch-project.
the class NodeJoinTests method joinNodeAsync.
private SimpleFuture joinNodeAsync(final JoinRequest joinRequest) {
final SimpleFuture future = new SimpleFuture("join of " + joinRequest + "]");
logger.debug("starting {}", future);
// disco node object serialized off the network
try {
final RequestHandlerRegistry<JoinRequest> joinHandler = transport.getRequestHandlers().getHandler(JoinHelper.JOIN_ACTION_NAME);
final ActionListener<TransportResponse> listener = new ActionListener<TransportResponse>() {
@Override
public void onResponse(TransportResponse transportResponse) {
logger.debug("{} completed", future);
future.markAsDone();
}
@Override
public void onFailure(Exception e) {
logger.error(() -> new ParameterizedMessage("unexpected error for {}", future), e);
future.markAsFailed(e);
}
};
joinHandler.processMessageReceived(joinRequest, new TestTransportChannel(listener));
} catch (Exception e) {
logger.error(() -> new ParameterizedMessage("unexpected error for {}", future), e);
future.markAsFailed(e);
}
return future;
}
use of org.opensearch.transport.TestTransportChannel in project OpenSearch by opensearch-project.
the class NodeJoinTests method handleStartJoinFrom.
private void handleStartJoinFrom(DiscoveryNode node, long term) throws Exception {
final RequestHandlerRegistry<StartJoinRequest> startJoinHandler = transport.getRequestHandlers().getHandler(JoinHelper.START_JOIN_ACTION_NAME);
startJoinHandler.processMessageReceived(new StartJoinRequest(node, term), new TestTransportChannel(new ActionListener<TransportResponse>() {
@Override
public void onResponse(TransportResponse transportResponse) {
}
@Override
public void onFailure(Exception e) {
fail();
}
}));
deterministicTaskQueue.runAllRunnableTasks();
assertFalse(isLocalNodeElectedMaster());
assertThat(coordinator.getMode(), equalTo(Coordinator.Mode.CANDIDATE));
}
Aggregations