Example usage for java.time ZonedDateTime plusNanos

List of usage examples for java.time ZonedDateTime plusNanos

Introduction

In this page you can find the example usage for java.time ZonedDateTime plusNanos.

Prototype

public ZonedDateTime plusNanos(long nanos) 

Source Link

Document

Returns a copy of this ZonedDateTime with the specified number of nanoseconds added.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.plusNanos(1234);
    System.out.println(n);//from   www.j a v  a2s.com
}

From source file:it.tidalwave.northernwind.frontend.media.impl.DefaultMetadataCacheTest.java

/*******************************************************************************************************************
 *
 ******************************************************************************************************************/
@Test// w w w . j a  v a 2 s .  c  o m
public void must_reload_metadata_after_expiration_time_when_file_has_been_changed() throws Exception {
    // given
    ZonedDateTime nextExpectedExpirationTime = initialTime.plusSeconds(underTest.getMedatataExpirationTime());
    final Metadata metadata = underTest.findMetadataById(mediaId, siteNodeProperties);

    for (int count = 1; count < 10; count++) {
        final ZonedDateTime now = nextExpectedExpirationTime.plusNanos(1);
        setTime(now);
        when(mediaFile.getLatestModificationTime()).thenReturn(now.plusNanos(1));
        nextExpectedExpirationTime = now.plusSeconds(underTest.getMedatataExpirationTime());
        // when
        final Metadata metadata2 = underTest.findMetadataById(mediaId, siteNodeProperties);
        // then
        assertThat(metadata2, is(not(sameInstance(metadata))));

        final ExpirableMetadata expirableMetadata = underTest.metadataMapById.get(mediaId);
        assertThat(expirableMetadata, is(notNullValue()));
        assertThat(expirableMetadata.getMetadata(), sameInstance(metadata2));
        assertThat(expirableMetadata.getCreationTime(), is(now));
        assertThat(expirableMetadata.getExpirationTime(), is(nextExpectedExpirationTime));
        log.info(">>>> next expiration time: {}", expirableMetadata.getExpirationTime());

        verify(metadataLoader, times(count + 1)).loadMetadata(eq(mediaFile));
        verify(mediaFile, times(count)).getLatestModificationTime();
    }
}

From source file:it.tidalwave.northernwind.frontend.media.impl.DefaultMetadataCacheTest.java

/*******************************************************************************************************************
 *
 ******************************************************************************************************************/
@Test// www  .  j  a v a 2s  .  c  o  m
public void must_check_file_modification_after_expiration_time_and_still_keep_in_cache_when_no_modifications()
        throws Exception {
    // given
    ZonedDateTime nextExpectedExpirationTime = initialTime.plusSeconds(underTest.getMedatataExpirationTime());
    when(mediaFile.getLatestModificationTime()).thenReturn(initialTime.minusNanos(1));

    final Metadata metadata = underTest.findMetadataById(mediaId, siteNodeProperties);

    for (int count = 1; count <= 10; count++) {
        final ZonedDateTime now = nextExpectedExpirationTime.plusNanos(1);
        setTime(now);
        nextExpectedExpirationTime = now.plusSeconds(underTest.getMedatataExpirationTime());
        // when
        final Metadata metadata2 = underTest.findMetadataById(mediaId, siteNodeProperties);
        // then
        assertThat(metadata2, is(sameInstance(metadata)));

        final ExpirableMetadata expirableMetadata = underTest.metadataMapById.get(mediaId);
        assertThat(expirableMetadata, is(notNullValue()));
        assertThat(expirableMetadata.getMetadata(), sameInstance(metadata2));
        assertThat(expirableMetadata.getCreationTime(), is(initialTime));
        assertThat(expirableMetadata.getExpirationTime(), is(nextExpectedExpirationTime));
        log.info(">>>> next expiration time: {}", expirableMetadata.getExpirationTime());

        verify(metadataLoader, times(1)).loadMetadata(eq(mediaFile));
        verify(mediaFile, times(count)).getLatestModificationTime();
    }
}