Search in sources :

Example 6 with NoopScope

use of com.uber.m3.tally.NoopScope in project sdk-java by temporalio.

the class ReplayWorkflowRunTaskHandlerCacheTests method whenHistoryIsFullNewWorkflowExecutorIsReturned_InitiallyCached.

@Test
public void whenHistoryIsFullNewWorkflowExecutorIsReturned_InitiallyCached() throws Exception {
    TestWorkflowService testService = new TestWorkflowService();
    WorkflowServiceStubs service = testService.newClientStub();
    // Arrange
    WorkflowExecutorCache cache = new WorkflowExecutorCache(10, new NoopScope());
    PollWorkflowTaskQueueResponse workflowTask1 = HistoryUtils.generateWorkflowTaskWithInitialHistory("namespace", "taskQueue", "workflowType", service);
    WorkflowRunTaskHandler workflowRunTaskHandler = cache.getOrCreate(workflowTask1, metricsScope, () -> createFakeExecutor(workflowTask1));
    cache.addToCache(workflowTask1.getWorkflowExecution(), workflowRunTaskHandler);
    PollWorkflowTaskQueueResponse workflowTask2 = HistoryUtils.generateWorkflowTaskWithPartialHistoryFromExistingTask(workflowTask1, "namespace", "stickyTaskQueue", service);
    assertEquals(workflowRunTaskHandler, cache.getOrCreate(workflowTask2, metricsScope, () -> doNotCreateFakeExecutor(workflowTask2)));
    // Act
    WorkflowRunTaskHandler workflowRunTaskHandler2 = cache.getOrCreate(workflowTask2, metricsScope, () -> createFakeExecutor(workflowTask2));
    // Assert
    assertEquals(workflowRunTaskHandler2, cache.getOrCreate(workflowTask2, metricsScope, () -> createFakeExecutor(workflowTask2)));
    assertSame(workflowRunTaskHandler2, workflowRunTaskHandler);
    testService.close();
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) TestWorkflowService(io.temporal.internal.testservice.TestWorkflowService) NoopScope(com.uber.m3.tally.NoopScope) WorkflowServiceStubs(io.temporal.serviceclient.WorkflowServiceStubs) Test(org.junit.Test)

Example 7 with NoopScope

use of com.uber.m3.tally.NoopScope in project sdk-java by temporalio.

the class ReplayWorkflowRunTaskHandlerCacheTests method whenHistoryIsFullNewWorkflowExecutorIsReturnedAndCached_InitiallyEmpty.

@Test
public void whenHistoryIsFullNewWorkflowExecutorIsReturnedAndCached_InitiallyEmpty() throws Exception {
    // Arrange
    WorkflowExecutorCache cache = new WorkflowExecutorCache(10, new NoopScope());
    PollWorkflowTaskQueueResponse workflowTask = HistoryUtils.generateWorkflowTaskWithInitialHistory();
    String runId = workflowTask.getWorkflowExecution().getRunId();
    assertCacheIsEmpty(cache, runId);
    // Act
    WorkflowRunTaskHandler workflowRunTaskHandler = cache.getOrCreate(workflowTask, metricsScope, () -> createFakeExecutor(workflowTask));
    // Assert
    assertNotEquals(workflowRunTaskHandler, cache.getOrCreate(workflowTask, metricsScope, () -> createFakeExecutor(workflowTask)));
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) NoopScope(com.uber.m3.tally.NoopScope) Test(org.junit.Test)

Example 8 with NoopScope

use of com.uber.m3.tally.NoopScope in project sdk-java by temporalio.

the class ReplayWorkflowRunTaskHandlerTaskHandlerTests method ifStickyExecutionAttributesAreNotSetThenWorkflowsAreNotCached.

@Test
public void ifStickyExecutionAttributesAreNotSetThenWorkflowsAreNotCached() throws Throwable {
    // Arrange
    WorkflowExecutorCache cache = new WorkflowExecutorCache(10, new NoopScope());
    WorkflowTaskHandler taskHandler = new ReplayWorkflowTaskHandler("namespace", setUpMockWorkflowFactory(), cache, SingleWorkerOptions.newBuilder().build(), null, Duration.ofSeconds(5), service, null);
    // Act
    WorkflowTaskHandler.Result result = taskHandler.handleWorkflowTask(HistoryUtils.generateWorkflowTaskWithInitialHistory());
    // Assert
    assertEquals(0, cache.size());
    assertNotNull(result.getTaskCompleted());
    assertFalse(result.getTaskCompleted().hasStickyAttributes());
}
Also used : WorkflowTaskHandler(io.temporal.internal.worker.WorkflowTaskHandler) NoopScope(com.uber.m3.tally.NoopScope) Test(org.junit.Test)

Example 9 with NoopScope

use of com.uber.m3.tally.NoopScope in project sdk-java by temporalio.

the class DeterministicRunnerTest method workflowThreadsWillNotEvictCacheWhenMaxThreadCountIsHit.

@Test
public void workflowThreadsWillNotEvictCacheWhenMaxThreadCountIsHit() throws Throwable {
    // Arrange
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 5, 1, TimeUnit.SECONDS, new SynchronousQueue<>());
    AtomicReference<String> status = new AtomicReference<>();
    WorkflowExecutorCache cache = new WorkflowExecutorCache(3, new NoopScope());
    DeterministicRunnerImpl d = new DeterministicRunnerImpl(threadPool, DummySyncWorkflowContext.newDummySyncWorkflowContext(), () -> {
        Promise<Void> thread = Async.procedure(() -> {
            status.set("started");
            WorkflowThread.await("doing something", () -> false);
            status.set("done");
        });
        thread.get();
    }, cache);
    WorkflowRunTaskHandler workflowRunTaskHandler = new DeterministicRunnerTestWorkflowRunTaskHandler(d);
    PollWorkflowTaskQueueResponse response = HistoryUtils.generateWorkflowTaskWithInitialHistory();
    cache.getOrCreate(response, new com.uber.m3.tally.NoopScope(), () -> workflowRunTaskHandler);
    cache.addToCache(response.getWorkflowExecution(), workflowRunTaskHandler);
    d.runUntilAllBlocked(DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT_MS);
    assertEquals(2, threadPool.getActiveCount());
    assertEquals(1, cache.size());
    DeterministicRunnerImpl d2 = new DeterministicRunnerImpl(threadPool, DummySyncWorkflowContext.newDummySyncWorkflowContext(), () -> {
        Promise<Void> thread = Async.procedure(() -> {
            status.set("started");
            WorkflowThread.await("doing something else", () -> false);
            status.set("done");
        });
        thread.get();
    }, cache);
    // Act: This should not kick out threads consumed by 'd' since there's enough capacity
    d2.runUntilAllBlocked(DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT_MS);
    // Assert: Cache is not evicted and all threads remain.
    assertEquals(4, threadPool.getActiveCount());
    assertEquals(1, cache.size());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) NoopScope(com.uber.m3.tally.NoopScope) PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NoopScope(com.uber.m3.tally.NoopScope)

Example 10 with NoopScope

use of com.uber.m3.tally.NoopScope in project sdk-java by temporalio.

the class SearchAttributesTest method testSearchAttributes.

@Test
public void testSearchAttributes() {
    if (testWorkflowRule.isUseExternalService()) {
        // LocalDateTime fails to deserialize in the real service, with a message like
        // INVALID_ARGUMENT: 2021-08-26T13:21:52.059738 is not a valid value for search attribute
        // CustomDatetimeField of type Datetime
        // Tracked in https://github.com/temporalio/sdk-java/issues/673
        searchAttributes.remove(testKeyDateTime);
    }
    WorkflowOptions workflowOptions = SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder().setSearchAttributes(searchAttributes).build();
    TestNoArgsWorkflowFunc stubF = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestNoArgsWorkflowFunc.class, workflowOptions);
    WorkflowExecution executionF = WorkflowClient.start(stubF::func);
    GetWorkflowExecutionHistoryResponse historyResp = WorkflowClientHelper.getHistoryPage(testWorkflowRule.getTestEnvironment().getWorkflowService(), SDKTestWorkflowRule.NAMESPACE, executionF, ByteString.EMPTY, new NoopScope());
    HistoryEvent startEvent = historyResp.getHistory().getEvents(0);
    SearchAttributes searchAttrFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes();
    Map<String, Payload> fieldsMap = searchAttrFromEvent.getIndexedFieldsMap();
    Payload searchAttrStringBytes = fieldsMap.get(testKeyString);
    DataConverter converter = DataConverter.getDefaultInstance();
    String retrievedString = converter.fromPayload(searchAttrStringBytes, String.class, String.class);
    assertEquals(testValueString, retrievedString);
    Payload searchAttrIntegerBytes = fieldsMap.get(testKeyInteger);
    Integer retrievedInteger = converter.fromPayload(searchAttrIntegerBytes, Integer.class, Integer.class);
    assertEquals(testValueInteger, retrievedInteger);
    Payload searchAttrDateTimeBytes = fieldsMap.get(testKeyDateTime);
    if (!testWorkflowRule.isUseExternalService()) {
        LocalDateTime retrievedDateTime = converter.fromPayload(searchAttrDateTimeBytes, LocalDateTime.class, LocalDateTime.class);
        assertEquals(testValueDateTime, retrievedDateTime);
    }
    Payload searchAttrBoolBytes = fieldsMap.get(testKeyBool);
    Boolean retrievedBool = converter.fromPayload(searchAttrBoolBytes, Boolean.class, Boolean.class);
    assertEquals(testValueBool, retrievedBool);
    Payload searchAttrDoubleBytes = fieldsMap.get(testKeyDouble);
    Double retrievedDouble = converter.fromPayload(searchAttrDoubleBytes, Double.class, Double.class);
    assertEquals(testValueDouble, retrievedDouble);
}
Also used : LocalDateTime(java.time.LocalDateTime) SearchAttributes(io.temporal.api.common.v1.SearchAttributes) TestNoArgsWorkflowFunc(io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc) ByteString(com.google.protobuf.ByteString) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) WorkflowOptions(io.temporal.client.WorkflowOptions) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) GetWorkflowExecutionHistoryResponse(io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse) NoopScope(com.uber.m3.tally.NoopScope) DataConverter(io.temporal.common.converter.DataConverter) Test(org.junit.Test)

Aggregations

NoopScope (com.uber.m3.tally.NoopScope)9 Test (org.junit.Test)7 PollWorkflowTaskQueueResponse (io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse)5 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)3 ByteString (com.google.protobuf.ByteString)2 Payload (io.temporal.api.common.v1.Payload)2 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)2 GetWorkflowExecutionHistoryResponse (io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse)2 WorkflowOptions (io.temporal.client.WorkflowOptions)2 WorkflowTaskHandler (io.temporal.internal.worker.WorkflowTaskHandler)2 TestNoArgsWorkflowFunc (io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc)2 WorkflowClientOptions (com.uber.cadence.client.WorkflowClientOptions)1 Buckets (com.uber.m3.tally.Buckets)1 Capabilities (com.uber.m3.tally.Capabilities)1 CapableOf (com.uber.m3.tally.CapableOf)1 Counter (com.uber.m3.tally.Counter)1 Gauge (com.uber.m3.tally.Gauge)1 Histogram (com.uber.m3.tally.Histogram)1 Scope (com.uber.m3.tally.Scope)1 Stopwatch (com.uber.m3.tally.Stopwatch)1