Java Code Examples for java.util.concurrent.ConcurrentLinkedDeque#getLast()

The following examples show how to use java.util.concurrent.ConcurrentLinkedDeque#getLast() . 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: DedupCache.java    From eagle with Apache License 2.0 6 votes vote down vote up
private DedupValue updateCount(EventUniq eventEniq) {
    ConcurrentLinkedDeque<DedupValue> dedupValues = events.get(eventEniq);
    if (dedupValues == null || dedupValues.size() <= 0) {
        LOG.warn("{} No dedup values found for {}, cannot update count", this.publishName, eventEniq);
        return null;
    } else {
        DedupValue dedupValue = dedupValues.getLast();
        dedupValue.setCount(dedupValue.getCount() + 1);
        String updateMsg = String.format(
            "%s Update count for dedup key %s, value %s and count %s", this.publishName, eventEniq,
            dedupValue.getStateFieldValue(), dedupValue.getCount());
        if (LOG.isDebugEnabled()) {
            LOG.debug(updateMsg);
        }
        return dedupValue;
    }
}
 
Example 2
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * getLast() returns last element, or throws NSEE if empty
 */
public void testLastElement() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.getLast());
        assertEquals(i, q.pollLast());
    }
    try {
        q.getLast();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekLast());
}
 
Example 3
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * getLast() returns last element, or throws NSEE if empty
 */
public void testLastElement() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.getLast());
        assertEquals(i, q.pollLast());
    }
    try {
        q.getLast();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekLast());
}
 
Example 4
Source File: NoCredentialsTestCase.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 5
Source File: SubjectTestCase.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 6
Source File: CriTestCase.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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();
}