Search in sources :

Example 96 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class RemoteRequestBuildersTests method testInitialSearchParamsMisc.

public void testInitialSearchParamsMisc() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
    TimeValue scroll = null;
    if (randomBoolean()) {
        scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
        searchRequest.scroll(scroll);
    }
    int size = between(0, Integer.MAX_VALUE);
    searchRequest.source().size(size);
    Boolean fetchVersion = null;
    if (randomBoolean()) {
        fetchVersion = randomBoolean();
        searchRequest.source().version(fetchVersion);
    }
    Map<String, String> params = initialSearchParams(searchRequest, remoteVersion);
    assertThat(params, scroll == null ? not(hasKey("scroll")) : hasEntry("scroll", scroll.toString()));
    assertThat(params, hasEntry("size", Integer.toString(size)));
    assertThat(params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null)));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Version(org.elasticsearch.Version) Matchers.containsString(org.hamcrest.Matchers.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 97 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class RemoteScrollableHitSourceTests method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    final ExecutorService directExecutor = EsExecutors.newDirectExecutorService();
    threadPool = new TestThreadPool(getTestName()) {

        @Override
        public ExecutorService executor(String name) {
            return directExecutor;
        }

        @Override
        public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
            command.run();
            return null;
        }
    };
    retries = 0;
    searchRequest = new SearchRequest();
    searchRequest.scroll(timeValueMinutes(5));
    searchRequest.source(new SearchSourceBuilder().size(10).version(true).sort("_doc").size(123));
    retriesAllowed = 0;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ExecutorService(java.util.concurrent.ExecutorService) Matchers.containsString(org.hamcrest.Matchers.containsString) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TimeValue(org.elasticsearch.common.unit.TimeValue) ScheduledFuture(java.util.concurrent.ScheduledFuture) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Before(org.junit.Before)

Example 98 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class Netty4Transport method connectToChannels.

@Override
protected NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile profile) {
    final Channel[] channels = new Channel[profile.getNumConnections()];
    final NodeChannels nodeChannels = new NodeChannels(node, channels, profile);
    boolean success = false;
    try {
        final TimeValue connectTimeout;
        final Bootstrap bootstrap;
        final TimeValue defaultConnectTimeout = defaultConnectionProfile.getConnectTimeout();
        if (profile.getConnectTimeout() != null && profile.getConnectTimeout().equals(defaultConnectTimeout) == false) {
            bootstrap = this.bootstrap.clone(this.bootstrap.config().group());
            bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(profile.getConnectTimeout().millis()));
            connectTimeout = profile.getConnectTimeout();
        } else {
            connectTimeout = defaultConnectTimeout;
            bootstrap = this.bootstrap;
        }
        final ArrayList<ChannelFuture> connections = new ArrayList<>(channels.length);
        final InetSocketAddress address = node.getAddress().address();
        for (int i = 0; i < channels.length; i++) {
            connections.add(bootstrap.connect(address));
        }
        final Iterator<ChannelFuture> iterator = connections.iterator();
        try {
            for (int i = 0; i < channels.length; i++) {
                assert iterator.hasNext();
                ChannelFuture future = iterator.next();
                future.awaitUninterruptibly((long) (connectTimeout.millis() * 1.5));
                if (!future.isSuccess()) {
                    throw new ConnectTransportException(node, "connect_timeout[" + connectTimeout + "]", future.cause());
                }
                channels[i] = future.channel();
                channels[i].closeFuture().addListener(new ChannelCloseListener(node));
            }
            assert iterator.hasNext() == false : "not all created connection have been consumed";
        } catch (final RuntimeException e) {
            for (final ChannelFuture future : Collections.unmodifiableList(connections)) {
                FutureUtils.cancel(future);
                if (future.channel() != null && future.channel().isOpen()) {
                    try {
                        future.channel().close();
                    } catch (Exception inner) {
                        e.addSuppressed(inner);
                    }
                }
            }
            throw e;
        }
        success = true;
    } finally {
        if (success == false) {
            try {
                nodeChannels.close();
            } catch (IOException e) {
                logger.trace("exception while closing channels", e);
            }
        }
    }
    return nodeChannels;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) IOException(java.io.IOException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 99 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class RoundTripTests method testReindexRequest.

public void testReindexRequest() throws IOException {
    ReindexRequest reindex = new ReindexRequest(new SearchRequest(), new IndexRequest());
    randomRequest(reindex);
    reindex.getDestination().version(randomFrom(Versions.MATCH_ANY, Versions.MATCH_DELETED, 12L, 1L, 123124L, 12L));
    reindex.getDestination().index("test");
    if (randomBoolean()) {
        int port = between(1, Integer.MAX_VALUE);
        BytesReference query = new BytesArray(randomAsciiOfLength(5));
        String username = randomBoolean() ? randomAsciiOfLength(5) : null;
        String password = username != null && randomBoolean() ? randomAsciiOfLength(5) : null;
        int headersCount = randomBoolean() ? 0 : between(1, 10);
        Map<String, String> headers = new HashMap<>(headersCount);
        while (headers.size() < headersCount) {
            headers.put(randomAsciiOfLength(5), randomAsciiOfLength(5));
        }
        TimeValue socketTimeout = parseTimeValue(randomPositiveTimeValue(), "socketTimeout");
        TimeValue connectTimeout = parseTimeValue(randomPositiveTimeValue(), "connectTimeout");
        reindex.setRemoteInfo(new RemoteInfo(randomAsciiOfLength(5), randomAsciiOfLength(5), port, query, username, password, headers, socketTimeout, connectTimeout));
    }
    ReindexRequest tripped = new ReindexRequest();
    roundTrip(reindex, tripped);
    assertRequestEquals(reindex, tripped);
    // Try slices with a version that doesn't support slices. That should fail.
    reindex.setSlices(between(2, 1000));
    Exception e = expectThrows(IllegalArgumentException.class, () -> roundTrip(Version.V_5_0_0_rc1, reindex, null));
    assertEquals("Attempting to send sliced reindex-style request to a node that doesn't support it. " + "Version is [5.0.0-rc1] but must be [5.1.1]", e.getMessage());
    // Try without slices with a version that doesn't support slices. That should work.
    tripped = new ReindexRequest();
    reindex.setSlices(1);
    roundTrip(Version.V_5_0_0_rc1, reindex, tripped);
    assertRequestEquals(Version.V_5_0_0_rc1, reindex, tripped);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SearchRequest(org.elasticsearch.action.search.SearchRequest) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo) TestUtil.randomSimpleString(org.apache.lucene.util.TestUtil.randomSimpleString) IndexRequest(org.elasticsearch.action.index.IndexRequest) TimeValue(org.elasticsearch.common.unit.TimeValue) TimeValue.parseTimeValue(org.elasticsearch.common.unit.TimeValue.parseTimeValue) IOException(java.io.IOException)

Example 100 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class CacheBuilderTests method testSettingExpireAfterWrite.

public void testSettingExpireAfterWrite() {
    IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> CacheBuilder.builder().setExpireAfterWrite(TimeValue.MINUS_ONE));
    assertThat(iae.getMessage(), containsString("expireAfterWrite <="));
    iae = expectThrows(IllegalArgumentException.class, () -> CacheBuilder.builder().setExpireAfterWrite(TimeValue.ZERO));
    assertThat(iae.getMessage(), containsString("expireAfterWrite <="));
    final TimeValue timeValue = TimeValue.parseTimeValue(randomPositiveTimeValue(), "");
    Cache<Object, Object> cache = CacheBuilder.builder().setExpireAfterWrite(timeValue).build();
    assertEquals(timeValue.getNanos(), cache.getExpireAfterWriteNanos());
}
Also used : TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

TimeValue (org.elasticsearch.common.unit.TimeValue)139 ClusterState (org.elasticsearch.cluster.ClusterState)26 IOException (java.io.IOException)24 CountDownLatch (java.util.concurrent.CountDownLatch)18 ArrayList (java.util.ArrayList)17 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)17 Settings (org.elasticsearch.common.settings.Settings)17 Supplier (org.apache.logging.log4j.util.Supplier)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 SearchResponse (org.elasticsearch.action.search.SearchResponse)15 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 Map (java.util.Map)12 TimeUnit (java.util.concurrent.TimeUnit)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 List (java.util.List)10 HashMap (java.util.HashMap)9 Iterator (java.util.Iterator)8 ExecutionException (java.util.concurrent.ExecutionException)8