Skip to content

Commit fbdc476

Browse files
committed
Address comments
1 parent 2ac714a commit fbdc476

File tree

5 files changed

+78
-15
lines changed

5 files changed

+78
-15
lines changed

src/main/java/com/uber/cadence/client/WorkflowOptions.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,19 @@ public Builder setCronSchedule(String cronSchedule) {
190190
return this;
191191
}
192192

193-
/** Specifies additional non-indexed information in result of list workflow. */
193+
/**
194+
* Specifies additional non-indexed information in result of list workflow. The type of value
195+
* can be any object that are serializable by {@link com.uber.cadence.converter.DataConverter}
196+
*/
194197
public Builder setMemo(Map<String, Object> memo) {
195198
this.memo = memo;
196199
return this;
197200
}
198201

199-
/** Specifies additional indexed information in result of list workflow. */
202+
/**
203+
* Specifies additional indexed information in result of list workflow. The type of value should
204+
* be basic type such as: String, Integer, Boolean, Double,LocalDateTime
205+
*/
200206
public Builder setSearchAttributes(Map<String, Object> searchAttributes) {
201207
this.searchAttributes = searchAttributes;
202208
return this;

src/main/java/com/uber/cadence/internal/sync/WorkflowClientInternal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static WorkflowClient newInstance(String domain) {
6868
* default port (7933).
6969
*
7070
* @param domain domain that worker uses to poll.
71-
* @param options Options (like {@link com.uber.cadence.converter.DataConverter}er override) for
71+
* @param options Options (like {@link com.uber.cadence.converter.DataConverter} override) for
7272
* configuring client.
7373
*/
7474
public static WorkflowClient newInstance(String domain, WorkflowClientOptions options) {
@@ -95,7 +95,7 @@ public static WorkflowClient newInstance(String host, int port, String domain) {
9595
* @param host of the Cadence Service endpoint
9696
* @param port of the Cadence Service endpoint
9797
* @param domain domain that worker uses to poll.
98-
* @param options Options (like {@link com.uber.cadence.converter.DataConverter}er override) for
98+
* @param options Options (like {@link com.uber.cadence.converter.DataConverter} override) for
9999
* configuring client.
100100
*/
101101
public static WorkflowClient newInstance(
@@ -118,7 +118,7 @@ public static WorkflowClient newInstance(IWorkflowService service, String domain
118118
*
119119
* @param service client to the Cadence Service endpoint.
120120
* @param domain domain that worker uses to poll.
121-
* @param options Options (like {@link com.uber.cadence.converter.DataConverter}er override) for
121+
* @param options Options (like {@link com.uber.cadence.converter.DataConverter} override) for
122122
* configuring client.
123123
*/
124124
public static WorkflowClient newInstance(

src/main/java/com/uber/cadence/internal/sync/WorkflowStubImpl.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.uber.cadence.client.WorkflowStub;
3434
import com.uber.cadence.converter.DataConverter;
3535
import com.uber.cadence.converter.DataConverterException;
36+
import com.uber.cadence.converter.JsonDataConverter;
3637
import com.uber.cadence.internal.common.CheckedExceptionWrapper;
3738
import com.uber.cadence.internal.common.SignalWithStartWorkflowExecutionParameters;
3839
import com.uber.cadence.internal.common.StartWorkflowExecutionParameters;
@@ -139,12 +140,13 @@ private StartWorkflowExecutionParameters getStartWorkflowExecutionParameters(
139140
}
140141
p.setInput(dataConverter.toData(args));
141142
p.setWorkflowType(new WorkflowType().setName(workflowType.get()));
142-
p.setMemo(convertMapFromObjectToBytes(o.getMemo()));
143-
p.setSearchAttributes(convertMapFromObjectToBytes(o.getSearchAttributes()));
143+
p.setMemo(convertMemoFromObjectToBytes(o.getMemo()));
144+
p.setSearchAttributes(convertSearchAttributesFromObjectToBytes(o.getSearchAttributes()));
144145
return p;
145146
}
146147

147-
private Map<String, byte[]> convertMapFromObjectToBytes(Map<String, Object> map) {
148+
private Map<String, byte[]> convertMapFromObjectToBytes(
149+
Map<String, Object> map, DataConverter dataConverter) {
148150
if (map == null) {
149151
return null;
150152
}
@@ -159,6 +161,14 @@ private Map<String, byte[]> convertMapFromObjectToBytes(Map<String, Object> map)
159161
return result;
160162
}
161163

164+
private Map<String, byte[]> convertMemoFromObjectToBytes(Map<String, Object> map) {
165+
return convertMapFromObjectToBytes(map, dataConverter);
166+
}
167+
168+
private Map<String, byte[]> convertSearchAttributesFromObjectToBytes(Map<String, Object> map) {
169+
return convertMapFromObjectToBytes(map, JsonDataConverter.getInstance());
170+
}
171+
162172
@Override
163173
public WorkflowExecution start(Object... args) {
164174
if (!options.isPresent()) {

src/test/java/com/uber/cadence/client/WorkflowOptionsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.uber.cadence.workflow.WorkflowMethod;
2626
import java.lang.reflect.Method;
2727
import java.time.Duration;
28+
import java.time.LocalDateTime;
2829
import java.util.HashMap;
2930
import java.util.Map;
3031
import org.junit.Assert;
@@ -194,12 +195,17 @@ public void testInvalidCronScheduleAnnotation() throws NoSuchMethodException {
194195
private Map<String, Object> getTestMemo() {
195196
Map<String, Object> memo = new HashMap<>();
196197
memo.put("testKey", "testObject");
198+
memo.put("objectKey", new WorkflowOptions.Builder().build());
197199
return memo;
198200
}
199201

200202
private Map<String, Object> getTestSearchAttributes() {
201203
Map<String, Object> searchAttr = new HashMap<>();
202204
searchAttr.put("CustomKeywordField", "testKey");
205+
searchAttr.put("CustomIntField", 1);
206+
searchAttr.put("CustomDoubleField", 1.23);
207+
searchAttr.put("CustomBoolField", false);
208+
searchAttr.put("CustomDatetimeField", LocalDateTime.now());
203209
return searchAttr;
204210
}
205211
}

src/test/java/com/uber/cadence/workflow/WorkflowTest.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import java.lang.reflect.Type;
7979
import java.text.SimpleDateFormat;
8080
import java.time.Duration;
81+
import java.time.LocalDateTime;
8182
import java.util.ArrayDeque;
8283
import java.util.ArrayList;
8384
import java.util.Arrays;
@@ -1393,10 +1394,24 @@ public void testMemo() {
13931394
@Test
13941395
public void testSearchAttributes() {
13951396
if (testEnvironment != null) {
1396-
String testKey = "CustomKeywordField";
1397-
String testValue = "testKeyword";
1397+
String testKeyString = "CustomKeywordField";
1398+
String testValueString = "testKeyword";
1399+
String testKeyInteger = "CustomIntField";
1400+
Integer testValueInteger = 1;
1401+
String testKeyDateTime = "CustomDateTimeField";
1402+
LocalDateTime testValueDateTime = LocalDateTime.now();
1403+
String testKeyBool = "CustomBoolField";
1404+
Boolean testValueBool = true;
1405+
String testKeyDouble = "CustomDoubleField";
1406+
Double testValueDouble = 1.23;
1407+
1408+
// add more type to test
13981409
Map<String, Object> searchAttr = new HashMap<>();
1399-
searchAttr.put(testKey, testValue);
1410+
searchAttr.put(testKeyString, testValueString);
1411+
searchAttr.put(testKeyInteger, testValueInteger);
1412+
searchAttr.put(testKeyDateTime, testValueDateTime);
1413+
searchAttr.put(testKeyBool, testValueBool);
1414+
searchAttr.put(testKeyDouble, testValueDouble);
14001415

14011416
startWorkerFor(TestMultiargsWorkflowsImpl.class);
14021417
WorkflowOptions workflowOptions =
@@ -1411,10 +1426,36 @@ public void testSearchAttributes() {
14111426
HistoryEvent startEvent = historyResp.history.getEvents().get(0);
14121427
SearchAttributes searchAttrFromEvent =
14131428
startEvent.workflowExecutionStartedEventAttributes.getSearchAttributes();
1414-
byte[] searchAttrBytes = searchAttrFromEvent.getIndexedFields().get(testKey).array();
1415-
String searchAttrRetrieved =
1416-
JsonDataConverter.getInstance().fromData(searchAttrBytes, String.class, String.class);
1417-
assertEquals(testValue, searchAttrRetrieved);
1429+
1430+
byte[] searchAttrStringBytes =
1431+
searchAttrFromEvent.getIndexedFields().get(testKeyString).array();
1432+
String retrievedString =
1433+
JsonDataConverter.getInstance()
1434+
.fromData(searchAttrStringBytes, String.class, String.class);
1435+
assertEquals(testValueString, retrievedString);
1436+
byte[] searchAttrIntegerBytes =
1437+
searchAttrFromEvent.getIndexedFields().get(testKeyInteger).array();
1438+
Integer retrievedInteger =
1439+
JsonDataConverter.getInstance()
1440+
.fromData(searchAttrIntegerBytes, Integer.class, Integer.class);
1441+
assertEquals(testValueInteger, retrievedInteger);
1442+
byte[] searchAttrDateTimeBytes =
1443+
searchAttrFromEvent.getIndexedFields().get(testKeyDateTime).array();
1444+
LocalDateTime retrievedDateTime =
1445+
JsonDataConverter.getInstance()
1446+
.fromData(searchAttrDateTimeBytes, LocalDateTime.class, LocalDateTime.class);
1447+
assertEquals(testValueDateTime, retrievedDateTime);
1448+
byte[] searchAttrBoolBytes = searchAttrFromEvent.getIndexedFields().get(testKeyBool).array();
1449+
Boolean retrievedBool =
1450+
JsonDataConverter.getInstance()
1451+
.fromData(searchAttrBoolBytes, Boolean.class, Boolean.class);
1452+
assertEquals(testValueBool, retrievedBool);
1453+
byte[] searchAttrDoubleBytes =
1454+
searchAttrFromEvent.getIndexedFields().get(testKeyDouble).array();
1455+
Double retrievedDouble =
1456+
JsonDataConverter.getInstance()
1457+
.fromData(searchAttrDoubleBytes, Double.class, Double.class);
1458+
assertEquals(testValueDouble, retrievedDouble);
14181459
}
14191460
}
14201461

0 commit comments

Comments
 (0)