use of org.geotoolkit.sml.xml.v100.History in project sdk-java by temporalio.
the class WorkflowHistoryIteratorTest method verifyHasNextIsFalseWhenHistoryIsEmpty.
/*
This test Scenario verifies following things:
1. hasNext() method makes a call to the server to retrieve workflow history when current
history is empty and history token is available and cached the result.
2. next() method reuses cached history when possible.
3. hasNext() fetches an empty page and return false.
4. next() throws NoSuchElementException when neither history no history token is available.
*/
@Test
public void verifyHasNextIsFalseWhenHistoryIsEmpty() {
PollWorkflowTaskQueueResponse workflowTask = PollWorkflowTaskQueueResponse.newBuilder().setNextPageToken(NEXT_PAGE_TOKEN).build();
AtomicInteger timesCalledServer = new AtomicInteger(0);
WorkflowHistoryIterator iterator = new WorkflowHistoryIterator(null, "default", workflowTask, Duration.ofSeconds(10), null) {
GetWorkflowExecutionHistoryResponse queryWorkflowExecutionHistory() {
timesCalledServer.incrementAndGet();
try {
if (EMPTY_PAGE_TOKEN.equals(nextPageToken)) {
return GetWorkflowExecutionHistoryResponse.newBuilder().build();
}
History history = HistoryUtils.generateWorkflowTaskWithInitialHistory().getHistory();
return GetWorkflowExecutionHistoryResponse.newBuilder().setHistory(history).setNextPageToken(EMPTY_PAGE_TOKEN).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
Assert.assertEquals(0, timesCalledServer.get());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(1, timesCalledServer.get());
Assert.assertNotNull(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertNotNull(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertNotNull(iterator.next());
Assert.assertEquals(1, timesCalledServer.get());
Assert.assertFalse(iterator.hasNext());
Assert.assertEquals(2, timesCalledServer.get());
Assert.assertThrows(NoSuchElementException.class, iterator::next);
Assert.assertEquals(2, timesCalledServer.get());
}
use of org.geotoolkit.sml.xml.v100.History in project sdk-java by temporalio.
the class SDKTestWorkflowRule method getHistoryEvents.
/**
* Returns list of all events of the given EventType found in the history.
*/
public List<HistoryEvent> getHistoryEvents(WorkflowExecution execution, EventType eventType) {
List<HistoryEvent> result = new ArrayList<>();
History history = getHistory(execution);
for (HistoryEvent event : history.getEventsList()) {
if (eventType == event.getEventType()) {
result.add(event);
}
}
return result;
}
use of org.geotoolkit.sml.xml.v100.History in project sdk-java by temporalio.
the class SDKTestWorkflowRule method assertHistoryEvent.
/**
* Asserts that an event of the given EventType is found in the history.
*/
public void assertHistoryEvent(WorkflowExecution execution, EventType eventType) {
History history = getHistory(execution);
for (HistoryEvent event : history.getEventsList()) {
if (eventType == event.getEventType()) {
return;
}
}
fail("No event of " + eventType + " found in the history");
}
use of org.geotoolkit.sml.xml.v100.History in project sdk-java by temporalio.
the class WorkflowExecutionHistory method fromJson.
public static WorkflowExecutionHistory fromJson(String serialized) {
String protoJson = HistoryJsonUtils.historyFormatJsonToProtoJson(serialized);
JsonFormat.Parser parser = JsonFormat.parser().ignoringUnknownFields();
History.Builder historyBuilder = History.newBuilder();
try {
parser.merge(protoJson, historyBuilder);
} catch (InvalidProtocolBufferException e) {
throw new DataConverterException(e);
}
History history = historyBuilder.build();
checkHistory(history);
return new WorkflowExecutionHistory(history);
}
use of org.geotoolkit.sml.xml.v100.History in project sdk-java by temporalio.
the class WorkflowAwaitCancellationTest method awaitCancellation.
@Test
public void awaitCancellation() {
TestWorkflows.TestWorkflow1 workflow = testWorkflowRule.newWorkflowStub(TestWorkflows.TestWorkflow1.class);
WorkflowExecution execution = null;
try {
execution = WorkflowClient.start(workflow::execute, "input1");
WorkflowStub untyped = WorkflowStub.fromTyped(workflow);
untyped.cancel();
untyped.getResult(String.class);
fail("unreacheable");
} catch (WorkflowFailedException e) {
assertTrue(e.getCause() instanceof CanceledFailure);
History history = testWorkflowRule.getHistory(execution);
HistoryEvent lastEvent = history.getEvents(history.getEventsCount() - 1);
assertEquals("WorkflowExecutionCancelled event is expected", EventType.EVENT_TYPE_WORKFLOW_EXECUTION_CANCELED, lastEvent.getEventType());
}
}
Aggregations