Skip to content

Commit 91e1ade

Browse files
committed
fixed #516
1 parent f6bc28b commit 91e1ade

File tree

2 files changed

+137
-50
lines changed

2 files changed

+137
-50
lines changed

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

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -85,58 +85,64 @@ declare function debug:dump-env()
8585

8686
declare function debug:dump-env($name as xs:string?)
8787
{
88-
let $request-path := xdmp:get-request-path()
89-
let $request-path :=
90-
if ($request-path = '/MarkLogic/rest-api/endpoints/resource-service-query.xqy') then
91-
let $params := fn:string-join(
92-
for $f in xdmp:get-request-field-names()[fn:starts-with(., "rs:")]
93-
let $value := xdmp:get-request-field($f)
88+
if (debug:on()) then
89+
let $request-path := xdmp:get-request-path()
90+
let $request-path :=
91+
if ($request-path = '/MarkLogic/rest-api/endpoints/resource-service-query.xqy') then
92+
let $params := fn:string-join(
93+
for $f in xdmp:get-request-field-names()[fn:starts-with(., "rs:")]
94+
let $value := xdmp:get-request-field($f)
95+
return
96+
$f || "=" || fn:string-join($value, ", "),
97+
"&")
9498
return
95-
$f || "=" || fn:string-join($value, ", "),
96-
"&")
97-
return
98-
"/v1/resources/" || xdmp:get-request-field("name") || "?" || $params
99-
else
100-
$request-path
101-
return
102-
debug:log((
103-
"",
104-
"",
105-
"################################################################",
106-
"REQUEST DETAILS:",
107-
"",
108-
if ($name) then
109-
(
110-
" **" || $name || "**",
111-
""
112-
)
113-
else (),
114-
" [" || xdmp:get-request-method() || "] " || $request-path,
115-
"",
116-
" [Headers]",
117-
for $h in xdmp:get-request-header-names()
118-
return
119-
" " || $h || " => " || xdmp:get-request-header($h),
120-
"",
121-
" [Request Params]",
122-
for $p in xdmp:get-request-field-names()[fn:not(fn:starts-with(., "rs:"))]
123-
return
124-
" " || $p || " => " || fn:string-join(xdmp:get-request-field($p), ", "),
125-
let $body := xdmp:get-request-body()
126-
return
127-
if (fn:exists($body)) then
128-
(
129-
"",
130-
" [Body]",
131-
" " || xdmp:describe($body, (), ())
132-
)
99+
"/v1/resources/" || xdmp:get-request-field("name") || "?" || $params
100+
else
101+
$request-path
102+
return
103+
debug:log((
104+
"",
105+
"",
106+
"################################################################",
107+
"REQUEST DETAILS:",
108+
"",
109+
if ($name) then
110+
(
111+
" **" || $name || "**",
112+
""
113+
)
133114
else (),
134-
"",
135-
"################################################################",
136-
"",
137-
"",
138-
""
139-
))
115+
" [" || xdmp:get-request-method() || "] " || $request-path,
116+
"",
117+
" [Headers]",
118+
for $h in xdmp:get-request-header-names()
119+
return
120+
" " || $h || " => " || xdmp:get-request-header($h),
121+
"",
122+
" [Request Params]",
123+
for $p in xdmp:get-request-field-names()[fn:not(fn:starts-with(., "rs:"))]
124+
return
125+
" " || $p || " => " || fn:string-join(xdmp:get-request-field($p), ", "),
126+
let $body :=
127+
try {
128+
xdmp:get-request-body()
129+
}
130+
catch($ex) {()}
131+
return
132+
if (fn:exists($body)) then
133+
(
134+
"",
135+
" [Body]",
136+
" " || xdmp:describe($body, (), ())
137+
)
138+
else (),
139+
"",
140+
"################################################################",
141+
"",
142+
"",
143+
""
144+
))
145+
else ()
140146
};
141147

142148
declare function debug:dump-map($m as map:map)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.marklogic.hub;
2+
3+
import com.marklogic.client.datamovement.DataMovementManager;
4+
import com.marklogic.client.datamovement.WriteBatcher;
5+
import com.marklogic.client.document.ServerTransform;
6+
import com.marklogic.client.io.StringHandle;
7+
import com.marklogic.hub.flow.CodeFormat;
8+
import com.marklogic.hub.flow.DataFormat;
9+
import com.marklogic.hub.flow.FlowType;
10+
import com.marklogic.hub.scaffold.Scaffolding;
11+
import org.junit.Assert;
12+
import org.junit.BeforeClass;
13+
import org.junit.Test;
14+
15+
import java.util.UUID;
16+
17+
import static org.junit.Assert.assertFalse;
18+
19+
public class DebugLibTest extends HubTestBase {
20+
21+
private static final String entityName = "bug-516";
22+
private static final String flowName = "harmonize-go";
23+
24+
private String errorMessage;
25+
private boolean runFlowFailed;
26+
27+
@BeforeClass
28+
public static void setup() {
29+
installHub();
30+
31+
Scaffolding scaffolding = new Scaffolding(PROJECT_PATH, stagingClient);
32+
scaffolding.createFlow(entityName, flowName, FlowType.INPUT, CodeFormat.XQUERY, DataFormat.XML);
33+
34+
getDataHub().installUserModules(true);
35+
}
36+
37+
// testing https://github.com/marklogic-community/marklogic-data-hub/issues/516
38+
// when debugging is enable the debug-lib explodes if http post body is multi-part
39+
@Test
40+
public void testBug516WithDebugging() {
41+
enableDebugging();
42+
run516();
43+
}
44+
45+
// testing https://github.com/marklogic-community/marklogic-data-hub/issues/516
46+
// when debugging is enable the debug-lib explodes if http post body is multi-part
47+
@Test
48+
public void testBug516WithoutDebugging() {
49+
disableDebugging();
50+
run516();
51+
}
52+
53+
private void run516() {
54+
clearDatabases(HubConfig.DEFAULT_STAGING_NAME);
55+
Assert.assertEquals(0, getStagingDocCount());
56+
57+
ServerTransform runFlow = new ServerTransform("run-flow");
58+
runFlow.addParameter("entity-name", entityName);
59+
runFlow.addParameter("flow-name", flowName);
60+
runFlow.addParameter("job-id", UUID.randomUUID().toString());
61+
DataMovementManager dataMovementManager = stagingClient.newDataMovementManager();
62+
runFlowFailed = false;
63+
WriteBatcher batcher = dataMovementManager.newWriteBatcher();
64+
batcher
65+
.withBatchSize(10)
66+
.withThreadCount(4)
67+
.withTransform(runFlow)
68+
.onBatchFailure((batch, failure) -> {
69+
errorMessage = failure.getMessage();
70+
runFlowFailed = true;
71+
});
72+
dataMovementManager.startJob(batcher);
73+
74+
batcher.add("/employee1.xml", new StringHandle(getResource("flow-manager-test/input/employee1.xml")));
75+
batcher.add("/employee2.xml", new StringHandle(getResource("flow-manager-test/input/employee2.xml")));
76+
batcher.flushAndWait();
77+
78+
assertFalse(errorMessage, runFlowFailed);
79+
Assert.assertEquals(2, getStagingDocCount());
80+
}
81+
}

0 commit comments

Comments
 (0)