List of usage examples for org.apache.lucene.util ArrayUtil MAX_ARRAY_LENGTH
int MAX_ARRAY_LENGTH
To view the source code for org.apache.lucene.util ArrayUtil MAX_ARRAY_LENGTH.
Click Source Link
From source file:io.crate.execution.engine.sort.SortingTopNCollector.java
License:Apache License
/** * @param inputs contains output {@link Input}s and orderBy {@link Input}s * @param expressions expressions linked to the inputs * @param numOutputs number of output columns * @param comparator used to sort the rows * @param limit the max number of rows the result should contain * @param offset the number of rows to skip (after sort) *///w w w .j ava2s .c o m public SortingTopNCollector(Collection<? extends Input<?>> inputs, Iterable<? extends CollectExpression<Row, ?>> expressions, int numOutputs, Comparator<Object[]> comparator, int limit, int offset) { Preconditions.checkArgument(limit > 0, "Invalid LIMIT: value must be > 0; got: " + limit); Preconditions.checkArgument(offset >= 0, "Invalid OFFSET: value must be >= 0; got: " + offset); this.inputs = inputs; this.expressions = expressions; this.numOutputs = numOutputs; this.comparator = comparator; this.offset = offset; this.maxSize = limit + offset; if (maxSize >= ArrayUtil.MAX_ARRAY_LENGTH || maxSize < 0) { // Throw exception to prevent confusing OOME in PriorityQueue // 1) if offset + limit exceeds maximum array length // 2) if offset + limit exceeds Integer.MAX_VALUE (then maxSize is negative!) throw new IllegalArgumentException("Invalid LIMIT + OFFSET: value must be <= " + (ArrayUtil.MAX_ARRAY_LENGTH - 1) + "; got: " + maxSize); } }
From source file:org.codelibs.elasticsearch.common.io.stream.StreamInput.java
License:Apache License
/** * Reads a vint via {#readVInt()} and applies basic checks to ensure the read array size is sane. * This method uses {#ensureCanReadBytes(int)} to ensure this stream has enough bytes to read for the read array size. */// w w w . j av a2 s . c om private int readArraySize() throws IOException { final int arraySize = readVInt(); if (arraySize > ArrayUtil.MAX_ARRAY_LENGTH) { throw new IllegalStateException( "array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: " + arraySize); } if (arraySize < 0) { throw new NegativeArraySizeException("array size must be positive but was: " + arraySize); } // lets do a sanity check that if we are reading an array size that is bigger that the remaining bytes we can safely // throw an exception instead of allocating the array based on the size. A simple corrutpted byte can make a node go OOM // if the size is large and for perf reasons we allocate arrays ahead of time ensureCanReadBytes(arraySize); return arraySize; }
From source file:org.elasticsearch.join.query.InnerHitsIT.java
License:Apache License
public void testUseMaxDocInsteadOfSize() throws Exception { if (legacy()) { assertAcked(prepareCreate("index1").addMapping("child", "_parent", "type=parent")); } else {/* w w w.j a v a 2 s .c o m*/ assertAcked(prepareCreate("index1").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); } client().admin().indices().prepareUpdateSettings("index1").setSettings(Collections .singletonMap(IndexSettings.MAX_INNER_RESULT_WINDOW_SETTING.getKey(), ArrayUtil.MAX_ARRAY_LENGTH)) .get(); List<IndexRequestBuilder> requests = new ArrayList<>(); requests.add(createIndexRequest("index1", "parent", "1", null)); requests.add(createIndexRequest("index1", "child", "2", "1", "field", "value1")); indexRandom(true, requests); QueryBuilder query = hasChildQuery("child", matchQuery("field", "value1"), ScoreMode.None) .innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)); SearchResponse response = client().prepareSearch("index1").setQuery(query).get(); assertNoFailures(response); assertHitCount(response, 1); }
From source file:org.elasticsearch.messy.tests.InnerHitsTests.java
License:Apache License
@Test public void testDontExplode() throws Exception { assertAcked(prepareCreate("index1").addMapping("child", "_parent", "type=parent")); List<IndexRequestBuilder> requests = new ArrayList<>(); requests.add(client().prepareIndex("index1", "parent", "1").setSource("{}")); requests.add(client().prepareIndex("index1", "child", "1").setParent("1").setSource("field", "value1")); indexRandom(true, requests);//from w w w . j a va2s . c o m SearchResponse response = client().prepareSearch("index1") .setQuery(hasChildQuery("child", matchQuery("field", "value1")).innerHit(new QueryInnerHits(null, new InnerHitsBuilder.InnerHit().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)))) .addSort("_uid", SortOrder.ASC).get(); assertNoFailures(response); assertHitCount(response, 1); assertAcked(prepareCreate("index2").addMapping("type", "nested", "type=nested")); client().prepareIndex("index2", "type", "1").setSource(jsonBuilder().startObject().startArray("nested") .startObject().field("field", "value1").endObject().endArray().endObject()).setRefresh(true).get(); response = client().prepareSearch("index2") .setQuery(nestedQuery("nested", matchQuery("nested.field", "value1")).innerHit(new QueryInnerHits( null, new InnerHitsBuilder.InnerHit().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)))) .addSort("_uid", SortOrder.ASC).get(); assertNoFailures(response); assertHitCount(response, 1); }
From source file:org.elasticsearch.messy.tests.TopHitsTests.java
License:Apache License
@Test public void testDontExplode() throws Exception { SearchResponse response = client().prepareSearch("idx").setTypes("type") .addAggregation(terms("terms").executionHint(randomExecutionHint()).field(TERMS_AGGS_FIELD) .subAggregation(topHits("hits").setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1) .addSort(SortBuilders.fieldSort(SORT_FIELD).order(SortOrder.DESC)))) .get();/*from ww w . j a v a2s . c om*/ assertNoFailures(response); }
From source file:org.elasticsearch.search.fetch.subphase.InnerHitsIT.java
License:Apache License
public void testDontExplode() throws Exception { assertAcked(prepareCreate("index1").addMapping("child", "_parent", "type=parent")); List<IndexRequestBuilder> requests = new ArrayList<>(); requests.add(client().prepareIndex("index1", "parent", "1").setSource("{}")); requests.add(client().prepareIndex("index1", "child", "1").setParent("1").setSource("field", "value1")); indexRandom(true, requests);//from w w w. ja v a2 s.c om QueryBuilder query = hasChildQuery("child", matchQuery("field", "value1"), ScoreMode.None) .innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)); SearchResponse response = client().prepareSearch("index1").setQuery(query).addSort("_uid", SortOrder.ASC) .get(); assertNoFailures(response); assertHitCount(response, 1); assertAcked(prepareCreate("index2").addMapping("type", "nested", "type=nested")); client().prepareIndex("index2", "type", "1").setSource(jsonBuilder().startObject().startArray("nested") .startObject().field("field", "value1").endObject().endArray().endObject()) .setRefreshPolicy(IMMEDIATE).get(); query = nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg) .innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)); response = client().prepareSearch("index2").setQuery(query).addSort("_uid", SortOrder.ASC).get(); assertNoFailures(response); assertHitCount(response, 1); }
From source file:org.elasticsearch.search.innerhits.InnerHitsIT.java
License:Apache License
@Test public void testDontExplode() throws Exception { assertAcked(prepareCreate("index1").addMapping("child", "_parent", "type=parent")); List<IndexRequestBuilder> requests = new ArrayList<>(); requests.add(client().prepareIndex("index1", "parent", "1").setSource("{}")); requests.add(client().prepareIndex("index1", "child", "1").setParent("1").setSource("field", "value1")); indexRandom(true, requests);/* w w w.j a v a2 s . co m*/ SearchResponse response = client().prepareSearch("index1") .setQuery(hasChildQuery("child", matchQuery("field", "value1")) .innerHit(new QueryInnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1))) .addSort("_uid", SortOrder.ASC).get(); assertNoFailures(response); assertHitCount(response, 1); assertAcked(prepareCreate("index2").addMapping("type", "nested", "type=nested")); client().prepareIndex("index2", "type", "1").setSource(jsonBuilder().startObject().startArray("nested") .startObject().field("field", "value1").endObject().endArray().endObject()).setRefresh(true).get(); response = client().prepareSearch("index2") .setQuery(nestedQuery("nested", matchQuery("nested.field", "value1")) .innerHit(new QueryInnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1))) .addSort("_uid", SortOrder.ASC).get(); assertNoFailures(response); assertHitCount(response, 1); }
From source file:org.elasticsearch.xpack.security.authc.AuthenticationServiceTests.java
License:Open Source License
public void testInvalidToken() throws Exception { final User user = new User("_username", "r1"); when(firstRealm.token(threadContext)).thenReturn(token); when(firstRealm.supports(token)).thenReturn(true); mockAuthenticate(firstRealm, token, user); final int numBytes = randomIntBetween(TokenService.MINIMUM_BYTES, TokenService.MINIMUM_BYTES + 32); final byte[] randomBytes = new byte[numBytes]; random().nextBytes(randomBytes);// w ww . j a v a2 s. c o m final CountDownLatch latch = new CountDownLatch(1); final Authentication expected = new Authentication(user, new RealmRef(firstRealm.name(), firstRealm.type(), "authc_test"), null); AtomicBoolean success = new AtomicBoolean(false); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.putHeader("Authorization", "Bearer " + Base64.getEncoder().encodeToString(randomBytes)); service.authenticate("_action", message, (User) null, ActionListener.wrap(result -> { assertThat(result, notNullValue()); assertThat(result.getUser(), is(user)); assertThat(result.getLookedUpBy(), is(nullValue())); assertThat(result.getAuthenticatedBy(), is(notNullValue())); assertThreadContextContainsAuthentication(result); assertEquals(expected, result); success.set(true); latch.countDown(); }, e -> { if (e instanceof IllegalStateException) { assertThat(e.getMessage(), containsString( "array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: ")); latch.countDown(); } else if (e instanceof NegativeArraySizeException) { assertThat(e.getMessage(), containsString("array size must be positive but was: ")); latch.countDown(); } else { logger.error("unexpected exception", e); latch.countDown(); fail("unexpected exception: " + e.getMessage()); } })); } catch (IllegalStateException ex) { assertThat(ex.getMessage(), containsString("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: ")); latch.countDown(); } catch (NegativeArraySizeException ex) { assertThat(ex.getMessage(), containsString("array size must be positive but was: ")); latch.countDown(); } // we need to use a latch here because the key computation goes async on another thread! latch.await(); if (success.get()) { verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message); } verifyNoMoreInteractions(auditTrail); }