Search in sources :

Example 26 with History

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());
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) History(io.temporal.api.history.v1.History) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 27 with History

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;
}
Also used : ArrayList(java.util.ArrayList) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) WorkflowExecutionHistory(io.temporal.internal.common.WorkflowExecutionHistory) History(io.temporal.api.history.v1.History)

Example 28 with History

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");
}
Also used : WorkflowExecutionHistory(io.temporal.internal.common.WorkflowExecutionHistory) History(io.temporal.api.history.v1.History) HistoryEvent(io.temporal.api.history.v1.HistoryEvent)

Example 29 with 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);
}
Also used : JsonFormat(com.google.protobuf.util.JsonFormat) DataConverterException(io.temporal.common.converter.DataConverterException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) History(io.temporal.api.history.v1.History)

Example 30 with 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());
    }
}
Also used : WorkflowFailedException(io.temporal.client.WorkflowFailedException) WorkflowStub(io.temporal.client.WorkflowStub) CanceledFailure(io.temporal.failure.CanceledFailure) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) TestWorkflows(io.temporal.workflow.shared.TestWorkflows) History(io.temporal.api.history.v1.History) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 History (org.orcid.jaxb.model.record_v2.History)13 History (io.temporal.api.history.v1.History)9 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)7 IOException (java.io.IOException)5 InputStreamReader (java.io.InputStreamReader)5 Reader (java.io.Reader)5 OrcidIdentifier (org.orcid.jaxb.model.common_v2.OrcidIdentifier)5 Email (org.orcid.jaxb.model.record_v2.Email)5 WorkflowExecutionHistory (io.temporal.internal.common.WorkflowExecutionHistory)4 Address (org.orcid.jaxb.model.record_v2.Address)4 Record (org.orcid.jaxb.model.record_v2.Record)4 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)4 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)3 ArrayList (java.util.ArrayList)3 History (org.orcid.jaxb.model.record_rc2.History)3 History (org.orcid.jaxb.model.record_rc3.History)3 History (org.orcid.jaxb.model.record_rc4.History)3 WorkflowFailedException (io.temporal.client.WorkflowFailedException)2 WorkflowStub (io.temporal.client.WorkflowStub)2