Disallow negative time value settings

- Consolidated setting validation under `WatcherSettingsValidation`
- `WatcherSettingsException` is now only used for settings errors

We need this consolidation as Guice doesn't deal well with exceptions in constructors. So instead, `WatcherSettingsValidation` can be injected and used as a registry for settings errors and then, since it's a service, if there any registered errors, it'll throw `WatcherSettingsException` when it's started.

Fixes elastic/elasticsearch#539

Original commit: elastic/x-pack-elasticsearch@2c1895d18c
This commit is contained in:
uboness 2015-05-28 00:56:59 +02:00
parent f66f460313
commit 6175b9efda
38 changed files with 223 additions and 131 deletions

View File

@ -26,6 +26,7 @@ import org.elasticsearch.watcher.support.http.HttpClientModule;
import org.elasticsearch.watcher.support.init.InitializingModule;
import org.elasticsearch.watcher.support.secret.SecretModule;
import org.elasticsearch.watcher.support.template.TemplateModule;
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
import org.elasticsearch.watcher.transform.TransformModule;
import org.elasticsearch.watcher.transport.WatcherTransportModule;
import org.elasticsearch.watcher.trigger.TriggerModule;
@ -67,6 +68,7 @@ public class WatcherModule extends AbstractModule implements SpawnModules {
protected void configure() {
bind(WatcherLifeCycleService.class).asEagerSingleton();
bind(TemplateUtils.class).asEagerSingleton();
bind(WatcherSettingsValidation.class).asEagerSingleton();
}
}

View File

@ -17,6 +17,7 @@ import org.elasticsearch.watcher.history.HistoryModule;
import org.elasticsearch.watcher.license.LicenseService;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.init.InitializingService;
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
import java.util.Collection;
@ -67,7 +68,8 @@ public class WatcherPlugin extends AbstractPlugin {
InitializingService.class,
LicenseService.class,
InternalEmailService.class,
HttpClient.class);
HttpClient.class,
WatcherSettingsValidation.class);
}
@Override

View File

@ -1,21 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher;
/**
*
*/
public class WatcherSettingsException extends WatcherException {
public WatcherSettingsException(String msg, Object... args) {
super(msg, args);
}
public WatcherSettingsException(String msg, Throwable cause, Object... args) {
super(msg, cause, args);
}
}

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.execution.Wid;
import org.elasticsearch.watcher.license.LicenseService;
import org.elasticsearch.watcher.support.Validation;
import org.elasticsearch.watcher.support.validation.Validation;
import org.elasticsearch.watcher.support.clock.Clock;
import org.elasticsearch.watcher.transform.TransformRegistry;

View File

@ -24,6 +24,7 @@ import org.elasticsearch.watcher.history.HistoryStore;
import org.elasticsearch.watcher.history.WatchRecord;
import org.elasticsearch.watcher.input.Input;
import org.elasticsearch.watcher.support.clock.Clock;
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
import org.elasticsearch.watcher.trigger.TriggerEvent;
import org.elasticsearch.watcher.watch.Watch;
import org.elasticsearch.watcher.watch.WatchLockService;
@ -53,15 +54,17 @@ public class ExecutionService extends AbstractComponent {
@Inject
public ExecutionService(Settings settings, HistoryStore historyStore, WatchExecutor executor, WatchStore watchStore,
WatchLockService watchLockService, Clock clock) {
WatchLockService watchLockService, Clock clock, WatcherSettingsValidation settingsValidation) {
super(settings);
this.historyStore = historyStore;
this.executor = executor;
this.watchStore = watchStore;
this.watchLockService = watchLockService;
this.clock = clock;
TimeValue throttlePeriod = componentSettings.getAsTime("default_throttle_period", TimeValue.timeValueSeconds(5));
this.defaultThrottlePeriod = throttlePeriod.millis() == 0 ? null : throttlePeriod;
this.defaultThrottlePeriod = componentSettings.getAsTime("default_throttle_period", TimeValue.timeValueSeconds(5));
if (ExecutionService.this.defaultThrottlePeriod.millis() < 0) {
settingsValidation.addError("watcher.execution.default_throttle_period", "time value cannot be negative");
}
}
public void start(ClusterState state) {

View File

@ -17,7 +17,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.support.validation.WatcherSettingsException;
import org.elasticsearch.watcher.actions.ActionRegistry;
import org.elasticsearch.watcher.condition.Condition;
import org.elasticsearch.watcher.condition.ConditionRegistry;
@ -197,7 +197,7 @@ public class WatchRecord implements ToXContent {
try {
return valueOf(id.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException iae) {
throw new WatcherSettingsException("unknown watch record state [{}]", id);
throw new HistoryException("unknown watch record state [{}]", id);
}
}

View File

@ -12,14 +12,11 @@ import org.elasticsearch.common.joda.DateMathParser;
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.joda.time.DateTime;
import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.PeriodType;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.actions.ActionException;
import org.elasticsearch.watcher.rest.action.RestExecuteWatchAction;
import org.elasticsearch.watcher.support.clock.Clock;
import java.io.IOException;
@ -130,12 +127,20 @@ public class WatcherDateTimeUtils {
return defaultValue;
}
if (token == XContentParser.Token.VALUE_NUMBER) {
return new TimeValue(parser.longValue(), defaultTimeUnit);
} else if (token == XContentParser.Token.VALUE_STRING) {
return TimeValue.parseTimeValue(parser.text(), defaultValue);
} else {
throw new ParseException("could not parse time value. expected either a string or a numeric value but found [{}] instead", token);
long millis = parser.longValue();
if (millis < 0) {
throw new ParseException("could not parse milli-seconds time value [{}]. Time value cannot be negative.", millis);
}
return new TimeValue(millis, defaultTimeUnit);
}
if (token == XContentParser.Token.VALUE_STRING) {
TimeValue value = TimeValue.parseTimeValue(parser.text(), defaultValue);
if (value.millis() < 0) {
throw new ParseException("could not parse time value [{}]. Time value cannot be negative.", parser.text());
}
return value;
}
throw new ParseException("could not parse time value. expected either a string or a numeric value but found [{}] instead", token);
}
public static class ParseException extends WatcherException {

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher.support;
package org.elasticsearch.watcher.support.validation;
import org.elasticsearch.common.logging.support.LoggerMessageFormat;

View File

@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher.support.validation;
import org.elasticsearch.watcher.WatcherException;
/**
*
*/
public class WatcherSettingsException extends WatcherException {
public WatcherSettingsException() {
super("invalid settings");
}
public void addError(String error) {
addSuppressed(new InvalidSettingException(error));
}
static class InvalidSettingException extends WatcherException {
public InvalidSettingException(String error) {
super(error);
}
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher.support.validation;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.support.LoggerMessageFormat;
import org.elasticsearch.common.settings.Settings;
import java.util.*;
/**
*
*/
public class WatcherSettingsValidation extends AbstractLifecycleComponent<WatcherSettingsValidation> {
private List<String> errors = new ArrayList<>();
@Inject
public WatcherSettingsValidation(Settings settings) {
super(settings);
}
@Override
protected void doStart() throws ElasticsearchException {
validate();
}
@Override
protected void doStop() throws ElasticsearchException {
}
@Override
protected void doClose() throws ElasticsearchException {
}
public void addError(String setting, String reason) {
errors.add(LoggerMessageFormat.format("", "invalid [{}] setting value [{}]. {}", setting, settings.get(setting), reason));
}
private void validate() throws ElasticsearchException {
if (errors.isEmpty()) {
return;
}
WatcherSettingsException exception = new WatcherSettingsException();
for (String error : errors) {
exception.addError(error);
}
throw exception;
}
}

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.watcher.support.Validation;
import org.elasticsearch.watcher.support.validation.Validation;
import java.io.IOException;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.watcher.support.Validation;
import org.elasticsearch.watcher.support.validation.Validation;
import java.io.IOException;

View File

@ -14,7 +14,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.watcher.support.Validation;
import org.elasticsearch.watcher.support.validation.Validation;
import org.elasticsearch.watcher.trigger.TriggerEvent;
import org.elasticsearch.watcher.execution.ActionExecutionMode;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.watcher.support.Validation;
import org.elasticsearch.watcher.support.validation.Validation;
import java.io.IOException;

View File

@ -15,7 +15,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.watcher.support.Validation;
import org.elasticsearch.watcher.support.validation.Validation;
import java.io.IOException;

View File

@ -7,7 +7,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import java.io.IOException;
import java.util.ArrayList;
@ -56,24 +55,24 @@ public class CronSchedule extends CronnableSchedule {
crons.add(parser.text());
break;
default:
throw new WatcherSettingsException("could not parse [cron] schedule. expected a string value in the cron array but found [" + token + "]");
throw new ScheduleTriggerException("could not parse [cron] schedule. expected a string value in the cron array but found [" + token + "]");
}
}
if (crons.isEmpty()) {
throw new WatcherSettingsException("could not parse [cron] schedule. no cron expression found in cron array");
throw new ScheduleTriggerException("could not parse [cron] schedule. no cron expression found in cron array");
}
return new CronSchedule(crons.toArray(new String[crons.size()]));
} else {
throw new WatcherSettingsException("could not parse [cron] schedule. expected either a cron string value or an array of cron string values, but found [" + token + "]");
throw new ScheduleTriggerException("could not parse [cron] schedule. expected either a cron string value or an array of cron string values, but found [" + token + "]");
}
} catch (ValidationException ve) {
throw new WatcherSettingsException("could not parse [cron] schedule. invalid cron expression [" + ve.expression + "]", ve);
throw new ScheduleTriggerException("could not parse [cron] schedule. invalid cron expression [" + ve.expression + "]", ve);
}
}
}
public static class ValidationException extends WatcherSettingsException {
public static class ValidationException extends ScheduleTriggerException {
private String expression;

View File

@ -8,7 +8,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import java.io.IOException;
@ -96,19 +95,19 @@ public class DailySchedule extends CronnableSchedule {
try {
times.add(DayTimes.parse(parser, token));
} catch (DayTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [daily] schedule. invalid time value for field [at] - [" + token + "]", pe);
throw new ScheduleTriggerException("could not parse [daily] schedule. invalid time value for field [at] - [" + token + "]", pe);
}
} else {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
try {
times.add(DayTimes.parse(parser, token));
} catch (DayTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [daily] schedule. invalid time value for field [at] - [" + token + "]", pe);
throw new ScheduleTriggerException("could not parse [daily] schedule. invalid time value for field [at] - [" + token + "]", pe);
}
}
}
} else {
throw new WatcherSettingsException("could not parse [daily] schedule. unexpected field [" + currentFieldName + "]");
throw new ScheduleTriggerException("could not parse [daily] schedule. unexpected field [" + currentFieldName + "]");
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import java.io.IOException;
@ -70,7 +69,7 @@ public class HourlySchedule extends CronnableSchedule {
sb.append(",");
}
if (!validMinute(minutes[i])) {
throw new WatcherSettingsException("invalid hourly minute [" + minutes[i] + "]. minute must be between 0 and 59 incl.");
throw new ScheduleTriggerException("invalid hourly minute [" + minutes[i] + "]. minute must be between 0 and 59 incl.");
}
sb.append(minutes[i]);
}
@ -100,27 +99,27 @@ public class HourlySchedule extends CronnableSchedule {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (currentFieldName == null) {
throw new WatcherSettingsException("could not parse [{}] schedule. unexpected token [{}]", TYPE, token);
throw new ScheduleTriggerException("could not parse [{}] schedule. unexpected token [{}]", TYPE, token);
} else if (MINUTE_FIELD.match(currentFieldName)) {
if (token.isValue()) {
try {
minutes.add(DayTimes.parseMinuteValue(parser, token));
} catch (DayTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [hourly] schedule. invalid value for [minute]", pe);
throw new ScheduleTriggerException("could not parse [hourly] schedule. invalid value for [minute]", pe);
}
} else if (token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
try {
minutes.add(DayTimes.parseMinuteValue(parser, token));
} catch (DayTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [hourly] schedule. invalid value for [minute]", pe);
throw new ScheduleTriggerException("could not parse [hourly] schedule. invalid value for [minute]", pe);
}
}
} else {
throw new WatcherSettingsException("could not parse [hourly] schedule. invalid minute value. expected either string/value or an array of string/number values, but found [" + token + "]");
throw new ScheduleTriggerException("could not parse [hourly] schedule. invalid minute value. expected either string/value or an array of string/number values, but found [" + token + "]");
}
} else {
throw new WatcherSettingsException("could not parse [hourly] schedule. unexpected field [" + currentFieldName + "]");
throw new ScheduleTriggerException("could not parse [hourly] schedule. unexpected field [" + currentFieldName + "]");
}
}

View File

@ -8,7 +8,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import java.io.IOException;
import java.util.Locale;
@ -93,7 +92,7 @@ public class IntervalSchedule implements Schedule {
String value = parser.text();
return new IntervalSchedule(Interval.parse(value));
}
throw new WatcherSettingsException("could not parse [interval] schedule. expected either a numeric value " +
throw new ScheduleTriggerException("could not parse [interval] schedule. expected either a numeric value " +
"(millis) or a string value representing time value (e.g. '5s'), but found [" + token + "]");
}
}
@ -133,7 +132,7 @@ public class IntervalSchedule implements Schedule {
try {
return Long.parseLong(num);
} catch (NumberFormatException nfe) {
throw new WatcherSettingsException("could not parse [interval] schedule. could not parse ["
throw new ScheduleTriggerException("could not parse [interval] schedule. could not parse ["
+ num + "] as a " + name().toLowerCase(Locale.ROOT) + " duration");
}
}
@ -196,7 +195,7 @@ public class IntervalSchedule implements Schedule {
return new Interval(unit.parse(value), unit);
}
}
throw new WatcherSettingsException("could not parse [interval] schedule. unrecognized interval format [" + value + "]");
throw new ScheduleTriggerException("could not parse [interval] schedule. unrecognized interval format [" + value + "]");
}
}
}

View File

@ -7,7 +7,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.MonthTimes;
import java.io.IOException;
@ -83,7 +82,7 @@ public class MonthlySchedule extends CronnableSchedule {
try {
return new MonthlySchedule(MonthTimes.parse(parser, parser.currentToken()));
} catch (MonthTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [monthly] schedule. invalid month times", pe);
throw new ScheduleTriggerException("could not parse [monthly] schedule. invalid month times", pe);
}
}
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
@ -93,12 +92,12 @@ public class MonthlySchedule extends CronnableSchedule {
try {
times.add(MonthTimes.parse(parser, token));
} catch (MonthTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [monthly] schedule. invalid month times", pe);
throw new ScheduleTriggerException("could not parse [monthly] schedule. invalid month times", pe);
}
}
return times.isEmpty() ? new MonthlySchedule() : new MonthlySchedule(times.toArray(new MonthTimes[times.size()]));
}
throw new WatcherSettingsException("could not parse [monthly] schedule. expected either an object or an array " +
throw new ScheduleTriggerException("could not parse [monthly] schedule. expected either an object or an array " +
"of objects representing month times, but found [" + parser.currentToken() + "] instead");
}
}

View File

@ -8,7 +8,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import java.io.IOException;
import java.util.Map;
@ -40,11 +39,11 @@ public class ScheduleRegistry {
} else if (type != null) {
schedule = parse(context, type, parser);
} else {
throw new WatcherSettingsException("could not parse schedule. expected a schedule type field, but found [" + token + "]");
throw new ScheduleTriggerException("could not parse schedule. expected a schedule type field, but found [" + token + "]");
}
}
if (schedule == null) {
throw new WatcherSettingsException("could not parse schedule. expected a schedule type field, but no fields were found");
throw new ScheduleTriggerException("could not parse schedule. expected a schedule type field, but no fields were found");
}
return schedule;
}
@ -52,7 +51,7 @@ public class ScheduleRegistry {
public Schedule parse(String context, String type, XContentParser parser) throws IOException {
Schedule.Parser scheduleParser = parsers.get(type);
if (scheduleParser == null) {
throw new WatcherSettingsException("could not parse schedule for [" + context + "]. unknown schedule type [" + type + "]");
throw new ScheduleTriggerException("could not parse schedule for [" + context + "]. unknown schedule type [" + type + "]");
}
return scheduleParser.parse(parser);
}

View File

@ -58,7 +58,7 @@ public class Schedules {
* @param minutes the minutes within the hour that the schedule should trigger at. values must be
* between 0 and 59 (inclusive).
* @return the newly created hourly schedule
* @throws org.elasticsearch.watcher.WatcherSettingsException if any of the provided minutes are out of valid range
* @throws ScheduleTriggerException if any of the provided minutes are out of valid range
*/
public static HourlySchedule hourly(int... minutes) {
return new HourlySchedule(minutes);

View File

@ -7,7 +7,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.WeekTimes;
import java.io.IOException;
@ -83,7 +82,7 @@ public class WeeklySchedule extends CronnableSchedule {
try {
return new WeeklySchedule(WeekTimes.parse(parser, parser.currentToken()));
} catch (WeekTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [weekly] schedule. invalid weekly times", pe);
throw new ScheduleTriggerException("could not parse [weekly] schedule. invalid weekly times", pe);
}
}
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
@ -93,12 +92,12 @@ public class WeeklySchedule extends CronnableSchedule {
try {
times.add(WeekTimes.parse(parser, token));
} catch (WeekTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [weekly] schedule. invalid weekly times", pe);
throw new ScheduleTriggerException("could not parse [weekly] schedule. invalid weekly times", pe);
}
}
return times.isEmpty() ? new WeeklySchedule() : new WeeklySchedule(times.toArray(new WeekTimes[times.size()]));
}
throw new WatcherSettingsException("could not parse [weekly] schedule. expected either an object or an array " +
throw new ScheduleTriggerException("could not parse [weekly] schedule. expected either an object or an array " +
"of objects representing weekly times, but found [" + parser.currentToken() + "] instead");
}
}

View File

@ -7,7 +7,6 @@ package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.YearTimes;
import java.io.IOException;
@ -83,7 +82,7 @@ public class YearlySchedule extends CronnableSchedule {
try {
return new YearlySchedule(YearTimes.parse(parser, parser.currentToken()));
} catch (YearTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [yearly] schedule. invalid year times", pe);
throw new ScheduleTriggerException("could not parse [yearly] schedule. invalid year times", pe);
}
}
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
@ -93,12 +92,12 @@ public class YearlySchedule extends CronnableSchedule {
try {
times.add(YearTimes.parse(parser, token));
} catch (YearTimes.ParseException pe) {
throw new WatcherSettingsException("could not parse [yearly] schedule. invalid year times", pe);
throw new ScheduleTriggerException("could not parse [yearly] schedule. invalid year times", pe);
}
}
return times.isEmpty() ? new YearlySchedule() : new YearlySchedule(times.toArray(new YearTimes[times.size()]));
}
throw new WatcherSettingsException("could not parse [yearly] schedule. expected either an object or an array " +
throw new ScheduleTriggerException("could not parse [yearly] schedule. expected either an object or an array " +
"of objects representing year times, but found [" + parser.currentToken() + "] instead");
}
}

View File

@ -9,7 +9,7 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerException;
import java.io.IOException;
import java.util.ArrayList;
@ -99,12 +99,12 @@ public class DayTimes implements Times {
public void validate() {
for (int i = 0; i < hour.length; i++) {
if (!validHour(hour[i])) {
throw new WatcherSettingsException("invalid time [" + this + "]. invalid time hour value [" + hour[i] + "]. time hours must be between 0 and 23 incl.");
throw new ScheduleTriggerException("invalid time [" + this + "]. invalid time hour value [" + hour[i] + "]. time hours must be between 0 and 23 incl.");
}
}
for (int i = 0; i < minute.length; i++) {
if (!validMinute(minute[i])) {
throw new WatcherSettingsException("invalid time [" + this + "]. invalid time minute value [" + minute[i] + "]. time minutes must be between 0 and 59 incl.");
throw new ScheduleTriggerException("invalid time [" + this + "]. invalid time minute value [" + minute[i] + "]. time minutes must be between 0 and 59 incl.");
}
}
}

View File

@ -11,7 +11,7 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerException;
import java.io.IOException;
import java.util.Arrays;
@ -47,7 +47,7 @@ public class MonthTimes implements Times {
void validate() {
for (int day : days) {
if (day < 1 || day > 32) { //32 represents the last day of the month
throw new WatcherSettingsException("invalid month day [" + day + "]");
throw new ScheduleTriggerException("invalid month day [" + day + "]");
}
}
for (DayTimes dayTimes : times) {

View File

@ -11,7 +11,7 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerException;
import java.io.IOException;
import java.util.*;
@ -44,7 +44,7 @@ public class YearTimes implements Times {
void validate() {
for (int day : days) {
if (day < 1 || day > 32) { //32 represents the last day of the month
throw new WatcherSettingsException("invalid month day [" + day + "]");
throw new ScheduleTriggerException("invalid month day [" + day + "]");
}
}
for (DayTimes dayTimes : times) {

View File

@ -21,6 +21,7 @@ import org.elasticsearch.watcher.support.clock.Clock;
import org.elasticsearch.watcher.support.clock.ClockMock;
import org.elasticsearch.watcher.actions.throttler.ActionThrottler;
import org.elasticsearch.watcher.actions.throttler.Throttler;
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
import org.elasticsearch.watcher.transform.ExecutableTransform;
import org.elasticsearch.watcher.transform.Transform;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent;
@ -58,8 +59,9 @@ public class ExecutionServiceTests extends ElasticsearchTestCase {
WatchExecutor executor = mock(WatchExecutor.class);
WatchStore watchStore = mock(WatchStore.class);
WatchLockService watchLockService = mock(WatchLockService.class);
WatcherSettingsValidation settingsValidator = mock(WatcherSettingsValidation.class);
Clock clock = new ClockMock();
executionService = new ExecutionService(ImmutableSettings.EMPTY, historyStore, executor, watchStore, watchLockService, clock);
executionService = new ExecutionService(ImmutableSettings.EMPTY, historyStore, executor, watchStore, watchLockService, clock, settingsValidator);
}
@Test

View File

@ -14,6 +14,7 @@ import org.junit.Test;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.*;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.test.WatcherTestUtils.xContentParser;
import static org.hamcrest.CoreMatchers.nullValue;
@ -26,7 +27,7 @@ import static org.hamcrest.Matchers.notNullValue;
*/
public class WatcherDateTimeUtilsTests extends ElasticsearchTestCase {
@Test @Repeat(iterations = 20)
@Test @Repeat(iterations = 10)
public void testParseTimeValue_Numeric() throws Exception {
TimeValue value = new TimeValue(randomInt(100), randomFrom(TimeUnit.values()));
@ -40,13 +41,26 @@ public class WatcherDateTimeUtilsTests extends ElasticsearchTestCase {
assertThat(parsed.millis(), is(value.millis()));
}
@Test(expected = WatcherDateTimeUtils.ParseException.class) @Repeat(iterations = 10)
public void testParseTimeValue_Numeric_Negative() throws Exception {
TimeValue value = new TimeValue(randomIntBetween(1, 100), randomFrom(MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS));
XContentParser parser = xContentParser(jsonBuilder().startObject().field("value", -1 * value.getMillis()).endObject());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
WatcherDateTimeUtils.parseTimeValue(parser, null);
}
@Test @Repeat(iterations = 10)
public void testParseTimeValue_String() throws Exception {
int value = randomIntBetween(2, 200);
ImmutableMap<String, TimeValue> values = ImmutableMap.<String, TimeValue>builder()
.put("5s", TimeValue.timeValueSeconds(5))
.put("5m", TimeValue.timeValueMinutes(5))
.put("5h", TimeValue.timeValueHours(5))
.put("5", TimeValue.timeValueMillis(5))
.put(value + "s", TimeValue.timeValueSeconds(value))
.put(value + "m", TimeValue.timeValueMinutes(value))
.put(value + "h", TimeValue.timeValueHours(value))
.put(value + "", TimeValue.timeValueMillis(value))
.build();
String key = randomFrom(values.keySet().toArray(new String[values.size()]));
@ -61,6 +75,26 @@ public class WatcherDateTimeUtilsTests extends ElasticsearchTestCase {
assertThat(parsed.millis(), is(values.get(key).millis()));
}
@Test(expected = WatcherDateTimeUtils.ParseException.class) @Repeat(iterations = 10)
public void testParseTimeValue_String_Negative() throws Exception {
int value = -1 * randomIntBetween(2, 200);
ImmutableMap<String, TimeValue> values = ImmutableMap.<String, TimeValue>builder()
.put(value + "s", TimeValue.timeValueSeconds(value))
.put(value + "m", TimeValue.timeValueMinutes(value))
.put(value + "h", TimeValue.timeValueHours(value))
.put(value + "", TimeValue.timeValueMillis(value))
.build();
String key = randomFrom(values.keySet().toArray(new String[values.size()]));
XContentParser parser = xContentParser(jsonBuilder().startObject().field("value", key).endObject());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
WatcherDateTimeUtils.parseTimeValue(parser, null);
}
@Test
public void testParseTimeValue_Null() throws Exception {
XContentParser parser = xContentParser(jsonBuilder().startObject().nullField("value").endObject());

View File

@ -28,8 +28,6 @@ import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.authc.esusers.ESUsersRealm;
import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
import org.elasticsearch.shield.crypto.InternalCryptoService;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
@ -51,7 +49,6 @@ import org.elasticsearch.watcher.license.LicenseService;
import org.elasticsearch.watcher.support.clock.ClockMock;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.transport.actions.stats.WatcherStatsResponse;
import org.elasticsearch.watcher.trigger.ScheduleTriggerEngineMock;
import org.elasticsearch.watcher.trigger.TriggerService;
import org.elasticsearch.watcher.trigger.schedule.ScheduleModule;

View File

@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.client.WatchSourceBuilder;
import org.elasticsearch.watcher.client.WatcherClient;
import org.elasticsearch.watcher.condition.ConditionBuilders;
@ -392,7 +391,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
.addAction("_logger", loggingAction("executed!")))
.get();
fail("put watch should have failed");
} catch (WatcherSettingsException e) {
} catch (ScheduleTriggerException e) {
assertThat(e.getMessage(), equalTo("invalid hourly minute [-10]. minute must be between 0 and 59 incl."));
}
@ -405,7 +404,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
.addAction("_logger", loggingAction("executed!")))
.get();
fail("put watch should have failed");
} catch (WatcherSettingsException e) {
} catch (ScheduleTriggerException e) {
assertThat(e.getMessage(), equalTo("invalid time [0-10:00]. invalid time hour value [-10]. time hours must be between 0 and 23 incl."));
}
@ -418,7 +417,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
.addAction("_logger", loggingAction("executed!")))
.get();
fail("put watch should have failed");
} catch (WatcherSettingsException e) {
} catch (ScheduleTriggerException e) {
assertThat(e.getMessage(), equalTo("invalid time [0-10:00]. invalid time hour value [-10]. time hours must be between 0 and 23 incl."));
}
@ -431,7 +430,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
.addAction("_logger", loggingAction("executed!")))
.get();
fail("put watch should have failed");
} catch (WatcherSettingsException e) {
} catch (ScheduleTriggerException e) {
assertThat(e.getMessage(), equalTo("invalid time [0-10:00]. invalid time hour value [-10]. time hours must be between 0 and 23 incl."));
}
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
@ -64,13 +63,13 @@ public class CronScheduleTests extends ScheduleTestCase {
try {
new CronSchedule.Parser().parse(parser);
fail("expected cron parsing to fail when using invalid cron expression");
} catch (WatcherSettingsException ase) {
} catch (ScheduleTriggerException ase) {
// expected
assertThat(ase.getCause(), instanceOf(CronSchedule.ValidationException.class));
}
}
@Test(expected = WatcherSettingsException.class)
@Test(expected = ScheduleTriggerException.class)
public void testParse_Invalid_Empty() throws Exception {
XContentBuilder builder = jsonBuilder();
BytesReference bytes = builder.bytes();
@ -79,7 +78,7 @@ public class CronScheduleTests extends ScheduleTestCase {
new CronSchedule.Parser().parse(parser);
}
@Test(expected = WatcherSettingsException.class)
@Test(expected = ScheduleTriggerException.class)
public void testParse_Invalid_Object() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
@ -88,7 +87,7 @@ public class CronScheduleTests extends ScheduleTestCase {
new CronSchedule.Parser().parse(parser);
}
@Test(expected = WatcherSettingsException.class)
@Test(expected = ScheduleTriggerException.class)
public void testParse_Invalid_EmptyArray() throws Exception {
XContentBuilder builder = jsonBuilder().value(new String[0]);
BytesReference bytes = builder.bytes();

View File

@ -11,7 +11,6 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import org.junit.Test;
@ -48,7 +47,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
fail("expected either a parse exception or an watcher settings exception on invalid time input");
} catch (DayTimes.ParseException pe) {
// expected
} catch (WatcherSettingsException ase) {
} catch (ScheduleTriggerException ase) {
// expected
}
}
@ -95,7 +94,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
assertThat(schedule.times()[0], is(time));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleTime_Object_Invalid() throws Exception {
HourAndMinute time = invalidDayTime();
XContentBuilder builder = jsonBuilder()
@ -127,7 +126,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
assertThat(schedule.times()[0], is(DayTimes.parse(timeStr)));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleTime_String_Invalid() throws Exception {
XContentBuilder builder = jsonBuilder()
.startObject()
@ -157,7 +156,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleTimes_Objects_Invalid() throws Exception {
HourAndMinute[] times = invalidDayTimes();
XContentBuilder builder = jsonBuilder()
@ -188,7 +187,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleTimes_Strings_Invalid() throws Exception {
String[] times = invalidDayTimesAsStrings();
XContentBuilder builder = jsonBuilder()

View File

@ -12,7 +12,6 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -40,7 +39,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
assertThat(crons, arrayContaining("0 " + minute + " * * * ?"));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void test_SingleMinute_Invalid() throws Exception {
new HourlySchedule(invalidMinute());
}
@ -55,7 +54,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
assertThat(crons, arrayContaining("0 " + minutesStr + " * * * ?"));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void test_MultipleMinutes_Invalid() throws Exception {
int[] minutes = invalidMinutes();
new HourlySchedule(minutes);
@ -89,7 +88,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
assertThat(schedule.minutes()[0], is(minute));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleMinute_Number_Invalid() throws Exception {
XContentBuilder builder = jsonBuilder()
.startObject()
@ -117,7 +116,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
assertThat(schedule.minutes()[0], is(minute));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleMinute_String_Invalid() throws Exception {
XContentBuilder builder = jsonBuilder()
.startObject()
@ -147,7 +146,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleMinutes_Numbers_Invalid() throws Exception {
int[] minutes = invalidMinutes();
XContentBuilder builder = jsonBuilder()
@ -178,7 +177,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleMinutes_Strings_Invalid() throws Exception {
int[] minutes = invalidMinutes();
XContentBuilder builder = jsonBuilder()

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.watcher.trigger.schedule;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
@ -60,7 +59,7 @@ public class IntervalScheduleTests extends ElasticsearchTestCase {
assertThat(schedule.interval(), is(value));
}
@Test(expected = WatcherSettingsException.class)
@Test(expected = ScheduleTriggerException.class)
public void testParse_Invalid_String() throws Exception {
XContentBuilder builder = jsonBuilder().value("43S");
BytesReference bytes = builder.bytes();
@ -69,7 +68,7 @@ public class IntervalScheduleTests extends ElasticsearchTestCase {
new IntervalSchedule.Parser().parse(parser);
}
@Test(expected = WatcherSettingsException.class)
@Test(expected = ScheduleTriggerException.class)
public void testParse_Invalid_Object() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();

View File

@ -11,7 +11,6 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.watcher.trigger.schedule.support.MonthTimes;
import org.junit.Test;
@ -104,7 +103,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
assertThat(schedule.times()[0].times(), hasItemInArray(time));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleTime_Invalid() throws Exception {
HourAndMinute time = invalidDayTime();
XContentBuilder builder = jsonBuilder()
@ -136,7 +135,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleTimes_Invalid() throws Exception {
HourAndMinute[] times = invalidDayTimes();
XContentBuilder builder = jsonBuilder()

View File

@ -12,7 +12,6 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.watcher.trigger.schedule.support.WeekTimes;
@ -97,7 +96,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
assertThat(schedule.times()[0].times(), hasItemInArray(time));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleTime_Invalid() throws Exception {
HourAndMinute time = invalidDayTime();
XContentBuilder builder = jsonBuilder()
@ -129,7 +128,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleTimes_Objects_Invalid() throws Exception {
HourAndMinute[] times = invalidDayTimes();
XContentBuilder builder = jsonBuilder()

View File

@ -12,7 +12,6 @@ import org.elasticsearch.common.primitives.Ints;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.watcher.trigger.schedule.support.YearTimes;
import org.junit.Test;
@ -111,7 +110,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
assertThat(schedule.times()[0].times(), hasItemInArray(time));
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_SingleTime_Invalid() throws Exception {
HourAndMinute time = invalidDayTime();
XContentBuilder builder = jsonBuilder()
@ -144,7 +143,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
}
}
@Test(expected = WatcherSettingsException.class) @Repeat(iterations = 20)
@Test(expected = ScheduleTriggerException.class) @Repeat(iterations = 20)
public void testParser_MultipleTimes_Invalid() throws Exception {
HourAndMinute[] times = invalidDayTimes();
XContentBuilder builder = jsonBuilder()