Search in sources :

Example 61 with TimeUnit

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];
}
Also used : TimeUnit(java.util.concurrent.TimeUnit)

Example 62 with TimeUnit

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");
    }
}
Also used : SignalFxReporter(com.signalfx.codahale.reporter.SignalFxReporter) Matchers.anyLong(org.mockito.Matchers.anyLong) TimeUnit(java.util.concurrent.TimeUnit) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 63 with TimeUnit

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);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) Test(org.junit.Test)

Example 64 with 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);
}
Also used : MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) SignalFxReporterFactory(com.nike.riposte.metrics.codahale.contrib.SignalFxReporterFactory) TimeUnit(java.util.concurrent.TimeUnit) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) Pair(com.nike.internal.util.Pair) Test(org.junit.Test)

Example 65 with TimeUnit

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.");
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) TimeUnit(java.util.concurrent.TimeUnit)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3