Search in sources :

Example 1 with TestTransportChannel

use of org.elasticsearch.transport.TestTransportChannel in project crate by crate.

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;
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) TestTransportChannel(org.elasticsearch.transport.TestTransportChannel) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) TransportResponse(org.elasticsearch.transport.TransportResponse) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 2 with TestTransportChannel

use of org.elasticsearch.transport.TestTransportChannel in project crate by crate.

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));
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) TestTransportChannel(org.elasticsearch.transport.TestTransportChannel) TransportResponse(org.elasticsearch.transport.TransportResponse) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 3 with TestTransportChannel

use of org.elasticsearch.transport.TestTransportChannel in project crate by crate.

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));
}
Also used : TestTransportChannel(org.elasticsearch.transport.TestTransportChannel) TransportResponse(org.elasticsearch.transport.TransportResponse) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Aggregations

BrokenBarrierException (java.util.concurrent.BrokenBarrierException)3 TestTransportChannel (org.elasticsearch.transport.TestTransportChannel)3 TransportResponse (org.elasticsearch.transport.TransportResponse)3 ActionListener (org.elasticsearch.action.ActionListener)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1