當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。