当前位置: 首页>>代码示例>>Java>>正文


Java XContentType.SMILE属性代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentType.SMILE属性的典型用法代码示例。如果您正苦于以下问题:Java XContentType.SMILE属性的具体用法?Java XContentType.SMILE怎么用?Java XContentType.SMILE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.elasticsearch.common.xcontent.XContentType的用法示例。


在下文中一共展示了XContentType.SMILE属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: enforceSameContentType

/**
 * Ensure that the {@link IndexRequest}'s content type is supported by the Bulk API and that it conforms
 * to the current {@link BulkRequest}'s content type (if it's known at the time of this method get called).
 *
 * @return the {@link IndexRequest}'s content type
 */
static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
    XContentType requestContentType = indexRequest.getContentType();
    if (requestContentType != XContentType.JSON && requestContentType != XContentType.SMILE) {
        throw new IllegalArgumentException("Unsupported content-type found for request with content-type [" + requestContentType
                + "], only JSON and SMILE are supported");
    }
    if (xContentType == null) {
        return requestContentType;
    }
    if (requestContentType != xContentType) {
        throw new IllegalArgumentException("Mismatching content-type found for request with content-type [" + requestContentType
                + "], previous requests have content-type [" + xContentType + "]");
    }
    return xContentType;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:Request.java

示例2: testEnforceSameContentType

public void testEnforceSameContentType() {
    XContentType xContentType = randomFrom(XContentType.JSON, XContentType.SMILE);
    IndexRequest indexRequest = new IndexRequest().source(singletonMap("field", "value"), xContentType);
    assertEquals(xContentType, enforceSameContentType(indexRequest, null));
    assertEquals(xContentType, enforceSameContentType(indexRequest, xContentType));

    XContentType bulkContentType = randomBoolean() ? xContentType : null;

    IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () ->
            enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), XContentType.CBOR), bulkContentType));
    assertEquals("Unsupported content-type found for request with content-type [CBOR], only JSON and SMILE are supported",
            exception.getMessage());

    exception = expectThrows(IllegalArgumentException.class, () ->
            enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), XContentType.YAML), bulkContentType));
    assertEquals("Unsupported content-type found for request with content-type [YAML], only JSON and SMILE are supported",
            exception.getMessage());

    XContentType requestContentType = xContentType == XContentType.JSON ? XContentType.SMILE : XContentType.JSON;

    exception = expectThrows(IllegalArgumentException.class, () ->
            enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), requestContentType), xContentType));
    assertEquals("Mismatching content-type found for request with content-type [" + requestContentType + "], "
            + "previous requests have content-type [" + xContentType + "]", exception.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RequestTests.java

示例3: testBlobStoreOperations

public void testBlobStoreOperations() throws IOException {
    BlobStore blobStore = createTestBlobStore();
    BlobContainer blobContainer = blobStore.blobContainer(BlobPath.cleanPath());
    ChecksumBlobStoreFormat<BlobObj> checksumJSON = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent,
        xContentRegistry(), false, XContentType.JSON);
    ChecksumBlobStoreFormat<BlobObj> checksumSMILE = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent,
        xContentRegistry(), false, XContentType.SMILE);
    ChecksumBlobStoreFormat<BlobObj> checksumSMILECompressed = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent,
        xContentRegistry(), true, XContentType.SMILE);

    // Write blobs in different formats
    checksumJSON.write(new BlobObj("checksum json"), blobContainer, "check-json");
    checksumSMILE.write(new BlobObj("checksum smile"), blobContainer, "check-smile");
    checksumSMILECompressed.write(new BlobObj("checksum smile compressed"), blobContainer, "check-smile-comp");

    // Assert that all checksum blobs can be read by all formats
    assertEquals(checksumJSON.read(blobContainer, "check-json").getText(), "checksum json");
    assertEquals(checksumSMILE.read(blobContainer, "check-json").getText(), "checksum json");
    assertEquals(checksumJSON.read(blobContainer, "check-smile").getText(), "checksum smile");
    assertEquals(checksumSMILE.read(blobContainer, "check-smile").getText(), "checksum smile");
    assertEquals(checksumJSON.read(blobContainer, "check-smile-comp").getText(), "checksum smile compressed");
    assertEquals(checksumSMILE.read(blobContainer, "check-smile-comp").getText(), "checksum smile compressed");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:BlobStoreFormatIT.java

示例4: testCompressionIsApplied

public void testCompressionIsApplied() throws IOException {
    BlobStore blobStore = createTestBlobStore();
    BlobContainer blobContainer = blobStore.blobContainer(BlobPath.cleanPath());
    StringBuilder veryRedundantText = new StringBuilder();
    for (int i = 0; i < randomIntBetween(100, 300); i++) {
        veryRedundantText.append("Blah ");
    }
    ChecksumBlobStoreFormat<BlobObj> checksumFormat = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent,
        xContentRegistry(), false, randomBoolean() ? XContentType.SMILE : XContentType.JSON);
    ChecksumBlobStoreFormat<BlobObj> checksumFormatComp = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent,
        xContentRegistry(), true, randomBoolean() ? XContentType.SMILE : XContentType.JSON);
    BlobObj blobObj = new BlobObj(veryRedundantText.toString());
    checksumFormatComp.write(blobObj, blobContainer, "blob-comp");
    checksumFormat.write(blobObj, blobContainer, "blob-not-comp");
    Map<String, BlobMetaData> blobs = blobContainer.listBlobsByPrefix("blob-");
    assertEquals(blobs.size(), 2);
    assertThat(blobs.get("blob-not-comp").length(), greaterThan(blobs.get("blob-comp").length()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:BlobStoreFormatIT.java

示例5: testAtomicWrite

public void testAtomicWrite() throws Exception {
    final BlobStore blobStore = createTestBlobStore();
    final BlobContainer blobContainer = blobStore.blobContainer(BlobPath.cleanPath());
    String testString = randomAsciiOfLength(randomInt(10000));
    final CountDownLatch block = new CountDownLatch(1);
    final CountDownLatch unblock = new CountDownLatch(1);
    final BlobObj blobObj = new BlobObj(testString) {
        @Override
        public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
            super.toXContent(builder, params);
            // Block before finishing writing
            try {
                block.countDown();
                unblock.await(5, TimeUnit.SECONDS);
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
            return builder;
        }
    };
    final ChecksumBlobStoreFormat<BlobObj> checksumFormat = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent,
        xContentRegistry(), randomBoolean(), randomBoolean() ? XContentType.SMILE : XContentType.JSON);
    ExecutorService threadPool = Executors.newFixedThreadPool(1);
    try {
        Future<Void> future = threadPool.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                checksumFormat.writeAtomic(blobObj, blobContainer, "test-blob");
                return null;
            }
        });
        block.await(5, TimeUnit.SECONDS);
        assertFalse(blobContainer.blobExists("test-blob"));
        unblock.countDown();
        future.get();
        assertTrue(blobContainer.blobExists("test-blob"));
    } finally {
        threadPool.shutdown();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:BlobStoreFormatIT.java

示例6: testSmileIsSupported

public void testSmileIsSupported() throws IOException {
    XContentType xContentType = XContentType.SMILE;
    BytesReference data;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        try(XContentBuilder builder = XContentFactory.contentBuilder(xContentType, out)) {
            builder.startObject();
            builder.startObject("index");
            builder.field("_index", "index");
            builder.field("_type", "type");
            builder.field("_id", "test");
            builder.endObject();
            builder.endObject();
        }
        out.write(xContentType.xContent().streamSeparator());
        try(XContentBuilder builder = XContentFactory.contentBuilder(xContentType, out)) {
            builder.startObject();
            builder.field("field", "value");
            builder.endObject();
        }
        out.write(xContentType.xContent().streamSeparator());
        data = out.bytes();
    }

    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(data, null, null, xContentType);
    assertEquals(1, bulkRequest.requests().size());
    DocWriteRequest docWriteRequest = bulkRequest.requests().get(0);
    assertEquals(DocWriteRequest.OpType.INDEX, docWriteRequest.opType());
    assertEquals("index", docWriteRequest.index());
    assertEquals("type", docWriteRequest.type());
    assertEquals("test", docWriteRequest.id());
    assertThat(docWriteRequest, instanceOf(IndexRequest.class));
    IndexRequest request = (IndexRequest) docWriteRequest;
    assertEquals(1, request.sourceAsMap().size());
    assertEquals("value", request.sourceAsMap().get("field"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:BulkRequestTests.java

示例7: restoreContentType

@AfterClass
public static void restoreContentType() {
    Requests.CONTENT_TYPE = XContentType.SMILE;
    Requests.INDEX_CONTENT_TYPE = XContentType.JSON;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ESTestCase.java

示例8: contentType

@Override
public XContentType contentType() {
    return XContentType.SMILE;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:SmileXContentGenerator.java

示例9: type

@Override
public XContentType type() {
    return XContentType.SMILE;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:SmileXContent.java

示例10: getXContentType

@Override
protected XContentType getXContentType() {
    return XContentType.SMILE;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:SmileFilteringGeneratorTests.java

示例11: xcontentType

@Override
public XContentType xcontentType() {
    return XContentType.SMILE;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:SmileXContentTests.java


注:本文中的org.elasticsearch.common.xcontent.XContentType.SMILE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。