Search in sources :

Example 51 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class CancelTests method testUpdateByQueryCancelWithWorkers.

public void testUpdateByQueryCancelWithWorkers() throws Exception {
    BytesReference pipeline = new BytesArray("{\n" + "  \"description\" : \"sets processed to true\",\n" + "  \"processors\" : [ {\n" + "      \"test\" : {}\n" + "  } ]\n" + "}");
    assertAcked(client().admin().cluster().preparePutPipeline("set-processed", pipeline, XContentType.JSON).get());
    testCancel(UpdateByQueryAction.NAME, updateByQuery().setPipeline("set-processed").source(INDEX).setSlices(5), (response, total, modified) -> {
        assertThat(response, matcher().updated(modified).reasonCancelled(equalTo("by user request")).slices(hasSize(5)));
        assertHitCount(client().prepareSearch(INDEX).setSize(0).setQuery(termQuery("processed", true)).get(), modified);
    }, equalTo("update-by-query [" + INDEX + "]"));
    assertAcked(client().admin().cluster().deletePipeline(new DeletePipelineRequest("set-processed")).get());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) BytesArray(org.elasticsearch.common.bytes.BytesArray)

Example 52 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class RestReindexActionTests method testReindexFromRemoteRequestParsing.

public void testReindexFromRemoteRequestParsing() throws IOException {
    BytesReference request;
    try (XContentBuilder b = JsonXContent.contentBuilder()) {
        b.startObject();
        {
            b.startObject("source");
            {
                b.startObject("remote");
                {
                    b.field("host", "http://localhost:9200");
                }
                b.endObject();
                b.field("index", "source");
            }
            b.endObject();
            b.startObject("dest");
            {
                b.field("index", "dest");
            }
            b.endObject();
        }
        b.endObject();
        request = b.bytes();
    }
    try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
        ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
        RestReindexAction.PARSER.parse(p, r, null);
        assertEquals("localhost", r.getRemoteInfo().getHost());
        assertArrayEquals(new String[] { "source" }, r.getSearchRequest().indices());
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SearchRequest(org.elasticsearch.action.search.SearchRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 53 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class Netty4UtilsTests method testToChannelBuffer.

public void testToChannelBuffer() throws IOException {
    BytesReference ref = getRandomizedBytesReference(randomIntBetween(1, 3 * PAGE_SIZE));
    ByteBuf buffer = Netty4Utils.toByteBuf(ref);
    BytesReference bytesReference = Netty4Utils.toBytesReference(buffer);
    if (ref instanceof ByteBufBytesReference) {
        assertEquals(buffer, ((ByteBufBytesReference) ref).toByteBuf());
    } else if (AbstractBytesReferenceTestCase.getNumPages(ref) > 1) {
        // we gather the buffers into a channel buffer
        assertTrue(buffer instanceof CompositeByteBuf);
    }
    assertArrayEquals(BytesReference.toBytes(ref), BytesReference.toBytes(bytesReference));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) ByteBuf(io.netty.buffer.ByteBuf)

Example 54 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class Netty4UtilsTests method testToChannelBufferWithSliceAfter.

public void testToChannelBufferWithSliceAfter() throws IOException {
    BytesReference ref = getRandomizedBytesReference(randomIntBetween(1, 3 * PAGE_SIZE));
    int sliceOffset = randomIntBetween(0, ref.length());
    int sliceLength = randomIntBetween(ref.length() - sliceOffset, ref.length() - sliceOffset);
    ByteBuf buffer = Netty4Utils.toByteBuf(ref);
    BytesReference bytesReference = Netty4Utils.toBytesReference(buffer);
    assertArrayEquals(BytesReference.toBytes(ref.slice(sliceOffset, sliceLength)), BytesReference.toBytes(bytesReference.slice(sliceOffset, sliceLength)));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) ByteBuf(io.netty.buffer.ByteBuf)

Example 55 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class ByteBufBytesReferenceTests method testSliceOnAdvancedBuffer.

public void testSliceOnAdvancedBuffer() throws IOException {
    BytesReference bytesReference = newBytesReference(randomIntBetween(10, 3 * PAGE_SIZE));
    BytesRef bytesRef = bytesReference.toBytesRef();
    ByteBuf channelBuffer = Unpooled.wrappedBuffer(bytesRef.bytes, bytesRef.offset, bytesRef.length);
    int numBytesToRead = randomIntBetween(1, 5);
    for (int i = 0; i < numBytesToRead; i++) {
        channelBuffer.readByte();
    }
    BytesReference other = Netty4Utils.toBytesReference(channelBuffer);
    BytesReference slice = bytesReference.slice(numBytesToRead, bytesReference.length() - numBytesToRead);
    assertEquals(other, slice);
    assertEquals(other.slice(3, 1), slice.slice(3, 1));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) ByteBuf(io.netty.buffer.ByteBuf) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

BytesReference (org.elasticsearch.common.bytes.BytesReference)318 Matchers.containsString (org.hamcrest.Matchers.containsString)72 XContentParser (org.elasticsearch.common.xcontent.XContentParser)63 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)61 IOException (java.io.IOException)58 XContentType (org.elasticsearch.common.xcontent.XContentType)50 BytesArray (org.elasticsearch.common.bytes.BytesArray)47 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)37 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)30 Map (java.util.Map)26 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)26 Test (org.junit.Test)25 List (java.util.List)24 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)24 Version (org.elasticsearch.Version)22 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)20 ReleasableBytesReference (org.elasticsearch.common.bytes.ReleasableBytesReference)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 BytesRef (org.apache.lucene.util.BytesRef)18