Skip to content

Commit 4458f4f

Browse files
addjuarezkaibocaieNeRGy164artursouzaMregXN
authored
Show registered workflows and Activities (#953)
* Show registered workflow Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * Add `NewWorkflowOption` to config version, time, input, etc when start a new workflow (#945) * add NewWorkflowOption Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> * fix style Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> * add unit test Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> * add more unit tests for improving coverage Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> --------- Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * Update CLI link in example readme's (#951) * Updated pre-requisite link to Dapr CLI Signed-off-by: Michaël Hompus <michael@hompus.nl> * Update JDK list to match all other examples Signed-off-by: Michaël Hompus <michael@hompus.nl> --------- Signed-off-by: Michaël Hompus <michael@hompus.nl> Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * remove static Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * Add determinstic UUID generation (#947) * add determinstic UUID generation Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> * add unit test to improve coverage Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> * update grpc version to 1.59.0 to be compatible updated durabletask-java Signed-off-by: kaibocai <kaibocai@microsoft.com> --------- Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> Signed-off-by: kaibocai <kaibocai@microsoft.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * fix flaky integration test ActorExceptionIT (#954) Signed-off-by: MregXN <mregxn@gmail.com> Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * fix flaky it ActorReminderRecovery (#958) Signed-off-by: MregXN <mregxn@gmail.com> Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * fix flaky integration test MethodInvokeIT (#959) * fix flaky it MethodInvokeIT Signed-off-by: MregXN <mregxn@gmail.com> * add debug print Signed-off-by: MregXN <mregxn@gmail.com> * add debug print Signed-off-by: MregXN <mregxn@gmail.com> * add more waiting time Signed-off-by: MregXN <mregxn@gmail.com> * wait before invoke Signed-off-by: MregXN <mregxn@gmail.com> * wait for health before invoke Signed-off-by: MregXN <mregxn@gmail.com> --------- Signed-off-by: MregXN <mregxn@gmail.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * Fix errors Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> * make thead safe * Fix code and test. Signed-off-by: Artur Souza <asouza.pro@gmail.com> --------- Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com> Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com> Signed-off-by: Michaël Hompus <michael@hompus.nl> Signed-off-by: kaibocai <kaibocai@microsoft.com> Signed-off-by: MregXN <mregxn@gmail.com> Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Artur Souza <asouza.pro@gmail.com> Co-authored-by: kaibocai <89094811+kaibocai@users.noreply.github.com> Co-authored-by: Michaël Hompus <michael@hompus.nl> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Co-authored-by: MregXN <46479059+MregXN@users.noreply.github.com> Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Artur Souza <asouza.pro@gmail.com>
1 parent a0ae3c3 commit 4458f4f

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowRuntimeBuilder.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 The Dapr Authors
2+
* Copyright 2024 The Dapr Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -18,11 +18,11 @@
1818
import io.dapr.workflows.Workflow;
1919
import io.dapr.workflows.internal.ApiTokenClientInterceptor;
2020
import io.grpc.ClientInterceptor;
21-
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import java.util.Collections;
2224
import java.util.HashSet;
2325
import java.util.Set;
24-
import java.util.logging.Level;
25-
import java.util.logging.Logger;
2626

2727
public class WorkflowRuntimeBuilder {
2828
private static volatile WorkflowRuntime instance;
@@ -31,14 +31,20 @@ public class WorkflowRuntimeBuilder {
3131
private Set<String> workflows = new HashSet<String>();
3232
private Set<String> activities = new HashSet<String>();
3333
private static ClientInterceptor WORKFLOW_INTERCEPTOR = new ApiTokenClientInterceptor();
34+
private final Set<String> activitySet = Collections.synchronizedSet(new HashSet<>());
35+
private final Set<String> workflowSet = Collections.synchronizedSet(new HashSet<>());
3436

3537
/**
3638
* Constructs the WorkflowRuntimeBuilder.
3739
*/
3840
public WorkflowRuntimeBuilder() {
41+
this(LoggerFactory.getLogger(WorkflowRuntimeBuilder.class));
42+
}
43+
44+
WorkflowRuntimeBuilder(Logger logger) {
3945
this.builder = new DurableTaskGrpcWorkerBuilder().grpcChannel(
40-
NetworkUtils.buildGrpcManagedChannel(WORKFLOW_INTERCEPTOR));
41-
this.logger = Logger.getLogger(WorkflowRuntimeBuilder.class.getName());
46+
NetworkUtils.buildGrpcManagedChannel(WORKFLOW_INTERCEPTOR));
47+
this.logger = logger;
4248
}
4349

4450
/**
@@ -54,7 +60,9 @@ public WorkflowRuntime build() {
5460
}
5561
}
5662
}
57-
this.logger.log(Level.INFO, "Successfully built dapr workflow runtime");
63+
this.logger.info("List of registered workflows: " + this.workflowSet);
64+
this.logger.info("List of registered activites: " + this.activitySet);
65+
this.logger.info("Successfully built dapr workflow runtime");
5866
return instance;
5967
}
6068

@@ -69,7 +77,8 @@ public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(Class<T> cla
6977
this.builder = this.builder.addOrchestration(
7078
new OrchestratorWrapper<>(clazz)
7179
);
72-
this.logger.log(Level.INFO, "Registered Workflow: " + clazz.getSimpleName());
80+
this.workflowSet.add(clazz.getCanonicalName());
81+
this.logger.info("Registered Workflow: " + clazz.getSimpleName());
7382
this.workflows.add(clazz.getSimpleName());
7483
return this;
7584
}
@@ -84,7 +93,8 @@ public <T extends WorkflowActivity> void registerActivity(Class<T> clazz) {
8493
this.builder = this.builder.addActivity(
8594
new ActivityWrapper<>(clazz)
8695
);
87-
this.logger.log(Level.INFO, "Registered Activity: " + clazz.getSimpleName());
96+
this.activitySet.add(clazz.getCanonicalName());
97+
this.logger.info("Registered Activity: " + clazz.getSimpleName());
8898
this.activities.add(clazz.getSimpleName());
8999
}
90100

sdk-workflows/src/test/java/io/dapr/workflows/runtime/WorkflowRuntimeBuilderTest.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
/*
2+
* Copyright 2024 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
113
package io.dapr.workflows.runtime;
214

315

416
import io.dapr.workflows.Workflow;
517
import io.dapr.workflows.WorkflowStub;
618
import org.junit.jupiter.api.Test;
19+
import org.mockito.Mockito;
20+
import org.slf4j.Logger;
721

8-
import static org.junit.Assert.assertNotEquals;
922
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1023

1124
import java.io.ByteArrayOutputStream;
1225
import java.io.PrintStream;
13-
import java.util.logging.Logger;
14-
import java.util.logging.Handler;
15-
import java.util.logging.LogRecord;
1626

1727
public class WorkflowRuntimeBuilderTest {
1828
public static class TestWorkflow extends Workflow {
@@ -51,36 +61,19 @@ public void loggingOutputTest() {
5161
ByteArrayOutputStream outStreamCapture = new ByteArrayOutputStream();
5262
System.setOut(new PrintStream(outStreamCapture));
5363

54-
LogCaptureHandler testLoggerHandler = new LogCaptureHandler();
55-
Logger testLogger = Logger.getLogger(WorkflowRuntimeBuilder.class.getName());
64+
Logger testLogger = Mockito.mock(Logger.class);
5665

57-
testLogger.addHandler(testLoggerHandler);
58-
59-
// indexOf will return -1 if the string is not found.
60-
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(TestWorkflow.class));
61-
assertNotEquals(-1, testLoggerHandler.capturedLog.indexOf("Registered Workflow: TestWorkflow"));
62-
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerActivity(TestActivity.class));
63-
assertNotEquals(-1, testLoggerHandler.capturedLog.indexOf("Registered Activity: TestActivity"));
66+
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder(testLogger).registerWorkflow(TestWorkflow.class));
67+
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder(testLogger).registerActivity(TestActivity.class));
6468

6569
WorkflowRuntimeBuilder wfRuntime = new WorkflowRuntimeBuilder();
6670

6771
wfRuntime.build();
68-
}
69-
70-
private static class LogCaptureHandler extends Handler {
71-
private StringBuilder capturedLog = new StringBuilder();
72-
73-
@Override
74-
public void publish(LogRecord record) {
75-
capturedLog.append(record.getMessage()).append(System.lineSeparator());
76-
}
77-
78-
@Override
79-
public void flush(){
80-
}
8172

82-
@Override
83-
public void close() throws SecurityException {
84-
}
73+
Mockito.verify(testLogger, Mockito.times(1))
74+
.info(Mockito.eq("Registered Workflow: TestWorkflow"));
75+
Mockito.verify(testLogger, Mockito.times(1))
76+
.info(Mockito.eq("Registered Activity: TestActivity"));
8577
}
78+
8679
}

0 commit comments

Comments
 (0)