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();
}
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)));
}
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());
}
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());
}
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);
}
Aggregations