|
20 | 20 | */
|
21 | 21 |
|
22 | 22 | import com.carrotsearch.hppc.cursors.IntObjectCursor;
|
| 23 | +import org.elasticsearch.action.DocWriteResponse; |
23 | 24 | import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder;
|
24 | 25 | import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse;
|
| 26 | +import org.elasticsearch.action.bulk.BulkResponse; |
25 | 27 | import org.elasticsearch.action.index.IndexResponse;
|
26 | 28 | import org.elasticsearch.action.support.ActiveShardCount;
|
27 | 29 | import org.elasticsearch.cluster.ClusterState;
|
|
30 | 32 | import org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand;
|
31 | 33 | import org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand;
|
32 | 34 | import org.elasticsearch.cluster.service.ClusterService;
|
| 35 | +import org.elasticsearch.common.Strings; |
33 | 36 | import org.elasticsearch.common.collect.ImmutableOpenIntMap;
|
34 | 37 | import org.elasticsearch.common.settings.Settings;
|
35 | 38 | import org.elasticsearch.common.util.set.Sets;
|
@@ -89,6 +92,34 @@ protected Settings nodeSettings(int nodeOrdinal) {
|
89 | 92 | .put(TestZenDiscovery.USE_MOCK_PINGS.getKey(), false).build();
|
90 | 93 | }
|
91 | 94 |
|
| 95 | + public void testBulkWeirdScenario() throws Exception { |
| 96 | + String master = internalCluster().startMasterOnlyNode(Settings.EMPTY); |
| 97 | + internalCluster().startDataOnlyNodes(2); |
| 98 | + |
| 99 | + assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder() |
| 100 | + .put("index.number_of_shards", 1).put("index.number_of_replicas", 1)).get()); |
| 101 | + ensureGreen(); |
| 102 | + |
| 103 | + BulkResponse bulkResponse = client().prepareBulk() |
| 104 | + .add(client().prepareIndex().setIndex("test").setType("_doc").setId("1").setSource("field1", "value1")) |
| 105 | + .add(client().prepareUpdate().setIndex("test").setType("_doc").setId("1").setDoc("field2", "value2")) |
| 106 | + .execute().actionGet(); |
| 107 | + |
| 108 | + assertThat(bulkResponse.hasFailures(), equalTo(false)); |
| 109 | + assertThat(bulkResponse.getItems().length, equalTo(2)); |
| 110 | + |
| 111 | + logger.info(Strings.toString(bulkResponse, true, true)); |
| 112 | + |
| 113 | + internalCluster().assertSeqNos(); |
| 114 | + |
| 115 | + assertThat(bulkResponse.getItems()[0].getResponse().getId(), equalTo("1")); |
| 116 | + assertThat(bulkResponse.getItems()[0].getResponse().getVersion(), equalTo(1L)); |
| 117 | + assertThat(bulkResponse.getItems()[0].getResponse().getResult(), equalTo(DocWriteResponse.Result.CREATED)); |
| 118 | + assertThat(bulkResponse.getItems()[1].getResponse().getId(), equalTo("1")); |
| 119 | + assertThat(bulkResponse.getItems()[1].getResponse().getVersion(), equalTo(2L)); |
| 120 | + assertThat(bulkResponse.getItems()[1].getResponse().getResult(), equalTo(DocWriteResponse.Result.UPDATED)); |
| 121 | + } |
| 122 | + |
92 | 123 | private void createStaleReplicaScenario(String master) throws Exception {
|
93 | 124 | client().prepareIndex("test", "type1").setSource(jsonBuilder()
|
94 | 125 | .startObject().field("field", "value1").endObject()).get();
|
|
0 commit comments