@@ -953,6 +953,56 @@ public void testHistoryUUIDIsAdded() throws Exception {
953953 }
954954 }
955955
956+ public void testSoftDeletes () throws Exception {
957+ if (isRunningAgainstOldCluster ()) {
958+ XContentBuilder mappingsAndSettings = jsonBuilder ();
959+ mappingsAndSettings .startObject ();
960+ {
961+ mappingsAndSettings .startObject ("settings" );
962+ mappingsAndSettings .field ("number_of_shards" , 1 );
963+ mappingsAndSettings .field ("number_of_replicas" , 1 );
964+ if (getOldClusterVersion ().onOrAfter (Version .V_6_5_0 )) {
965+ mappingsAndSettings .field ("soft_deletes.enabled" , true );
966+ }
967+ mappingsAndSettings .endObject ();
968+ }
969+ mappingsAndSettings .endObject ();
970+ Request createIndex = new Request ("PUT" , "/" + index );
971+ createIndex .setJsonEntity (Strings .toString (mappingsAndSettings ));
972+ client ().performRequest (createIndex );
973+ int numDocs = between (10 , 100 );
974+ for (int i = 0 ; i < numDocs ; i ++) {
975+ String doc = Strings .toString (JsonXContent .contentBuilder ().startObject ().field ("field" , "v1" ).endObject ());
976+ Request request = new Request ("POST" , "/" + index + "/doc/" + i );
977+ request .setJsonEntity (doc );
978+ client ().performRequest (request );
979+ if (rarely ()) {
980+ refresh ();
981+ }
982+ }
983+ client ().performRequest (new Request ("POST" , "/" + index + "/_flush" ));
984+ int liveDocs = numDocs ;
985+ assertTotalHits (liveDocs , entityAsMap (client ().performRequest (new Request ("GET" , "/" + index + "/_search" ))));
986+ for (int i = 0 ; i < numDocs ; i ++) {
987+ if (randomBoolean ()) {
988+ String doc = Strings .toString (JsonXContent .contentBuilder ().startObject ().field ("field" , "v2" ).endObject ());
989+ Request request = new Request ("POST" , "/" + index + "/doc/" + i );
990+ request .setJsonEntity (doc );
991+ client ().performRequest (request );
992+ } else if (randomBoolean ()) {
993+ client ().performRequest (new Request ("DELETE" , "/" + index + "/doc/" + i ));
994+ liveDocs --;
995+ }
996+ }
997+ refresh ();
998+ assertTotalHits (liveDocs , entityAsMap (client ().performRequest (new Request ("GET" , "/" + index + "/_search" ))));
999+ saveInfoDocument ("doc_count" , Integer .toString (liveDocs ));
1000+ } else {
1001+ int liveDocs = Integer .parseInt (loadInfoDocument ("doc_count" ));
1002+ assertTotalHits (liveDocs , entityAsMap (client ().performRequest (new Request ("GET" , "/" + index + "/_search" ))));
1003+ }
1004+ }
1005+
9561006 private void checkSnapshot (String snapshotName , int count , Version tookOnVersion ) throws IOException {
9571007 // Check the snapshot metadata, especially the version
9581008 Request listSnapshotRequest = new Request ("GET" , "/_snapshot/repo/" + snapshotName );
0 commit comments