Example usage for java.time Instant EPOCH

List of usage examples for java.time Instant EPOCH

Introduction

In this page you can find the example usage for java.time Instant EPOCH.

Prototype

Instant EPOCH

To view the source code for java.time Instant EPOCH.

Click Source Link

Document

Constant for the 1970-01-01T00:00:00Z epoch instant.

Usage

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testAddTagEvent() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("ABCD"), 0);
    snapshot = addTagEvent.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamTagMap().tagToTeam("ABCD").get(), Matchers.equalTo(0));
}

From source file:io.pivotal.strepsirrhini.chaosloris.web.EventControllerTest.java

@Test
public void read() throws Exception {
    Application application = new Application(UUID.randomUUID());
    application.setId(-1L);/*ww  w.  j a va2  s.c  om*/

    Schedule schedule = new Schedule("0 0 * * * *", "hourly");
    schedule.setId(-2L);

    Chaos chaos = new Chaos(application, 0.2, schedule);
    chaos.setId(-3L);

    Event event = new Event(chaos, Instant.EPOCH, Arrays.asList(0, 1), Integer.MIN_VALUE);
    event.setId(-4L);

    when(this.eventRepository.getOne(schedule.getId())).thenReturn(event);

    this.mockMvc.perform(get("/events/{id}", schedule.getId()).accept(HAL_JSON)).andExpect(status().isOk())
            .andExpect(jsonPath("$.executedAt").value(Instant.EPOCH.toString()))
            .andExpect(jsonPath("$.terminatedInstances").value(contains(0, 1)))
            .andExpect(jsonPath("$.totalInstanceCount").value(Integer.MIN_VALUE))
            .andExpect(jsonPath("$._links.self").exists()).andExpect(jsonPath("$._links.chaos").exists());
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testTagSeenEvents_ShouldAddLap() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("ABCD"), 0);
    snapshot = addTagEvent.doApply(snapshot);
    StartEvent startEvent = new StartEvent(Instant.EPOCH.plus(2, ChronoUnit.SECONDS));
    snapshot = startEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(3, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 0L);/*from w  ww.jav  a 2s  . c o  m*/
    snapshot = tagSeenEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(60, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamStates().getNbLapsForTeam(0), Matchers.equalTo(1));
}

From source file:org.ulyssis.ipp.processor.Processor.java

public Processor(final ProcessorOptions options) {
    Database.setDatabaseURI(options.getDatabaseUri());
    try (Connection connection = Database.createConnection(EnumSet.of(READ_WRITE))) {
        if (options.shouldClearDb()) {
            Database.clearDb(connection);
        }/* ww  w.  ja v a 2s . com*/
        Database.initDb(connection);
        connection.commit();
    } catch (SQLException e) {
        LOG.fatal("Error initializing database!", e);
    }
    URI uri = options.getRedisUri();
    this.eventQueue = new LinkedBlockingQueue<>();
    this.eventCallbacks = new ConcurrentHashMap<>();
    this.onStartedCallbacks = new CopyOnWriteArrayList<>();
    this.readerListeners = new ArrayList<>();
    this.threads = new ArrayList<>();
    // TODO: Move status reporting and processing of commands to ZeroMQ?
    // Also: post some stuff to a log in the db?
    this.statusReporter = new StatusReporter(uri, Config.getCurrentConfig().getStatusChannel());
    this.commandProcessor = new CommandProcessor(uri, Config.getCurrentConfig().getControlChannel(),
            statusReporter);
    initCommandProcessor();
    snapshot = new Snapshot(Instant.EPOCH);
    if (!restoreFromDb()) {
        registerInitialTags();
    }
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testTagSeenEventBeforeStart_ShouldBeIgnored() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("ABCD"), 0);
    snapshot = addTagEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(2, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 0L);// w w  w .  j  ava 2s .  c o  m
    snapshot = tagSeenEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(3, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamStates().getNbLapsForTeam(0), Matchers.equalTo(0));
}

From source file:io.pivotal.strepsirrhini.chaosloris.docs.EventDocumentation.java

@Test
public void eventRead() throws Exception {
    Application application = new Application(UUID.randomUUID());
    application.setId(-1L);//from  ww w . j a  va2  s. c  o  m

    Schedule schedule = new Schedule("0 0 * * * *", "hourly");
    schedule.setId(-2L);

    Chaos chaos = new Chaos(application, 0.2, schedule);
    chaos.setId(-3L);

    Event event = new Event(chaos, Instant.EPOCH, Arrays.asList(0, 1), Integer.MIN_VALUE);
    event.setId(-4L);

    when(this.eventRepository.getOne(schedule.getId())).thenReturn(event);

    this.mockMvc.perform(get("/events/{id}", schedule.getId()).accept(HAL_JSON)).andDo(document(
            pathParameters(parameterWithName("id").description("The event's id")),
            responseFields(
                    fieldWithPath("executedAt")
                            .description("An ISO-8601 timestamp for when the event occurred"),
                    fieldWithPath("terminatedInstances")
                            .description("The instances terminated during the event"),
                    fieldWithPath("totalInstanceCount").description(
                            "The total number of instances that were candidates for termination during the event"),
                    fieldWithPath("terminatedInstanceCount")
                            .description("The total number of instances terminated during the event")),
            links(linkWithRel("chaos").description("The [Chaos](#chaoses) that triggered the event"))));
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testTagSeenEventAfterEnd_ShouldBeIgnored() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("DCBA"), 3);
    snapshot = addTagEvent.doApply(snapshot);
    StartEvent startEvent = new StartEvent(Instant.EPOCH.plus(2, ChronoUnit.SECONDS));
    snapshot = startEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(3, ChronoUnit.SECONDS), new TagId("DCBA"),
            0, 0L);//from  w w w  . j a  va2  s.  co m
    snapshot = tagSeenEvent.doApply(snapshot);
    EndEvent endEvent = new EndEvent(Instant.EPOCH.plus(50, ChronoUnit.SECONDS));
    snapshot = endEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(100, ChronoUnit.SECONDS),
            new TagId("DCBA"), 0, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamStates().getNbLapsForTeam(3), Matchers.equalTo(0));
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testPredictedSpeedWhenStartedThenFirstEvent() throws Exception {
    TagId tag = new TagId("DCBA");
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH, tag, 3);
    snapshot = addTagEvent.doApply(snapshot);
    StartEvent startEvent = new StartEvent(Instant.EPOCH);
    snapshot = startEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(10, ChronoUnit.SECONDS), tag, 0, 0L);
    snapshot = tagSeenEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(50, ChronoUnit.SECONDS), tag, 1, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    double speedShouldBe = 100D / (50D - 10D);
    MatcherAssert.assertThat(snapshot.getTeamStates().getStateForTeam(3).get().getPredictedSpeed(),
            Matchers.equalTo(speedShouldBe));
    MatcherAssert.assertThat(snapshot.getTeamStates().getStateForTeam(3).get().getSpeed(),
            Matchers.equalTo(speedShouldBe));
}

From source file:org.ulyssis.ipp.processor.Processor.java

private void registerInitialTags() {
    Snapshot oldSnapshot = this.snapshot;
    Connection connection = null;
    try {/*  w w w.  j  ava2  s.com*/
        connection = Database.createConnection(EnumSet.of(READ_WRITE));
        for (Team team : Config.getCurrentConfig().getTeams()) {
            for (TagId tag : team.getTags()) {
                AddTagEvent e = new AddTagEvent(Instant.EPOCH, tag, team.getTeamNb());
                e.save(connection);
                this.snapshot = e.apply(this.snapshot);
                this.snapshot.save(connection);
            }
        }
        connection.commit();
    } catch (SQLException e) {
        LOG.error("An error occurred when registering initial tags!", e);
        this.snapshot = oldSnapshot;
        try {
            if (connection != null) {
                connection.rollback();
            }
        } catch (SQLException e2) {
            LOG.error("Error in rollback after previous error", e2);
        }
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                LOG.error("Error while closing connection", e);
            }
        }
    }
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testPredictedSpeedWhenFirstEventThenStarted() throws Exception {
    TagId tag = new TagId("DCBA");
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH, tag, 3);
    snapshot = addTagEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.minus(10, ChronoUnit.SECONDS), tag, 0, 0L);
    snapshot = tagSeenEvent.doApply(snapshot);
    StartEvent startEvent = new StartEvent(Instant.EPOCH);
    snapshot = startEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(50, ChronoUnit.SECONDS), tag, 1, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    double speedShouldBe = 100D / 50D;
    MatcherAssert.assertThat(snapshot.getTeamStates().getStateForTeam(3).get().getPredictedSpeed(),
            Matchers.equalTo(speedShouldBe));
    MatcherAssert.assertThat(snapshot.getTeamStates().getStateForTeam(3).get().getSpeed(),
            Matchers.equalTo(speedShouldBe));
}