diff --git a/src/test/java/org/elasticsearch/test/integration/ttl/SimpleTTLTests.java b/src/test/java/org/elasticsearch/test/integration/ttl/SimpleTTLTests.java index 89f4ab78fe1..3b8f00c041b 100644 --- a/src/test/java/org/elasticsearch/test/integration/ttl/SimpleTTLTests.java +++ b/src/test/java/org/elasticsearch/test/integration/ttl/SimpleTTLTests.java @@ -39,7 +39,12 @@ public class SimpleTTLTests extends AbstractNodesTests { @BeforeClass public void createNodes() throws Exception { - Settings settings = settingsBuilder().put("indices.ttl.interval", purgeInterval).build(); + Settings settings = settingsBuilder() + .put("indices.ttl.interval", purgeInterval) + .put("index.number_of_shards", 2) // 2 shards to test TTL purge with routing properly + .put("cluster.routing.operation.use_type", false) // make sure we control the shard computation + .put("cluster.routing.operation.hash.type", "djb") + .build(); startNode("node1", settings); startNode("node2", settings); client = getClient(); @@ -71,7 +76,9 @@ public class SimpleTTLTests extends AbstractNodesTests { client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); long providedTTLValue = 3000; logger.info("--> checking ttl"); + // Index one doc without routing and one doc with routing client.prepareIndex("test", "type1", "1").setSource("field1", "value1").setTTL(providedTTLValue).setRefresh(true).execute().actionGet(); + client.prepareIndex("test", "type1", "with_routing").setSource("field1", "value1").setTTL(providedTTLValue).setRouting("routing").setRefresh(true).execute().actionGet(); long now = System.currentTimeMillis(); // realtime get check @@ -100,7 +107,7 @@ public class SimpleTTLTests extends AbstractNodesTests { assertThat(ttl0, lessThan(providedTTLValue - (now1 - now))); logger.info("--> checking purger"); - // make sure the purger has done its job + // make sure the purger has done its job for all indexed docs that are expired long shouldBeExpiredDate = now + providedTTLValue + purgeInterval + 2000; now1 = System.currentTimeMillis(); if (shouldBeExpiredDate - now1 > 0) { @@ -109,14 +116,22 @@ public class SimpleTTLTests extends AbstractNodesTests { // realtime get check getResponse = client.prepareGet("test", "type1", "1").setFields("_ttl").setRealtime(true).execute().actionGet(); assertThat(getResponse.exists(), equalTo(false)); + getResponse = client.prepareGet("test", "type1", "with_routing").setRouting("routing").setFields("_ttl").setRealtime(true).execute().actionGet(); + assertThat(getResponse.exists(), equalTo(false)); // replica realtime get check getResponse = client.prepareGet("test", "type1", "1").setFields("_ttl").setRealtime(true).execute().actionGet(); assertThat(getResponse.exists(), equalTo(false)); + getResponse = client.prepareGet("test", "type1", "with_routing").setRouting("routing").setFields("_ttl").setRealtime(true).execute().actionGet(); + assertThat(getResponse.exists(), equalTo(false)); // non realtime get (stored) check getResponse = client.prepareGet("test", "type1", "1").setFields("_ttl").setRealtime(false).execute().actionGet(); assertThat(getResponse.exists(), equalTo(false)); + getResponse = client.prepareGet("test", "type1", "with_routing").setRouting("routing").setFields("_ttl").setRealtime(false).execute().actionGet(); + assertThat(getResponse.exists(), equalTo(false)); // non realtime get going the replica check getResponse = client.prepareGet("test", "type1", "1").setFields("_ttl").setRealtime(false).execute().actionGet(); assertThat(getResponse.exists(), equalTo(false)); + getResponse = client.prepareGet("test", "type1", "with_routing").setRouting("routing").setFields("_ttl").setRealtime(false).execute().actionGet(); + assertThat(getResponse.exists(), equalTo(false)); } }