Search in sources :

Example 41 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class CommandSchedulingShould method reschedule_commands_from_storage.

@Test
public void reschedule_commands_from_storage() {
    final Timestamp schedulingTime = minutesAgo(3);
    final Duration delayPrimary = Durations2.fromMinutes(5);
    // = 5 - 3
    final Duration newDelayExpected = Durations2.fromMinutes(2);
    final List<Command> commandsPrimary = newArrayList(createProject(), addTask(), startProject());
    storeAsScheduled(commandsPrimary, delayPrimary, schedulingTime);
    commandBus.rescheduleCommands();
    final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(scheduler, times(commandsPrimary.size())).schedule(commandCaptor.capture());
    final List<Command> commandsRescheduled = commandCaptor.getAllValues();
    for (Command cmd : commandsRescheduled) {
        final long actualDelay = getDelaySeconds(cmd);
        Tests.assertSecondsEqual(newDelayExpected.getSeconds(), actualDelay, /*maxDiffSec=*/
        1);
    }
}
Also used : Command(io.spine.core.Command) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 42 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class EntityClassShould method create_and_initialize_entity_instance.

@Test
public void create_and_initialize_entity_instance() {
    final Long id = 100L;
    final Timestamp before = TimeTests.Past.secondsAgo(1);
    // Create and init the entity.
    final EntityClass<NanoEntity> entityClass = new EntityClass<>(NanoEntity.class);
    final AbstractVersionableEntity<Long, StringValue> entity = entityClass.createEntity(id);
    final Timestamp after = Time.getCurrentTime();
    // The interval with a much earlier start to allow non-zero interval on faster computers.
    final Interval whileWeCreate = Intervals.between(before, after);
    assertEquals(id, entity.getId());
    assertEquals(0, entity.getVersion().getNumber());
    assertTrue(Intervals.contains(whileWeCreate, entity.whenModified()));
    assertEquals(StringValue.getDefaultInstance(), entity.getState());
    assertFalse(entity.isArchived());
    assertFalse(entity.isDeleted());
}
Also used : StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 43 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class QueryParametersShould method keep_multiple_filters_for_single_column.

@Test
public void keep_multiple_filters_for_single_column() throws ParseException {
    final String columnName = "time";
    final EntityColumn column = mock(EntityColumn.class);
    // Some valid Timestamp values
    final Timestamp startTime = Timestamps.parse("2000-01-01T10:00:00.000-05:00");
    final Timestamp deadline = Timestamps.parse("2017-01-01T10:00:00.000-05:00");
    final ColumnFilter startTimeFilter = gt(columnName, startTime);
    final ColumnFilter deadlineFilter = le(columnName, deadline);
    final Multimap<EntityColumn, ColumnFilter> columnFilters = ImmutableMultimap.<EntityColumn, ColumnFilter>builder().put(column, startTimeFilter).put(column, deadlineFilter).build();
    final CompositeQueryParameter parameter = from(columnFilters, ALL);
    final QueryParameters parameters = newBuilder().add(parameter).build();
    final List<CompositeQueryParameter> aggregatingParameters = newArrayList(parameters);
    assertSize(1, aggregatingParameters);
    final Multimap<EntityColumn, ColumnFilter> actualColumnFilters = aggregatingParameters.get(0).getFilters();
    final Collection<ColumnFilter> timeFilters = actualColumnFilters.get(column);
    assertSize(2, timeFilters);
    assertContainsAll(timeFilters, startTimeFilter, deadlineFilter);
}
Also used : ColumnFilter(io.spine.client.ColumnFilter) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 44 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class AggregateShould method return_non_null_time_when_was_last_modified.

@Test
public void return_non_null_time_when_was_last_modified() {
    final Timestamp creationTime = new TestAggregate(ID).whenModified();
    assertNotNull(creationTime);
}
Also used : TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 45 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class AggregateShould method record_modification_time_when_command_handled.

@Test
public void record_modification_time_when_command_handled() {
    try {
        final Timestamp frozenTime = Time.getCurrentTime();
        Time.setProvider(new TimeTests.FrozenMadHatterParty(frozenTime));
        dispatchCommand(aggregate, env(createProject));
        assertEquals(frozenTime, aggregate.whenModified());
    } finally {
        Time.resetProvider();
    }
}
Also used : TimeTests(io.spine.test.TimeTests) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)120 Test (org.junit.Test)84 Duration (com.google.protobuf.Duration)24 Interval (io.spine.time.Interval)16 Command (io.spine.core.Command)9 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Nullable (javax.annotation.Nullable)7 StringValue (com.google.protobuf.StringValue)6 Event (io.spine.core.Event)6 Message (com.google.protobuf.Message)5 Predicate (com.google.common.base.Predicate)4 TimeTests (io.spine.test.TimeTests)4 CommandContext (io.spine.core.CommandContext)3 EventContext (io.spine.core.EventContext)3 Version (io.spine.core.Version)3 Any (com.google.protobuf.Any)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2