@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()));
  }
예제 #2
0
 public static ClusterState readFrom(
     StreamInput in, @Nullable Settings globalSettings, @Nullable DiscoveryNode localNode)
     throws IOException {
   Builder builder = new Builder();
   builder.version = in.readLong();
   builder.metaData = MetaData.Builder.readFrom(in, globalSettings);
   builder.routingTable = RoutingTable.Builder.readFrom(in);
   builder.nodes = DiscoveryNodes.Builder.readFrom(in, localNode);
   builder.blocks = ClusterBlocks.Builder.readClusterBlocks(in);
   builder.allocationExplanation = AllocationExplanation.readAllocationExplanation(in);
   return builder.build();
 }