本文整理汇总了Java中org.elasticsearch.common.io.stream.BytesStreamOutput.setVersion方法的典型用法代码示例。如果您正苦于以下问题:Java BytesStreamOutput.setVersion方法的具体用法?Java BytesStreamOutput.setVersion怎么用?Java BytesStreamOutput.setVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.io.stream.BytesStreamOutput
的用法示例。
在下文中一共展示了BytesStreamOutput.setVersion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerialize50RequestForIndexBoost
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的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());
}
}
示例2: testDiscoveryNodeSerializationKeepsHost
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testDiscoveryNodeSerializationKeepsHost() throws Exception {
InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1});
TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535));
DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
BytesStreamOutput streamOutput = new BytesStreamOutput();
streamOutput.setVersion(Version.CURRENT);
node.writeTo(streamOutput);
StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
DiscoveryNode serialized = new DiscoveryNode(in);
assertEquals(transportAddress.address().getHostString(), serialized.getHostName());
assertEquals(transportAddress.address().getHostString(), serialized.getAddress().address().getHostString());
assertEquals(transportAddress.getAddress(), serialized.getHostAddress());
assertEquals(transportAddress.getAddress(), serialized.getAddress().getAddress());
assertEquals(transportAddress.getPort(), serialized.getAddress().getPort());
}
示例3: testDiscoveryNodeSerializationToOldVersion
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testDiscoveryNodeSerializationToOldVersion() throws Exception {
InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1});
TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535));
DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
BytesStreamOutput streamOutput = new BytesStreamOutput();
streamOutput.setVersion(Version.V_5_0_0);
node.writeTo(streamOutput);
StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
in.setVersion(Version.V_5_0_0);
DiscoveryNode serialized = new DiscoveryNode(in);
assertEquals(transportAddress.address().getHostString(), serialized.getHostName());
assertEquals(transportAddress.address().getHostString(), serialized.getAddress().address().getHostString());
assertEquals(transportAddress.getAddress(), serialized.getHostAddress());
assertEquals(transportAddress.getAddress(), serialized.getAddress().getAddress());
assertEquals(transportAddress.getPort(), serialized.getAddress().getPort());
assertFalse("if the minimum compatibility version moves past 5.0.3, remove the special casing in DiscoverNode(StreamInput) and " +
"the TransportAddress(StreamInput, String) constructor",
Version.CURRENT.minimumCompatibilityVersion().onOrAfter(Version.V_5_0_3_UNRELEASED));
}
示例4: testSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testSerialization() throws Exception {
int iterations = randomIntBetween(5, 20);
for (int i = 0; i < iterations; i++) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
ClusterStateRequest clusterStateRequest = new ClusterStateRequest().routingTable(randomBoolean()).metaData(randomBoolean())
.nodes(randomBoolean()).blocks(randomBoolean()).indices("testindex", "testindex2").indicesOptions(indicesOptions);
Version testVersion = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(testVersion);
clusterStateRequest.writeTo(output);
StreamInput streamInput = output.bytes().streamInput();
streamInput.setVersion(testVersion);
ClusterStateRequest deserializedCSRequest = new ClusterStateRequest();
deserializedCSRequest.readFrom(streamInput);
assertThat(deserializedCSRequest.routingTable(), equalTo(clusterStateRequest.routingTable()));
assertThat(deserializedCSRequest.metaData(), equalTo(clusterStateRequest.metaData()));
assertThat(deserializedCSRequest.nodes(), equalTo(clusterStateRequest.nodes()));
assertThat(deserializedCSRequest.blocks(), equalTo(clusterStateRequest.blocks()));
assertThat(deserializedCSRequest.indices(), equalTo(clusterStateRequest.indices()));
assertOptionsMatch(deserializedCSRequest.indicesOptions(), clusterStateRequest.indicesOptions());
}
}
示例5: testSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testSerialization() throws Exception {
int iterations = randomIntBetween(5, 20);
for (int i = 0; i < iterations; i++) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
BytesStreamOutput output = new BytesStreamOutput();
Version outputVersion = randomVersion(random());
output.setVersion(outputVersion);
indicesOptions.writeIndicesOptions(output);
StreamInput streamInput = output.bytes().streamInput();
streamInput.setVersion(randomVersion(random()));
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);
assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable()));
assertThat(indicesOptions2.allowNoIndices(), equalTo(indicesOptions.allowNoIndices()));
assertThat(indicesOptions2.expandWildcardsOpen(), equalTo(indicesOptions.expandWildcardsOpen()));
assertThat(indicesOptions2.expandWildcardsClosed(), equalTo(indicesOptions.expandWildcardsClosed()));
assertThat(indicesOptions2.forbidClosedIndices(), equalTo(indicesOptions.forbidClosedIndices()));
assertThat(indicesOptions2.allowAliasesToMultipleIndices(), equalTo(indicesOptions.allowAliasesToMultipleIndices()));
}
}
示例6: testOriginalIndicesSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testOriginalIndicesSerialization() throws IOException {
int iterations = iterations(10, 30);
for (int i = 0; i < iterations; i++) {
OriginalIndices originalIndices = randomOriginalIndices();
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersion(random()));
OriginalIndices.writeOriginalIndices(originalIndices, out);
StreamInput in = out.bytes().streamInput();
in.setVersion(out.getVersion());
OriginalIndices originalIndices2 = OriginalIndices.readOriginalIndices(in);
assertThat(originalIndices2.indices(), equalTo(originalIndices.indices()));
assertThat(originalIndices2.indicesOptions(), equalTo(originalIndices.indicesOptions()));
}
}
示例7: roundTrip
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private void roundTrip(Version version, Streamable example, Streamable empty) throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
example.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(version);
empty.readFrom(in);
}
示例8: serialize
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private static BytesReference serialize(Version version, Streamable streamable) throws IOException {
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
streamable.writeTo(output);
output.flush();
return output.bytes();
}
示例9: assertSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private void assertSerialization(FieldStats stats, Version version) throws IOException {
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
stats.writeTo(output);
output.flush();
StreamInput input = output.bytes().streamInput();
input.setVersion(version);
FieldStats deserializedStats = FieldStats.readFrom(input);
assertEquals(stats, deserializedStats);
assertEquals(stats.hashCode(), deserializedStats.hashCode());
}
示例10: serialize
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private <T extends Exception> T serialize(T exception, Version version) throws IOException {
ElasticsearchAssertions.assertVersionSerializable(version, exception);
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
out.writeException(exception);
StreamInput in = out.bytes().streamInput();
in.setVersion(version);
return in.readException();
}
示例11: testSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testSerialization() throws Exception {
int iterations = randomIntBetween(10, 100);
for (int i = 0; i < iterations; i++) {
// Get a random version
Version version = randomVersion(random());
// Get a random list of ClusterBlockLevels
EnumSet<ClusterBlockLevel> levels = EnumSet.noneOf(ClusterBlockLevel.class);
int nbLevels = randomIntBetween(1, ClusterBlockLevel.values().length);
for (int j = 0; j < nbLevels; j++) {
levels.add(randomFrom(ClusterBlockLevel.values()));
}
ClusterBlock clusterBlock = new ClusterBlock(randomInt(), "cluster block #" + randomInt(), randomBoolean(),
randomBoolean(), randomFrom(RestStatus.values()), levels);
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
clusterBlock.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(version);
ClusterBlock result = ClusterBlock.readClusterBlock(in);
assertThat(result.id(), equalTo(clusterBlock.id()));
assertThat(result.status(), equalTo(clusterBlock.status()));
assertThat(result.description(), equalTo(clusterBlock.description()));
assertThat(result.retryable(), equalTo(clusterBlock.retryable()));
assertThat(result.disableStatePersistence(), equalTo(clusterBlock.disableStatePersistence()));
assertArrayEquals(result.levels().toArray(), clusterBlock.levels().toArray());
}
}
示例12: testSerialize50Request
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testSerialize50Request() throws IOException {
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");
BytesArray requestBytes = new BytesArray(Base64.getDecoder()
// this is a base64 encoded request generated with the same input
.decode("AAABBWluZGV4BHR5cGUCaWQBDHNvbWVfcm91dGluZwEOdGhlX3ByZWZlcmVuY2UEdGVybT" +
"+AAAAABWZpZWxkFQV2YWx1ZQIGYWxpYXMwBmFsaWFzMQECBmZpZWxkMQZmaWVsZDIBAQEIZmllbGQxLioBCGZpZWxkMi4qAA"));
try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
in.setVersion(Version.V_5_0_0);
ExplainRequest readRequest = new ExplainRequest();
readRequest.readFrom(in);
assertEquals(0, in.available());
assertArrayEquals(request.filteringAlias().getAliases(), readRequest.filteringAlias().getAliases());
expectThrows(IllegalStateException.class, () -> readRequest.filteringAlias().getQueryBuilder());
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());
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(Version.V_5_0_0);
readRequest.writeTo(output);
assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
}
}
示例13: testPutIndexTemplateRequest510
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testPutIndexTemplateRequest510() throws IOException {
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest("test");
putRequest.patterns(Collections.singletonList("test*"));
putRequest.order(5);
PutIndexTemplateRequest multiPatternRequest = new PutIndexTemplateRequest("test");
multiPatternRequest.patterns(Arrays.asList("test*", "*test2", "*test3*"));
multiPatternRequest.order(5);
// These bytes were retrieved by Base64 encoding the result of the above with 5_0_0 code.
// Note: Instead of a list for the template, in 5_0_0 the element was provided as a string.
String putRequestBytes = "ADwDAAR0ZXN0BXRlc3QqAAAABQAAAAAAAA==";
BytesArray bytes = new BytesArray(Base64.getDecoder().decode(putRequestBytes));
try (StreamInput in = bytes.streamInput()) {
in.setVersion(Version.V_5_0_0);
PutIndexTemplateRequest readRequest = new PutIndexTemplateRequest();
readRequest.readFrom(in);
assertEquals(putRequest.patterns(), readRequest.patterns());
assertEquals(putRequest.order(), readRequest.order());
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(Version.V_5_0_0);
readRequest.writeTo(output);
assertEquals(bytes.toBytesRef(), output.bytes().toBytesRef());
// test that multi templates are reverse-compatible.
// for the bwc case, if multiple patterns, use only the first pattern seen.
output.reset();
multiPatternRequest.writeTo(output);
assertEquals(bytes.toBytesRef(), output.bytes().toBytesRef());
}
}
示例14: testGetIndexedScriptRequestSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testGetIndexedScriptRequestSerialization() throws IOException {
GetStoredScriptRequest request = new GetStoredScriptRequest("lang", "id");
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersion(random()));
request.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(out.getVersion());
GetStoredScriptRequest request2 = new GetStoredScriptRequest();
request2.readFrom(in);
assertThat(request2.id(), equalTo(request.id()));
assertThat(request2.lang(), equalTo(request.lang()));
}
示例15: testFieldStatsBWC
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testFieldStatsBWC() throws Exception {
int size = randomIntBetween(5, 20);
Map<String, FieldStats<?> > stats = new HashMap<> ();
for (int i = 0; i < size; i++) {
stats.put(Integer.toString(i), FieldStatsTests.randomFieldStats(true));
}
FieldStatsShardResponse response = new FieldStatsShardResponse(new ShardId("test", "test", 0), stats);
for (int i = 0; i < 10; i++) {
Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.CURRENT);
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
response.writeTo(output);
output.flush();
StreamInput input = output.bytes().streamInput();
input.setVersion(version);
FieldStatsShardResponse deserialized = new FieldStatsShardResponse();
deserialized.readFrom(input);
final Map<String, FieldStats<?>> expected;
if (version.before(Version.V_5_2_0_UNRELEASED)) {
expected = deserialized.filterNullMinMax();
} else {
expected = deserialized.getFieldStats();
}
assertEquals(expected.size(), deserialized.getFieldStats().size());
assertThat(expected, equalTo(deserialized.getFieldStats()));
}
}