Skip to content

Commit b848a18

Browse files
committed
fixed #235 - exception when writer has error
1 parent c7e6e91 commit b848a18

File tree

17 files changed

+258
-12
lines changed

17 files changed

+258
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.gradle/
33
.settings/
44
.metadata/
5+
.idea/
56
marklogic-data-hub/bin/
67
quick-start/bin/
78
build/

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,9 @@ declare function flow:run-flow(
517517
{
518518
let $envelope := flow:run-plugins($flow, $identifier, $content, $options)
519519
let $_ :=
520-
xdmp:invoke-function(function() {
521-
for $writer in $flow/hub:writer
522-
return
523-
flow:run-writer($writer, $identifier, $envelope, $flow/hub:type, $options)
524-
},
525-
map:new((
526-
map:entry("isolation", "different-transaction"),
527-
map:entry("database", xdmp:database($config:FINAL-DATABASE)),
528-
map:entry("transactionMode", "update-auto-commit")
529-
)))
520+
for $writer in $flow/hub:writer
521+
return
522+
flow:run-writer($writer, $identifier, $envelope, $flow/hub:type, $options)
530523
let $_ := trace:write-trace()
531524
return
532525
()
@@ -739,7 +732,14 @@ declare function flow:run-writer(
739732
let $before := xdmp:elapsed-time()
740733
let $resp :=
741734
try {
742-
$func($identifier, $envelope, $options)
735+
xdmp:invoke-function(function() {
736+
$func($identifier, $envelope, $options)
737+
},
738+
map:new((
739+
map:entry("isolation", "different-transaction"),
740+
map:entry("database", xdmp:database($config:FINAL-DATABASE)),
741+
map:entry("transactionMode", "update-auto-commit")
742+
)))
743743
}
744744
catch($ex) {
745745
xdmp:log(xdmp:describe($ex, (), ())),

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/trace-lib.xqy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare function trace:enable-tracing($enabled as xs:boolean)
4747

4848
declare function trace:enabled() as xs:boolean
4949
{
50-
let $value := cts:element-values(xs:QName("trace:is-tracing-enabled"), (), "limit=1")
50+
let $value := cts:element-values(xs:QName("trace:is-tracing-enabled"), (), ("type=unsignedInt","limit=1"))
5151
return
5252
if ($value) then
5353
$value eq 1

marklogic-data-hub/src/test/java/com/marklogic/hub/TracingTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ public void runXMLErrorFlowWithoutTracing() {
159159
assertEquals(1, getTracingDocCount());
160160
}
161161

162+
@Test
163+
public void runXMLWriterErrorFlowWithoutTracing() {
164+
assertEquals(0, getFinalDocCount());
165+
assertEquals(0, getTracingDocCount());
166+
167+
Tracing t = new Tracing(stagingClient);
168+
assertFalse(t.isEnabled());
169+
170+
FlowManager fm = new FlowManager(stagingClient);
171+
Flow flow = fm.getFlow("trace-entity", "tracemeXMLWriterError");
172+
173+
JobFinishedListener listener = new JobFinishedListener();
174+
fm.runFlow(flow, 10, listener);
175+
listener.waitForFinish();
176+
177+
assertEquals(0, getFinalDocCount());
178+
assertEquals(1, getTracingDocCount());
179+
}
180+
162181
@Test
163182
public void runJSONErrorFlowWithoutTracing() {
164183
assertEquals(0, getFinalDocCount());
@@ -179,4 +198,22 @@ public void runJSONErrorFlowWithoutTracing() {
179198
}
180199

181200

201+
@Test
202+
public void runJSONWriterErrorFlowWithoutTracing() {
203+
assertEquals(0, getFinalDocCount());
204+
assertEquals(0, getTracingDocCount());
205+
206+
Tracing t = new Tracing(stagingClient);
207+
assertFalse(t.isEnabled());
208+
209+
FlowManager fm = new FlowManager(stagingClient);
210+
Flow flow = fm.getFlow("trace-entity", "tracemeJSONWriterError");
211+
212+
JobFinishedListener listener = new JobFinishedListener();
213+
fm.runFlow(flow, 10, listener);
214+
listener.waitForFinish();
215+
216+
assertEquals(0, getFinalDocCount());
217+
assertEquals(1, getTracingDocCount());
218+
}
182219
}

marklogic-data-hub/src/test/resources/flow-manager-test/my-test-flow-with-all/writer/writer-with-error.xqy

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Collect IDs plugin
3+
*
4+
* @param options - a map containing options. Options are sent from Java
5+
*
6+
* @return - an array of ids or uris
7+
*/
8+
function collect(options) {
9+
return ['1', '2', '3', '4', '5'];
10+
}
11+
12+
module.exports = {
13+
collect: collect
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Create Content Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param options - an object containing options. Options are sent from Java
6+
*
7+
* @return - your content
8+
*/
9+
function createContent(id, options) {
10+
return {
11+
id: id
12+
};
13+
}
14+
15+
module.exports = {
16+
createContent: createContent
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Create Headers Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param content - the output of your content plugin
6+
* @param options - an object containing options. Options are sent from Java
7+
*
8+
* @return - an object of headers
9+
*/
10+
function createHeaders(id, content, options) {
11+
return { id: id };
12+
}
13+
14+
module.exports = {
15+
createHeaders: createHeaders
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" ?>
2+
<flow xmlns="http://marklogic.com/data-hub">
3+
<complexity>simple</complexity>
4+
<data-format>application/json</data-format>
5+
<plugins></plugins>
6+
</flow>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Create Triples Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param content - the output of your content plugin
6+
* @param headers - the output of your heaaders plugin
7+
* @param options - an object containing options. Options are sent from Java
8+
*
9+
* @return - an array of triples
10+
*/
11+
function createTriples(id, content, headers, options) {
12+
return [];
13+
}
14+
15+
module.exports = {
16+
createTriples: createTriples
17+
};
18+

0 commit comments

Comments
 (0)