use of java.util.concurrent.TimeUnit in project MantaroBot by Mantaro.
the class AudioCmdUtils method parseTime.
public static long parseTime(String s) {
s = s.toLowerCase();
long[] time = { 0 };
iterate(pattern.matcher(s)).forEach(string -> {
String l = string.substring(0, string.length() - 1);
TimeUnit unit;
switch(string.charAt(string.length() - 1)) {
case 's':
unit = TimeUnit.SECONDS;
break;
case 'm':
unit = TimeUnit.MINUTES;
break;
case 'h':
unit = TimeUnit.HOURS;
break;
case 'd':
unit = TimeUnit.DAYS;
break;
default:
unit = TimeUnit.SECONDS;
break;
}
time[0] += unit.toMillis(Long.parseLong(l));
});
return time[0];
}
use of java.util.concurrent.TimeUnit in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null.
@DataProvider(value = { "true | false", "false | true" }, splitBy = "\\|")
@Test
public void three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null(boolean amountIsNull, boolean timeUnitIsNull) {
// given
SignalFxReporter reporterMock = mock(SignalFxReporter.class);
wireUpReporterForConstructor(reporterMock);
Long amount = (amountIsNull) ? null : 42L;
TimeUnit timeUnit = (timeUnitIsNull) ? null : TimeUnit.DAYS;
// when
Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterMock, Pair.of(amount, timeUnit), metricRegistryMock));
// then
if (amountIsNull) {
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency amount cannot be null");
}
if (timeUnitIsNull) {
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage("reportingFrequency TimeUnit cannot be null");
}
}
use of java.util.concurrent.TimeUnit in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_constructor_sets_fields_as_expected.
@Test
public void RollingWindowTimerBuilder_constructor_sets_fields_as_expected() {
// given
long amount = 42;
TimeUnit timeUnit = TimeUnit.DAYS;
// when
RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
// then
assertThat(rwtb.amount).isEqualTo(amount);
assertThat(rwtb.timeUnit).isEqualTo(timeUnit);
}
use of java.util.concurrent.TimeUnit in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method two_arg_constructor_sets_fields_as_expected.
@Test
public void two_arg_constructor_sets_fields_as_expected() {
// given
SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class);
Pair<Pair<SignalFxReporter, MetricMetadata>, Pair<Long, TimeUnit>> wiredUpMocksAndData = wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock);
MetricMetadata expectedMetricMetadata = wiredUpMocksAndData.getLeft().getRight();
long expectedReportingInterval = wiredUpMocksAndData.getRight().getLeft();
TimeUnit expectedReportingTimeUnit = wiredUpMocksAndData.getRight().getRight();
// when
SignalFxEndpointMetricsHandler instance = new SignalFxEndpointMetricsHandler(reporterFactoryMock, metricRegistryMock);
// then
assertThat(instance.metricMetadata).isSameAs(expectedMetricMetadata);
assertThat(instance.metricRegistry).isSameAs(metricRegistryMock);
assertThat(instance.requestTimerBuilder).isInstanceOf(RollingWindowTimerBuilder.class);
RollingWindowTimerBuilder rwtb = (RollingWindowTimerBuilder) instance.requestTimerBuilder;
assertThat(rwtb.amount).isEqualTo(expectedReportingInterval);
assertThat(rwtb.timeUnit).isEqualTo(expectedReportingTimeUnit);
assertThat(instance.requestTimerDimensionConfigurator).isSameAs(DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR);
}
use of java.util.concurrent.TimeUnit in project OpenAM by OpenRock.
the class RecordProperties method fromThreadDumpJson.
/**
* Import the thead dump json content
*
* @param recordProperties the result record properties modify by board effect.
* @param jsonProperties the sub json content about thread dump
*/
private static void fromThreadDumpJson(RecordProperties recordProperties, JsonValue jsonProperties) {
JsonValue jsonThreadDump = jsonProperties.get(RecordConstants.THREAD_DUMP_LABEL).required();
recordProperties.threadDumpEnable = jsonThreadDump.get(RecordConstants.THREAD_DUMP_ENABLE_LABEL).required().asBoolean();
// Delay block
if (recordProperties.threadDumpEnable) {
JsonValue jsonThreadDumpDelay = jsonThreadDump.get(RecordConstants.THREAD_DUMP_DELAY_LABEL).required();
TimeUnit timeUnit = jsonThreadDumpDelay.get(RecordConstants.THREAD_DUMP_DELAY_TIME_UNIT_LABEL).required().asEnum(TimeUnit.class);
Long timeValue = jsonThreadDumpDelay.get(RecordConstants.THREAD_DUMP_DELAY_VALUE_LABEL).required().asLong();
recordProperties.threadDumpDelayInSeconds = timeUnit.toSeconds(timeValue);
if (recordProperties.threadDumpDelayInSeconds < 1) {
debug.message("For performance reason, {} can't be under the second.", RecordConstants.THREAD_DUMP_DELAY_TIME_UNIT_LABEL);
throw new IllegalArgumentException("For performance reason, " + RecordConstants.THREAD_DUMP_DELAY_TIME_UNIT_LABEL + " can't be under the second.");
}
} else if (jsonThreadDump.isDefined(RecordConstants.THREAD_DUMP_DELAY_LABEL)) {
debug.message("{} is disabled but {} is defined.", RecordConstants.THREAD_DUMP_ENABLE_LABEL, RecordConstants.THREAD_DUMP_DELAY_LABEL);
throw new IllegalArgumentException(RecordConstants.THREAD_DUMP_ENABLE_LABEL + " is disabled but " + RecordConstants.THREAD_DUMP_DELAY_LABEL + " is defined.");
}
}
Aggregations