Java Code Examples for java.util.concurrent.ConcurrentLinkedDeque#getFirst()
The following examples show how to use
java.util.concurrent.ConcurrentLinkedDeque#getFirst() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcurrentLinkedDequeTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * getFirst() returns first element, or throws NSEE if empty */ public void testFirstElement() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.getFirst()); assertEquals(i, q.pollFirst()); } try { q.getFirst(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example 2
Source File: ConcurrentLinkedDequeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * getFirst() returns first element, or throws NSEE if empty */ public void testFirstElement() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.getFirst()); assertEquals(i, q.pollFirst()); } try { q.getFirst(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example 3
Source File: SmokeTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Error * @throws Throwable In case of an error */ @Test @SuppressWarnings("unchecked") public void testError() throws Throwable { assertNotNull(cf); assertNotNull(dr); assertEquals(1, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr.findByJndi("java:/eis/TxLogConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator().next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool)p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>)TestUtils.extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); TxLogConnection c = cf.getConnection(); assertNotNull(c); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>)TestUtils.extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); c.fail(); assertEquals(DESTROYED, cl.getState()); assertEquals(0, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 4
Source File: SmokeTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Close * @throws Throwable In case of an error */ @Test @SuppressWarnings("unchecked") public void testClose() throws Throwable { assertNotNull(cf); assertNotNull(dr); assertEquals(1, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr.findByJndi("java:/eis/TxLogConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator().next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool)p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>)TestUtils.extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); TxLogConnection c = cf.getConnection(); assertNotNull(c); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>)TestUtils.extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); c.close(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 5
Source File: CriTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/ XATx, calls w/ same credentials -> 1 CL * * @throws Throwable In case of an error */ @Test public void testOneCredentialXATxWithTransaction() throws Throwable { assertNotNull(xaTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityXATxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); ut.begin(); UnifiedSecurityConnection c = xaTxCf.getConnection("user", "pwd"); assertNotNull(c); assertEquals("user", c.getUserName()); assertEquals("pwd", c.getPassword()); UnifiedSecurityConnection c1 = xaTxCf.getConnection("user", "pwd"); assertNotNull(c1); assertEquals("user", c1.getUserName()); assertEquals("pwd", c1.getPassword()); assertEquals(1, mcps.size()); assertNotEquals(c, c1); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); c1.close(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); c.close(); ut.commit(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 6
Source File: CriTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/ LocalTx, calls w/ same credentials -> 1 CL * * @throws Throwable In case of an error */ @Test public void testOneCredentialLocalTxWithTransaction() throws Throwable { assertNotNull(localTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityLocalTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); ut.begin(); UnifiedSecurityConnection c = localTxCf.getConnection("user", "pwd"); assertNotNull(c); assertEquals("user", c.getUserName()); assertEquals("pwd", c.getPassword()); UnifiedSecurityConnection c1 = localTxCf.getConnection("user", "pwd"); assertNotNull(c1); assertEquals("user", c1.getUserName()); assertEquals("pwd", c1.getPassword()); assertNotEquals(c, c1); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); c1.close(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); c.close(); ut.commit(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 7
Source File: CriTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/o Tx 2 w/ 2 different credential -> 2 connections -> 2 CLs * * @throws Throwable In case of an error */ @Test public void testTwoCredentialsNoTxWithoutTransaction() throws Throwable { assertNotNull(noTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityNoTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); UnifiedSecurityConnection firstConnection = noTxCf.getConnection("user", "pwd"); assertNotNull(firstConnection); assertEquals("user", firstConnection.getUserName()); assertEquals("pwd", firstConnection.getPassword()); UnifiedSecurityConnection secondConnection = noTxCf.getConnection("user1", "pwd1"); assertNotNull(secondConnection); assertEquals("user1", secondConnection.getUserName()); assertEquals("pwd1", secondConnection.getPassword()); assertNotEquals(firstConnection, secondConnection); assertEquals(2, mcps.size()); Iterator<ManagedConnectionPool> iter = mcps.values().iterator(); ManagedConnectionPool firstMcp = iter.next(); assertNotNull(firstMcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(firstMcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); firstConnection.close(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); ManagedConnectionPool secondMcp = iter.next(); assertNotNull(secondMcp); listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(secondMcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertEquals("user1", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd1", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); secondConnection.close(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(2, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 8
Source File: CriTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/o Tx, 2 calls w/ same credentials * * @throws Throwable In case of an error */ @Test public void testOneCredentialNoTxWithoutTransaction() throws Throwable { assertNotNull(noTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityNoTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); UnifiedSecurityConnection c = noTxCf.getConnection("user", "pwd"); assertNotNull(c); assertEquals("user", c.getUserName()); assertEquals("pwd", c.getPassword()); UnifiedSecurityConnection c1 = noTxCf.getConnection("user", "pwd"); assertNotNull(c1); assertEquals("user", c1.getUserName()); assertEquals("pwd", c1.getPassword()); assertNotEquals(c, c1); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(2, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); c1.close(); assertEquals(FREE, cl.getState()); cl = listeners.getLast(); assertEquals(IN_USE, cl.getState()); assertEquals("user", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getUserName()); assertEquals("pwd", ((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo()).getPassword()); c.close(); assertEquals(FREE, cl.getState()); assertEquals(2, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 9
Source File: SubjectTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/ XATx, calls w/ same credentials -> 1 CL * * @throws Throwable In case of an error */ @Test public void testOneCredentialXATxWithTransaction() throws Throwable { assertNotNull(xaTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityXATxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); ut.begin(); UnifiedSecurityConnection c = xaTxCf.getConnection(); assertNotNull(c); assertEquals("user", c.getUserName()); UnifiedSecurityConnection c1 = xaTxCf.getConnection(); assertNotNull(c1); assertEquals("user", c1.getUserName()); assertEquals(1, mcps.size()); assertNotEquals(c, c1); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertNotNull(cl.getCredential().getSubject()); PasswordCredential firstPC = getPasswordCredential(cl.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); c1.close(); assertEquals(IN_USE, cl.getState()); assertNotNull(cl.getCredential().getSubject()); firstPC = getPasswordCredential(cl.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); c.close(); ut.commit(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 10
Source File: SubjectTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/ LocalTx, calls w/ same credentials -> 1 CL * * @throws Throwable In case of an error */ @Test public void testOneCredentialLocalTxWithTransaction() throws Throwable { assertNotNull(localTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityLocalTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); ut.begin(); UnifiedSecurityConnection c = localTxCf.getConnection(); assertNotNull(c); assertEquals("user", c.getUserName()); UnifiedSecurityConnection c1 = localTxCf.getConnection(); assertNotNull(c1); assertEquals("user", c1.getUserName()); assertEquals(1, mcps.size()); assertNotEquals(c, c1); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertNotNull(cl.getCredential().getSubject()); PasswordCredential firstPC = getPasswordCredential(cl.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); c1.close(); assertEquals(IN_USE, cl.getState()); assertNotNull(cl.getCredential().getSubject()); firstPC = getPasswordCredential(cl.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); c.close(); ut.commit(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 11
Source File: SubjectTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/o Tx 2 w/ 2 different credential -> 2 connections -> 2 CLs * * @throws Throwable In case of an error */ @Test public void testTwoCredentialsNoTxWithoutTransaction() throws Throwable { assertNotNull(noTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityNoTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); UnifiedSecurityConnection firstConnection = noTxCf.getConnection(); assertNotNull(firstConnection); assertEquals("user", firstConnection.getUserName()); defaultSubjectFactory.setUserName("user1"); defaultSubjectFactory.setPassword("pwd1"); UnifiedSecurityConnection secondConnection = noTxCf.getConnection(); assertNotNull(secondConnection); assertEquals("user1", secondConnection.getUserName()); assertEquals(2, mcps.size()); assertNotEquals(firstConnection, secondConnection); Iterator<ManagedConnectionPool> iter = mcps.values().iterator(); ManagedConnectionPool firstMcp = iter.next(); assertNotNull(firstMcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(firstMcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener firstCL = listeners.getFirst(); assertEquals(IN_USE, firstCL.getState()); assertNotNull(firstCL.getCredential().getSubject()); PasswordCredential firstPC = getPasswordCredential(firstCL.getCredential().getSubject()); assertEquals("user1", firstPC.getUserName()); secondConnection.close(); assertEquals(FREE, firstCL.getState()); assertEquals(1, listeners.size()); ManagedConnectionPool secondMcp = iter.next(); assertNotNull(secondMcp); listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(secondMcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener secondCL = listeners.getFirst(); assertEquals(IN_USE, secondCL.getState()); assertNotNull(secondCL.getCredential().getSubject()); firstPC = getPasswordCredential(secondCL.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); firstConnection.close(); assertEquals(FREE, secondCL.getState()); assertEquals(FREE, firstCL.getState()); assertNotEquals(firstCL, secondCL); assertEquals(2, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultSubjectFactory.setUserName("user"); defaultSubjectFactory.setPassword("pwd"); defaultPool.shutdown(); }
Example 12
Source File: SubjectTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * test w/o Tx, 2 calls w/ same credentials * * @throws Throwable In case of an error */ @Test public void testOneCredentialNoTxWithoutTransaction() throws Throwable { assertNotNull(noTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityNoTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); UnifiedSecurityConnection c = noTxCf.getConnection(); assertNotNull(c); assertEquals("user", c.getUserName()); UnifiedSecurityConnection c1 = noTxCf.getConnection(); assertNotNull(c1); assertEquals("user", c1.getUserName()); assertEquals(1, mcps.size()); assertNotEquals(c, c1); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(2, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertNotNull(cl.getCredential().getSubject()); PasswordCredential firstPC = getPasswordCredential(cl.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); c1.close(); assertEquals(FREE, cl.getState()); cl = listeners.getLast(); assertEquals(IN_USE, cl.getState()); assertNotNull(cl.getCredential().getSubject()); firstPC = getPasswordCredential(cl.getCredential().getSubject()); assertEquals("user", firstPC.getUserName()); c.close(); assertEquals(FREE, cl.getState()); assertEquals(2, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 13
Source File: NoCredentialsTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Deployment test w/o Tx * * @throws Throwable In case of an error */ @Test public void testNoTx() throws Throwable { assertNotNull(noTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityNoTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); UnifiedSecurityConnection c = noTxCf.getConnection(); assertNotNull(c); assertNull(c.getUserName()); assertNull(c.getPassword()); UnifiedSecurityConnection c1 = noTxCf.getConnection(); assertNotNull(c1); assertNull(c1.getUserName()); assertNull(c1.getPassword()); assertNotEquals(c, c1); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(2, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertNull(((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo())); c1.close(); assertEquals(FREE, cl.getState()); cl = listeners.getLast(); assertEquals(IN_USE, cl.getState()); assertNull(((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo())); c.close(); assertEquals(FREE, cl.getState()); assertEquals(2, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 14
Source File: NoCredentialsTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Deployment test w/ XATx * * @throws Throwable In case of an error */ @Test public void testXATx() throws Throwable { assertNotNull(xaTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityXATxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); ut.begin(); UnifiedSecurityConnection c = xaTxCf.getConnection(); assertNotNull(c); assertNull(c.getUserName()); assertNull(c.getPassword()); UnifiedSecurityConnection c1 = xaTxCf.getConnection(); assertNotNull(c1); assertNull(c1.getUserName()); assertNull(c1.getPassword()); assertNotEquals(c, c1); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertNull(((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo())); c.close(); c1.close(); ut.commit(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 15
Source File: NoCredentialsTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Deployment test w/ LocalTx * * @throws Throwable In case of an error */ @Test public void testLocalTx() throws Throwable { assertNotNull(localTxCf); assertNotNull(dr); assertEquals(3, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr .findByJndi("java:/eis/UnifiedSecurityLocalTxConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator() .next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); DefaultPool defaultPool = (DefaultPool) p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>) TestUtils .extract(defaultPool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); ut.begin(); UnifiedSecurityConnection c = localTxCf.getConnection(); assertNotNull(c); assertNull(c.getUserName()); assertNull(c.getPassword()); UnifiedSecurityConnection c1 = localTxCf.getConnection(); assertNotNull(c1); assertNull(c1.getUserName()); assertNull(c1.getPassword()); assertNotEquals(c, c1); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>) TestUtils .extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertNull(((UnifiedSecurityCri) cl.getCredential().getConnectionRequestInfo())); c.close(); c1.close(); ut.commit(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps defaultPool.shutdown(); }
Example 16
Source File: SmokeTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Error * @throws Throwable In case of an error */ @Test @SuppressWarnings("unchecked") public void testError() throws Throwable { assertNotNull(cf); assertNotNull(dr); assertEquals(1, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr.findByJndi("java:/eis/TxLogConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator().next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); assertTrue(p.getPool() instanceof StablePool); StablePool stablePool = (StablePool)p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>)TestUtils.extract(stablePool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); TxLogConnection c = cf.getConnection(); assertNotNull(c); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>)TestUtils.extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); c.fail(); assertEquals(DESTROYED, cl.getState()); assertEquals(0, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps stablePool.shutdown(); }
Example 17
Source File: SmokeTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Close * @throws Throwable In case of an error */ @Test @SuppressWarnings("unchecked") public void testClose() throws Throwable { assertNotNull(cf); assertNotNull(dr); assertEquals(1, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr.findByJndi("java:/eis/TxLogConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator().next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); assertTrue(p.getPool() instanceof StablePool); StablePool stablePool = (StablePool)p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>)TestUtils.extract(stablePool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); TxLogConnection c = cf.getConnection(); assertNotNull(c); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>)TestUtils.extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); c.close(); assertEquals(FREE, cl.getState()); assertEquals(1, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps stablePool.shutdown(); }
Example 18
Source File: SharedConnectionTestCase.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * Enlist * @throws Throwable In case of an error */ @Test @SuppressWarnings("unchecked") public void testEnlist() throws Throwable { assertNotNull(cf); assertNotNull(dr); assertNotNull(ut); ut.begin(); assertEquals(1, dr.getDeployments().size()); org.ironjacamar.core.api.deploymentrepository.Deployment d = dr.findByJndi("java:/eis/TxLogConnectionFactory"); assertNotNull(d); org.ironjacamar.core.api.deploymentrepository.ConnectionFactory dcf = d.getConnectionFactories().iterator().next(); assertNotNull(dcf); org.ironjacamar.core.api.deploymentrepository.Pool p = dcf.getPool(); assertNotNull(p); assertTrue(p.getPool() instanceof StablePool); StablePool stablePool = (StablePool)p.getPool(); ConcurrentHashMap<Credential, ManagedConnectionPool> mcps = (ConcurrentHashMap<Credential, ManagedConnectionPool>)TestUtils.extract(stablePool, "pools"); assertNotNull(mcps); assertEquals(0, mcps.size()); TxLogConnection c = cf.getConnection(); assertNotNull(c); assertEquals(1, mcps.size()); ManagedConnectionPool mcp = mcps.values().iterator().next(); assertNotNull(mcp); ConcurrentLinkedDeque<ConnectionListener> listeners = (ConcurrentLinkedDeque<ConnectionListener>)TestUtils.extract(mcp, "listeners"); assertNotNull(listeners); assertEquals(1, listeners.size()); ConnectionListener cl = listeners.getFirst(); assertEquals(IN_USE, cl.getState()); assertTrue(cl.isEnlisted()); // We can enlist() in the same transaction cl.enlist(); CountDownLatch cdl = new CountDownLatch(1); ConnectionListenerRunnable clr = new ConnectionListenerRunnable(cl, ut, cdl); new Thread(clr).start(); cdl.await(); // But not in another assertNotNull(clr.getException()); assertEquals(DESTROY, cl.getState()); c.close(); ut.rollback(); assertEquals(DESTROYED, cl.getState()); assertEquals(0, listeners.size()); assertEquals(1, mcps.size()); // We cheat and shutdown the pool to clear out mcps stablePool.shutdown(); }