/**
   * Test that orientation parameter correctly persists across cluster restart
   *
   * @throws IOException
   */
  public void testOrientationPersistence() throws Exception {
    String idxName = "orientation";
    String mapping =
        XContentFactory.jsonBuilder()
            .startObject()
            .startObject("shape")
            .startObject("properties")
            .startObject("location")
            .field("type", "geo_shape")
            .field("orientation", "left")
            .endObject()
            .endObject()
            .endObject()
            .endObject()
            .string();

    // create index
    assertAcked(prepareCreate(idxName).addMapping("shape", mapping));

    mapping =
        XContentFactory.jsonBuilder()
            .startObject()
            .startObject("shape")
            .startObject("properties")
            .startObject("location")
            .field("type", "geo_shape")
            .field("orientation", "right")
            .endObject()
            .endObject()
            .endObject()
            .endObject()
            .string();

    assertAcked(prepareCreate(idxName + "2").addMapping("shape", mapping));
    ensureGreen(idxName, idxName + "2");

    internalCluster().fullRestart();
    ensureGreen(idxName, idxName + "2");

    // left orientation test
    IndicesService indicesService =
        internalCluster().getInstance(IndicesService.class, findNodeName(idxName));
    IndexService indexService = indicesService.indexService(idxName);
    FieldMapper fieldMapper = indexService.mapperService().smartNameFieldMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper gsfm = (GeoShapeFieldMapper) fieldMapper;
    ShapeBuilder.Orientation orientation = gsfm.orientation();
    assertThat(orientation, equalTo(ShapeBuilder.Orientation.CLOCKWISE));
    assertThat(orientation, equalTo(ShapeBuilder.Orientation.LEFT));
    assertThat(orientation, equalTo(ShapeBuilder.Orientation.CW));

    // right orientation test
    indicesService =
        internalCluster().getInstance(IndicesService.class, findNodeName(idxName + "2"));
    indexService = indicesService.indexService(idxName + "2");
    fieldMapper = indexService.mapperService().smartNameFieldMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    gsfm = (GeoShapeFieldMapper) fieldMapper;
    orientation = gsfm.orientation();
    assertThat(orientation, equalTo(ShapeBuilder.Orientation.COUNTER_CLOCKWISE));
    assertThat(orientation, equalTo(ShapeBuilder.Orientation.RIGHT));
    assertThat(orientation, equalTo(ShapeBuilder.Orientation.CCW));
  }