Search in sources :

Example 1 with TransportResponseOptions

use of org.elasticsearch.transport.TransportResponseOptions in project elasticsearch by elastic.

the class ZenDiscoveryUnitTests method testValidateOnUnsupportedIndexVersionCreated.

public void testValidateOnUnsupportedIndexVersionCreated() throws Exception {
    final int iters = randomIntBetween(3, 10);
    for (int i = 0; i < iters; i++) {
        ClusterState.Builder stateBuilder = ClusterState.builder(ClusterName.DEFAULT);
        final DiscoveryNode otherNode = new DiscoveryNode("other_node", buildNewFakeTransportAddress(), emptyMap(), EnumSet.allOf(DiscoveryNode.Role.class), Version.CURRENT);
        MembershipAction.ValidateJoinRequestRequestHandler request = new MembershipAction.ValidateJoinRequestRequestHandler();
        final boolean incompatible = randomBoolean();
        IndexMetaData indexMetaData = IndexMetaData.builder("test").settings(Settings.builder().put(SETTING_VERSION_CREATED, incompatible ? VersionUtils.getPreviousVersion(Version.CURRENT.minimumIndexCompatibilityVersion()) : VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumIndexCompatibilityVersion(), Version.CURRENT)).put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_CREATION_DATE, System.currentTimeMillis())).state(IndexMetaData.State.OPEN).build();
        IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(indexMetaData.getIndex());
        RoutingTable.Builder routing = new RoutingTable.Builder();
        routing.addAsNew(indexMetaData);
        final ShardId shardId = new ShardId("test", "_na_", 0);
        IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId);
        final DiscoveryNode primaryNode = otherNode;
        indexShardRoutingBuilder.addShard(TestShardRouting.newShardRouting("test", 0, primaryNode.getId(), null, true, ShardRoutingState.INITIALIZING, new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, "getting there")));
        indexRoutingTableBuilder.addIndexShard(indexShardRoutingBuilder.build());
        IndexRoutingTable indexRoutingTable = indexRoutingTableBuilder.build();
        IndexMetaData updatedIndexMetaData = updateActiveAllocations(indexRoutingTable, indexMetaData);
        stateBuilder.metaData(MetaData.builder().put(updatedIndexMetaData, false).generateClusterUuidIfNeeded()).routingTable(RoutingTable.builder().add(indexRoutingTable).build());
        if (incompatible) {
            IllegalStateException ex = expectThrows(IllegalStateException.class, () -> request.messageReceived(new MembershipAction.ValidateJoinRequest(stateBuilder.build()), null));
            assertEquals("index [test] version not supported: " + VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()) + " minimum compatible index version is: " + Version.CURRENT.minimumCompatibilityVersion(), ex.getMessage());
        } else {
            AtomicBoolean sendResponse = new AtomicBoolean(false);
            request.messageReceived(new MembershipAction.ValidateJoinRequest(stateBuilder.build()), new TransportChannel() {

                @Override
                public String action() {
                    return null;
                }

                @Override
                public String getProfileName() {
                    return null;
                }

                @Override
                public long getRequestId() {
                    return 0;
                }

                @Override
                public String getChannelType() {
                    return null;
                }

                @Override
                public void sendResponse(TransportResponse response) throws IOException {
                    sendResponse.set(true);
                }

                @Override
                public void sendResponse(TransportResponse response, TransportResponseOptions options) throws IOException {
                }

                @Override
                public void sendResponse(Exception exception) throws IOException {
                }
            });
            assertTrue(sendResponse.get());
        }
    }
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) TransportResponse(org.elasticsearch.transport.TransportResponse) ShardId(org.elasticsearch.index.shard.ShardId) TransportChannel(org.elasticsearch.transport.TransportChannel) ClusterState(org.elasticsearch.cluster.ClusterState) ZenDiscovery.shouldIgnoreOrRejectNewClusterState(org.elasticsearch.discovery.zen.ZenDiscovery.shouldIgnoreOrRejectNewClusterState) IOException(java.io.IOException) IOException(java.io.IOException) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) TransportResponseOptions(org.elasticsearch.transport.TransportResponseOptions)

Aggregations

IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 Role (org.elasticsearch.cluster.node.DiscoveryNode.Role)1 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)1 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)1 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)1 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)1 ZenDiscovery.shouldIgnoreOrRejectNewClusterState (org.elasticsearch.discovery.zen.ZenDiscovery.shouldIgnoreOrRejectNewClusterState)1 ShardId (org.elasticsearch.index.shard.ShardId)1 TransportChannel (org.elasticsearch.transport.TransportChannel)1 TransportResponse (org.elasticsearch.transport.TransportResponse)1 TransportResponseOptions (org.elasticsearch.transport.TransportResponseOptions)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1