@Test
public void testMultipleJobDetails() {
String updateId1 = "u1";
String updateId2 = "u2";
IJobUpdateDetails details1 =
makeJobDetails(makeJobUpdate(JobKeys.from("role", "env", "name1"), updateId1));
IJobUpdateDetails details2 =
makeJobDetails(makeJobUpdate(JobKeys.from("role", "env", "name2"), updateId2));
assertEquals(ImmutableList.<IJobInstanceUpdateEvent>of(), getInstanceEvents(updateId2, 3));
saveUpdate(details1.getUpdate(), Optional.of("lock1"));
saveUpdate(details2.getUpdate(), Optional.of("lock2"));
details1 = updateJobDetails(populateExpected(details1.getUpdate()), FIRST_EVENT);
details2 = updateJobDetails(populateExpected(details2.getUpdate()), FIRST_EVENT);
assertEquals(Optional.of(details1), getUpdateDetails(updateId1));
assertEquals(Optional.of(details2), getUpdateDetails(updateId2));
IJobUpdateEvent jEvent11 = makeJobUpdateEvent(ROLLING_FORWARD, 456L);
IJobUpdateEvent jEvent12 = makeJobUpdateEvent(ERROR, 457L);
IJobInstanceUpdateEvent iEvent11 = makeJobInstanceEvent(1, 451L, INSTANCE_UPDATED);
IJobInstanceUpdateEvent iEvent12 = makeJobInstanceEvent(2, 452L, INSTANCE_UPDATING);
IJobUpdateEvent jEvent21 = makeJobUpdateEvent(ROLL_FORWARD_PAUSED, 567L);
IJobUpdateEvent jEvent22 = makeJobUpdateEvent(ABORTED, 568L);
IJobInstanceUpdateEvent iEvent21 = makeJobInstanceEvent(3, 561L, INSTANCE_UPDATING);
IJobInstanceUpdateEvent iEvent22 = makeJobInstanceEvent(3, 562L, INSTANCE_UPDATED);
saveJobEvent(jEvent11, updateId1);
saveJobEvent(jEvent12, updateId1);
saveJobInstanceEvent(iEvent11, updateId1);
saveJobInstanceEvent(iEvent12, updateId1);
saveJobEvent(jEvent21, updateId2);
saveJobEvent(jEvent22, updateId2);
assertEquals(ImmutableList.<IJobInstanceUpdateEvent>of(), getInstanceEvents(updateId2, 3));
saveJobInstanceEvent(iEvent21, updateId2);
assertEquals(ImmutableList.of(iEvent21), getInstanceEvents(updateId2, 3));
saveJobInstanceEvent(iEvent22, updateId2);
assertEquals(ImmutableList.of(iEvent21, iEvent22), getInstanceEvents(updateId2, 3));
details1 = updateJobDetails(
populateExpected(details1.getUpdate(), ERROR, CREATED_MS, 457L),
ImmutableList.of(FIRST_EVENT, jEvent11, jEvent12), ImmutableList.of(iEvent11, iEvent12));
details2 = updateJobDetails(
populateExpected(details2.getUpdate(), ABORTED, CREATED_MS, 568L),
ImmutableList.of(FIRST_EVENT, jEvent21, jEvent22), ImmutableList.of(iEvent21, iEvent22));
assertEquals(Optional.of(details1), getUpdateDetails(updateId1));
assertEquals(Optional.of(details2), getUpdateDetails(updateId2));
assertEquals(
ImmutableSet.of(
new StoredJobUpdateDetails(details1.newBuilder(), "lock1"),
new StoredJobUpdateDetails(details2.newBuilder(), "lock2")),
getAllUpdateDetails());
}