Search in sources :

Example 1 with NoopScope

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

the class MemoTest method testMemo.

@Test
public void testMemo() {
    if (testWorkflowRule.getTestEnvironment() == null) {
        return;
    }
    WorkflowOptions workflowOptions = SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).setMemo(MEMO).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);
    Memo memoFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getMemo();
    Payload memoBytes = memoFromEvent.getFieldsMap().get(MEMO_KEY);
    String memoRetrieved = GsonJsonPayloadConverter.getInstance().fromData(memoBytes, String.class, String.class);
    assertEquals(MEMO_VALUE, memoRetrieved);
}
Also used : TestNoArgsWorkflowFunc(io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc) 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) ByteString(com.google.protobuf.ByteString) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) NoopScope(com.uber.m3.tally.NoopScope) Memo(io.temporal.api.common.v1.Memo) Test(org.junit.Test)

Example 2 with NoopScope

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

the class ReplayWorkflowRunTaskHandlerCacheTests method evictAnyWillNotInvalidateItself.

@Test
public void evictAnyWillNotInvalidateItself() throws Exception {
    // Arrange
    WorkflowExecutorCache cache = new WorkflowExecutorCache(50, new NoopScope());
    PollWorkflowTaskQueueResponse workflowTask1 = HistoryUtils.generateWorkflowTaskWithInitialHistory();
    // Act
    WorkflowRunTaskHandler workflowRunTaskHandler = cache.getOrCreate(workflowTask1, metricsScope, () -> createFakeExecutor(workflowTask1));
    WorkflowExecution execution = workflowTask1.getWorkflowExecution();
    cache.addToCache(execution, workflowRunTaskHandler);
    assertEquals(1, cache.size());
    cache.evictAnyNotInProcessing(execution, metricsScope);
    // Assert
    assertEquals(1, cache.size());
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) NoopScope(com.uber.m3.tally.NoopScope) Test(org.junit.Test)

Example 3 with NoopScope

use of com.uber.m3.tally.NoopScope in project cadence-client by uber-java.

the class ShadowingWorkerTest method init.

@Before
public void init() {
    WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setMetricsScope(new NoopScope()).build();
    when(mockClient.getOptions()).thenReturn(clientOptions);
    when(mockClient.getService()).thenReturn(mockService);
}
Also used : WorkflowClientOptions(com.uber.cadence.client.WorkflowClientOptions) NoopScope(com.uber.m3.tally.NoopScope) Before(org.junit.Before)

Example 4 with NoopScope

use of com.uber.m3.tally.NoopScope in project cadence-client by uber-java.

the class NoopScope method getInstance.

public static synchronized Scope getInstance() {
    if (noopScope == null) {
        noopCounter = delta -> {
        };
        noopGauge = value -> {
        };
        noopTimer = new Timer() {

            @Override
            public void record(Duration interval) {
            }

            @Override
            public Stopwatch start() {
                return new Stopwatch(0, stopwatchStart -> {
                });
            }
        };
        noopHistogram = new Histogram() {

            @Override
            public void recordValue(double value) {
            }

            @Override
            public void recordDuration(Duration value) {
            }

            @Override
            public Stopwatch start() {
                return new Stopwatch(0, stopwatchStart -> {
                });
            }
        };
        noopScope = new NoopScope();
    }
    return noopScope;
}
Also used : Stopwatch(com.uber.m3.tally.Stopwatch) Scope(com.uber.m3.tally.Scope) Timer(com.uber.m3.tally.Timer) CapableOf(com.uber.m3.tally.CapableOf) Map(java.util.Map) Counter(com.uber.m3.tally.Counter) Histogram(com.uber.m3.tally.Histogram) Capabilities(com.uber.m3.tally.Capabilities) Gauge(com.uber.m3.tally.Gauge) Duration(com.uber.m3.util.Duration) Buckets(com.uber.m3.tally.Buckets) Histogram(com.uber.m3.tally.Histogram) Timer(com.uber.m3.tally.Timer) Stopwatch(com.uber.m3.tally.Stopwatch) Duration(com.uber.m3.util.Duration)

Example 5 with NoopScope

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

the class ReplayWorkflowRunTaskHandlerTaskHandlerTests method ifStickyExecutionAttributesAreSetThenWorkflowsAreCached.

@Test
public void ifStickyExecutionAttributesAreSetThenWorkflowsAreCached() throws Throwable {
    // Arrange
    WorkflowExecutorCache cache = new WorkflowExecutorCache(10, new NoopScope());
    WorkflowTaskHandler taskHandler = new ReplayWorkflowTaskHandler("namespace", setUpMockWorkflowFactory(), cache, SingleWorkerOptions.newBuilder().build(), "sticky", Duration.ofSeconds(5), service, null);
    PollWorkflowTaskQueueResponse workflowTask = HistoryUtils.generateWorkflowTaskWithInitialHistory();
    WorkflowTaskHandler.Result result = taskHandler.handleWorkflowTask(workflowTask);
    assertTrue(result.isCompletionCommand());
    // do not cache if completion command
    assertEquals(0, cache.size());
    assertNotNull(result.getTaskCompleted());
    StickyExecutionAttributes attributes = result.getTaskCompleted().getStickyAttributes();
    assertEquals("sticky", attributes.getWorkerTaskQueue().getName());
    assertEquals(Durations.fromSeconds(5), attributes.getScheduleToStartTimeout());
}
Also used : PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) WorkflowTaskHandler(io.temporal.internal.worker.WorkflowTaskHandler) StickyExecutionAttributes(io.temporal.api.taskqueue.v1.StickyExecutionAttributes) NoopScope(com.uber.m3.tally.NoopScope) 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