Search in sources :

Example 61 with BytesStreamOutput

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

the class OsStatsTests method testSerialization.

public void testSerialization() throws IOException {
    int numLoadAverages = randomIntBetween(1, 5);
    double[] loadAverages = new double[numLoadAverages];
    for (int i = 0; i < loadAverages.length; i++) {
        loadAverages[i] = randomDouble();
    }
    OsStats.Cpu cpu = new OsStats.Cpu(randomShort(), loadAverages);
    OsStats.Mem mem = new OsStats.Mem(randomLong(), randomLong());
    OsStats.Swap swap = new OsStats.Swap(randomLong(), randomLong());
    OsStats.Cgroup cgroup = new OsStats.Cgroup(randomAsciiOfLength(8), randomNonNegativeLong(), randomAsciiOfLength(8), randomNonNegativeLong(), randomNonNegativeLong(), new OsStats.Cgroup.CpuStat(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    OsStats osStats = new OsStats(System.currentTimeMillis(), cpu, mem, swap, cgroup);
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        osStats.writeTo(out);
        try (StreamInput in = out.bytes().streamInput()) {
            OsStats deserializedOsStats = new OsStats(in);
            assertEquals(osStats.getTimestamp(), deserializedOsStats.getTimestamp());
            assertEquals(osStats.getCpu().getPercent(), deserializedOsStats.getCpu().getPercent());
            assertArrayEquals(osStats.getCpu().getLoadAverage(), deserializedOsStats.getCpu().getLoadAverage(), 0);
            assertEquals(osStats.getMem().getFree(), deserializedOsStats.getMem().getFree());
            assertEquals(osStats.getMem().getTotal(), deserializedOsStats.getMem().getTotal());
            assertEquals(osStats.getSwap().getFree(), deserializedOsStats.getSwap().getFree());
            assertEquals(osStats.getSwap().getTotal(), deserializedOsStats.getSwap().getTotal());
            assertEquals(osStats.getCgroup().getCpuAcctControlGroup(), deserializedOsStats.getCgroup().getCpuAcctControlGroup());
            assertEquals(osStats.getCgroup().getCpuAcctUsageNanos(), deserializedOsStats.getCgroup().getCpuAcctUsageNanos());
            assertEquals(osStats.getCgroup().getCpuControlGroup(), deserializedOsStats.getCgroup().getCpuControlGroup());
            assertEquals(osStats.getCgroup().getCpuCfsPeriodMicros(), deserializedOsStats.getCgroup().getCpuCfsPeriodMicros());
            assertEquals(osStats.getCgroup().getCpuCfsQuotaMicros(), deserializedOsStats.getCgroup().getCpuCfsQuotaMicros());
            assertEquals(osStats.getCgroup().getCpuStat().getNumberOfElapsedPeriods(), deserializedOsStats.getCgroup().getCpuStat().getNumberOfElapsedPeriods());
            assertEquals(osStats.getCgroup().getCpuStat().getNumberOfTimesThrottled(), deserializedOsStats.getCgroup().getCpuStat().getNumberOfTimesThrottled());
            assertEquals(osStats.getCgroup().getCpuStat().getTimeThrottledNanos(), deserializedOsStats.getCgroup().getCpuStat().getTimeThrottledNanos());
        }
    }
}
Also used : BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) StreamInput(org.elasticsearch.common.io.stream.StreamInput)

Example 62 with BytesStreamOutput

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

the class IngestStatsTests method serialize.

private IngestStats serialize(IngestStats stats) throws IOException {
    BytesStreamOutput out = new BytesStreamOutput();
    stats.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    return new IngestStats(in);
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 63 with BytesStreamOutput

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

the class SerializationTests method testPutChunkReplicaRequestSerialization.

@Test
public void testPutChunkReplicaRequestSerialization() throws Exception {
    BytesStreamOutput outputStream = new BytesStreamOutput();
    UUID transferId = UUID.randomUUID();
    PutChunkReplicaRequest requestOut = new PutChunkReplicaRequest();
    requestOut.index("foo");
    requestOut.transferId = transferId;
    requestOut.currentPos = 10;
    requestOut.isLast = false;
    requestOut.content = new BytesArray(new byte[] { 0x65, 0x66 });
    requestOut.sourceNodeId = "nodeId";
    requestOut.writeTo(outputStream);
    StreamInput inputStream = StreamInput.wrap(outputStream.bytes());
    PutChunkReplicaRequest requestIn = new PutChunkReplicaRequest();
    requestIn.readFrom(inputStream);
    assertEquals(requestOut.currentPos, requestIn.currentPos);
    assertEquals(requestOut.isLast, requestIn.isLast);
    assertEquals(requestOut.content, requestIn.content);
    assertEquals(requestOut.transferId, requestIn.transferId);
    assertEquals(requestOut.index(), requestIn.index());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) PutChunkReplicaRequest(io.crate.blob.PutChunkReplicaRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 64 with BytesStreamOutput

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

the class DeleteBlobRequestTest method testDeleteBlobRequestStreaming.

@Test
public void testDeleteBlobRequestStreaming() throws Exception {
    byte[] digest = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    DeleteBlobRequest request = new DeleteBlobRequest("foo", digest);
    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);
    DeleteBlobRequest fromStream = new DeleteBlobRequest();
    StreamInput in = StreamInput.wrap(out.bytes());
    fromStream.readFrom(in);
    assertThat(fromStream.index(), is("foo"));
    assertThat(fromStream.id(), is(Hex.encodeHexString(digest)));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 65 with BytesStreamOutput

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

the class DeleteBlobResponseTest method testDeleteBlobResponseStreaming.

@Test
public void testDeleteBlobResponseStreaming() throws Exception {
    DeleteBlobResponse response = new DeleteBlobResponse();
    response.deleted = true;
    response.setShardInfo(new ActionWriteResponse.ShardInfo());
    BytesStreamOutput out = new BytesStreamOutput();
    response.writeTo(out);
    DeleteBlobResponse fromStream = new DeleteBlobResponse();
    StreamInput in = StreamInput.wrap(out.bytes());
    fromStream.readFrom(in);
    assertThat(fromStream.deleted, is(true));
}
Also used : ActionWriteResponse(org.elasticsearch.action.ActionWriteResponse) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)222 StreamInput (org.elasticsearch.common.io.stream.StreamInput)147 Test (org.junit.Test)45 CrateUnitTest (io.crate.test.integration.CrateUnitTest)36 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)24 IOException (java.io.IOException)21 BytesArray (org.elasticsearch.common.bytes.BytesArray)21 BytesReference (org.elasticsearch.common.bytes.BytesReference)18 Version (org.elasticsearch.Version)15 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 ArrayList (java.util.ArrayList)12 BytesRef (org.apache.lucene.util.BytesRef)11 Map (java.util.Map)10 UUID (java.util.UUID)9 Symbol (io.crate.analyze.symbol.Symbol)8 HashMap (java.util.HashMap)8 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)7 List (java.util.List)6