[jbossts-issues] [JBoss JIRA] (JBTM-3005) Add a quickstart showing the Tomcat and DBCP2

Michal Karm Babacek (JIRA) issues at jboss.org
Mon Apr 9 12:17:01 EDT 2018


    [ https://issues.jboss.org/browse/JBTM-3005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13558264#comment-13558264 ] 

Michal Karm Babacek edited comment on JBTM-3005 at 4/9/18 12:16 PM:
--------------------------------------------------------------------

[~zhfeng], do you happen to know what would be needed to make the recovery test run? There seems to be no commit IMHO...

1. I used your [TransactionalDataSourceFactory.java|https://github.com/jbosstm/quickstart/pull/221/files#diff-40c3726cfdb0ae0e4aafae6aa20f9140] in {{tomcat-jta/src/main/java/org/jboss/narayana/tomcat/jta/TransactionalDataSourceFactory.java}} with the modification so as it uses Tomcat's provided packages, see [full diff|http://www.mergely.com/6e5JT6ak/].
2. The packaged tomcat-jta jar is in Tomcat's lib, not in the war so as to avoid classloader issues for the time being...
3. context.xml:
{code}
<!-- Narayana resources -->
<Transaction factory="org.jboss.narayana.tomcat.jta.UserTransactionFactory"/>
<Resource name="TransactionManager" type="javax.transaction.TransactionManager"
          factory="org.jboss.narayana.tomcat.jta.TransactionManagerFactory"/>
<Resource name="TransactionSynchronizationRegistry" type="javax.transaction.TransactionSynchronizationRegistry"
          factory="org.jboss.narayana.tomcat.jta.TransactionSynchronizationRegistryFactory"/>

<!-- Database resources -->
<Resource 
    name="myDataSource"
    uniqueName="myDataSource"
    auth="Container"
    type="org.postgresql.xa.PGXADataSource"
    username="narayana_user"
    user="narayana_user"
    password="narayana_pass"
    url="jdbc:postgresql://127.0.0.1:5432/narayana_db"
    
    portNumber="5432"
    serverName="127.0.0.1"
    databaseName="narayana_db"
    description="Data Source"
    loginTimeout="0"
    factory="org.postgresql.xa.PGXADataSourceFactory"
/>
<Resource
    name="transactionalDataSource"
    uniqueName="transactionalDataSource"
    auth="Container"
    type="javax.sql.DataSource"
    transactionManager="TransactionManager"
    xaDataSource="myDataSource"
    initialSize="20"
    maxWaitMillis="15000"
    maxTotal="75"
    maxIdle="20"
    maxAge="120000"
    testOnBorrow="true"
    validationQuery="select 1"
    factory="org.jboss.narayana.tomcat.jta.TransactionalDataSourceFactory"/>
{code}
4. The test source remains the same: See [verifyRecovery|https://github.com/Karm/narayana/blob/narayana-tomcat-ts/tomcat/tomcat-jta/src/test/java/org/jboss/narayana/tomcat/jta/integration/app/TestExecutor.java#L92:L119]
5. It fails:
{noformat}
$ curl localhost:8080/test/executor/recovery -i
HTTP/1.1 500 

Recovery failed
{noformat}
6. Database trace:
{noformat}
transaction_id:0 LOG:  execute <unnamed>: CREATE TABLE IF NOT EXISTS test (value VARCHAR(100))
transaction_id:0 LOG:  execute <unnamed>: BEGIN
transaction_id:0 LOG:  execute <unnamed>: INSERT INTO test VALUES ('test-entry-17:57:51.360943')
transaction_id:561 LOG:  execute <unnamed>: PREPARE TRANSACTION '131077_AAAAAAAAAAAAAP//fwAAAQAApWFay1tIAAAAMjE=_AAAAAAAAAAAAAP//fwAAAQAApWFay1tIAAAANwAAAAAAAAAA'
transaction_id:0 LOG:  execute <unnamed>: SET extra_float_digits = 3
transaction_id:0 LOG:  execute <unnamed>: SET application_name = 'PostgreSQL JDBC Driver'
transaction_id:0 LOG:  execute <unnamed>: SELECT COUNT(*) FROM test WHERE value='test-entry-17:57:51.360943'
{noformat}
7. Tomcat log (could be more verbose if needed). Note: {{ Verifying TestXAResource methods. Expected=[start, end, prepare, commit], actual=[start, end, prepare]}}
See:
{noformat}
org.apache.tomcat.util.net.SocketWrapperBase.populateReadBuffer Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper at 2a697d24:org.apache.tomcat.util.net.NioChannel at 346c385c:java.nio.channels.SocketChannel[connected local=/127.0.0.1:8080 remote=/127.0.0.1:33094]], Read from buffer: [0]
org.jboss.narayana.tomcat.jta.integration.app.TestExecutor.verifyRecovery Verifying recovery
org.postgresql.jdbc.PgConnection.setAutoCommit   setAutoCommit = false
org.postgresql.jdbc.PgConnection.setAutoCommit   setAutoCommit = true
org.jboss.narayana.tomcat.jta.integration.app.TestExecutor.didRecoveryHappen Verifying TestXAResource methods. Expected=[start, end, prepare, commit], actual=[start, end, prepare]
org.postgresql.Driver.connect Connecting with URL: jdbc:postgresql://127.0.0.1:5432/narayana_db?user=narayana_user&password=narayana_pass&loginTimeout=0
org.postgresql.jdbc.PgConnection.<init> PostgreSQL JDBC Driver 42.2.1
org.postgresql.jdbc.PgConnection.setDefaultFetchSize   setDefaultFetchSize = 0
org.postgresql.jdbc.PgConnection.setPrepareThreshold   setPrepareThreshold = 5
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl Trying to establish a protocol version 3 connection to 127.0.0.1:5432
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl Receive Buffer Size is 530,904
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl Send Buffer Size is 1,313,280
org.postgresql.ds.common.BaseDataSource.getConnection Created a XA-enabled DataSource from PostgreSQL JDBC Driver 42.2.1 for narayana_user at jdbc:postgresql://127.0.0.1:5432/narayana_db?user=narayana_user&password=narayana_pass&loginTimeout=0
org.jboss.narayana.tomcat.jta.integration.app.TestExecutor.didRecoveryHappen Verifying if database entry exists:false
org.apache.tomcat.util.threads.LimitLatch.countDown Counting down[http-nio-8080-exec-29] latch=1
{noformat}


See JBTM-3004 for example on how you could easily setup my Tomcat + Docker PostgresDB environment...

WDYT? Should I rewrite the test? Is the enlist resource used correctly?

Might interest: [~tomjenkinson], [~rmaucher]


was (Author: mbabacek):
[~zhfeng], do you happen to know what would be needed to make the recovery test run? There seems to be no commit IMHO...

1. I used your [TransactionalDataSourceFactory.java|https://github.com/jbosstm/quickstart/pull/221/files#diff-40c3726cfdb0ae0e4aafae6aa20f9140] in {{tomcat-jta/src/main/java/org/jboss/narayana/tomcat/jta/TransactionalDataSourceFactory.java}} with the modification so as it uses Tomcat's provided packages, see [full diff|http://www.mergely.com/6e5JT6ak/].
2. The packaged tomcat-jta jar is in Tomcat's lib, not in the war so as to avoid classloader issues for the time being...
3. context.xml:
{code}
<!-- Narayana resources -->
<Transaction factory="org.jboss.narayana.tomcat.jta.UserTransactionFactory"/>
<Resource name="TransactionManager" type="javax.transaction.TransactionManager"
          factory="org.jboss.narayana.tomcat.jta.TransactionManagerFactory"/>
<Resource name="TransactionSynchronizationRegistry" type="javax.transaction.TransactionSynchronizationRegistry"
          factory="org.jboss.narayana.tomcat.jta.TransactionSynchronizationRegistryFactory"/>

<!-- Database resources -->
<Resource 
    name="myDataSource"
    uniqueName="myDataSource"
    auth="Container"
    type="org.postgresql.xa.PGXADataSource"
    username="narayana_user"
    user="narayana_user"
    password="narayana_pass"
    url="jdbc:postgresql://127.0.0.1:5432/narayana_db"
    
    portNumber="5432"
    serverName="127.0.0.1"
    databaseName="narayana_db"
    description="Data Source"
    loginTimeout="0"
    factory="org.postgresql.xa.PGXADataSourceFactory"
/>
<Resource
    name="transactionalDataSource"
    uniqueName="transactionalDataSource"
    auth="Container"
    type="javax.sql.DataSource"
    transactionManager="TransactionManager"
    xaDataSource="myDataSource"
    initialSize="20"
    maxWaitMillis="15000"
    maxTotal="75"
    maxIdle="20"
    maxAge="120000"
    testOnBorrow="true"
    validationQuery="select 1"
    factory="org.jboss.narayana.tomcat.jta.TransactionalDataSourceFactory"/>
{code}
4. The test source remains the same: See [verifyRecovery|https://github.com/Karm/narayana/blob/narayana-tomcat-ts/tomcat/tomcat-jta/src/test/java/org/jboss/narayana/tomcat/jta/integration/app/TestExecutor.java#L92:L119]
5. It fails:
{noformat}
$ curl localhost:8080/test/executor/recovery -i
HTTP/1.1 500 

Recovery failed
{noformat}
6. Database trace:
{noformat}
transaction_id:0 LOG:  execute <unnamed>: CREATE TABLE IF NOT EXISTS test (value VARCHAR(100))
transaction_id:0 LOG:  execute <unnamed>: BEGIN
transaction_id:0 LOG:  execute <unnamed>: INSERT INTO test VALUES ('test-entry-17:57:51.360943')
transaction_id:561 LOG:  execute <unnamed>: PREPARE TRANSACTION '131077_AAAAAAAAAAAAAP//fwAAAQAApWFay1tIAAAAMjE=_AAAAAAAAAAAAAP//fwAAAQAApWFay1tIAAAANwAAAAAAAAAA'
transaction_id:0 LOG:  execute <unnamed>: SET extra_float_digits = 3
transaction_id:0 LOG:  execute <unnamed>: SET application_name = 'PostgreSQL JDBC Driver'
transaction_id:0 LOG:  execute <unnamed>: SELECT COUNT(*) FROM test WHERE value='test-entry-17:57:51.360943'
{noforamt}
7. Tomcat log (could be more verbose if needed). Note: {{ Verifying TestXAResource methods. Expected=[start, end, prepare, commit], actual=[start, end, prepare]}}
See:
{noformat}
org.apache.tomcat.util.net.SocketWrapperBase.populateReadBuffer Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper at 2a697d24:org.apache.tomcat.util.net.NioChannel at 346c385c:java.nio.channels.SocketChannel[connected local=/127.0.0.1:8080 remote=/127.0.0.1:33094]], Read from buffer: [0]
org.jboss.narayana.tomcat.jta.integration.app.TestExecutor.verifyRecovery Verifying recovery
org.postgresql.jdbc.PgConnection.setAutoCommit   setAutoCommit = false
org.postgresql.jdbc.PgConnection.setAutoCommit   setAutoCommit = true
org.jboss.narayana.tomcat.jta.integration.app.TestExecutor.didRecoveryHappen Verifying TestXAResource methods. Expected=[start, end, prepare, commit], actual=[start, end, prepare]
org.postgresql.Driver.connect Connecting with URL: jdbc:postgresql://127.0.0.1:5432/narayana_db?user=narayana_user&password=narayana_pass&loginTimeout=0
org.postgresql.jdbc.PgConnection.<init> PostgreSQL JDBC Driver 42.2.1
org.postgresql.jdbc.PgConnection.setDefaultFetchSize   setDefaultFetchSize = 0
org.postgresql.jdbc.PgConnection.setPrepareThreshold   setPrepareThreshold = 5
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl Trying to establish a protocol version 3 connection to 127.0.0.1:5432
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl Receive Buffer Size is 530,904
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl Send Buffer Size is 1,313,280
org.postgresql.ds.common.BaseDataSource.getConnection Created a XA-enabled DataSource from PostgreSQL JDBC Driver 42.2.1 for narayana_user at jdbc:postgresql://127.0.0.1:5432/narayana_db?user=narayana_user&password=narayana_pass&loginTimeout=0
org.jboss.narayana.tomcat.jta.integration.app.TestExecutor.didRecoveryHappen Verifying if database entry exists:false
org.apache.tomcat.util.threads.LimitLatch.countDown Counting down[http-nio-8080-exec-29] latch=1
{noformat}


See JBTM-3004 for example on how you could easily setup my Tomcat + Docker PostgresDB environment...

WDYT? Should I rewrite the test? Is the enlist resource used correctly?

Might interest: [~tomjenkinson], [~rmaucher]

> Add a quickstart showing the Tomcat and DBCP2
> ---------------------------------------------
>
>                 Key: JBTM-3005
>                 URL: https://issues.jboss.org/browse/JBTM-3005
>             Project: JBoss Transaction Manager
>          Issue Type: Task
>          Components: Demonstrator
>            Reporter: Amos Feng
>            Assignee: Amos Feng
>             Fix For: 5.next
>
>
> This quickstart needs to show how to use the DBCP2 in Tomcat to support the XA transaction.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jbossts-issues mailing list