@Test
  public void testRoutingTableSerialization() throws Exception {
    MetaData metaData =
        MetaData.builder()
            .put(IndexMetaData.builder("test").numberOfShards(10).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build();

    DiscoveryNodes nodes =
        DiscoveryNodes.builder()
            .put(newNode("node1"))
            .put(newNode("node2"))
            .put(newNode("node3"))
            .build();

    ClusterState clusterState =
        ClusterState.builder().nodes(nodes).metaData(metaData).routingTable(routingTable).build();

    AllocationService strategy = createAllocationService();
    RoutingTable source = strategy.reroute(clusterState).routingTable();

    BytesStreamOutput outStream = new BytesStreamOutput();
    RoutingTable.Builder.writeTo(source, outStream);
    BytesStreamInput inStream = new BytesStreamInput(outStream.bytes().toBytes(), false);
    RoutingTable target = RoutingTable.Builder.readFrom(inStream);

    assertThat(target.prettyPrint(), equalTo(source.prettyPrint()));
  }
Exemplo n.º 2
0
 public static void writeTo(ClusterState state, StreamOutput out) throws IOException {
   out.writeLong(state.version());
   MetaData.Builder.writeTo(state.metaData(), out);
   RoutingTable.Builder.writeTo(state.routingTable(), out);
   DiscoveryNodes.Builder.writeTo(state.nodes(), out);
   ClusterBlocks.Builder.writeClusterBlocks(state.blocks(), out);
   state.allocationExplanation().writeTo(out);
 }