add missing units to tests

This commit is contained in:
Michael McCandless 2015-05-25 06:48:34 -04:00 committed by mikemccand
parent 6a6df5f8ce
commit 5aaebb6d83
18 changed files with 60 additions and 42 deletions

View File

@ -45,7 +45,7 @@
type: test
id: 1
body: { foo: bar }
ttl: 100000
ttl: 100000ms
- do:
get:
index: test_1

View File

@ -40,7 +40,7 @@
type: test
id: 1
body: { foo: bar }
ttl: 100000
ttl: 100000ms
- do:
get:
index: test_1

View File

@ -44,7 +44,7 @@
body:
doc: { foo: baz }
upsert: { foo: bar }
ttl: 100000
ttl: 100000ms
- do:
get:

View File

@ -806,7 +806,7 @@ public class ImmutableSettings implements Settings {
* @return The builder
*/
public Builder put(String setting, long value, TimeUnit timeUnit) {
put(setting, timeUnit.toMillis(value));
put(setting, timeUnit.toMillis(value) + "ms");
return this;
}

View File

@ -255,6 +255,8 @@ public class TimeValue implements Serializable, Streamable {
millis = 0;
} else {
// Missing units:
// nocommit
System.out.println("MKM: Failed to parse setting [" + settingName + "] with value [" + sValue + "] as a time value: unit is missing or unrecognized");
throw new ElasticsearchParseException("Failed to parse setting [" + settingName + "] with value [" + sValue + "] as a time value: unit is missing or unrecognized");
}
return new TimeValue(millis, TimeUnit.MILLISECONDS);

View File

@ -63,4 +63,4 @@ public class DateHistogramInterval {
public String toString() {
return expression;
}
}
}

View File

@ -106,7 +106,7 @@ public class DerivativeParser implements PipelineAggregator.Parser {
if (dateTimeUnit != null) {
xAxisUnits = dateTimeUnit.field().getDurationField().getUnitMillis();
} else {
TimeValue timeValue = TimeValue.parseTimeValue(units, null, "DerivativeParser.units");
TimeValue timeValue = TimeValue.parseTimeValue(units, null, "DerivativeParser.unit");
if (timeValue != null) {
xAxisUnits = timeValue.getMillis();
}

View File

@ -19,9 +19,6 @@
package org.elasticsearch.cluster.ack;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
@ -47,6 +44,11 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ -70,11 +72,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
createIndex("test");
assertAcked(client().admin().indices().prepareUpdateSettings("test")
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999)));
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999, TimeUnit.MILLISECONDS)));
for (Client client : clients()) {
String refreshInterval = getLocalClusterState(client).metaData().index("test").settings().get("index.refresh_interval");
assertThat(refreshInterval, equalTo("9999"));
assertThat(refreshInterval, equalTo("9999ms"));
}
}
@ -82,7 +84,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
public void testUpdateSettingsNoAcknowledgement() {
createIndex("test");
UpdateSettingsResponse updateSettingsResponse = client().admin().indices().prepareUpdateSettings("test").setTimeout("0s")
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999)).get();
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999, TimeUnit.MILLISECONDS)).get();
assertThat(updateSettingsResponse.isAcknowledged(), equalTo(false));
}

View File

@ -159,7 +159,7 @@ public class FuzzinessTests extends ElasticsearchTestCase {
assertThat(Fuzziness.AUTO.asDouble(), equalTo(1d));
assertThat(Fuzziness.AUTO.asLong(), equalTo(1l));
assertThat(Fuzziness.AUTO.asShort(), equalTo((short) 1));
assertThat(Fuzziness.AUTO.asTimeValue(), equalTo(TimeValue.parseTimeValue("1", TimeValue.timeValueMillis(1), "fuzziness")));
assertThat(Fuzziness.AUTO.asTimeValue(), equalTo(TimeValue.parseTimeValue("1ms", TimeValue.timeValueMillis(1), "fuzziness")));
}

View File

@ -31,12 +31,8 @@ import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
/**
*
*/
public class TimeValueTests extends ElasticsearchTestCase {
@Test
public void testSimple() {
assertThat(TimeUnit.MILLISECONDS.toMillis(10), equalTo(new TimeValue(10, TimeUnit.MILLISECONDS).millis()));
assertThat(TimeUnit.MICROSECONDS.toMicros(10), equalTo(new TimeValue(10, TimeUnit.MICROSECONDS).micros()));
@ -46,7 +42,6 @@ public class TimeValueTests extends ElasticsearchTestCase {
assertThat(TimeUnit.DAYS.toDays(10), equalTo(new TimeValue(10, TimeUnit.DAYS).days()));
}
@Test
public void testToString() {
assertThat("10ms", equalTo(new TimeValue(10, TimeUnit.MILLISECONDS).toString()));
assertThat("1.5s", equalTo(new TimeValue(1533, TimeUnit.MILLISECONDS).toString()));
@ -56,7 +51,6 @@ public class TimeValueTests extends ElasticsearchTestCase {
assertThat("1000d", equalTo(new TimeValue(1000, TimeUnit.DAYS).toString()));
}
@Test
public void testFormat() {
assertThat(new TimeValue(1025, TimeUnit.MILLISECONDS).format(PeriodType.dayTime()), equalTo("1 second and 25 milliseconds"));
assertThat(new TimeValue(1, TimeUnit.MINUTES).format(PeriodType.dayTime()), equalTo("1 minute"));
@ -64,11 +58,18 @@ public class TimeValueTests extends ElasticsearchTestCase {
assertThat(new TimeValue(24 * 600 + 85, TimeUnit.MINUTES).format(PeriodType.dayTime()), equalTo("241 hours and 25 minutes"));
}
@Test
public void testMinusOne() {
assertThat(new TimeValue(-1).nanos(), lessThan(0l));
}
public void testParseTimeValue() {
// Space is allowed before unit
assertEquals(new TimeValue(10, TimeUnit.SECONDS),
TimeValue.parseTimeValue("10 s", null, "ten seconds"));
assertEquals(new TimeValue(10, TimeUnit.SECONDS),
TimeValue.parseTimeValue("10s", null, "ten seconds"));
}
private void assertEqualityAfterSerialize(TimeValue value) throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
value.writeTo(out);
@ -79,7 +80,6 @@ public class TimeValueTests extends ElasticsearchTestCase {
assertThat(inValue, equalTo(value));
}
@Test
public void testSerialize() throws Exception {
assertEqualityAfterSerialize(new TimeValue(100, TimeUnit.DAYS));
assertEqualityAfterSerialize(new TimeValue(-1));

View File

@ -24,6 +24,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ -48,7 +50,11 @@ public class InternalEngineSettingsTest extends ElasticsearchSingleNodeTest {
final int iters = between(1, 20);
for (int i = 0; i < iters; i++) {
boolean compoundOnFlush = randomBoolean();
long gcDeletes = Math.max(0, randomLong());
// Tricky: TimeValue.parseTimeValue casts this long to a double, which steals 11 of the 64 bits for exponent, so we can't use
// the full long range here else the assert below fails:
long gcDeletes = random().nextLong() & (Long.MAX_VALUE >> 11);
boolean versionMapAsPercent = randomBoolean();
double versionMapPercent = randomIntBetween(0, 100);
long versionMapSizeInMB = randomIntBetween(10, 20);
@ -56,9 +62,10 @@ public class InternalEngineSettingsTest extends ElasticsearchSingleNodeTest {
Settings build = ImmutableSettings.builder()
.put(EngineConfig.INDEX_COMPOUND_ON_FLUSH, compoundOnFlush)
.put(EngineConfig.INDEX_GC_DELETES_SETTING, gcDeletes)
.put(EngineConfig.INDEX_GC_DELETES_SETTING, gcDeletes, TimeUnit.MILLISECONDS)
.put(EngineConfig.INDEX_VERSION_MAP_SIZE, versionMapString)
.build();
assertEquals(gcDeletes, build.getAsTime(EngineConfig.INDEX_GC_DELETES_SETTING, null).millis());
client().admin().indices().prepareUpdateSettings("foo").setSettings(build).get();
LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();
@ -79,7 +86,7 @@ public class InternalEngineSettingsTest extends ElasticsearchSingleNodeTest {
}
Settings settings = ImmutableSettings.builder()
.put(EngineConfig.INDEX_GC_DELETES_SETTING, 1000)
.put(EngineConfig.INDEX_GC_DELETES_SETTING, 1000, TimeUnit.MILLISECONDS)
.build();
client().admin().indices().prepareUpdateSettings("foo").setSettings(settings).get();
assertEquals(engine.getGcDeletesInMillis(), 1000);
@ -95,7 +102,7 @@ public class InternalEngineSettingsTest extends ElasticsearchSingleNodeTest {
assertTrue(engine.config().isEnableGcDeletes());
settings = ImmutableSettings.builder()
.put(EngineConfig.INDEX_GC_DELETES_SETTING, 1000)
.put(EngineConfig.INDEX_GC_DELETES_SETTING, 1000, TimeUnit.MILLISECONDS)
.build();
client().admin().indices().prepareUpdateSettings("foo").setSettings(settings).get();
assertEquals(engine.getGcDeletesInMillis(), 1000);

View File

@ -59,7 +59,7 @@ public class TTLPercolatorTests extends ElasticsearchIntegrationTest {
protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("indices.ttl.interval", PURGE_INTERVAL)
.put("indices.ttl.interval", PURGE_INTERVAL, TimeUnit.MILLISECONDS)
.build();
}
@ -163,7 +163,7 @@ public class TTLPercolatorTests extends ElasticsearchIntegrationTest {
public void testEnsureTTLDoesNotCreateIndex() throws IOException, InterruptedException {
ensureGreen();
client().admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder()
.put("indices.ttl.interval", 60) // 60 sec
.put("indices.ttl.interval", 60, TimeUnit.SECONDS) // 60 sec
.build()).get();
String typeMapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
@ -176,7 +176,7 @@ public class TTLPercolatorTests extends ElasticsearchIntegrationTest {
.execute().actionGet();
ensureGreen();
client().admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder()
.put("indices.ttl.interval", 1) // 60 sec
.put("indices.ttl.interval", 1, TimeUnit.SECONDS)
.build()).get();
for (int i = 0; i < 100; i++) {

View File

@ -23,6 +23,8 @@ import org.elasticsearch.indices.recovery.RecoverySettings;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
public class RecoverySettingsTest extends ElasticsearchSingleNodeTest {
@Override
@ -68,31 +70,31 @@ public class RecoverySettingsTest extends ElasticsearchSingleNodeTest {
assertEquals(null, recoverySettings.rateLimiter());
}
});
innerTestSettings(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_STATE_SYNC, randomIntBetween(1, 200), new Validator() {
innerTestSettings(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_STATE_SYNC, randomIntBetween(1, 200), TimeUnit.MILLISECONDS, new Validator() {
@Override
public void validate(RecoverySettings recoverySettings, int expectedValue) {
assertEquals(expectedValue, recoverySettings.retryDelayStateSync().millis());
}
});
innerTestSettings(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK, randomIntBetween(1, 200), new Validator() {
innerTestSettings(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK, randomIntBetween(1, 200), TimeUnit.MILLISECONDS, new Validator() {
@Override
public void validate(RecoverySettings recoverySettings, int expectedValue) {
assertEquals(expectedValue, recoverySettings.retryDelayNetwork().millis());
}
});
innerTestSettings(RecoverySettings.INDICES_RECOVERY_ACTIVITY_TIMEOUT, randomIntBetween(1, 200), new Validator() {
innerTestSettings(RecoverySettings.INDICES_RECOVERY_ACTIVITY_TIMEOUT, randomIntBetween(1, 200), TimeUnit.MILLISECONDS, new Validator() {
@Override
public void validate(RecoverySettings recoverySettings, int expectedValue) {
assertEquals(expectedValue, recoverySettings.activityTimeout().millis());
}
});
innerTestSettings(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT, randomIntBetween(1, 200), new Validator() {
innerTestSettings(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT, randomIntBetween(1, 200), TimeUnit.MILLISECONDS, new Validator() {
@Override
public void validate(RecoverySettings recoverySettings, int expectedValue) {
assertEquals(expectedValue, recoverySettings.internalActionTimeout().millis());
}
});
innerTestSettings(RecoverySettings.INDICES_RECOVERY_INTERNAL_LONG_ACTION_TIMEOUT, randomIntBetween(1, 200), new Validator() {
innerTestSettings(RecoverySettings.INDICES_RECOVERY_INTERNAL_LONG_ACTION_TIMEOUT, randomIntBetween(1, 200), TimeUnit.MILLISECONDS, new Validator() {
@Override
public void validate(RecoverySettings recoverySettings, int expectedValue) {
assertEquals(expectedValue, recoverySettings.internalActionLongTimeout().millis());
@ -120,6 +122,11 @@ public class RecoverySettingsTest extends ElasticsearchSingleNodeTest {
validator.validate(getInstanceFromNode(RecoverySettings.class), newValue);
}
private void innerTestSettings(String key, int newValue, TimeUnit timeUnit, Validator validator) {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(ImmutableSettings.builder().put(key, newValue, timeUnit)).get();
validator.validate(getInstanceFromNode(RecoverySettings.class), newValue);
}
private void innerTestSettings(String key, boolean newValue, Validator validator) {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(ImmutableSettings.builder().put(key, newValue)).get();
validator.validate(getInstanceFromNode(RecoverySettings.class), newValue);

View File

@ -1307,14 +1307,14 @@ public class DateHistogramTests extends ElasticsearchIntegrationTest {
/**
* see issue #9634, negative interval in date_histogram should raise exception
*/
public void testExeptionOnNegativerInterval() {
public void testExeptionOnNegativeInterval() {
try {
client().prepareSearch("idx")
.addAggregation(dateHistogram("histo").field("date").interval(-TimeUnit.DAYS.toMillis(1)).minDocCount(0)).execute()
.actionGet();
fail();
} catch (SearchPhaseExecutionException e) {
assertThat(e.toString(), containsString("IllegalArgumentException"));
assertThat(e.toString(), containsString("ElasticsearchParseException"));
}
}
}

View File

@ -211,8 +211,8 @@ public class DerivativeTests extends ElasticsearchIntegrationTest {
.prepareSearch("idx")
.addAggregation(
histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).minDocCount(0)
.subAggregation(derivative("deriv").setBucketsPaths("_count").unit("1"))
.subAggregation(derivative("2nd_deriv").setBucketsPaths("deriv").unit("10"))).execute().actionGet();
.subAggregation(derivative("deriv").setBucketsPaths("_count").unit("1ms"))
.subAggregation(derivative("2nd_deriv").setBucketsPaths("deriv").unit("10ms"))).execute().actionGet();
assertSearchResponse(response);

View File

@ -286,7 +286,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
logger.info("--> create index with foo type");
assertAcked(prepareCreate("test-idx", 2, ImmutableSettings.builder()
.put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 10)));
.put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 10, TimeUnit.SECONDS)));
NumShards numShards = getNumShards("test-idx");
@ -301,7 +301,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
logger.info("--> delete the index and recreate it with bar type");
cluster().wipeIndices("test-idx");
assertAcked(prepareCreate("test-idx", 2, ImmutableSettings.builder()
.put(SETTING_NUMBER_OF_SHARDS, numShards.numPrimaries).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 5)));
.put(SETTING_NUMBER_OF_SHARDS, numShards.numPrimaries).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 5, TimeUnit.SECONDS)));
assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("bar").setSource("baz", "type=string"));
ensureGreen();
@ -319,7 +319,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
logger.info("--> assert that old settings are restored");
GetSettingsResponse getSettingsResponse = client.admin().indices().prepareGetSettings("test-idx").execute().actionGet();
assertThat(getSettingsResponse.getSetting("test-idx", "index.refresh_interval"), equalTo("10"));
assertThat(getSettingsResponse.getSetting("test-idx", "index.refresh_interval"), equalTo("10000ms"));
}
@Test

View File

@ -451,7 +451,7 @@ public final class InternalTestCluster extends TestCluster {
if (rarely(random)) {
builder.put(TranslogConfig.INDEX_TRANSLOG_SYNC_INTERVAL, 0); // 0 has special meaning to sync each op
} else {
builder.put(TranslogConfig.INDEX_TRANSLOG_SYNC_INTERVAL, RandomInts.randomIntBetween(random, 100, 5000));
builder.put(TranslogConfig.INDEX_TRANSLOG_SYNC_INTERVAL, RandomInts.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
}
}

View File

@ -58,7 +58,7 @@ public class SimpleTTLTests extends ElasticsearchIntegrationTest {
protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("indices.ttl.interval", PURGE_INTERVAL)
.put("indices.ttl.interval", PURGE_INTERVAL, TimeUnit.MILLISECONDS)
.put("cluster.routing.operation.use_type", false) // make sure we control the shard computation
.put("cluster.routing.operation.hash.type", "djb")
.build();