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());
}
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());
}
}
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));
}
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)));
}
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));
}
Aggregations