Codota Logo
Duration.ofSeconds
Code IndexAdd Codota to your IDE (free)

How to use
ofSeconds
method
in
org.threeten.bp.Duration

Best Java code snippets using org.threeten.bp.Duration.ofSeconds (Showing top 20 results out of 315)

  • Common ways to obtain Duration
private void myMethod () {
Duration d =
  • Codota IconDuration.ofSeconds(long1)
  • Codota IconDuration.ofMillis(long1)
  • Smart code suggestions by Codota
}
origin: googleapis/google-cloud-java

 private static Duration systemProperty(String name, int defaultValue) {
  String stringValue = System.getProperty(name, "");
  return Duration.ofSeconds(stringValue.isEmpty() ? defaultValue : Integer.parseInt(stringValue));
 }
}
origin: googleapis/google-cloud-java

/**
 * Stops the Datastore emulator. The same as {@link stop(Duration)} but with timeout duration of
 * 20 seconds.
 *
 * <p>It is important to stop the emulator. Since the emulator runs in its own process, not
 * stopping it might cause it to become orphan.
 *
 * <p>It is not required to call {@link #reset()} before {@code stop()}.
 */
public void stop() throws IOException, InterruptedException, TimeoutException {
 stop(Duration.ofSeconds(20));
}
origin: googleapis/google-cloud-java

MockRetryingFuture() {
 this(Duration.ofSeconds(5));
}
origin: googleapis/google-cloud-java

/** Gets the configured maximum age */
public Duration getMaxAge() {
 return Duration.ofSeconds(builder.getSeconds(), builder.getNanos());
}
origin: googleapis/google-cloud-java

public Publisher getPublisherWithCustomRetrySettings(ProjectTopicName topicName)
  throws Exception {
 // [START pubsub_publisher_retry_settings]
 // Retry settings control how the publisher handles retryable failures
 Duration retryDelay = Duration.ofMillis(100); // default : 1 ms
 double retryDelayMultiplier = 2.0; // back off for repeated failures
 Duration maxRetryDelay = Duration.ofSeconds(5); // default : 10 seconds
 Duration totalTimeout = Duration.ofSeconds(1); // default: 0
 Duration initialRpcTimeout = Duration.ofSeconds(1); // default: 0
 Duration maxRpcTimeout = Duration.ofSeconds(10); // default: 0
 RetrySettings retrySettings =
   RetrySettings.newBuilder()
     .setInitialRetryDelay(retryDelay)
     .setRetryDelayMultiplier(retryDelayMultiplier)
     .setMaxRetryDelay(maxRetryDelay)
     .setTotalTimeout(totalTimeout)
     .setInitialRpcTimeout(initialRpcTimeout)
     .setMaxRpcTimeout(maxRpcTimeout)
     .build();
 Publisher publisher = Publisher.newBuilder(topicName).setRetrySettings(retrySettings).build();
 // [END pubsub_publisher_retry_settings]
 return publisher;
}
origin: googleapis/google-cloud-java

@Test
public void durationSeconds() {
 GcRule actual = GCRULES.maxAge(Duration.ofSeconds(1)).toProto();
 GcRule expected = buildAgeRule(1, 0);
 assertThat(actual).isEqualTo(expected);
}
origin: googleapis/google-cloud-java

/** Example extracting data to single Google Cloud Storage file. */
// [TARGET extract(String, String, JobOption...)]
// [VARIABLE "CSV"]
// [VARIABLE "gs://my_bucket/filename.csv"]
public Job extractSingle(String format, String gcsUrl) {
 // [START bigquery_extract_table]
 Job job = table.extract(format, gcsUrl);
 // Wait for the job to complete
 try {
  Job completedJob =
    job.waitFor(
      RetryOption.initialRetryDelay(Duration.ofSeconds(1)),
      RetryOption.totalTimeout(Duration.ofMinutes(3)));
  if (completedJob != null && completedJob.getStatus().getError() == null) {
   // Job completed successfully
  } else {
   // Handle error case
  }
 } catch (InterruptedException e) {
  // Handle interrupted wait
 }
 // [END bigquery_extract_table]
 return job;
}
origin: googleapis/google-cloud-java

 /** Example loading data from a single Google Cloud Storage file. */
 // [TARGET load(FormatOptions, String, JobOption...)]
 // [VARIABLE "gs://my_bucket/filename.csv"]
 public Job loadSingle(String sourceUri) {
  // [START bigquery_load_table_gcs_csv]
  Job job = table.load(FormatOptions.csv(), sourceUri);
  // Wait for the job to complete
  try {
   Job completedJob =
     job.waitFor(
       RetryOption.initialRetryDelay(Duration.ofSeconds(1)),
       RetryOption.totalTimeout(Duration.ofMinutes(3)));
   if (completedJob != null && completedJob.getStatus().getError() == null) {
    // Job completed successfully
   } else {
    // Handle error case
   }
  } catch (InterruptedException e) {
   // Handle interrupted wait
  }
  // [END bigquery_load_table_gcs_csv]
  return job;
 }
}
origin: googleapis/google-cloud-java

@Test
public void duration() {
 DurationRule actual = GCRULES.maxAge(Duration.ofSeconds(61, 9));
 GcRule expected = buildAgeRule(61, 9);
 assertNotNull(actual.getMaxAge());
 assertThat(actual.toProto()).isEqualTo(expected);
}
origin: googleapis/google-cloud-java

@Test
public void testSettingsArePreserved() {
 String endpoint = "some.other.host:123";
 CredentialsProvider credentialsProvider = Mockito.mock(CredentialsProvider.class);
 Duration watchdogInterval = Duration.ofSeconds(12);
 WatchdogProvider watchdogProvider = Mockito.mock(WatchdogProvider.class);
 EnhancedBigQueryStorageStubSettings.Builder builder =
   EnhancedBigQueryStorageStubSettings.newBuilder()
     .setEndpoint(endpoint)
     .setCredentialsProvider(credentialsProvider)
     .setStreamWatchdogCheckInterval(watchdogInterval)
     .setStreamWatchdogProvider(watchdogProvider);
 verifyBuilder(builder, endpoint, credentialsProvider, watchdogInterval, watchdogProvider);
 verifySettings(
   builder.build(), endpoint, credentialsProvider, watchdogInterval, watchdogProvider);
 verifyBuilder(
   builder.build().toBuilder(),
   endpoint,
   credentialsProvider,
   watchdogInterval,
   watchdogProvider);
}
origin: googleapis/google-cloud-java

@Test
public void testErrorPropagation() throws Exception {
 Publisher publisher =
   getTestPublisherBuilder()
     .setExecutorProvider(SINGLE_THREAD_EXECUTOR)
     .setBatchingSettings(
       Publisher.Builder.DEFAULT_BATCHING_SETTINGS
         .toBuilder()
         .setElementCountThreshold(1L)
         .setDelayThreshold(Duration.ofSeconds(5))
         .build())
     .build();
 testPublisherServiceImpl.addPublishError(Status.DATA_LOSS.asException());
 try {
  sendTestMessage(publisher, "A").get();
  fail("should throw exception");
 } catch (ExecutionException e) {
  assertThat(e.getCause()).isInstanceOf(DataLossException.class);
 }
}
origin: googleapis/google-cloud-java

MockRetryingFuture(Duration totalTimeout) {
 this.timedAttemptSettings =
   TimedAttemptSettings.newBuilder()
     .setRpcTimeout(Duration.ofSeconds(1))
     .setRetryDelay(Duration.ZERO)
     .setRandomizedRetryDelay(Duration.ZERO)
     .setAttemptCount(0)
     .setFirstAttemptStartTimeNanos(0)
     .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build())
     .build();
}
origin: googleapis/google-cloud-java

@Before
public void setUp() {
 ClientContext clientContext =
   ClientContext.newBuilder().setDefaultCallContext(CALL_CONTEXT).build();
 RetrySettings retrySettings =
   RetrySettings.newBuilder()
     .setTotalTimeout(Duration.ofMillis(100))
     // Delay settings: 1 ms const
     .setInitialRetryDelay(Duration.ofMillis(1))
     .setMaxRetryDelay(Duration.ofMillis(1))
     .setRetryDelayMultiplier(1.0)
     // RPC timeout: ignored const 1 s
     .setInitialRpcTimeout(Duration.ofSeconds(1))
     .setMaxRpcTimeout(Duration.ofSeconds(1))
     .setRpcTimeoutMultiplier(1.0)
     .build();
 callable =
   AwaitReplicationCallable.create(
     mockGenerateConsistencyTokenCallable,
     mockCheckConsistencyCallable,
     clientContext,
     retrySettings);
}
origin: googleapis/google-cloud-java

@Test
public void testPublishFailureRetries_maxRetriesSetUnlimited() throws Exception {
 Publisher publisher =
   getTestPublisherBuilder()
     .setExecutorProvider(SINGLE_THREAD_EXECUTOR)
     .setRetrySettings(
       Publisher.Builder.DEFAULT_RETRY_SETTINGS
         .toBuilder()
         .setTotalTimeout(Duration.ofSeconds(10))
         .setMaxAttempts(0)
         .build())
     .build();
 testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing"));
 testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing"));
 testPublisherServiceImpl.addPublishResponse(PublishResponse.newBuilder().addMessageIds("1"));
 ApiFuture<String> publishFuture1 = sendTestMessage(publisher, "A");
 assertEquals("1", publishFuture1.get());
 assertEquals(3, testPublisherServiceImpl.getCapturedRequests().size());
 publisher.shutdown();
 publisher.awaitTermination(1, TimeUnit.MINUTES);
}
origin: googleapis/google-cloud-java

@Test
public void testPublishFailureRetries_maxRetriesSetup() throws Exception {
 Publisher publisher =
   getTestPublisherBuilder()
     .setExecutorProvider(SINGLE_THREAD_EXECUTOR)
     .setRetrySettings(
       Publisher.Builder.DEFAULT_RETRY_SETTINGS
         .toBuilder()
         .setTotalTimeout(Duration.ofSeconds(10))
         .setMaxAttempts(3)
         .build())
     .build();
 testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing"));
 testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing"));
 testPublisherServiceImpl.addPublishResponse(PublishResponse.newBuilder().addMessageIds("1"));
 ApiFuture<String> publishFuture1 = sendTestMessage(publisher, "A");
 assertEquals("1", publishFuture1.get());
 assertEquals(3, testPublisherServiceImpl.getCapturedRequests().size());
 publisher.shutdown();
 publisher.awaitTermination(1, TimeUnit.MINUTES);
}
origin: googleapis/google-cloud-java

@Test
public void unionTwo() {
 GcRule actual =
   GCRULES
     .union()
     .rule(GCRULES.maxVersions(1))
     .rule(GCRULES.maxAge(Duration.ofSeconds(1)))
     .toProto();
 GcRule expected =
   GcRule.newBuilder()
     .setUnion(
       Union.newBuilder().addRules(buildVersionsRule(1)).addRules(buildAgeRule(1, 0)))
     .build();
 assertThat(actual).isEqualTo(expected);
}
origin: googleapis/google-cloud-java

@Test
public void testPublishFailureRetries() throws Exception {
 Publisher publisher =
   getTestPublisherBuilder()
     .setExecutorProvider(SINGLE_THREAD_EXECUTOR)
     .setBatchingSettings(
       Publisher.Builder.DEFAULT_BATCHING_SETTINGS
         .toBuilder()
         .setElementCountThreshold(1L)
         .setDelayThreshold(Duration.ofSeconds(5))
         .build())
     .build(); // To demonstrate that reaching duration will trigger publish
 testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing"));
 testPublisherServiceImpl.addPublishResponse(PublishResponse.newBuilder().addMessageIds("1"));
 ApiFuture<String> publishFuture1 = sendTestMessage(publisher, "A");
 assertEquals("1", publishFuture1.get());
 assertEquals(2, testPublisherServiceImpl.getCapturedRequests().size());
 publisher.shutdown();
 publisher.awaitTermination(1, TimeUnit.MINUTES);
}
origin: googleapis/google-cloud-java

@Test
public void intersectionTwo() {
 GcRule actual =
   GCRULES
     .intersection()
     .rule(GCRULES.maxVersions(1))
     .rule(GCRULES.maxAge(Duration.ofSeconds(1)))
     .toProto();
 GcRule expected =
   GcRule.newBuilder()
     .setIntersection(
       Intersection.newBuilder()
         .addRules(buildVersionsRule(1))
         .addRules(buildAgeRule(1, 0)))
     .build();
 assertThat(actual).isEqualTo(expected);
}
origin: googleapis/google-cloud-java

@Test
public void intersectionThree() {
 GcRule actual =
   GCRULES
     .intersection()
     .rule(GCRULES.maxVersions(1))
     .rule(GCRULES.maxAge(Duration.ofSeconds(1)))
     .rule(GCRULES.maxAge(Duration.ofNanos(1)))
     .toProto();
 GcRule expected =
   GcRule.newBuilder()
     .setIntersection(
       Intersection.newBuilder()
         .addRules(buildVersionsRule(1))
         .addRules(buildAgeRule(1, 0))
         .addRules(buildAgeRule(0, 1)))
     .build();
 assertThat(actual).isEqualTo(expected);
}
origin: googleapis/google-cloud-java

@Test
public void unionThree() {
 GcRule actual =
   GCRULES
     .union()
     .rule(GCRULES.maxVersions(1))
     .rule(GCRULES.maxAge(Duration.ofSeconds(1)))
     .rule(GCRULES.maxAge(Duration.ofNanos(1)))
     .toProto();
 GcRule expected =
   GcRule.newBuilder()
     .setUnion(
       Union.newBuilder()
         .addRules(buildVersionsRule(1))
         .addRules(buildAgeRule(1, 0))
         .addRules(buildAgeRule(0, 1)))
     .build();
 assertThat(actual).isEqualTo(expected);
}
org.threeten.bpDurationofSeconds

Javadoc

Obtains an instance of Duration from a number of seconds.

The nanosecond in second field is set to zero.

Popular methods of Duration

  • ofMillis
    Obtains an instance of Duration from a number of milliseconds. The seconds and nanoseconds are extra
  • toMillis
    Converts this duration to the total length in milliseconds. If this duration is too large to fit in
  • ofMinutes
    Obtains an instance of Duration from a number of standard length minutes. The seconds are calculated
  • compareTo
    Compares this duration to the specified Duration. The comparison is based on the total length of the
  • getSeconds
    Gets the number of seconds in this duration. The length of the duration is stored using two fields -
  • isZero
    Checks if this duration is zero length. A Duration represents a directed distance between two points
  • between
    Obtains an instance of Duration representing the duration between two instants. Obtains a Duration
  • getNano
    Gets the number of nanoseconds within the second in this duration. The length of the duration is sto
  • isNegative
    Checks if this duration is negative, excluding zero. A Duration represents a directed distance betwe
  • toNanos
    Converts this duration to the total length in nanoseconds expressed as a long. If this duration is
  • ofHours
    Obtains an instance of Duration from a number of standard length hours. The seconds are calculated b
  • ofNanos
    Obtains an instance of Duration from a number of nanoseconds. The seconds and nanoseconds are extrac
  • ofHours,
  • ofNanos,
  • equals,
  • of,
  • ofDays,
  • plus,
  • toMinutes,
  • <init>,
  • create

Popular in Java

  • Parsing JSON documents to java classes using gson
  • startActivity (Activity)
  • orElseThrow (Optional)
  • setContentView (Activity)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • HashSet (java.util)
    This class implements the Set interface, backed by a hash table (actually a HashMap instance). It m
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now