Search in sources :

Example 16 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project elasticsearch by elastic.

the class StoreTests method testStreamStoreFilesMetaData.

public void testStreamStoreFilesMetaData() throws Exception {
    Store.MetadataSnapshot metadataSnapshot = createMetaDataSnapshot();
    TransportNodesListShardStoreMetaData.StoreFilesMetaData outStoreFileMetaData = new TransportNodesListShardStoreMetaData.StoreFilesMetaData(new ShardId("test", "_na_", 0), metadataSnapshot);
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    org.elasticsearch.Version targetNodeVersion = randomVersion(random());
    out.setVersion(targetNodeVersion);
    outStoreFileMetaData.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    in.setVersion(targetNodeVersion);
    TransportNodesListShardStoreMetaData.StoreFilesMetaData inStoreFileMetaData = TransportNodesListShardStoreMetaData.StoreFilesMetaData.readStoreFilesMetaData(in);
    Iterator<StoreFileMetaData> outFiles = outStoreFileMetaData.iterator();
    for (StoreFileMetaData inFile : inStoreFileMetaData) {
        assertThat(inFile.name(), equalTo(outFiles.next().name()));
    }
    assertThat(outStoreFileMetaData.syncId(), equalTo(inStoreFileMetaData.syncId()));
}
Also used : TransportNodesListShardStoreMetaData(org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ShardId(org.elasticsearch.index.shard.ShardId) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Example 17 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project elasticsearch by elastic.

the class SignificanceHeuristicTests method testStreamResponse.

// test that stream output can actually be read - does not replace bwc test
public void testStreamResponse() throws Exception {
    Version version = randomVersion(random());
    InternalMappedSignificantTerms<?, ?> sigTerms = getRandomSignificantTerms(getRandomSignificanceheuristic());
    // write
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    out.setVersion(version);
    out.writeNamedWriteable(sigTerms);
    // read
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    StreamInput in = new InputStreamStreamInput(inBuffer);
    // populates the registry through side effects
    SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
    NamedWriteableRegistry registry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    in = new NamedWriteableAwareStreamInput(in, registry);
    in.setVersion(version);
    InternalMappedSignificantTerms<?, ?> read = (InternalMappedSignificantTerms<?, ?>) in.readNamedWriteable(InternalAggregation.class);
    assertEquals(sigTerms.significanceHeuristic, read.significanceHeuristic);
    SignificantTerms.Bucket originalBucket = sigTerms.getBuckets().get(0);
    SignificantTerms.Bucket streamedBucket = read.getBuckets().get(0);
    assertThat(originalBucket.getKeyAsString(), equalTo(streamedBucket.getKeyAsString()));
    assertThat(originalBucket.getSupersetDf(), equalTo(streamedBucket.getSupersetDf()));
    assertThat(originalBucket.getSubsetDf(), equalTo(streamedBucket.getSubsetDf()));
    assertThat(streamedBucket.getSubsetSize(), equalTo(10L));
    assertThat(streamedBucket.getSupersetSize(), equalTo(20L));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) Version(org.elasticsearch.Version) VersionUtils.randomVersion(org.elasticsearch.test.VersionUtils.randomVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) SearchModule(org.elasticsearch.search.SearchModule) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Example 18 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project elasticsearch by elastic.

the class TermVectorsUnitTests method testStreamResponse.

public void testStreamResponse() throws Exception {
    TermVectorsResponse outResponse = new TermVectorsResponse("a", "b", "c");
    outResponse.setExists(true);
    writeStandardTermVector(outResponse);
    // write
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    outResponse.writeTo(out);
    // read
    ByteArrayInputStream esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput esBuffer = new InputStreamStreamInput(esInBuffer);
    TermVectorsResponse inResponse = new TermVectorsResponse("a", "b", "c");
    inResponse.readFrom(esBuffer);
    // see if correct
    checkIfStandardTermVector(inResponse);
    outResponse = new TermVectorsResponse("a", "b", "c");
    writeEmptyTermVector(outResponse);
    // write
    outBuffer = new ByteArrayOutputStream();
    out = new OutputStreamStreamOutput(outBuffer);
    outResponse.writeTo(out);
    // read
    esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    esBuffer = new InputStreamStreamInput(esInBuffer);
    inResponse = new TermVectorsResponse("a", "b", "c");
    inResponse.readFrom(esBuffer);
    assertTrue(inResponse.isExists());
}
Also used : OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Example 19 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project crate by crate.

the class NodeStatsContextTest method testStreamEmptyContext.

@Test
public void testStreamEmptyContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(false);
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    NodeStatsContext ctx2 = new NodeStatsContext(false);
    ctx2.readFrom(in);
    assertNull(ctx2.id());
    assertNull(ctx2.name());
    assertNull(ctx2.hostname());
    assertNull(ctx2.restUrl());
    assertNull(ctx2.port());
    assertNull(ctx2.jvmStats());
    assertNull(ctx2.osInfo());
    assertNull(ctx2.processStats());
    assertNull(ctx2.osStats());
    assertNull(ctx2.extendedOsStats());
    assertNull(ctx2.networkStats());
    assertNull(ctx2.extendedProcessCpuStats());
    assertNull(ctx2.extendedFsStats());
    assertNull(ctx2.threadPools());
}
Also used : OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 20 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project crate by crate.

the class NodeStatsContextTest method testStreamContext.

@Test
public void testStreamContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(true);
    ctx1.id("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18");
    ctx1.name("crate1");
    ctx1.hostname("crate1.example.com");
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.httpPort(4200);
    ctx1.transportPort(4300);
    ctx1.restUrl("10.0.0.1:4200");
    ctx1.jvmStats(JvmStats.jvmStats());
    ctx1.osInfo(DummyOsInfo.INSTANCE);
    ProcessProbe processProbe = ProcessProbe.getInstance();
    ctx1.processStats(processProbe.processStats());
    OsProbe osProbe = OsProbe.getInstance();
    ctx1.osStats(osProbe.osStats());
    ctx1.extendedOsStats(extendedNodeInfo.osStats());
    ctx1.threadPools(threadPool.stats());
    ctx1.clusterStateVersion(10L);
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    NodeStatsContext ctx2 = new NodeStatsContext(in, true);
    assertThat(ctx1.id(), is(ctx2.id()));
    assertThat(ctx1.name(), is(ctx2.name()));
    assertThat(ctx1.hostname(), is(ctx2.hostname()));
    assertThat(ctx1.timestamp(), is(100L));
    assertThat(ctx1.version(), is(ctx2.version()));
    assertThat(ctx1.build().hash(), is(ctx2.build().hash()));
    assertThat(ctx1.restUrl(), is(ctx2.restUrl()));
    assertThat(ctx1.httpPort(), is(ctx2.httpPort()));
    assertThat(ctx1.transportPort(), is(ctx2.transportPort()));
    assertThat(ctx1.pgPort(), is(ctx2.pgPort()));
    assertThat(ctx1.jvmStats().getTimestamp(), is(ctx2.jvmStats().getTimestamp()));
    assertThat(ctx1.osInfo().getArch(), is(ctx2.osInfo().getArch()));
    assertThat(ctx1.processStats().getTimestamp(), is(ctx2.processStats().getTimestamp()));
    assertThat(ctx1.osStats().getTimestamp(), is(ctx2.osStats().getTimestamp()));
    assertThat(ctx1.extendedOsStats().uptime(), is(ctx2.extendedOsStats().uptime()));
    assertThat(ctx1.threadPools().iterator().next().getActive(), is(ctx2.threadPools().iterator().next().getActive()));
    assertThat(ctx1.clusterStateVersion(), is(ctx2.clusterStateVersion()));
}
Also used : OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessProbe(org.elasticsearch.monitor.process.ProcessProbe) OsProbe(org.elasticsearch.monitor.os.OsProbe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) Test(org.junit.Test)

Aggregations

OutputStreamStreamOutput (org.elasticsearch.common.io.stream.OutputStreamStreamOutput)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 InputStreamStreamInput (org.elasticsearch.common.io.stream.InputStreamStreamInput)16 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)9 Test (org.junit.Test)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)3 ShardId (org.elasticsearch.index.shard.ShardId)3 ThreadPools (io.crate.monitor.ThreadPools)2 BufferedOutputStream (java.io.BufferedOutputStream)2 OutputStream (java.io.OutputStream)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Deflater (java.util.zip.Deflater)2 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)2 Version (org.elasticsearch.Version)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2