@Test public void testDefaultRecoverAfterTime() throws IOException { // check that the default is not set GatewayService service = createService(Settings.builder()); assertNull(service.recoverAfterTime()); // ensure default is set when setting expected_nodes service = createService(Settings.builder().put("gateway.expected_nodes", 1)); assertThat( service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET)); // ensure default is set when setting expected_data_nodes service = createService(Settings.builder().put("gateway.expected_data_nodes", 1)); assertThat( service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET)); // ensure default is set when setting expected_master_nodes service = createService(Settings.builder().put("gateway.expected_master_nodes", 1)); assertThat( service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET)); // ensure settings override default TimeValue timeValue = TimeValue.timeValueHours(3); // ensure default is set when setting expected_nodes service = createService( Settings.builder() .put("gateway.expected_nodes", 1) .put("gateway.recover_after_time", timeValue.toString())); assertThat(service.recoverAfterTime().millis(), Matchers.equalTo(timeValue.millis())); }
private static String renderValue(RestRequest request, Object value) { if (value == null) { return null; } if (value instanceof ByteSizeValue) { ByteSizeValue v = (ByteSizeValue) value; String resolution = request.param("bytes"); if ("b".equals(resolution)) { return Long.toString(v.bytes()); } else if ("k".equals(resolution)) { return Long.toString(v.kb()); } else if ("m".equals(resolution)) { return Long.toString(v.mb()); } else if ("g".equals(resolution)) { return Long.toString(v.gb()); } else if ("t".equals(resolution)) { return Long.toString(v.tb()); } else if ("p".equals(resolution)) { return Long.toString(v.pb()); } else { return v.toString(); } } if (value instanceof SizeValue) { SizeValue v = (SizeValue) value; String resolution = request.param("size"); if ("b".equals(resolution)) { return Long.toString(v.singles()); } else if ("k".equals(resolution)) { return Long.toString(v.kilo()); } else if ("m".equals(resolution)) { return Long.toString(v.mega()); } else if ("g".equals(resolution)) { return Long.toString(v.giga()); } else if ("t".equals(resolution)) { return Long.toString(v.tera()); } else if ("p".equals(resolution)) { return Long.toString(v.peta()); } else { return v.toString(); } } if (value instanceof TimeValue) { TimeValue v = (TimeValue) value; String resolution = request.param("time"); if ("ms".equals(resolution)) { return Long.toString(v.millis()); } else if ("s".equals(resolution)) { return Long.toString(v.seconds()); } else if ("m".equals(resolution)) { return Long.toString(v.minutes()); } else if ("h".equals(resolution)) { return Long.toString(v.hours()); } else { return v.toString(); } } // Add additional built in data points we can render based on request parameters? return value.toString(); }
public void testInitialSearchParamsMisc() { SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder()); Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id)); TimeValue scroll = null; if (randomBoolean()) { scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test"); searchRequest.scroll(scroll); } int size = between(0, Integer.MAX_VALUE); searchRequest.source().size(size); Boolean fetchVersion = null; if (randomBoolean()) { fetchVersion = randomBoolean(); searchRequest.source().version(fetchVersion); } Map<String, String> params = initialSearchParams(searchRequest, remoteVersion); assertThat( params, scroll == null ? not(hasKey("scroll")) : hasEntry("scroll", scroll.toString())); assertThat(params, hasEntry("size", Integer.toString(size))); assertThat( params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null))); assertThat(params, hasEntry("_source", "true")); }
public XContentBuilder timeValueField( String rawFieldName, String readableFieldName, TimeValue timeValue) throws IOException { if (humanReadable) { field(readableFieldName, timeValue.toString()); } field(rawFieldName, timeValue.millis()); return this; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(name, XContentBuilder.FieldCaseConversion.NONE); builder.field(Fields.TYPE, type); if (min != -1) { builder.field(Fields.MIN, min); } if (max != -1) { builder.field(Fields.MAX, max); } if (keepAlive != null) { builder.field(Fields.KEEP_ALIVE, keepAlive.toString()); } if (queueSize != null) { builder.field(Fields.QUEUE_SIZE, queueSize.toString()); } builder.endObject(); return builder; }
public void testScrollParams() { TimeValue scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test"); assertThat(scrollParams(scroll), hasEntry("scroll", scroll.toString())); }