Search in sources :

Example 6 with OutputStreamStreamOutput

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

the class NodeStatsContextTest method testStreamContextWithNullPorts.

@Test
public void testStreamContextWithNullPorts() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(false);
    ctx1.port(new HashMap<String, Integer>() {

        {
            put("http", null);
            put("transport", 4300);
        }
    });
    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);
    assertThat(ctx2.port().get("http"), nullValue());
    assertThat(ctx2.port().get("transport"), is(4300));
}
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 7 with OutputStreamStreamOutput

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

the class NodeStatsContextTest method testStreamThreadPools.

@Test
public void testStreamThreadPools() throws Exception {
    ThreadPools pools1 = ThreadPools.newInstance();
    int size = 3;
    for (int i = 0; i < size; i++) {
        ThreadPools.ThreadPoolExecutorContext ctx = new ThreadPools.ThreadPoolExecutorContext(10 * i + 1, 10 * i + 2, 10 * i + 3, 10 * i + 4, 100L * i + 1L, 100L * i + 2L);
        pools1.add(String.format("threadpool-%d", i), ctx);
    }
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    pools1.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    ThreadPools pools2 = ThreadPools.newInstance();
    pools2.readFrom(in);
    assertThat(pools1, is(pools2));
}
Also used : ThreadPools(io.crate.monitor.ThreadPools) 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 8 with OutputStreamStreamOutput

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

the class NodeStatsContextTest method testStreamThreadPoolsContext.

@Test
public void testStreamThreadPoolsContext() throws Exception {
    ThreadPools.ThreadPoolExecutorContext ctx1 = new ThreadPools.ThreadPoolExecutorContext(10, 15, 20, 50, 1_000_000_000_000_000L, 1L);
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    ThreadPools.ThreadPoolExecutorContext ctx2 = new ThreadPools.ThreadPoolExecutorContext();
    ctx2.readFrom(in);
    assertThat(ctx1, is(ctx2));
}
Also used : ThreadPools(io.crate.monitor.ThreadPools) 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 9 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(BytesRefs.toBytesRef("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18"));
    ctx1.name(BytesRefs.toBytesRef("crate1"));
    ctx1.hostname(BytesRefs.toBytesRef("crate1.example.com"));
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.restUrl(BytesRefs.toBytesRef("10.0.0.1:4200"));
    ctx1.port(new HashMap<String, Integer>(2) {

        {
            put("http", 4200);
            put("transport", 4300);
        }
    });
    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.networkStats(extendedNodeInfo.networkStats());
    ctx1.extendedProcessCpuStats(extendedNodeInfo.processCpuStats());
    ctx1.extendedFsStats(extendedNodeInfo.fsStats());
    ctx1.threadPools(ThreadPools.newInstance(threadPool));
    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(true);
    ctx2.readFrom(in);
    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.port(), is(ctx2.port()));
    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.networkStats().timestamp(), is(ctx2.networkStats().timestamp()));
    assertThat(ctx1.extendedProcessCpuStats().percent(), is(ctx2.extendedProcessCpuStats().percent()));
    assertThat(ctx1.extendedFsStats().size(), is(ctx2.extendedFsStats().size()));
    assertThat(ctx1.threadPools(), is(ctx2.threadPools()));
}
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) 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 10 with OutputStreamStreamOutput

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

the class DeflateCompressTests method doTest.

private void doTest(byte[] bytes) throws IOException {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    StreamInput rawIn = new ByteBufferStreamInput(bb);
    Compressor c = compressor;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStreamStreamOutput rawOs = new OutputStreamStreamOutput(bos);
    StreamOutput os = c.streamOutput(rawOs);
    Random r = random();
    int bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
    int prepadding = r.nextInt(70000);
    int postpadding = r.nextInt(70000);
    byte[] buffer = new byte[prepadding + bufferSize + postpadding];
    // fill block completely with junk
    r.nextBytes(buffer);
    int len;
    while ((len = rawIn.read(buffer, prepadding, bufferSize)) != -1) {
        os.write(buffer, prepadding, len);
    }
    os.close();
    rawIn.close();
    // now we have compressed byte array
    byte[] compressed = bos.toByteArray();
    ByteBuffer bb2 = ByteBuffer.wrap(compressed);
    StreamInput compressedIn = new ByteBufferStreamInput(bb2);
    StreamInput in = c.streamInput(compressedIn);
    // randomize constants again
    bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
    prepadding = r.nextInt(70000);
    postpadding = r.nextInt(70000);
    buffer = new byte[prepadding + bufferSize + postpadding];
    // fill block completely with junk
    r.nextBytes(buffer);
    ByteArrayOutputStream uncompressedOut = new ByteArrayOutputStream();
    while ((len = in.read(buffer, prepadding, bufferSize)) != -1) {
        uncompressedOut.write(buffer, prepadding, len);
    }
    uncompressedOut.close();
    assertArrayEquals(bytes, uncompressedOut.toByteArray());
}
Also used : ByteBufferStreamInput(org.elasticsearch.common.io.stream.ByteBufferStreamInput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) Random(java.util.Random) ByteBufferStreamInput(org.elasticsearch.common.io.stream.ByteBufferStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteBuffer(java.nio.ByteBuffer)

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