Java Code Examples for java.time.Duration#ofMinutes()

The following examples show how to use java.time.Duration#ofMinutes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceMeterMaintainerTest.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void testMaintainer() {
    setUpZones();

    ResourceMeterMaintainer resourceMeterMaintainer = new ResourceMeterMaintainer(tester.controller(), Duration.ofMinutes(5), metrics, snapshotConsumer);
    resourceMeterMaintainer.maintain();
    Collection<ResourceSnapshot> consumedResources = snapshotConsumer.consumedResources();

    // The mocked repository contains two applications, so we should also consume two ResourceSnapshots
    assertEquals(4, consumedResources.size());
    ResourceSnapshot app1 = consumedResources.stream().filter(snapshot -> snapshot.getApplicationId().equals(ApplicationId.from("tenant1", "app1", "default"))).findFirst().orElseThrow();
    ResourceSnapshot app2 = consumedResources.stream().filter(snapshot -> snapshot.getApplicationId().equals(ApplicationId.from("tenant2", "app2", "default"))).findFirst().orElseThrow();

    assertEquals(24, app1.getCpuCores(), Double.MIN_VALUE);
    assertEquals(24, app1.getMemoryGb(), Double.MIN_VALUE);
    assertEquals(500, app1.getDiskGb(), Double.MIN_VALUE);

    assertEquals(40, app2.getCpuCores(), Double.MIN_VALUE);
    assertEquals(24, app2.getMemoryGb(), Double.MIN_VALUE);
    assertEquals(500, app2.getDiskGb(), Double.MIN_VALUE);

    assertEquals(tester.clock().millis()/1000, metrics.getMetric("metering_last_reported"));
    assertEquals(2224.0d, (Double) metrics.getMetric("metering_total_reported"), Double.MIN_VALUE);
}
 
Example 2
Source File: HttpVerificationServiceTests.java    From smartapp-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void canParseCert() {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.put("host", "here.example.com");
    builder.put("content-type", "application/json");
    Map<String, String> headers = builder.build();
    PseudoRequest unsigned = new PseudoRequest("POST", "https://there.example.com/smartapp", headers, "{}");

    when(keyResolver.getKeyString(any())).thenReturn(goodCertContents);

    HttpVerificationService tester = new HttpVerificationService(Duration.ofMinutes(1), keyResolver, ticker);

    PseudoRequest signed = signPsuedoRequest(unsigned);

    boolean result = tester.verify(signed.method, "/smartapp", signed.headers);

    verify(keyResolver).getKeyString("/SmartThings/dd:b9:e6:0b:be:63:6e:ae:ca:98:89:15:fd:40:b3:da");

    assertFalse(result);
}
 
Example 3
Source File: TCKYear.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="minusInvalidUnit")
Object[][] data_minusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}
 
Example 4
Source File: TCKYear.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="minusInvalidUnit")
Object[][] data_minusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}
 
Example 5
Source File: RangeFilterTests.java    From morpheus-core with Apache License 2.0 5 votes vote down vote up
@DataProvider(name="ZonedDateTimeRanges")
public Object[][] zonedDateTimeRanges() {
    final ZoneId gmt = ZoneId.of("GMT");
    return new Object[][] {
            { ZonedDateTime.of(1990, 1, 1, 9, 0, 0, 0, gmt), ZonedDateTime.of(1990, 12, 31, 13, 0, 0, 0, gmt), Duration.ofMinutes(1), false },
            { ZonedDateTime.of(1990, 1, 1, 9, 0, 0, 0, gmt), ZonedDateTime.of(1990, 12, 31, 15, 30, 0, 0, gmt), Duration.ofMinutes(5), false },
            { ZonedDateTime.of(2014, 12, 1, 7 ,25, 0, 0, gmt), ZonedDateTime.of(2013, 1, 1, 9, 15, 0, 0, gmt), Duration.ofMinutes(1), false },
            { ZonedDateTime.of(2014, 12, 1, 6, 30, 0, 0, gmt), ZonedDateTime.of(2014, 1, 1, 10, 45, 0, 0, gmt), Duration.ofMinutes(7), false },
            { ZonedDateTime.of(1990, 1, 1, 9, 0, 0, 0, gmt), ZonedDateTime.of(1990, 12, 31, 13, 0, 0, 0, gmt), Duration.ofMinutes(1), true },
            { ZonedDateTime.of(1990, 1, 1, 9, 0, 0, 0, gmt), ZonedDateTime.of(1990, 12, 31, 15, 30, 0, 0, gmt), Duration.ofMinutes(5), true },
            { ZonedDateTime.of(2014, 12, 1, 7 ,25, 0, 0, gmt), ZonedDateTime.of(2013, 1, 1, 9, 15, 0, 0, gmt), Duration.ofMinutes(1), true },
            { ZonedDateTime.of(2014, 12, 1, 6, 30, 0, 0, gmt), ZonedDateTime.of(2014, 1, 1, 10, 45, 0, 0, gmt), Duration.ofMinutes(7), true },
    };
}
 
Example 6
Source File: ExpiryUtilsTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Test
public void getExpiryForCreation_negative() {
  Duration expected = Duration.ofMinutes(-1);
  when(expiry.getExpiryForCreation(1, 2)).thenReturn(expected);
  Duration actual = ExpiryUtils.getExpiryForCreation(1, 2, expiry);
  assertThat(actual).isEqualTo(Duration.ZERO);
}
 
Example 7
Source File: TCKDuration.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void factory_minutes_tooSmall() {
    Duration.ofMinutes(Long.MIN_VALUE / 60 - 1);
}
 
Example 8
Source File: MailingListBridgeBotFactory.java    From skara with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<Bot> create(BotConfiguration configuration) {
    var ret = new ArrayList<Bot>();
    var specific = configuration.specific();

    var from = EmailAddress.from(specific.get("name").asString(), specific.get("mail").asString());
    var ignoredUsers = specific.get("ignored").get("users").stream()
                               .map(JSONValue::asString)
                               .collect(Collectors.toSet());
    var ignoredComments = specific.get("ignored").get("comments").stream()
                                  .map(JSONValue::asString)
                                  .map(pattern -> Pattern.compile(pattern, Pattern.MULTILINE | Pattern.DOTALL))
                                  .collect(Collectors.toSet());
    var listArchive = URIBuilder.base(specific.get("server").get("archive").asString()).build();
    var listSmtp = specific.get("server").get("smtp").asString();
    var interval = specific.get("server").contains("interval") ? Duration.parse(specific.get("server").get("interval").asString()) : Duration.ofSeconds(1);

    var webrevRepo = configuration.repository(specific.get("webrevs").get("repository").asString());
    var webrevRef = configuration.repositoryRef(specific.get("webrevs").get("repository").asString());
    var webrevWeb = specific.get("webrevs").get("web").asString();

    var archiveRepo = configuration.repository(specific.get("archive").asString());
    var archiveRef = configuration.repositoryRef(specific.get("archive").asString());
    var issueTracker = URIBuilder.base(specific.get("issues").asString()).build();

    var listNamesForReading = new HashSet<EmailAddress>();
    var allRepositories = new HashSet<HostedRepository>();

    var readyLabels = specific.get("ready").get("labels").stream()
            .map(JSONValue::asString)
            .collect(Collectors.toSet());
    var readyComments = specific.get("ready").get("comments").stream()
            .map(JSONValue::asObject)
            .collect(Collectors.toMap(obj -> obj.get("user").asString(),
                                      obj -> Pattern.compile(obj.get("pattern").asString())));
    var cooldown = specific.contains("cooldown") ? Duration.parse(specific.get("cooldown").asString()) : Duration.ofMinutes(1);

    for (var repoConfig : specific.get("repositories").asArray()) {
        var repo = repoConfig.get("repository").asString();
        var censusRepo = configuration.repository(repoConfig.get("census").asString());
        var censusRef = configuration.repositoryRef(repoConfig.get("census").asString());

        Map<String, String> headers = repoConfig.contains("headers") ?
                repoConfig.get("headers").fields().stream()
                          .collect(Collectors.toMap(JSONObject.Field::name, field -> field.value().asString())) :
                Map.of();
        var lists = parseLists(repoConfig.get("lists"));
        var folder = repoConfig.contains("folder") ? repoConfig.get("folder").asString() : configuration.repositoryName(repo);
        var botBuilder = MailingListBridgeBot.newBuilder().from(from)
                                             .repo(configuration.repository(repo))
                                             .archive(archiveRepo)
                                             .archiveRef(archiveRef)
                                             .censusRepo(censusRepo)
                                             .censusRef(censusRef)
                                             .lists(lists)
                                             .ignoredUsers(ignoredUsers)
                                             .ignoredComments(ignoredComments)
                                             .listArchive(listArchive)
                                             .smtpServer(listSmtp)
                                             .webrevStorageRepository(webrevRepo)
                                             .webrevStorageRef(webrevRef)
                                             .webrevStorageBase(Path.of(folder))
                                             .webrevStorageBaseUri(URIBuilder.base(webrevWeb).build())
                                             .readyLabels(readyLabels)
                                             .readyComments(readyComments)
                                             .issueTracker(issueTracker)
                                             .headers(headers)
                                             .sendInterval(interval)
                                             .cooldown(cooldown)
                                             .seedStorage(configuration.storageFolder().resolve("seeds"));

        if (repoConfig.contains("reponame")) {
            botBuilder.repoInSubject(repoConfig.get("reponame").asBoolean());
        }
        if (repoConfig.contains("branchname")) {
            botBuilder.branchInSubject(Pattern.compile(repoConfig.get("branchname").asString()));
        }
        ret.add(botBuilder.build());

        if (!repoConfig.contains("bidirectional") || repoConfig.get("bidirectional").asBoolean()) {
            for (var list : lists) {
                listNamesForReading.add(list.list());
            }
        }
        allRepositories.add(configuration.repository(repo));
    }

    var mailmanServer = MailingListServerFactory.createMailmanServer(listArchive, listSmtp, Duration.ZERO);
    var listsForReading = listNamesForReading.stream()
                               .map(name -> mailmanServer.getList(name.toString()))
                               .collect(Collectors.toSet());

    var bot = new MailingListArchiveReaderBot(from, listsForReading, allRepositories);
    ret.add(bot);

    return ret;
}
 
Example 9
Source File: TCKDuration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void minusMinutes_long_overflowTooBig() {
    Duration t = Duration.ofMinutes(Long.MAX_VALUE/60);
    t.minusMinutes(-1);
}
 
Example 10
Source File: TCKDuration.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void plusMinutes_long_overflowTooSmall() {
    Duration t = Duration.ofMinutes(-1);
    t.plusMinutes(Long.MIN_VALUE/60);
}
 
Example 11
Source File: TCKDuration.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="MinusMinutes")
public void minusMinutes_long(long minutes, long amount, long expectedMinutes) {
    Duration t = Duration.ofMinutes(minutes);
    t = t.minusMinutes(amount);
    assertEquals(t.toMinutes(), expectedMinutes);
}
 
Example 12
Source File: SmoothlyDecayingRollingHitRatioTest.java    From rolling-metrics with Apache License 2.0 4 votes vote down vote up
@Test
public void getChunkCount() throws Exception {
    SmoothlyDecayingRollingHitRatio hitRatio = new SmoothlyDecayingRollingHitRatio(Duration.ofMinutes(1), 6);
    assertEquals(6, hitRatio.getChunkCount());
}
 
Example 13
Source File: TCKDuration.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="MinusMinutes")
public void minusMinutes_long(long minutes, long amount, long expectedMinutes) {
    Duration t = Duration.ofMinutes(minutes);
    t = t.minusMinutes(amount);
    assertEquals(t.toMinutes(), expectedMinutes);
}
 
Example 14
Source File: TCKLocalTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Duration getDuration() {
    return Duration.ofMinutes(95);
}
 
Example 15
Source File: TCKInstant.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Duration getDuration() {
    return Duration.ofMinutes(95);
}
 
Example 16
Source File: TCKDuration.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void factory_minutes_tooBig() {
    Duration.ofMinutes(Long.MAX_VALUE / 60 + 1);
}
 
Example 17
Source File: TCKInstant.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Duration getDuration() {
    return Duration.ofMinutes(90);
}
 
Example 18
Source File: TCKDuration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_minutes() {
    Duration test = Duration.ofMinutes(2);
    assertEquals(test.getSeconds(), 120);
    assertEquals(test.getNano(), 0);
}
 
Example 19
Source File: MotherlodeOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!plugin.isInMlm() || !config.showMiningStats())
	{
		return null;
	}

	MotherlodeSession session = motherlodeSession;

	if (session.getLastPayDirtMined() == null)
	{
		return null;
	}

	Duration statTimeout = Duration.ofMinutes(config.statTimeout());
	Duration sinceCut = Duration.between(session.getLastPayDirtMined(), Instant.now());

	if (sinceCut.compareTo(statTimeout) >= 0)
	{
		return null;
	}

	if (config.showMiningState())
	{
		if (plugin.isMining())
		{
			panelComponent.getChildren().add(TitleComponent.builder()
				.text("Mining")
				.color(Color.GREEN)
				.build());
		}
		else
		{
			panelComponent.getChildren().add(TitleComponent.builder()
				.text("NOT mining")
				.color(Color.RED)
				.build());
		}
	}

	TableComponent tableComponent = new TableComponent();
	tableComponent.setColumnAlignments(TableAlignment.LEFT, TableAlignment.RIGHT);

	tableComponent.addRow("Pay-dirt mined:", Integer.toString(session.getTotalMined()));
	tableComponent.addRow("Pay-dirt/hr:", session.getRecentMined() > 2 ? Integer.toString(session.getPerHour()) : "");

	panelComponent.getChildren().add(tableComponent);

	return super.render(graphics);
}
 
Example 20
Source File: TCKDuration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {ArithmeticException.class})
public void plusMinutes_long_overflowTooSmall() {
    Duration t = Duration.ofMinutes(-1);
    t.plusMinutes(Long.MIN_VALUE/60);
}