Search in sources :

Example 36 with Duration

use of org.joda.time.Duration in project gocd by gocd.

the class LocalizedMessageTest method shouldLocalizeDurations.

@Test
public void shouldLocalizeDurations() throws Exception {
    Duration theDuration = new Duration(1000);
    String expected = "it took a long time";
    when(localizer.localize(theDuration)).thenReturn(expected);
    assertThat(LocalizedMessage.localizeDuration(theDuration).localize(localizer), is(expected));
}
Also used : Duration(org.joda.time.Duration) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 37 with Duration

use of org.joda.time.Duration in project gocd by gocd.

the class LocalizerTest method shouldLocalizeDurations.

@Test
public void shouldLocalizeDurations() {
    CurrentLocale locale = new CurrentLocale();
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("test_message");
    MessageSourceAccessor accessor = new MessageSourceAccessor(source);
    Localizer localizer = new Localizer(accessor, locale);
    assertThat(localizer.localize(new Duration(1000)), is("1 second"));
    assertThat(localizer.localize(new Duration(0)), is(""));
    locale.setLocaleString(Localizer.LOCALE_KANNADA);
    assertThat(localizer.localize(new Duration(1000)), is("1 second"));
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 38 with Duration

use of org.joda.time.Duration in project dhis2-core by dhis2.

the class DefaultFileResourceService method ensureStorageStatus.

/**
     * TODO Temporary fix. Remove at some point.
     *
     * Ensures correctness of the storageStatus of this FileResource.
     *
     * If the status has been 'PENDING' for more than 1 second we check to see if the content may actually have been stored.
     * If this is the case the status is corrected to STORED.
     *
     * This method is a TEMPORARY fix for the for now unsolved issue with a race occurring between the Hibernate object cache
     * and the upload callback attempting to modify the FileResource object upon completion.
     *
     * Resolving that issue (likely by breaking the StorageStatus into a separate table) should make this method redundant.
     */
private FileResource ensureStorageStatus(FileResource fileResource) {
    if (fileResource != null && fileResource.getStorageStatus() == FileResourceStorageStatus.PENDING) {
        Duration pendingDuration = new Duration(new DateTime(fileResource.getLastUpdated()), DateTime.now());
        if (pendingDuration.isLongerThan(Seconds.seconds(1).toStandardDuration())) {
            // Upload has been finished for 5+ seconds and is still PENDING.
            // Check if content has actually been stored and correct to STORED if this is the case.
            boolean contentIsStored = fileResourceContentStore.fileResourceContentExists(fileResource.getStorageKey());
            if (contentIsStored) {
                // We fix
                fileResource.setStorageStatus(FileResourceStorageStatus.STORED);
                fileResourceStore.update(fileResource);
                log.warn("Corrected issue: FileResource '" + fileResource.getUid() + "' had storageStatus PENDING but content was actually stored.");
            }
        }
    }
    return fileResource;
}
Also used : Duration(org.joda.time.Duration) DateTime(org.joda.time.DateTime)

Example 39 with Duration

use of org.joda.time.Duration in project verify-hub by alphagov.

the class AuthnRequestFromTransactionHandler method handleRequestFromTransaction.

public SessionId handleRequestFromTransaction(SamlResponseWithAuthnRequestInformationDto samlResponse, Optional<String> relayState, String ipAddress, URI assertionConsumerServiceUri, boolean transactionSupportsEidas) {
    Duration sessionLength = policyConfiguration.getSessionLength();
    DateTime sessionExpiryTimestamp = DateTime.now().plus(sessionLength);
    SessionId sessionId = SessionId.createNewSessionId();
    SessionStartedState sessionStartedState = new SessionStartedState(samlResponse.getId(), relayState.orNull(), samlResponse.getIssuer(), assertionConsumerServiceUri, samlResponse.getForceAuthentication().orNull(), sessionExpiryTimestamp, sessionId, transactionSupportsEidas);
    final List<LevelOfAssurance> transactionLevelsOfAssurance = transactionsConfigProxy.getLevelsOfAssurance(samlResponse.getIssuer());
    hubEventLogger.logSessionStartedEvent(samlResponse, ipAddress, sessionExpiryTimestamp, sessionId, transactionLevelsOfAssurance.get(0), transactionLevelsOfAssurance.get(transactionLevelsOfAssurance.size() - 1));
    return sessionRepository.createSession(sessionStartedState);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) Duration(org.joda.time.Duration) SessionId(uk.gov.ida.hub.policy.domain.SessionId) DateTime(org.joda.time.DateTime) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState)

Example 40 with Duration

use of org.joda.time.Duration in project FlareBot by FlareBot.

the class SeekCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        Long millis = GeneralUtils.parseTime(args[0]);
        if (millis == null || millis > Integer.MAX_VALUE) {
            MessageUtils.sendErrorMessage("You have entered an invalid duration to skip to!\n" + getExtraInfo(), channel);
            return;
        }
        Track t = FlareBot.instance().getMusicManager().getPlayer(guild.getGuildId()).getPlayingTrack();
        if (t == null) {
            MessageUtils.sendErrorMessage("There is no song currently playing!", channel);
            return;
        } else {
            if (t.getTrack().getInfo().isStream) {
                MessageUtils.sendErrorMessage("Cannot seek on a livestream!", channel);
                return;
            } else if (!t.getTrack().isSeekable()) {
                MessageUtils.sendErrorMessage("Cannot seek on this track!", channel);
                return;
            } else {
                if (millis >= t.getTrack().getDuration()) {
                    MessageUtils.sendErrorMessage("The duration specified is bigger than the length of the video!", channel);
                    return;
                } else {
                    t.getTrack().setPosition(millis);
                    MessageUtils.sendSuccessMessage("The track has been skipped to: " + FormatUtils.formatJodaTime(new Duration(millis).toPeriod()), channel);
                    return;
                }
            }
        }
    }
    MessageUtils.sendUsage(this, channel, sender, args);
}
Also used : Duration(org.joda.time.Duration) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Aggregations

Duration (org.joda.time.Duration)272 Test (org.junit.Test)148 Instant (org.joda.time.Instant)66 DateTime (org.joda.time.DateTime)32 Period (org.joda.time.Period)27 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)24 TestDruidCoordinatorConfig (org.apache.druid.server.coordinator.TestDruidCoordinatorConfig)22 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Category (org.junit.experimental.categories.Category)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 KV (org.apache.beam.sdk.values.KV)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 IndexSpec (org.apache.druid.segment.IndexSpec)12 Set (java.util.Set)10 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)10 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)10 Interval (org.joda.time.Interval)10 Request (com.metamx.http.client.Request)9