List of usage examples for java.time ZoneId of
public static ZoneId of(String zoneId)
From source file:io.stallion.jobs.Schedule.java
/** * Gets the next datetime matching the schedule, in the application timezone, as defined in the settings * * @return/*w w w.ja v a 2s . co m*/ */ public ZonedDateTime serverLocalNextAt() { ZoneId zoneId = null; if (zoneId == null) { zoneId = Context.getSettings().getTimeZoneId(); } if (zoneId == null) { zoneId = ZoneId.of("UTC"); } ZonedDateTime dt = ZonedDateTime.now(zoneId); return nextAt(dt); }
From source file:com.streamsets.pipeline.stage.destination.elasticsearch.ElasticsearchTarget.java
public ElasticsearchTarget(ElasticsearchTargetConfig conf) { this.conf = conf; if (this.conf.params == null) { this.conf.params = new HashMap<>(); }/* w w w . j a v a 2s . co m*/ this.timeZone = TimeZone.getTimeZone(ZoneId.of(conf.timeZoneID)); }
From source file:io.stallion.tests.integration.jobs.JobsTests.java
/** * Tests processing jobs with no threading involved for easy debugging. *//*from ww w. j ava2 s .c om*/ @Test public void testJobProcessing() throws Exception { ExampleJobOne.RUN_COUNT = 0; ExampleJobTwo.RUN_COUNT = 0; ExampleJobThree.RUN_COUNT = 0; // Define and load job 1, to run at 30 minutes after the hour JobDefinition job1 = new JobDefinition() { { setJobClass(ExampleJobOne.class); setAlertThresholdMinutes(150); setSchedule(new Schedule() { { minutes(30); everyHour(); everyDay(); everyMonth(); verify(); } }); } }; // Define and load job 2, to run at 12:30 every day JobDefinition job2 = new JobDefinition().setJobClass(ExampleJobTwo.class).setAlertThresholdMinutes(3000) .setSchedule(new Schedule().minutes(30).hours(12).everyDay().everyMonth().verify()); // Define and load job 3, to run at 5PM on Tuesday JobDefinition job3 = new JobDefinition().setJobClass(ExampleJobThree.class).setAlertThresholdMinutes(3000) .setSchedule( new Schedule().minutes(0).hours(17).daysOfWeek(DayOfWeek.TUESDAY).everyMonth().verify()); ZonedDateTime now = ZonedDateTime.of(2015, 1, 18, 10, 40, 12, 0, ZoneId.of("UTC")); JobCoordinator.instance().registerJobForTest(job1, now); JobCoordinator.instance().registerJobForTest(job2, now); JobCoordinator.instance().registerJobForTest(job3, now); // Run for time at 11:30 - Job 1 should run //now = ZonedDateTime.of(2015, 1, 18, 11, 30, 7, 121, ZoneId.of("UTC")); //JobCoordinator.instance().resetForDateTime(now.minusMinutes(1)).executeJobsForCurrentTime(now); JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 18, 11, 30, 7, 121, ZoneId.of("UTC"))); assertEquals(1, ExampleJobOne.RUN_COUNT); assertEquals(0, ExampleJobTwo.RUN_COUNT); assertEquals(0, ExampleJobThree.RUN_COUNT); // Run for time at 11:30 again - no additional runs should happen JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 18, 11, 30, 7, 121, ZoneId.of("UTC"))); //JobCoordinator.instance().resetForDateTime(now.minusMinutes(1)).executeJobsForCurrentTime(now); assertEquals(1, ExampleJobOne.RUN_COUNT); assertEquals(0, ExampleJobTwo.RUN_COUNT); assertEquals(0, ExampleJobThree.RUN_COUNT); // Run for time 12:30 - Job 1 and Job 2 should run JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 18, 12, 30, 7, 121, ZoneId.of("UTC"))); //JobCoordinator.instance().resetForDateTime(now.minusMinutes(1)).executeJobsForCurrentTime(now); assertEquals(1, ExampleJobTwo.RUN_COUNT); assertEquals(2, ExampleJobOne.RUN_COUNT); assertEquals(0, ExampleJobThree.RUN_COUNT); // Run for time 5PM monday - no jobs should run JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 19, 5, 0, 7, 121, ZoneId.of("UTC"))); //JobCoordinator.instance().resetForDateTime(now.minusMinutes(1)).executeJobsForCurrentTime(now); assertEquals(2, ExampleJobOne.RUN_COUNT); assertEquals(1, ExampleJobTwo.RUN_COUNT); assertEquals(0, ExampleJobThree.RUN_COUNT); // Run for 12:30 Tuesday - Job 1 and Job 2 should run // (After first running minutes before to get the time reset) JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 20, 12, 25, 7, 121, ZoneId.of("UTC"))); JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 20, 12, 30, 7, 121, ZoneId.of("UTC"))); //JobCoordinator.instance().resetForDateTime(now.minusMinutes(1)).executeJobsForCurrentTime(now); assertEquals(3, ExampleJobOne.RUN_COUNT); assertEquals(2, ExampleJobTwo.RUN_COUNT); assertEquals(0, ExampleJobThree.RUN_COUNT); // Run for time 5PM Tuesday - job 3 should run JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 20, 17, 0, 7, 121, ZoneId.of("UTC"))); JobCoordinator.instance() .executeJobsForCurrentTime(ZonedDateTime.of(2015, 1, 20, 17, 0, 7, 121, ZoneId.of("UTC"))); // JobCoordinator.instance().executeJobsForCurrentTime( // ZonedDateTime.of(2015, 1, 20, 17, 0, 7, 121, ZoneId.of("UTC"))); assertEquals(3, ExampleJobOne.RUN_COUNT); assertEquals(2, ExampleJobTwo.RUN_COUNT); assertEquals(1, ExampleJobThree.RUN_COUNT); }
From source file:org.codice.ddf.security.session.management.impl.SessionManagementServiceImplTest.java
@Test public void testGetExpiry() { sessionManagementServiceImpl.setClock(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))); String expiryString = sessionManagementServiceImpl.getExpiry(request); assertThat(expiryString, is("4522435794788")); }
From source file:org.apache.james.mailbox.elasticsearch.json.IndexableMessageTest.java
@Test public void textShouldContainsToWhenTo() throws Exception { MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1);/*from w w w. j a va2s. c o m*/ when(mailboxMessage.getMailboxId()).thenReturn(mailboxId); when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream( "To: First to <user@james.org>\nTo: Second to <user2@james.org>".getBytes())); when(mailboxMessage.createFlags()).thenReturn(new Flags()); IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThat(indexableMessage.getText()).isEqualTo("First to user@james.org Second to user2@james.org"); }
From source file:org.codice.ddf.security.servlet.expiry.SessionManagementServiceTest.java
@Test public void testGetExpiry() throws IOException { sessionManagementService.setClock(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))); Response expiry = sessionManagementService.getExpiry(request); assertThat(expiry.getStatus(), is(200)); assertThat(IOUtils.toString(new InputStreamReader((ByteArrayInputStream) expiry.getEntity())), is("4522435794788")); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setModSeq(MOD_SEQ);// w w w .ja va 2s . c o m assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/spamMail.json"), CHARSET)); }
From source file:com.streamsets.pipeline.stage.cloudstorage.destination.GoogleCloudStorageTarget.java
@Override protected List<ConfigIssue> init() { // Validate configuration values and open any required resources. List<ConfigIssue> issues = gcsTargetConfig.init(getContext(), super.init()); gcsTargetConfig.credentials.getCredentialsProvider(getContext(), issues) .ifPresent(p -> credentialsProvider = p); elVars = getContext().createELVars(); timeDriverElEval = getContext().createELEval(TIME_DRIVER); partitionEval = getContext().createELEval(PARTITION_TEMPLATE); calendar = Calendar.getInstance(TimeZone.getTimeZone(ZoneId.of(gcsTargetConfig.timeZoneID))); try {/*from w ww . j ava 2 s . c o m*/ storage = StorageOptions.newBuilder().setCredentials(credentialsProvider.getCredentials()).build() .getService(); } catch (IOException e) { issues.add(getContext().createConfigIssue(Groups.CREDENTIALS.name(), GoogleCloudCredentialsConfig.CONF_CREDENTIALS_CREDENTIALS_PROVIDER, Errors.GCS_01, e)); } if (gcsTargetConfig.dataFormat == DataFormat.WHOLE_FILE) { fileNameEval = getContext().createELEval("fileNameEL"); } return issues; }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthDataPointMapper.java
/** * Creates a data point header with information describing the data point created around the measure. * <p>// w w w . j a va 2 s .c om * Note: Additional properties within the header come from the iHealth API and are not defined by the data point * header schema. Additional properties are subject to change. */ protected DataPointHeader createDataPointHeader(JsonNode listEntryNode, Measure measure) { DataPointAcquisitionProvenance.Builder acquisitionProvenanceBuilder = new DataPointAcquisitionProvenance.Builder( RESOURCE_API_SOURCE_NAME); asOptionalString(listEntryNode, "DataSource") .ifPresent(dataSource -> setAppropriateModality(dataSource, acquisitionProvenanceBuilder)); DataPointAcquisitionProvenance acquisitionProvenance = acquisitionProvenanceBuilder.build(); asOptionalString(listEntryNode, "DataID") .ifPresent(externalId -> acquisitionProvenance.setAdditionalProperty("external_id", externalId)); asOptionalLong(listEntryNode, "LastChangeTime").ifPresent( lastUpdatedInUnixSecs -> acquisitionProvenance.setAdditionalProperty("source_updated_date_time", ofInstant(ofEpochSecond(lastUpdatedInUnixSecs), ZoneId.of("Z")))); return new DataPointHeader.Builder(UUID.randomUUID().toString(), measure.getSchemaId()) .setAcquisitionProvenance(acquisitionProvenance).build(); }
From source file:org.openmhealth.shim.withings.mapper.WithingsIntradayStepCountDataPointMapper.java
/** * Maps an individual list node from the array in the Withings activity measure endpoint response into a {@link * StepCount} data point.//from w ww . j av a2s. co m * * @param nodeWithSteps activity node from the array "activites" contained in the "body" of the endpoint response * @return a {@link DataPoint} object containing a {@link StepCount} measure with the appropriate values from * the JSON node parameter, wrapped as an {@link Optional} */ private Optional<DataPoint<StepCount>> asDataPoint(JsonNode nodeWithSteps, Long startDateTimeInUnixEpochSeconds) { Long stepCountValue = asRequiredLong(nodeWithSteps, "steps"); StepCount.Builder stepCountBuilder = new StepCount.Builder(stepCountValue); Optional<Long> duration = asOptionalLong(nodeWithSteps, "duration"); if (duration.isPresent()) { OffsetDateTime offsetDateTime = OffsetDateTime .ofInstant(Instant.ofEpochSecond(startDateTimeInUnixEpochSeconds), ZoneId.of("Z")); stepCountBuilder.setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndDuration(offsetDateTime, new DurationUnitValue(DurationUnit.SECOND, duration.get()))); } Optional<String> userComment = asOptionalString(nodeWithSteps, "comment"); if (userComment.isPresent()) { stepCountBuilder.setUserNotes(userComment.get()); } StepCount stepCount = stepCountBuilder.build(); return Optional.of(newDataPoint(stepCount, null, true, null)); }