當前位置: 首頁>>代碼示例>>Java>>正文


Java NamedWriteableAwareStreamInput類代碼示例

本文整理匯總了Java中org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput的典型用法代碼示例。如果您正苦於以下問題:Java NamedWriteableAwareStreamInput類的具體用法?Java NamedWriteableAwareStreamInput怎麽用?Java NamedWriteableAwareStreamInput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NamedWriteableAwareStreamInput類屬於org.elasticsearch.common.io.stream包,在下文中一共展示了NamedWriteableAwareStreamInput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSerialization

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
public void testSerialization() throws Exception {
    ShardSearchTransportRequest shardSearchTransportRequest = createShardSearchTransportRequest();
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        shardSearchTransportRequest.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ShardSearchTransportRequest deserializedRequest = new ShardSearchTransportRequest();
            deserializedRequest.readFrom(in);
            assertEquals(deserializedRequest.scroll(), shardSearchTransportRequest.scroll());
            assertEquals(deserializedRequest.filteringAliases(), shardSearchTransportRequest.filteringAliases());
            assertArrayEquals(deserializedRequest.indices(), shardSearchTransportRequest.indices());
            assertArrayEquals(deserializedRequest.types(), shardSearchTransportRequest.types());
            assertEquals(deserializedRequest.indicesOptions(), shardSearchTransportRequest.indicesOptions());
            assertEquals(deserializedRequest.isProfile(), shardSearchTransportRequest.isProfile());
            assertEquals(deserializedRequest.nowInMillis(), shardSearchTransportRequest.nowInMillis());
            assertEquals(deserializedRequest.source(), shardSearchTransportRequest.source());
            assertEquals(deserializedRequest.searchType(), shardSearchTransportRequest.searchType());
            assertEquals(deserializedRequest.shardId(), shardSearchTransportRequest.shardId());
            assertEquals(deserializedRequest.numberOfShards(), shardSearchTransportRequest.numberOfShards());
            assertEquals(deserializedRequest.cacheKey(), shardSearchTransportRequest.cacheKey());
            assertNotSame(deserializedRequest, shardSearchTransportRequest);
            assertEquals(deserializedRequest.filteringAliases(), shardSearchTransportRequest.filteringAliases());
            assertEquals(deserializedRequest.indexBoost(), shardSearchTransportRequest.indexBoost(), 0.0f);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:ShardSearchTransportRequestTests.java

示例2: testSerialize50RequestForIndexBoost

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
public void testSerialize50RequestForIndexBoost() throws IOException {
    BytesArray requestBytes = new BytesArray(Base64.getDecoder()
        // this is a base64 encoded request generated with the same input
        .decode("AAZpbmRleDEWTjEyM2trbHFUT21XZDY1Z2VDYlo5ZwABBAABAAIA/wD/////DwABBmluZGV4MUAAAAAAAAAAAP////8PAAAAAAAAAgAAAA" +
            "AAAPa/q8mOKwIAJg=="));

    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ShardSearchTransportRequest readRequest = new ShardSearchTransportRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        assertEquals(2.0f, readRequest.indexBoost(), 0);

        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:ShardSearchTransportRequestTests.java

示例3: testSerialize

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
public void testSerialize() throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        ExplainRequest request = new ExplainRequest("index", "type", "id");
        request.fetchSourceContext(new FetchSourceContext(true, new String[]{"field1.*"}, new String[] {"field2.*"}));
        request.filteringAlias(new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}));
        request.preference("the_preference");
        request.query(QueryBuilders.termQuery("field", "value"));
        request.storedFields(new String[] {"field1", "field2"});
        request.routing("some_routing");
        request.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ExplainRequest readRequest = new ExplainRequest();
            readRequest.readFrom(in);
            assertEquals(request.filteringAlias(), readRequest.filteringAlias());
            assertArrayEquals(request.storedFields(), readRequest.storedFields());
            assertEquals(request.preference(), readRequest.preference());
            assertEquals(request.query(), readRequest.query());
            assertEquals(request.routing(), readRequest.routing());
            assertEquals(request.fetchSourceContext(), readRequest.fetchSourceContext());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:ExplainRequestTests.java

示例4: testSerializeRequest

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
public void testSerializeRequest() throws IOException {
    ClusterRerouteRequest req = new ClusterRerouteRequest();
    req.setRetryFailed(randomBoolean());
    req.dryRun(randomBoolean());
    req.explain(randomBoolean());
    req.add(new AllocateEmptyPrimaryAllocationCommand("foo", 1, "bar", randomBoolean()));
    req.timeout(TimeValue.timeValueMillis(randomIntBetween(0, 100)));
    BytesStreamOutput out = new BytesStreamOutput();
    req.writeTo(out);
    BytesReference bytes = out.bytes();
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
    StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(),
        namedWriteableRegistry);
    ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest();
    deserializedReq.readFrom(wrap);

    assertEquals(req.isRetryFailed(), deserializedReq.isRetryFailed());
    assertEquals(req.dryRun(), deserializedReq.dryRun());
    assertEquals(req.explain(), deserializedReq.explain());
    assertEquals(req.timeout(), deserializedReq.timeout());
    assertEquals(1, deserializedReq.getCommands().commands().size()); // allocation commands have their own tests
    assertEquals(req.getCommands().commands().size(), deserializedReq.getCommands().commands().size());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:ClusterRerouteTests.java

示例5: testSerialize

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
public void testSerialize() throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
        validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
        validateQueryRequest.rewrite(true);
        validateQueryRequest.explain(false);
        validateQueryRequest.types("type1", "type2");
        ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
            new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
        request.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
            readRequest.readFrom(in);
            assertEquals(request.filteringAliases(), readRequest.filteringAliases());
            assertArrayEquals(request.types(), readRequest.types());
            assertEquals(request.explain(), readRequest.explain());
            assertEquals(request.query(), readRequest.query());
            assertEquals(request.rewrite(), readRequest.rewrite());
            assertEquals(request.shardId(), readRequest.shardId());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:ShardValidateQueryRequestTests.java

示例6: assertSerialization

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Serialize the given query builder and asserts that both are equal
 */
protected static QueryBuilder assertSerialization(QueryBuilder testQuery) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.writeNamedWriteable(testQuery);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), serviceHolder.namedWriteableRegistry)) {
            QueryBuilder deserializedQuery = in.readNamedWriteable(QueryBuilder.class);
            assertEquals(testQuery, deserializedQuery);
            assertEquals(testQuery.hashCode(), deserializedQuery.hashCode());
            assertNotSame(testQuery, deserializedQuery);
            return deserializedQuery;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:AbstractQueryTestCase.java

示例7: copyWriteable

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Create a copy of an original {@link Writeable} object by running it through a {@link BytesStreamOutput} and
 * reading it in again using a provided {@link Writeable.Reader}. The stream that is wrapped around the {@link StreamInput}
 * potentially need to use a {@link NamedWriteableRegistry}, so this needs to be provided too (although it can be
 * empty if the object that is streamed doesn't contain any {@link NamedWriteable} objects itself.
 */
public static <T extends Writeable> T copyWriteable(T original, NamedWriteableRegistry namedWritabelRegistry,
        Writeable.Reader<T> reader) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        original.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWritabelRegistry)) {
            return reader.read(in);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:ESTestCase.java

示例8: copyInstance

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Round trip {@code instance} through binary serialization, setting the wire compatibility version to {@code version}.
 */
protected T copyInstance(T instance, Version version) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.setVersion(version);
        instance.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(),
                getNamedWriteableRegistry())) {
            in.setVersion(version);
            T newInstance = createBlankInstance();
            newInstance.readFrom(in);
            return newInstance;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:AbstractStreamableTestCase.java

示例9: copyInstance

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
private T copyInstance(T instance) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        instance.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(),
                getNamedWriteableRegistry())) {
            return instanceReader().read(in);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:AbstractWireSerializingTestCase.java

示例10: copyInstance

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Simulates sending diffs over the wire
 */
public static <T extends Writeable> T copyInstance(T diffs, NamedWriteableRegistry namedWriteableRegistry,
                                                              Reader<T> reader) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        diffs.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            return reader.read(in);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:DiffableTestUtils.java

示例11: marshal

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to
 * marshal this object into something the tribe node can work with
 */
private MetaData.Custom marshal(MetaData.Custom custom)  {
    try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){
        bytesStreamOutput.writeNamedWriteable(custom);
        try(StreamInput input = bytesStreamOutput.bytes().streamInput()) {
            StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry);
            MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class);
            return marshaled;
        }
    } catch (IOException ex) {
        throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:TribeService.java

示例12: testBinaryRoundTrip

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
public void testBinaryRoundTrip() throws IOException {
    NamedWriteableRegistry registry = new NamedWriteableRegistry(Collections.singletonList(
        new NamedWriteableRegistry.Entry(Task.Status.class, RawTaskStatus.NAME, RawTaskStatus::new)));
    TaskResult result = randomTaskResult();
    TaskResult read;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        result.writeTo(out);
        try (StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry)) {
            read = new TaskResult(in);
        }
    } catch (IOException e) {
        throw new IOException("Error processing [" + result + "]", e);
    }
    assertEquals(result, read);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:TaskResultTests.java

示例13: testSerialization

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Test serialization and deserialization of the test AggregatorFactory.
 */
public void testSerialization() throws IOException {
    AF testAgg = createTestAggregatorFactory();
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.writeNamedWriteable(testAgg);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            PipelineAggregationBuilder deserializedQuery = in.readNamedWriteable(PipelineAggregationBuilder.class);
            assertEquals(deserializedQuery, testAgg);
            assertEquals(deserializedQuery.hashCode(), testAgg.hashCode());
            assertNotSame(deserializedQuery, testAgg);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:BasePipelineAggregationTestCase.java

示例14: copyAggregation

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
private AF copyAggregation(AF agg) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.writeNamedWriteable(agg);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            @SuppressWarnings("unchecked")
            AF secondAgg = (AF) in.readNamedWriteable(PipelineAggregationBuilder.class);
            return secondAgg;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:BasePipelineAggregationTestCase.java

示例15: testSerialization

import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //導入依賴的package包/類
/**
 * Test serialization and deserialization of the test AggregatorFactory.
 */
public void testSerialization() throws IOException {
    AB testAgg = createTestAggregatorBuilder();
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.writeNamedWriteable(testAgg);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            AggregationBuilder deserialized = in.readNamedWriteable(AggregationBuilder.class);
            assertEquals(testAgg, deserialized);
            assertEquals(testAgg.hashCode(), deserialized.hashCode());
            assertNotSame(testAgg, deserialized);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:BaseAggregationTestCase.java


注:本文中的org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。