Search in sources :

Example 1 with LazyConnection

use of org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection in project wildfly by wildfly.

the class LazyAssociationLocalTransactionTestCase method testTwoConnectionsWithoutEnlistment.

/**
     * Two connections - one managed connection - without enlistment
     *
     * @throws Throwable Thrown if case of an error
     */
@Test
public void testTwoConnectionsWithoutEnlistment() throws Throwable {
    assertNotNull(lcf);
    assertNotNull(userTransaction);
    boolean status = true;
    userTransaction.begin();
    LazyConnection lc1 = null;
    LazyConnection lc2 = null;
    try {
        lc1 = lcf.getConnection();
        assertTrue(lc1.isManagedConnectionSet());
        logger.trace("testTwoConnectionsWithoutEnlistment: Before 2nd getConnection");
        lc2 = lcf.getConnection();
        assertTrue(lc2.isManagedConnectionSet());
        assertFalse(lc1.isManagedConnectionSet());
        logger.trace("testTwoConnectionsWithoutEnlistment: Before closeManagedConnection");
        assertTrue(lc2.closeManagedConnection());
        assertFalse(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
        logger.trace("testTwoConnectionsWithoutEnlistment: Before associate");
        assertTrue(lc1.associate());
        assertTrue(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
        logger.infof("testTwoConnectionsWithoutEnlistment: After associate");
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        status = false;
        fail("Throwable:" + t.getMessage());
    } finally {
        if (lc1 != null) {
            lc1.close();
        }
        if (lc2 != null) {
            lc2.close();
        }
        if (status) {
            userTransaction.commit();
        } else {
            userTransaction.rollback();
        }
    }
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) Test(org.junit.Test)

Example 2 with LazyConnection

use of org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection in project wildfly by wildfly.

the class LazyAssociationLocalTransactionTestCase method testTwoConnectionsWithEnlistment.

/**
     * Two connections - one managed connection - with enlistment
     *
     * @throws Throwable Thrown if case of an error
     */
@Test
public void testTwoConnectionsWithEnlistment() throws Throwable {
    assertNotNull(lcf);
    assertNotNull(userTransaction);
    boolean status = true;
    userTransaction.begin();
    LazyConnection lc1 = null;
    LazyConnection lc2 = null;
    try {
        lc1 = lcf.getConnection();
        assertTrue(lc1.isManagedConnectionSet());
        assertFalse(lc1.isEnlisted());
        assertTrue(lc1.enlist());
        assertTrue(lc1.isEnlisted());
        lc2 = lcf.getConnection();
        assertTrue(lc2.isManagedConnectionSet());
        assertFalse(lc1.isManagedConnectionSet());
        assertTrue(lc2.closeManagedConnection());
        assertFalse(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
        assertTrue(lc1.associate());
        assertTrue(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        status = false;
        fail("Throwable:" + t.getMessage());
    } finally {
        if (lc1 != null) {
            lc1.close();
        }
        if (lc2 != null) {
            lc2.close();
        }
        if (status) {
            userTransaction.commit();
        } else {
            userTransaction.rollback();
        }
    }
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) Test(org.junit.Test)

Example 3 with LazyConnection

use of org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection in project wildfly by wildfly.

the class ResourceAdapterCapacityPoliciesTestCase method testNonDefaultDecrementerAndIncrementer.

/**
     * Test pool with
     * org.jboss.jca.core.connectionmanager.pool.capacity.MinPoolSizeDecrementer
     * org.jboss.jca.core.connectionmanager.pool.capacity.MaxPoolSizeIncrementer"
     *
     * @throws Exception
     */
@Test
public void testNonDefaultDecrementerAndIncrementer() throws Exception {
    checkStatistics(5, 0, 0, 0);
    LazyConnection[] connections = new LazyConnection[4];
    connections[0] = lcf.getConnection();
    // sometimes InUseCount is 2 and AvailableCount is 3 when statistics are checked right after
    // ds.getConnection, hence this sleep. I guess it's caused by CapacityFiller
    Thread.sleep(50);
    checkStatistics(4, 1, 5, 0);
    connections[1] = lcf.getConnection();
    checkStatistics(3, 2, 5, 0);
    connections[2] = lcf.getConnection();
    checkStatistics(2, 3, 5, 0);
    connections[3] = lcf.getConnection();
    checkStatistics(1, 4, 5, 0);
    for (int i = 0; i < 4; i++) {
        LazyConnection c = connections[i];
        c.close();
    }
    ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(lcf);
    JcaTestsUtil.callRemoveIdleConnections(mcp);
    checkStatistics(5, 0, 2, 3);
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) ManagedConnectionPool(org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool) Test(org.junit.Test)

Example 4 with LazyConnection

use of org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection in project wildfly by wildfly.

the class LazyAssociationXATransactionTestCase method testTwoConnectionsWithoutEnlistment.

/**
     * Two connections - one managed connection - without enlistment
     *
     * @throws Throwable Thrown if case of an error
     */
@Test
public void testTwoConnectionsWithoutEnlistment() throws Throwable {
    assertNotNull(lcf);
    assertNotNull(userTransaction);
    boolean status = true;
    userTransaction.begin();
    LazyConnection lc1 = null;
    LazyConnection lc2 = null;
    try {
        lc1 = lcf.getConnection();
        assertTrue(lc1.isManagedConnectionSet());
        lc2 = lcf.getConnection();
        assertTrue(lc2.isManagedConnectionSet());
        assertFalse(lc1.isManagedConnectionSet());
        assertTrue(lc2.closeManagedConnection());
        assertFalse(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
        assertTrue(lc1.associate());
        assertTrue(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        status = false;
        fail("Throwable:" + t.getMessage());
    } finally {
        if (lc1 != null) {
            lc1.close();
        }
        if (lc2 != null) {
            lc2.close();
        }
        if (status) {
            userTransaction.commit();
        } else {
            userTransaction.rollback();
        }
    }
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) Test(org.junit.Test)

Example 5 with LazyConnection

use of org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection in project wildfly by wildfly.

the class LazyAssociationXATransactionTestCase method testTwoConnectionsWithEnlistment.

/**
     * Two connections - one managed connection - with enlistment
     *
     * @throws Throwable Thrown if case of an error
     */
@Test
public void testTwoConnectionsWithEnlistment() throws Throwable {
    assertNotNull(lcf);
    assertNotNull(userTransaction);
    boolean status = true;
    userTransaction.begin();
    LazyConnection lc1 = null;
    LazyConnection lc2 = null;
    try {
        lc1 = lcf.getConnection();
        assertTrue(lc1.isManagedConnectionSet());
        assertFalse(lc1.isEnlisted());
        assertTrue(lc1.enlist());
        assertTrue(lc1.isEnlisted());
        lc2 = lcf.getConnection();
        assertTrue(lc2.isManagedConnectionSet());
        assertFalse(lc1.isManagedConnectionSet());
        assertTrue(lc2.closeManagedConnection());
        assertFalse(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
        assertTrue(lc1.associate());
        assertTrue(lc1.isManagedConnectionSet());
        assertFalse(lc2.isManagedConnectionSet());
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        status = false;
        fail("Throwable:" + t.getMessage());
    } finally {
        if (lc1 != null) {
            lc1.close();
        }
        if (lc2 != null) {
            lc2.close();
        }
        if (status) {
            userTransaction.commit();
        } else {
            userTransaction.rollback();
        }
    }
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) Test(org.junit.Test)

Aggregations

LazyConnection (org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection)12 Test (org.junit.Test)12 ResourceException (javax.resource.ResourceException)1 ManagedConnectionPool (org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool)1