use of org.elasticsearch.common.io.stream.StreamOutput in project elasticsearch by elastic.
the class PublishClusterStateActionTests method testSerializationFailureDuringDiffPublishing.
public void testSerializationFailureDuringDiffPublishing() throws Exception {
MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, new ClusterStateListener() {
@Override
public void clusterChanged(ClusterChangedEvent event) {
fail("Shouldn't send cluster state to myself");
}
}).setAsMaster();
MockNode nodeB = createMockNode("nodeB");
// Initial cluster state with both states - the second node still shouldn't get
// diff even though it's present in the previous cluster state
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(nodeA.nodes()).add(nodeB.discoveryNode).build();
ClusterState previousClusterState = ClusterState.builder(CLUSTER_NAME).nodes(discoveryNodes).build();
ClusterState clusterState = ClusterState.builder(previousClusterState).incrementVersion().build();
publishStateAndWait(nodeA.action, clusterState, previousClusterState);
assertSameStateFromFull(nodeB.clusterState, clusterState);
// cluster state update - add block
previousClusterState = clusterState;
clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.builder().addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK)).incrementVersion().build();
ClusterState unserializableClusterState = new ClusterState(clusterState.version(), clusterState.stateUUID(), clusterState) {
@Override
public Diff<ClusterState> diff(ClusterState previousState) {
return new Diff<ClusterState>() {
@Override
public ClusterState apply(ClusterState part) {
fail("this diff shouldn't be applied");
return part;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
throw new IOException("Simulated failure of diff serialization");
}
};
}
};
try {
publishStateAndWait(nodeA.action, unserializableClusterState, previousClusterState);
fail("cluster state published despite of diff errors");
} catch (Discovery.FailedToCommitClusterStateException e) {
assertThat(e.getCause(), notNullValue());
assertThat(e.getCause().getMessage(), containsString("failed to serialize"));
}
}
use of org.elasticsearch.common.io.stream.StreamOutput in project elasticsearch by elastic.
the class PublishClusterStateAction method serializeDiffClusterState.
public static BytesReference serializeDiffClusterState(Diff diff, Version nodeVersion) throws IOException {
BytesStreamOutput bStream = new BytesStreamOutput();
try (StreamOutput stream = CompressorFactory.COMPRESSOR.streamOutput(bStream)) {
stream.setVersion(nodeVersion);
stream.writeBoolean(false);
diff.writeTo(stream);
}
return bStream.bytes();
}
use of org.elasticsearch.common.io.stream.StreamOutput 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());
}
Aggregations