forked from mulesoft/mule-db-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't release the connection until LOB streams are read (mulesoft#372)
* When Select() page results are processed async, then close connection on flow end to be able to read LOB streams * Added mUnit test for LOB streams kept open * Ignore mUnits without a proper started DB instance
- Loading branch information
1 parent
13c2fe7
commit 0e0f82c
Showing
9 changed files
with
237 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
|
||
package org.mule.extension.db; | ||
|
||
import java.util.Properties; | ||
|
||
public class DbMunitUtils { | ||
|
||
private static final String DEFAULT_PORT = "100"; | ||
|
||
public static boolean isTestIgnored(String dbName) { | ||
Properties availableProperties = System.getProperties(); | ||
|
||
return !availableProperties.containsKey(dbName); | ||
} | ||
|
||
public static String getDbPort(String dbName) { | ||
Properties availableProperties = System.getProperties(); | ||
String port = String.format("%s.db.port", dbName); | ||
|
||
return availableProperties.containsKey(port) ? availableProperties.getProperty(port) : DEFAULT_PORT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" | ||
xmlns:db="http://www.mulesoft.org/schema/mule/db" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:batch="http://www.mulesoft.org/schema/mule/batch" | ||
xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools" | ||
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation=" | ||
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd | ||
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd | ||
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd | ||
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd | ||
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd | ||
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd"> | ||
<db:config name="oracleDbConfigWithoutPoolingProfile"> | ||
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getDbPort('oracle')]" instance="ORCLCDB" user="SYSTEM" password="Oradoc_db1"> | ||
</db:oracle-connection> | ||
</db:config> | ||
</mule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" | ||
xmlns:db="http://www.mulesoft.org/schema/mule/db" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:batch="http://www.mulesoft.org/schema/mule/batch" | ||
xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools" | ||
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation=" | ||
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd | ||
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd | ||
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd | ||
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd | ||
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd | ||
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd"> | ||
<munit:config name="SelectTestCase.xml" /> | ||
|
||
<munit:before-test name="createATableWithLOBs"> | ||
<try> | ||
<db:execute-script config-ref="oracleDbConfigWithoutPoolingProfile"> | ||
<db:sql><![CDATA[DROP TABLE LOBTEST]]></db:sql> | ||
</db:execute-script> | ||
<error-handler> | ||
<on-error-continue enableNotifications="true" logException="false"> | ||
</on-error-continue> | ||
</error-handler> | ||
</try> | ||
<db:execute-ddl config-ref="oracleDbConfigWithoutPoolingProfile"> | ||
<db:sql><![CDATA[CREATE TABLE LOBTEST(COL1 number, COL2 BLOB, COL3 CLOB, COL4 NCLOB)]]></db:sql> | ||
</db:execute-ddl> | ||
<foreach collection="#[1 to 3]"> | ||
<db:execute-script config-ref="oracleDbConfigWithoutPoolingProfile"> | ||
<db:sql ><![CDATA[INSERT INTO LOBTEST VALUES (1, hextoraw('453d7a34'), 'CLOB value is here', TO_NCLOB('NCLOB value is here'))]]></db:sql> | ||
</db:execute-script> | ||
</foreach> | ||
</munit:before-test> | ||
|
||
<!-- This test uses a batch job to process the results of the select operation. The select operation returns results | ||
from a table that has LOB columns. On Oracle, these columns are returned as input streams. This test assures | ||
that if there are open streams not yet consumed, the connection will stay open until the flow ends. In this way, | ||
there won't be any "Connection Closed" exception when trying to read the input streams. --> | ||
<munit:test name="whenStreamsAreConsumedAfterPagingProviderIsClosed_ThenNoExceptionIsThrown" ignore="#[java!org::mule::extension::db::DbMunitUtils::isTestIgnored('oracle')]"> | ||
<munit:execution> | ||
<db:select config-ref="oracleDbConfigWithoutPoolingProfile"> | ||
<ee:repeatable-file-store-iterable inMemoryObjects="10" /> | ||
<db:sql>SELECT * FROM LOBTEST</db:sql> | ||
</db:select> | ||
</munit:execution> | ||
|
||
<munit:validation> | ||
<batch:job blockSize="1000" jobName="testJob" maxFailedRecords="0"> | ||
<batch:process-records> | ||
<batch:step name="stepName"> | ||
<batch:aggregator size="100"> | ||
<ee:transform> | ||
<ee:message > | ||
<ee:set-payload ><![CDATA[%dw 2.0 | ||
output application/json | ||
--- | ||
payload]]></ee:set-payload> | ||
</ee:message> | ||
</ee:transform> | ||
<logger level="INFO" message="Aggregator data: #[payload]"/> | ||
</batch:aggregator> | ||
</batch:step> | ||
</batch:process-records> | ||
</batch:job> | ||
</munit:validation> | ||
</munit:test> | ||
|
||
<munit:after-test name="dropTable"> | ||
<try> | ||
<db:execute-script config-ref="oracleDbConfigWithoutPoolingProfile"> | ||
<db:sql><![CDATA[DROP TABLE LOBTEST]]></db:sql> | ||
</db:execute-script> | ||
<error-handler> | ||
<on-error-continue enableNotifications="true" logException="false"> | ||
</on-error-continue> | ||
</error-handler> | ||
</try> | ||
</munit:after-test> | ||
</mule> |