Skip to content

Commit b495d4f

Browse files
llingllinggit
authored andcommitted
#1296 modify the unit test
1 parent 7c00171 commit b495d4f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

marklogic-client-api/src/test/java/com/marklogic/client/test/dataservices/BulkIOEndpointTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ public void testInputOutputCallerImpl() throws IOException {
118118
InputOutputCaller.on(IOTestUtil.db, new JacksonHandle(apiObj), new InputStreamHandle(), new InputStreamHandle()
119119
);
120120

121+
IOEndpoint.CallContext callContext = endpoint.newCallContext()
122+
.withEndpointStateAs(endpointState)
123+
.withEndpointConstantsAs(endpointConstants);
121124
InputOutputCaller.BulkInputOutputCaller<InputStream, InputStream> bulkCaller =
122-
endpoint.bulkCaller(endpoint.newCallContext()
123-
.withEndpointStateAs(endpointState)
124-
.withEndpointConstantsAs(endpointConstants));
125+
endpoint.bulkCaller(callContext);
125126
bulkCaller.setOutputListener(value -> {
126127
String v = NodeConverter.InputStreamToString(value);
127128
// System.out.println("received: "+v);
@@ -134,7 +135,7 @@ public void testInputOutputCallerImpl() throws IOException {
134135
});
135136
bulkCaller.awaitCompletion();
136137

137-
ObjectNode finalState = mapper.readValue(bulkCaller.getEndpointState(), ObjectNode.class);
138+
ObjectNode finalState = mapper.readValue(callContext.getEndpointState().get(), ObjectNode.class);
138139

139140
assertEquals("mismatch between input and output size", input.size(), output.size());
140141
assertEquals("mismatch between input and output elements", input, output);
@@ -187,25 +188,25 @@ public void testInputOutputCallerImplAnyDoc() throws IOException {
187188
Set<String> output = new HashSet<>();
188189
InputOutputCaller<StringHandle, StringHandle> endpoint =
189190
InputOutputCaller.onHandles(IOTestUtil.db, new JacksonHandle(apiObj), new StringHandle(), new StringHandle());
190-
191+
IOEndpoint.CallContext callContext = endpoint.newCallContext()
192+
.withEndpointStateAs(endpointState)
193+
.withEndpointConstantsAs(endpointConstants);
191194
InputOutputCaller.BulkInputOutputCaller<StringHandle, StringHandle> bulkCaller =
192-
endpoint.bulkCaller(endpoint.newCallContext()
193-
.withEndpointStateAs(endpointState)
194-
.withEndpointConstantsAs(endpointConstants));
195+
endpoint.bulkCaller(callContext);
195196
bulkCaller.setOutputListener(value -> {
196197
String v = value.toString();
197-
System.out.println("received: "+v);
198+
//System.out.println("received: "+v);
198199
output.add(v);
199200
});
200201

201202
input.stream().forEach(value -> {
202-
System.out.println("adding "+value);
203+
//System.out.println("adding "+value);
203204
bulkCaller.accept(new StringHandle(value).withFormat(Format.JSON));
204205
});
205206

206207
bulkCaller.awaitCompletion();
207208

208-
ObjectNode finalState = mapper.readValue(bulkCaller.getEndpointState(), ObjectNode.class);
209+
ObjectNode finalState = mapper.readValue(callContext.getEndpointState().get(), ObjectNode.class);
209210

210211
assertEquals("mismatch between input and output size", input.size(), output.size());
211212
assertEquals("mismatch between input and output elements", input, output);
@@ -223,10 +224,10 @@ public void testInputOutputCallerImplAnyDoc() throws IOException {
223224
assertTrue("final max not number", finalMax.isNumber());
224225
assertEquals("mismatch on final max", workMax, finalMax.asInt());
225226

226-
// JsonNode sessionCounter = finalState.get("sessionCounter");
227-
// assertNotNull("null final sessionCounter", sessionCounter);
228-
// assertTrue("final sessionCounter not number", sessionCounter.isNumber());
229-
// assertEquals("mismatch on final sessionCounter", callCount - 1, sessionCounter.asInt());
227+
JsonNode sessionCounter = finalState.get("sessionCounter");
228+
assertNotNull("null final sessionCounter", sessionCounter);
229+
assertTrue("final sessionCounter not number", sessionCounter.isNumber());
230+
assertEquals("mismatch on final sessionCounter", callCount - 1, sessionCounter.asInt());
230231

231232
IOTestUtil.modMgr.delete(scriptPath, apiPath);
232233
}

marklogic-client-api/src/test/resources/dataservices/bulkIOAnyDocumentInputOutputCaller.sjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ var input; // jsonDocument*
55

66
const inputCount = fn.count(input);
77

8+
const callCounter = fn.head(xdmp.getSessionField('counter', 0));
9+
xdmp.setSessionField('counter', callCounter + 1);
10+
811
const work = fn.head(xdmp.fromJSON(endpointConstants));
912

1013
const state = fn.head(xdmp.fromJSON(endpointState));
1114
state.next = state.next + inputCount;
12-
15+
state.sessionCounter = callCounter;
1316
state.workMax = work.max;
1417

18+
// workaround for bug 53438
1519
const inputs =
1620
(input instanceof Sequence) ? input.toArray().map(item => fn.head(xdmp.fromJSON(item))) :
1721
(input instanceof Document) ? [fn.head(xdmp.fromJSON(input))] :

0 commit comments

Comments
 (0)