Examples of TestConnection


Examples of org.jboss.test.jca.adapter.TestConnection

   public boolean testUserTxJndi()
   {
      try
      {
         TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext().lookup("java:/JBossTestCF");
         TestConnection tc = (TestConnection)tcf.getConnection();
         UserTransaction ut = (UserTransaction)new InitialContext().lookup("UserTransaction");
         ut.begin();
         boolean result = tc.isInTx();
         log.info("Jndi test, inTx: " + result);
         ut.commit();
         tc.close();
         return result;
      }
      catch (Exception e)
      {
         throw new EJBException(e.getMessage());
View Full Code Here

Examples of org.jboss.test.jca.adapter.TestConnection

   public boolean testUserTxSessionCtx()
   {
      try
      {
         TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext().lookup("java:/JBossTestCF");
         TestConnection tc = (TestConnection)tcf.getConnection();
         UserTransaction ut = ctx.getUserTransaction();
         ut.begin();
         boolean result = tc.isInTx();
         log.info("ctx test, inTx: " + result);
         ut.commit();
         tc.close();
         return result;
      }
      catch (Exception e)
      {
         throw new EJBException(e.getMessage());
View Full Code Here

Examples of org.jboss.test.jca.adapter.TestConnection

         ConnectionFactory cf1 = (ConnectionFactory) ctx.lookup("java:/JBossTestCF");
         ConnectionFactory cf2 = (ConnectionFactory) ctx.lookup("java:/JBossTestCF2");
         Connection c1 = cf1.getConnection();
         try
         {
            TestConnection c2 = (TestConnection) cf2.getConnection();
            try
            {
               c2.setFailInPrepare(true, XAException.XA_RBROLLBACK);
            }
            finally
            {
               c2.close();
            }
         }
         finally
         {
            c1.close();
View Full Code Here

Examples of org.jboss.test.jca.adapter.TestConnection

      try
      {

         InitialContext ctx = new InitialContext();
         ConnectionFactory cf1 = (ConnectionFactory) ctx.lookup("java:/JBossTestCF");
         TestConnection c1 = (TestConnection) cf1.getConnection();
         try
         {
            c1.setFailInCommit(true, XAException.XAER_RMERR);

         }
         finally
         {
            c1.close();
         }

      }
      catch (Exception e)
      {
View Full Code Here

Examples of org.jboss.test.jca.adapter.TestConnection

      log.info("Simulating connection error");
      try
      {
         InitialContext ctx = new InitialContext();
         ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:/JBossTestCF");
         TestConnection c = (TestConnection) cf.getConnection();
         try
         {
            c.simulateConnectionError();
         }
         finally
         {
            c.close();
         }
      }
      catch (Exception e)
      {
         if (e.getMessage().equals("Simulated exception") == false)
View Full Code Here

Examples of org.jboss.test.jca.adapter.TestConnection

      log.info("Simulating connection error with two handles");
      try
      {
         InitialContext ctx = new InitialContext();
         ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:/JBossTestCFByTx");
         TestConnection c1 = (TestConnection) cf.getConnection();
         TestConnection c2 = (TestConnection) cf.getConnection();
         try
         {
            c2.simulateConnectionError();
         }
         finally
         {
            try
            {
               c1.close();
            }
            catch (Throwable ignored)
            {
            }
            try
            {
               c2.close();
            }
            catch (Throwable ignored)
            {
            }
         }
View Full Code Here

Examples of org.jboss.test.jca.jdbc.TestConnection

    * @ejb:interface-method
    * @ejb:transaction type="NotSupported"
    */
   public void testConnectionObtainable()
   {
      TestConnection tc = null;
      try
      {
         DataSource ds = (DataSource) new InitialContext().lookup("java:StatementTestsConnectionDS");
         Connection c = ds.getConnection();
         WrappedConnection wc = (WrappedConnection) c;
         Connection uc = wc.getUnderlyingConnection();
         tc = (TestConnection) Proxy.getInvocationHandler(uc);
         c.close();
         tc.setFail(true);
         int closeCount1 = tc.getClosedCount();
         c = ds.getConnection();
         if (closeCount1 == tc.getClosedCount())
         {
            throw new EJBException("no connections closed!, closedCount: " + closeCount1);
         }
         c.close();
         for (int i = 0; i < 10; i++)
         {

            int closeCount = tc.getClosedCount();
            c = ds.getConnection();
            if (closeCount == tc.getClosedCount())
            {
               throw new EJBException("no connections closed! at iteration: " + i + ", closedCount: " + closeCount);
            }
            c.close();
         }

      }
      catch (SQLException e)
      {
         throw new EJBException(e);
      }
      catch (NamingException e)
      {
         throw new EJBException(e);
      }
      finally
      {
         if (tc != null)
            tc.setFail(false);
      }
   }
View Full Code Here

Examples of org.jboss.test.jca.jdbc.TestConnection

      }
   }
  
   public void testRollbackOnCloseNoTx()
   {
      TestConnection tc = null;
      try
      {
         DataSource ds = (DataSource) new InitialContext().lookup("java:NoTxStatementTestsConnectionDS");
         Connection c = ds.getConnection();
         try
         {
            c.setAutoCommit(false);
            WrappedConnection wc = (WrappedConnection) c;
            Connection uc = wc.getUnderlyingConnection();
            tc = (TestConnection) Proxy.getInvocationHandler(uc);

            try
            {
               c.nativeSQL("ERROR");
            }
            catch (SQLException expected)
            {
            }
         }
         finally
         {
            try
            {
               c.close();
            }
            catch (SQLException ignored)
            {
            }
         }
        
         if (tc.isClosed() == false)
            throw new RuntimeException("Connection was not closed");
         if (tc.isRolledBack() == false)
            throw new RuntimeException("Connection was not rolled back");
      }
      catch (SQLException e)
      {
         throw new EJBException(e);
View Full Code Here

Examples of org.jboss.test.jca.jdbc.TestConnection

      }
   }
  
   public void testRollbackOnCloseManagedTx()
   {
      TestConnection tc = null;
      try
      {
         DataSource ds = (DataSource) new InitialContext().lookup("java:StatementTestsConnectionDS");
         Connection c = ds.getConnection();
         try
         {
            WrappedConnection wc = (WrappedConnection) c;
            Connection uc = wc.getUnderlyingConnection();
            tc = (TestConnection) Proxy.getInvocationHandler(uc);

            try
            {
               c.nativeSQL("ERROR");
            }
            catch (SQLException expected)
            {
            }
         }
         finally
         {
            try
            {
               c.close();
            }
            catch (SQLException ignored)
            {
            }
         }
        
         if (tc.isClosed() == false)
            throw new RuntimeException("Connection was not closed");
         if (tc.isRolledBack() == false)
            throw new RuntimeException("Connection was not rolled back");
      }
      catch (SQLException e)
      {
         throw new EJBException(e);
View Full Code Here

Examples of org.jboss.test.jca.jdbc.TestConnection

      ManagedConnectionPool mcp = new JBossManagedConnectionPool.OnePool(mcf, pp, false, log);
      NoTxConnectionManager noTxn = new NoTxConnectionManager(null, mcp);
      mcp.setConnectionListenerFactory(noTxn);
      Connection conn = (Connection)noTxn.allocateConnection(mcf, null);
      Object proxy = ((WrappedConnection)conn).getUnderlyingConnection();
      TestConnection uc = (TestConnection) Proxy.getInvocationHandler(proxy);
      uc.setFail(true);
     
      try
      {
         conn.createStatement().execute("blah");
        
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.