Skip to content

Commit b1bcb7e

Browse files
Allow setting nulls to data attributes (#166)
1 parent 6243726 commit b1bcb7e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/main/java/io/iworkflow/core/persistence/DataAttributesRWImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void setDataAttribute(String key, Object value) {
5454
}
5555

5656
Class<?> registeredType = keyToTypeMap.get(key);
57-
if (!registeredType.isInstance(value)) {
57+
if (value != null && !registeredType.isAssignableFrom(value.getClass())) {
5858
throw new IllegalArgumentException(String.format("Input is not an instance of class %s", registeredType.getName()));
5959
}
6060

src/test/java/io/iworkflow/integ/RpcTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ public void testRPCWorkflowFunc1() throws InterruptedException {
4545
RpcWorkflow.class, wfId, 10, 999);
4646

4747
final RpcWorkflow rpcStub = client.newRpcStub(RpcWorkflow.class, wfId, "");
48+
49+
client.invokeRPC(rpcStub::testRpcSetDataAttribute, "test-value");
50+
String value = client.invokeRPC(rpcStub::testRpcGetDataAttribute);
51+
Assertions.assertEquals("test-value", value);
52+
client.invokeRPC(rpcStub::testRpcSetDataAttribute, null);
53+
value = client.invokeRPC(rpcStub::testRpcGetDataAttribute);
54+
Assertions.assertNull(value);
55+
56+
client.invokeRPC(rpcStub::testRpcSetKeyword, "test-value");
57+
value = client.invokeRPC(rpcStub::testRpcGetKeyword);
58+
Assertions.assertEquals("test-value", value);
59+
client.invokeRPC(rpcStub::testRpcSetKeyword, null);
60+
value = client.invokeRPC(rpcStub::testRpcGetKeyword);
61+
Assertions.assertNull(value);
62+
4863
final Long rpcOutput = client.invokeRPC(rpcStub::testRpcFunc1, RPC_INPUT);
4964

5065
Assertions.assertEquals(RPC_OUTPUT, rpcOutput);

src/test/java/io/iworkflow/integ/rpc/RpcWorkflow.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public Long testRpcFunc1(Context context, String input, Persistence persistence,
5959
if (context.getWorkflowId().isEmpty() || context.getWorkflowRunId().isEmpty()) {
6060
throw new RuntimeException("invalid context");
6161
}
62+
persistence.setDataAttribute(TEST_DATA_OBJECT_KEY, null);// test setting to null
6263
persistence.setDataAttribute(TEST_DATA_OBJECT_KEY, input);
6364
persistence.setSearchAttributeKeyword(TEST_SEARCH_ATTRIBUTE_KEYWORD, input);
6465
persistence.setSearchAttributeInt64(TEST_SEARCH_ATTRIBUTE_INT, RPC_OUTPUT);
@@ -111,4 +112,36 @@ public Long testRpcFunc1Readonly(Context context, String input, Persistence pers
111112
}
112113
return RPC_OUTPUT;
113114
}
115+
116+
@RPC
117+
public void testRpcSetDataAttribute(Context context, String input, Persistence persistence, Communication communication) {
118+
if (context.getWorkflowId().isEmpty() || context.getWorkflowRunId().isEmpty()) {
119+
throw new RuntimeException("invalid context");
120+
}
121+
persistence.setDataAttribute(TEST_DATA_OBJECT_KEY, input);
122+
}
123+
124+
@RPC
125+
public String testRpcGetDataAttribute(Context context, Persistence persistence, Communication communication) {
126+
if (context.getWorkflowId().isEmpty() || context.getWorkflowRunId().isEmpty()) {
127+
throw new RuntimeException("invalid context");
128+
}
129+
return persistence.getDataAttribute(TEST_DATA_OBJECT_KEY, String.class);
130+
}
131+
132+
@RPC
133+
public void testRpcSetKeyword(Context context, String input, Persistence persistence, Communication communication) {
134+
if (context.getWorkflowId().isEmpty() || context.getWorkflowRunId().isEmpty()) {
135+
throw new RuntimeException("invalid context");
136+
}
137+
persistence.setSearchAttributeKeyword(TEST_SEARCH_ATTRIBUTE_KEYWORD, input);
138+
}
139+
140+
@RPC
141+
public String testRpcGetKeyword(Context context, Persistence persistence, Communication communication) {
142+
if (context.getWorkflowId().isEmpty() || context.getWorkflowRunId().isEmpty()) {
143+
throw new RuntimeException("invalid context");
144+
}
145+
return persistence.getSearchAttributeKeyword(TEST_SEARCH_ATTRIBUTE_KEYWORD);
146+
}
114147
}

0 commit comments

Comments
 (0)