下面列出了org.joda.time.Duration#standardHours ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Completable call(JobDetails jobDetails) {
Duration runtimeBlockSize = Duration.standardHours(2);
Trigger trigger = jobDetails.getTrigger();
DateTime timeSliceInclusive = new DateTime(trigger.getTriggerTime(), DateTimeZone.UTC).minus(runtimeBlockSize);
// Rewind to previous timeslice
DateTime timeSliceStart = DateTimeService.getTimeSlice(timeSliceInclusive, runtimeBlockSize);
long startOfSlice = timeSliceStart.getMillis();
Stopwatch stopwatch = Stopwatch.createStarted();
logger.infof("Starting to process temp table for starting time of %s", timeSliceStart.toString());
// TODO Optimization - new worker per token - use parallelism in Cassandra (with configured parallelism)
return metricsService.compressBlock(startOfSlice, pageSize, maxReadConcurrency)
.doOnError(t -> logger.errorf("Compression job failed: %s", t.getMessage()))
.doOnCompleted(() -> {
stopwatch.stop();
logger.info("Finished processing data in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) +
" ms");
});
}
/**
* Converts push frequency into duration. For invalid or less than 'hourly' push frequency, treats it as 'daily'.
*/
public static Duration convertToDuration(String pushFrequency) {
if ("hourly".equalsIgnoreCase(pushFrequency)) {
return Duration.standardHours(1L);
}
if ("daily".equalsIgnoreCase(pushFrequency)) {
return Duration.standardDays(1L);
}
if ("weekly".equalsIgnoreCase(pushFrequency)) {
return Duration.standardDays(7L);
}
if ("monthly".equalsIgnoreCase(pushFrequency)) {
return Duration.standardDays(30L);
}
return Duration.standardDays(1L);
}
static Duration getDefaultPeriod(Duration size) {
if (size.isLongerThan(Duration.standardHours(1))) {
return Duration.standardHours(1);
}
if (size.isLongerThan(Duration.standardMinutes(1))) {
return Duration.standardMinutes(1);
}
if (size.isLongerThan(Duration.standardSeconds(1))) {
return Duration.standardSeconds(1);
}
return Duration.millis(1);
}
@Test
public void testStringFormatting() throws IOException {
final Instant now = Instant.now();
final Duration oneHour = Duration.standardHours(1);
HasDisplayData component =
new HasDisplayData() {
@Override
public void populateDisplayData(DisplayData.Builder builder) {
builder
.add(DisplayData.item("string", "foobar"))
.add(DisplayData.item("integer", 123))
.add(DisplayData.item("float", 2.34))
.add(DisplayData.item("boolean", true))
.add(DisplayData.item("java_class", DisplayDataTest.class))
.add(DisplayData.item("timestamp", now))
.add(DisplayData.item("duration", oneHour));
}
};
DisplayData data = DisplayData.from(component);
assertThat(data, hasDisplayItem("string", "foobar"));
assertThat(data, hasDisplayItem("integer", 123));
assertThat(data, hasDisplayItem("float", 2.34));
assertThat(data, hasDisplayItem("boolean", true));
assertThat(data, hasDisplayItem("java_class", DisplayDataTest.class));
assertThat(data, hasDisplayItem("timestamp", now));
assertThat(data, hasDisplayItem("duration", oneHour));
}
@Test
public void testStateMachineForAfterProcessingTime() {
Duration minutes = Duration.standardMinutes(94);
Duration hours = Duration.standardHours(13);
RunnerApi.Trigger trigger =
RunnerApi.Trigger.newBuilder()
.setAfterProcessingTime(
RunnerApi.Trigger.AfterProcessingTime.newBuilder()
.addTimestampTransforms(
RunnerApi.TimestampTransform.newBuilder()
.setDelay(
RunnerApi.TimestampTransform.Delay.newBuilder()
.setDelayMillis(minutes.getMillis())))
.addTimestampTransforms(
RunnerApi.TimestampTransform.newBuilder()
.setAlignTo(
RunnerApi.TimestampTransform.AlignTo.newBuilder()
.setPeriod(hours.getMillis()))))
.build();
AfterDelayFromFirstElementStateMachine machine =
(AfterDelayFromFirstElementStateMachine)
TriggerStateMachines.stateMachineForTrigger(trigger);
assertThat(machine.getTimeDomain(), equalTo(TimeDomain.PROCESSING_TIME));
}
private WhoisHttpAction newWhoisHttpAction(String pathInfo) {
WhoisHttpAction whoisAction = new WhoisHttpAction();
whoisAction.clock = clock;
whoisAction.expires = Duration.standardHours(1);
whoisAction.requestPath = WhoisHttpAction.PATH + pathInfo;
whoisAction.response = response;
whoisAction.whoisReader =
new WhoisReader(new WhoisCommandFactory(), "Please contact registrar");
whoisAction.whoisMetrics = new WhoisMetrics();
whoisAction.metricBuilder = WhoisMetric.builderForRequest(clock);
whoisAction.disclaimer =
"Doodle Disclaimer\nI exist so that carriage return\nin disclaimer can be tested.";
return whoisAction;
}
@Before
public void setup() {
inject.setStaticField(Ofy.class, "clock", clock);
action = new RdeStagingAction();
action.clock = clock;
action.mrRunner = makeDefaultRunner();
action.lenient = false;
action.reducerFactory = new RdeStagingReducer.Factory();
action.reducerFactory.taskQueueUtils = new TaskQueueUtils(new Retrier(new SystemSleeper(), 1));
action.reducerFactory.lockHandler = new FakeLockHandler(true);
action.reducerFactory.gcsBufferSize = 0;
action.reducerFactory.bucket = "rde-bucket";
action.reducerFactory.lockTimeout = Duration.standardHours(1);
action.reducerFactory.stagingKeyBytes = PgpHelper.convertPublicKeyToBytes(encryptKey);
action.pendingDepositChecker = new PendingDepositChecker();
action.pendingDepositChecker.brdaDayOfWeek = DateTimeConstants.TUESDAY;
action.pendingDepositChecker.brdaInterval = Duration.standardDays(7);
action.pendingDepositChecker.clock = clock;
action.pendingDepositChecker.rdeInterval = Duration.standardDays(1);
action.response = response;
action.transactionCooldown = Duration.ZERO;
action.directory = Optional.empty();
action.modeStrings = ImmutableSet.of();
action.tlds = ImmutableSet.of();
action.watermarks = ImmutableSet.of();
action.revision = Optional.empty();
}
@Before
public void setUp() {
action = new SyncRegistrarsSheetAction();
action.response = response;
action.syncRegistrarsSheet = syncRegistrarsSheet;
action.timeout = Duration.standardHours(1);
action.lockHandler = new FakeLockHandler(true);
}
/**
* Returns the default time to live for DNS A and AAAA records.
*
* @see google.registry.dns.writer.clouddns.CloudDnsWriter
*/
@Provides
@Config("dnsDefaultATtl")
public static Duration provideDnsDefaultATtl() {
return Duration.standardHours(1);
}
/**
* Returns the default time to live for DNS NS records.
*
* @see google.registry.dns.writer.clouddns.CloudDnsWriter
*/
@Provides
@Config("dnsDefaultNsTtl")
public static Duration provideDnsDefaultNsTtl() {
return Duration.standardHours(3);
}
/**
* Returns the default time to live for DNS DS records.
*
* @see google.registry.dns.writer.clouddns.CloudDnsWriter
*/
@Provides
@Config("dnsDefaultDsTtl")
public static Duration provideDnsDefaultDsTtl() {
return Duration.standardHours(1);
}
/**
* Maximum amount of time generating an escrow deposit for a TLD could take, before killing.
*
* @see google.registry.rde.RdeStagingReducer
*/
@Provides
@Config("rdeStagingLockTimeout")
public static Duration provideRdeStagingLockTimeout() {
return Duration.standardHours(2);
}
/**
* Maximum amount of time for syncing a spreadsheet, before killing.
*
* @see google.registry.export.sheet.SyncRegistrarsSheetAction
*/
@Provides
@Config("sheetLockTimeout")
public static Duration provideSheetLockTimeout() {
return Duration.standardHours(1);
}
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception
{
log.info("createToken called");
return new AllowAllToken(request.getRemoteHost(), true, "anonymous", ImmutableSet.of("all"), "default", Duration.standardHours(1), "default");
}
@Override
public Duration getTokenLifetime() {
return Duration.standardHours(1);
}
@Override
public Duration getTokenLifetime() {
return Duration.standardHours(1);
}
/**
* Minimum amount of time to wait between consecutive SFTP uploads on a single TLD.
*
* <p>This value was communicated to us by the escrow provider.
*
* @see google.registry.rde.RdeStagingReducer
*/
@Provides
@Config("rdeUploadSftpCooldown")
public static Duration provideRdeUploadSftpCooldown() {
return Duration.standardHours(2);
}