Search in sources :

Example 16 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class OperationRoutingTests method testThatOnlyNodesSupportNodeIds.

public void testThatOnlyNodesSupportNodeIds() throws InterruptedException, IOException {
    TestThreadPool threadPool = null;
    ClusterService clusterService = null;
    try {
        threadPool = new TestThreadPool("testThatOnlyNodesSupportNodeIds");
        clusterService = ClusterServiceUtils.createClusterService(threadPool);
        final String indexName = "test";
        ClusterServiceUtils.setState(clusterService, ClusterStateCreationUtils.stateWithActivePrimary(indexName, true, randomInt(8)));
        final Index index = clusterService.state().metaData().index(indexName).getIndex();
        final List<ShardRouting> shards = clusterService.state().getRoutingNodes().assignedShards(new ShardId(index, 0));
        final int count = randomIntBetween(1, shards.size());
        int position = 0;
        final List<String> nodes = new ArrayList<>();
        final List<ShardRouting> expected = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            if (randomBoolean() && !shards.get(position).initializing()) {
                nodes.add(shards.get(position).currentNodeId());
                expected.add(shards.get(position));
                position++;
            } else {
                nodes.add("missing_" + i);
            }
        }
        if (expected.size() > 0) {
            final ShardIterator it = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)).getShards(clusterService.state(), indexName, 0, "_only_nodes:" + String.join(",", nodes));
            final List<ShardRouting> only = new ArrayList<>();
            ShardRouting shard;
            while ((shard = it.nextOrNull()) != null) {
                only.add(shard);
            }
            assertThat(new HashSet<>(only), equalTo(new HashSet<>(expected)));
        } else {
            final ClusterService cs = clusterService;
            final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)).getShards(cs.state(), indexName, 0, "_only_nodes:" + String.join(",", nodes)));
            if (nodes.size() == 1) {
                assertThat(e, hasToString(containsString("no data nodes with criteria [" + String.join(",", nodes) + "] found for shard: [test][0]")));
            } else {
                assertThat(e, hasToString(containsString("no data nodes with criterion [" + String.join(",", nodes) + "] found for shard: [test][0]")));
            }
        }
    } finally {
        IOUtils.close(clusterService);
        terminate(threadPool);
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HasToString.hasToString(org.hamcrest.object.HasToString.hasToString) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ShardId(org.elasticsearch.index.shard.ShardId) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashSet(java.util.HashSet)

Example 17 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class DelayedAllocationServiceTests method createDelayedAllocationService.

@Before
public void createDelayedAllocationService() {
    threadPool = new TestThreadPool(getTestName());
    clusterService = mock(ClusterService.class);
    allocationService = createAllocationService(Settings.EMPTY, new DelayedShardsMockGatewayAllocator());
    delayedAllocationService = new TestDelayAllocationService(Settings.EMPTY, threadPool, clusterService, allocationService);
    verify(clusterService).addListener(delayedAllocationService);
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 18 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class NodeConnectionsServiceTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.threadPool = new TestThreadPool(getClass().getName());
    this.transport = new MockTransport();
    transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> DiscoveryNode.createLocal(Settings.EMPTY, buildNewFakeTransportAddress(), UUIDs.randomBase64UUID()), null);
    transportService.start();
    transportService.acceptIncomingRequests();
}
Also used : Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) TransportServiceAdapter(org.elasticsearch.transport.TransportServiceAdapter) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) CheckedBiConsumer(org.elasticsearch.common.CheckedBiConsumer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) After(org.junit.After) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Transport(org.elasticsearch.transport.Transport) UUIDs(org.elasticsearch.common.UUIDs) Set(java.util.Set) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Lifecycle(org.elasticsearch.common.component.Lifecycle) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TransportException(org.elasticsearch.transport.TransportException) Collections(java.util.Collections) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 19 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class ActionModuleTests method testPluginCantOverwriteBuiltinRestHandler.

public void testPluginCantOverwriteBuiltinRestHandler() throws IOException {
    ActionPlugin dupsMainAction = new ActionPlugin() {

        @Override
        public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
            return singletonList(new RestMainAction(settings, restController));
        }
    };
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    ThreadPool threadPool = new TestThreadPool(getTestName());
    try {
        ActionModule actionModule = new ActionModule(false, settings.getSettings(), new IndexNameExpressionResolver(Settings.EMPTY), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(dupsMainAction), null, null);
        Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.initRestHandlers(null));
        assertThat(e.getMessage(), startsWith("Path [/] already has a value [" + RestMainAction.class.getName()));
    } finally {
        threadPool.shutdown();
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ActionPlugin(org.elasticsearch.plugins.ActionPlugin) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) RestController(org.elasticsearch.rest.RestController) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IOException(java.io.IOException) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) RestMainAction(org.elasticsearch.rest.action.RestMainAction) RestHandler(org.elasticsearch.rest.RestHandler) SettingsModule(org.elasticsearch.common.settings.SettingsModule) Supplier(java.util.function.Supplier) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 20 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class ActionModuleTests method testPluginCanRegisterRestHandler.

public void testPluginCanRegisterRestHandler() {
    class FakeHandler implements RestHandler {

        FakeHandler(RestController restController) {
            restController.registerHandler(Method.GET, "/_dummy", this);
        }

        @Override
        public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
        }
    }
    ActionPlugin registersFakeHandler = new ActionPlugin() {

        @Override
        public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
            return singletonList(new FakeHandler(restController));
        }
    };
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    ThreadPool threadPool = new TestThreadPool(getTestName());
    try {
        ActionModule actionModule = new ActionModule(false, settings.getSettings(), new IndexNameExpressionResolver(Settings.EMPTY), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(registersFakeHandler), null, null);
        actionModule.initRestHandlers(null);
        // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail
        Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.getRestController().registerHandler(Method.GET, "/_dummy", null));
        assertThat(e.getMessage(), startsWith("Path [/_dummy] already has a value [" + FakeHandler.class.getName()));
    } finally {
        threadPool.shutdown();
    }
}
Also used : NodeClient(org.elasticsearch.client.node.NodeClient) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ActionPlugin(org.elasticsearch.plugins.ActionPlugin) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) RestController(org.elasticsearch.rest.RestController) RestChannel(org.elasticsearch.rest.RestChannel) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IOException(java.io.IOException) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) RestRequest(org.elasticsearch.rest.RestRequest) RestHandler(org.elasticsearch.rest.RestHandler) SettingsModule(org.elasticsearch.common.settings.SettingsModule) Supplier(java.util.function.Supplier) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)48 ThreadPool (org.elasticsearch.threadpool.ThreadPool)21 Before (org.junit.Before)18 Settings (org.elasticsearch.common.settings.Settings)15 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)8 IOException (java.io.IOException)7 TimeValue (org.elasticsearch.common.unit.TimeValue)7 ClusterService (org.elasticsearch.cluster.service.ClusterService)6 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)6 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)6 TransportSettings (org.elasticsearch.transport.TransportSettings)6 ScheduledFuture (java.util.concurrent.ScheduledFuture)5 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 NetworkService (org.elasticsearch.common.network.NetworkService)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3