@Test public void testPasswordConverter() { logger.info("starting persistence converter test"); Citizen citizen = new Citizen(); citizen.setPassword("prova"); try { userTransaction.begin(); entityManager.persist(citizen); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } Citizen citizenFromDB = (Citizen) entityManager.createQuery("from citizen").getSingleResult(); assertEquals("the password is always converted by the converter", "prova", citizenFromDB.getPassword()); assertEquals("this is the password we have in the database", "cHJvdmE=", NEVER_DO_IT); }
/** * Tests annotation literals in a jar archive */ @Test @SuppressWarnings("unchecked") public void testSingleTable() { logger.info("starting single table inheritance test"); Pet pet = new Pet("jackrussell", "dog"); Dog dog = new Dog("mastino", "dog"); try { userTransaction.begin(); entityManager.persist(pet); entityManager.persist(dog); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } List<Pet> petsFromDB = entityManager.createNativeQuery("select * from pet").getResultList(); assertEquals("only the pet table exists", 2, petsFromDB.size()); }
/** * Tests annotation literals in a jar archive */ @Test @SuppressWarnings("unchecked") public void testTablePerClass() { logger.info("starting table per class inheritance test"); Vehicle vehicle = new Vehicle("peugeot", "car"); Car car = new Car("fiat", "car"); try { userTransaction.begin(); entityManager.persist(vehicle); entityManager.persist(car); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } List<Vehicle> vehiclesFromDB = entityManager.createNativeQuery("select * from vehicle").getResultList(); assertEquals("the vehicle table exists", 1, vehiclesFromDB.size()); List<Car> carsFromDB = entityManager.createNativeQuery("select * from car").getResultList(); assertEquals("the car table exists", 1, carsFromDB.size()); }
/** * Tests annotation literals in a jar archive */ @Test @SuppressWarnings("unchecked") public void testJoin() { logger.info("starting joined inheritance event test"); Watch watch = new Watch(); TopicWatch topicWatch = new TopicWatch(); try { userTransaction.begin(); entityManager.persist(watch); entityManager.persist(topicWatch); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } List<Watch> watchesFromDB = entityManager.createNativeQuery("select * from JBP_FORUMS_WATCH").getResultList(); assertEquals("the watch table exists", 2, watchesFromDB.size()); List<TopicWatch> topicWatchesFromDB = entityManager.createNativeQuery("select * from JBP_FORUMS_TOPICSWATCH") .getResultList(); assertEquals("the topic watch table exists", 1, topicWatchesFromDB.size()); }
@Test public void testSearch() { Forum forum = entityManager.find(Forum.class, 0); Poster poster = new Poster("root"); Topic topic = new Topic(forum, TOPIC_TEXT); topic.setPoster(poster); Post post = new Post(topic, POST_TEXT); post.setCreateDate(new Date()); post.setPoster(poster); try { userTransaction.begin(); entityManager.persist(poster); entityManager.persist(topic); entityManager.persist(post); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { e.printStackTrace(); } List<Topic> topics = findTopics(); List<Post> posts = findPosts(); assertEquals("find topics", 1, topics.size()); assertEquals("find posts", 1, posts.size()); }
@Test public void testDeleteManyToMany() { logger.info("starting merge many to many cascade test"); testPersistManyToMany(); try { userTransaction.begin(); Author davide_scala = (Author) entityManager.createQuery("from Author where fullName = :fullName") .setParameter("fullName", "Davide Scala").getSingleResult(); davide_scala.remove(); entityManager.remove(davide_scala); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } @SuppressWarnings("unchecked") List<Book> booksFromDb = entityManager.createNativeQuery("select * from Book").getResultList(); assertEquals("the book table exists", 2, booksFromDb.size()); @SuppressWarnings("unchecked") List<Author> authorsFromDb = entityManager.createNativeQuery("select * from Author").getResultList(); assertEquals("the author table exists", 2, authorsFromDb.size()); @SuppressWarnings("unchecked") List<Author> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_Author").getResultList(); assertEquals("the author table exists", 4, bookAuthorsFromDb.size()); }
@Test public void testDeleteBooksAllManyToMany() { logger.info("starting merge many to many cascade test"); testPersistManyToMany(); try { userTransaction.begin(); PMAuthor davide_scala = (PMAuthor) entityManager.createQuery("from PMAuthor where fullName = :fullName") .setParameter("fullName", "Davide Scala").getSingleResult(); entityManager.remove(davide_scala); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } @SuppressWarnings("unchecked") List<PMBook> booksFromDb = entityManager.createNativeQuery("select * from PMBook").getResultList(); assertEquals("the pm book table exists", 1, booksFromDb.size()); @SuppressWarnings("unchecked") List<PMAuthor> authorsFromDb = entityManager.createNativeQuery("select * from PMAuthor").getResultList(); assertEquals("the pm author table exists", 2, authorsFromDb.size()); @SuppressWarnings("unchecked") List<PMAuthor> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_PM_Author") .getResultList(); assertEquals("the pm book author table exists", 2, bookAuthorsFromDb.size()); }
@Test public void testDeleteBooksJoinTableAllManyToMany() { logger.info("starting merge many to many cascade test"); testPersistManyToMany(); try { userTransaction.begin(); AllAuthor davide_scala = (AllAuthor) entityManager.createQuery("from AllAuthor where fullName = :fullName") .setParameter("fullName", "Davide Scala").getSingleResult(); entityManager.remove(davide_scala); userTransaction.commit(); } catch (NotSupportedException | SystemException | IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | RollbackException e) { fail(); } @SuppressWarnings("unchecked") List<AllBook> booksFromDb = entityManager.createNativeQuery("select * from AllBook").getResultList(); assertEquals("the all book table doesn't exist", 0, booksFromDb.size()); @SuppressWarnings("unchecked") List<AllAuthor> authorsFromDb = entityManager.createNativeQuery("select * from AllAuthor").getResultList(); assertEquals("the all author table doesn't exist", 0, authorsFromDb.size()); @SuppressWarnings("unchecked") List<AllAuthor> bookAuthorsFromDb = entityManager.createNativeQuery("select * from Book_All_Author") .getResultList(); assertEquals("the all book author table exists", 0, bookAuthorsFromDb.size()); }
/** * Tests the fire of the event inside a transaction */ @Test public void testSimpleTransaction() { try { userTransaction.begin(); Bill bill = fire(); assertEquals( "The id generation passes through the always and it is incremented only by inprogess always observer method", 1, bill.getId()); userTransaction.commit(); assertEquals( "The id generation passes through the always and it is incremented only by transactional observer methods", 4, bill.getId()); } catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) { fail("no fail for the transaction"); } }
/** * Tests the fire of the event inside a failed transaction */ @Test public void testFailedTransaction() { Bill bill = null; try { userTransaction.begin(); bill = fire(); assertEquals( "The id generation passes through the always and it is incremented only by inprogess always observer method", 1, bill.getId()); throw new RollbackException(); } catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException e) { try { userTransaction.rollback(); assertEquals( "The id generation passes through the always and it is incremented only by transactional failure observer methods", 3, bill.getId()); } catch (SystemException se) { } } }
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException { try { if (isRollBackOnly) { throw new RollbackException("Commit failed: Transaction marked for rollback"); } } finally { transaction.set(null); } }
private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException { txn = transactionService.getUserTransaction(); txn.begin(); for (UserInfo user : userInfos) { String username = user.getUserName(); NodeRef nodeRef = personService.getPersonOrNull(username); boolean create = nodeRef == null; if (create) { PropertyMap testUser = new PropertyMap(); testUser.put(ContentModel.PROP_USERNAME, username); testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName()); testUser.put(ContentModel.PROP_LASTNAME, user.getLastName()); testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test"); testUser.put(ContentModel.PROP_PASSWORD, "password"); nodeRef = personService.createPerson(testUser); } userNodeRefs.add(nodeRef); // System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef); } txn.commit(); }
@Test public void test_RollbackExceptionHandling_rollbackafterthrown() throws Exception { TransactionManager tm = mockTm(); when(tm.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_MARKED_ROLLBACK); doThrow(new RollbackException().initCause(new OptimisticLockException())).when(tm).commit(); XAJpaTemplate tx = new XAJpaTemplate(emSupplier, tm, coordinator); try { tx.tx(TransactionType.Required, new EmConsumer() { public void accept(EntityManager em) { em.persist(new Object()); } }); } catch (RuntimeException e) { // this is ok } verify(tm, times(5)).getStatus(); verify(tm, times(1)).commit(); verify(tm, times(1)).rollback(); }
public void testPostRollbackCommitDetection() throws Exception { testNoTxnStatus(); txn.begin(); txn.rollback(); try { txn.commit(); fail("Failed to detect rolled back txn"); } catch (RollbackException e) { // expected } checkNoStatusOnThread(); }
public void testPostSetRollbackOnlyCommitDetection() throws Exception { testNoTxnStatus(); txn.begin(); txn.setRollbackOnly(); try { txn.commit(); fail("Failed to detect set rollback"); } catch (RollbackException e) { // expected txn.rollback(); } checkNoStatusOnThread(); }
@Test @DisplayName( "Multiple close test" ) public void multipleCloseTest() throws SQLException { TransactionManager txManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); TransactionSynchronizationRegistry txSyncRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple(); AgroalDataSourceConfigurationSupplier configurationSupplier = new AgroalDataSourceConfigurationSupplier() .connectionPoolConfiguration( cp -> cp .transactionIntegration( new NarayanaTransactionIntegration( txManager, txSyncRegistry ) ) ); try ( AgroalDataSource dataSource = AgroalDataSource.from( configurationSupplier ) ) { // there is a call to connection#close in the try-with-resources block and another on the callback from the transaction#commit() try ( Connection connection = dataSource.getConnection() ) { logger.info( format( "Got connection {0}", connection ) ); try { txManager.begin(); txManager.commit(); } catch ( NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e ) { fail( "Exception: " + e.getMessage() ); } } } }
/** * Configuración inicial de la prueba. * * @generated */ @Before public void configTest() { try { utx.begin(); clearData(); insertData(); utx.commit(); } catch (IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | NotSupportedException | RollbackException | SystemException e) { e.printStackTrace(); try { utx.rollback(); } catch (IllegalStateException | SecurityException | SystemException e1) { e1.printStackTrace(); } } }
/** * Configuración inicial de la prueba. * * @generated */ @Before public void configTest() { try { utx.begin(); clearData(); insertData(); utx.commit(); } catch (IllegalStateException | SecurityException | HeuristicMixedException | HeuristicRollbackException | NotSupportedException | RollbackException | SystemException e) { e.printStackTrace(); try { utx.rollback(); } catch (IllegalStateException | SecurityException | SystemException e1) { e1.printStackTrace(); } } }
@Override public AccountDataBean login(String userID, String password) throws RollbackException { AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); if (profile == null) { throw new EJBException("No such user: " + userID); } entityManager.merge(profile); AccountDataBean account = profile.getAccount(); if (Log.doTrace()) Log.trace("TradeSLSBBean:login", userID, password); account.login(password); if (Log.doTrace()) Log.trace("TradeSLSBBean:login(" + userID + "," + password + ") success" + account); return account; }
public UserTransaction getUserTransaction() { return new UserTransaction() { public void begin() throws NotSupportedException, SystemException { } public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { } public int getStatus() throws SystemException { return TransactionUtil.STATUS_NO_TRANSACTION; } public void rollback() throws IllegalStateException, SecurityException, SystemException { } public void setRollbackOnly() throws IllegalStateException, SystemException { } public void setTransactionTimeout(int i) throws SystemException { } }; }
/** * Test Task for DataSource Hydra test */ public static void testTask() { UserTransaction utx = null; try { Cache cache = CacheHelper.getCache(); Context ctx = cache.getJNDIContext(); utx = (UserTransaction) ctx.lookup("java:/UserTransaction"); Log.getLogWriter().info("Starting Transaction "); utx.begin(); (new JtaDataSourceHydraTest()).doRandomOperation(); utx.commit(); Log.getLogWriter().info("Committed Transaction "); } catch (RollbackException re) { Log.getLogWriter().info("Transaction did not commit successfully, rolled back ", re); } catch (Exception e) { if (utx != null) { try { utx.rollback(); Log.getLogWriter().info("explicitly Rolledback Transaction "); } catch (Exception e1) { throw new TestException("Error in Transaction on rollback in testTask " + TestHelper.getStackTrace(e1)); } } throw new TestException("Error in testTask " + TestHelper.getStackTrace(e)); } }
/** * Test Task for DataSource And Cache Hydra test */ public static void testCacheAndDBTask() { UserTransaction utx = null; try { Cache cache = CacheHelper.getCache(); Context ctx = cache.getJNDIContext(); utx = (UserTransaction) ctx.lookup("java:/UserTransaction"); Log.getLogWriter().info("Starting Transaction "); utx.begin(); (new JtaDataSourceHydraTest()).doRandomCacheAndDBOperation(); utx.commit(); Log.getLogWriter().info("Committed Transaction "); } catch (RollbackException re) { Log.getLogWriter().info("Transaction did not commit successfully, rolled back ", re); } catch (Exception e) { if (utx != null) { try { utx.rollback(); Log.getLogWriter().info("Explicitly Rolledback Transaction "); } catch (Exception e1) { throw new TestException("Error in Transaction on rollback in testTask " + TestHelper.getStackTrace(e1)); } } throw new TestException("Error in testTask " + TestHelper.getStackTrace(e)); } }
public AccountDataBean login(String userID, String password) throws RollbackException { AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); if (profile == null) { throw new EJBException("No such user: " + userID); } entityManager.merge(profile); AccountDataBean account = profile.getAccount(); if (Log.doTrace()) Log.trace("TradeSLSBBean:login", userID, password); account.login(password); if (Log.doTrace()) Log.trace("TradeSLSBBean:login(" + userID + "," + password + ") success" + account); return account; }
protected void invokeTransactionCommitIfNotLocalTransaction(CompensableTransaction compensable) throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { Transaction transaction = compensable.getTransaction(); org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext(); RemoteCoordinator transactionCoordinator = this.beanFactory.getTransactionCoordinator(); TransactionXid transactionXid = transactionContext.getXid(); try { transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS); TransactionContext compensableContext = compensable.getTransactionContext(); logger.error("[{}] jta-transaction in try-phase cannot be xa transaction.", ByteUtils.byteArrayToString(compensableContext.getXid().getGlobalTransactionId())); transactionCoordinator.rollback(transactionXid); throw new HeuristicRollbackException(); } catch (XAException xaEx) { transactionCoordinator.forgetQuietly(transactionXid); SystemException sysEx = new SystemException(); sysEx.initCause(xaEx); throw sysEx; } }
public void compensableCommit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { CompensableManager tompensableManager = this.beanFactory.getCompensableManager(); CompensableTransaction compensable = (CompensableTransaction) tompensableManager.getCompensableTransactionQuietly(); if (compensable == null) { throw new IllegalStateException(); } TransactionContext transactionContext = compensable.getTransactionContext(); if (transactionContext.isCoordinator() == false) { throw new IllegalStateException(); } this.invokeCompensableCommit(compensable); }
public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { if (this.transactionStatus == Status.STATUS_ACTIVE) { this.fireCommit(); } else if (this.transactionStatus == Status.STATUS_MARKED_ROLLBACK) { this.fireRollback(); throw new HeuristicRollbackException(); } else if (this.transactionStatus == Status.STATUS_ROLLEDBACK) /* should never happen */ { throw new RollbackException(); } else if (this.transactionStatus == Status.STATUS_COMMITTED) /* should never happen */ { logger.debug("Current transaction has already been committed."); } else { throw new IllegalStateException(); } }
protected void truncateTables(String... tables) { try { utx.begin(); for (String table : tables) { StringBuilder deleteQueryBuilder = new StringBuilder("delete from "); deleteQueryBuilder.append(table); getEm().createQuery(deleteQueryBuilder.toString()).executeUpdate(); } utx.commit(); } catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) { try { utx.rollback(); } catch (IllegalStateException | SecurityException | SystemException e1) { } } }
@Override public void commit() { if (initiatedTransaction) { try { transactionListener.beforeCommit(entities.types()); getUserTransaction().commit(); transactionListener.afterCommit(entities.types()); } catch (RollbackException | SystemException | HeuristicMixedException | HeuristicRollbackException e) { throw new TransactionException(e); } } try { entities.clear(); } finally { close(); } }
@Override public void commit() throws RollbackException, IllegalStateException, SystemException { switch (status) { case Status.STATUS_ACTIVE: if (System.currentTimeMillis() - startTime > timeoutMs) { doRollback(); throw new RollbackException("Transaction is timed out"); } doCommit(); break; case Status.STATUS_MARKED_ROLLBACK: doRollback(); throw new RollbackException("Transaction is marked for rollback"); default: throw new IllegalStateException("Transaction is not active"); } }
@Override @Produces(MediaType.APPLICATION_JSON) public Response toResponse(EJBException exception) { if (exception.getCause() instanceof IllegalArgumentException) { return handleIllegalArgumentException((IllegalArgumentException) exception.getCause()); } else if (exception.getCause() instanceof RollbackException) { return handleRollbackException((RollbackException) exception.getCause()); } else if(exception.getCause() instanceof IllegalStateException) { return handleIllegalStateException((IllegalStateException) exception.getCause()); } else if (exception.getCause() instanceof MessagingException) { return handleMessagingException((MessagingException) exception.getCause()); } else if (exception.getCause() instanceof SecurityException) { return handleSecurityException((SecurityException) exception.getCause()); } LOG.log(Level.INFO, "EJBException Caused by: {0}", exception.getCause().toString()); LOG.log(Level.INFO, "EJBException: {0}", exception.getCause().getMessage()); JsonResponse jsonResponse = new JsonResponse(); jsonResponse.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase()); jsonResponse.setStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); jsonResponse.setErrorMsg(exception.getCause().getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(jsonResponse).build(); }
@Override @Produces(MediaType.APPLICATION_JSON) public Response toResponse(EJBException exception) { if (exception.getCause() instanceof IllegalArgumentException) { return handleIllegalArgumentException((IllegalArgumentException) exception.getCause()); } else if (exception.getCause() instanceof AccessControlException) { return handleAccessControlException((AccessControlException) exception.getCause()); } else if (exception.getCause() instanceof ConstraintViolationException) { return handleConstraintViolation((ConstraintViolationException) exception.getCause()); } else if (exception.getCause() instanceof RollbackException) { return handleRollbackException((RollbackException) exception.getCause()); } else if (exception.getCause() instanceof AccessLocalException) { return handleAccessLocalException((AccessLocalException) exception.getCause()); } else if(exception.getCause() instanceof IllegalStateException) { return handleIllegalStateException((IllegalStateException) exception.getCause()); } LOG.log(Level.INFO, "EJBException Caused by: {0}", exception.getCause().toString()); LOG.log(Level.INFO, "EJBException: {0}", exception.getCause().getMessage()); JsonResponse jsonResponse = new JsonResponse(); jsonResponse.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase()); jsonResponse.setStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); jsonResponse.setErrorMsg(exception.getCause().getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(jsonResponse).build(); }
private Response handleRollbackException(RollbackException pe) { LOG.log(Level.INFO, "RollbackException: {0}", pe.getMessage()); Throwable e = pe; //get to the bottom of this while (e.getCause() != null) { e = e.getCause(); } LOG.log(Level.INFO, "RollbackException Caused by: {0}", e.getMessage()); if (e instanceof ConstraintViolationException) { return handleConstraintViolation((ConstraintViolationException) e); } JsonResponse jsonResponse = new JsonResponse(); jsonResponse.setStatus(Response.Status.BAD_REQUEST.getReasonPhrase()); jsonResponse.setStatusCode(Response.Status.BAD_REQUEST.getStatusCode()); jsonResponse.setErrorMsg(e.getMessage()); return Response.status(Response.Status.BAD_REQUEST).entity(jsonResponse).build(); }
public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException { TransactionImpl global = this.getCurrentTransaction(); TransactionContext transactionContext = global.getTransactionContext(); boolean compensable = transactionContext.isCompensable(); boolean coordinator = transactionContext.isCoordinator(); if (compensable == false) { this.commitRegularTransaction(global); } else if (coordinator) { if (global.isTransactionCompleting()) { global.commitCompleteTransaction(); } else { this.commitGlobalTransaction(global); } } else if (global.isTransactionCompleting()) { global.commitCompleteTransaction(); } else { global.commitTryingTransaction(); } }
@Test public void testNoTX() throws ResourceException, IllegalStateException, RollbackException, SystemException { final UserTransactionManager tm = mock(UserTransactionManager.class); when(tm.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION); BasicTransactionAssistanceFactory f = new BasicTransactionAssistanceFactoryImpl("a"){ @Override protected UserTransactionManager getTM() { return tm; } }; try{ //TEST f.getTransactionAssistant(); fail("no exception"); }catch(ResourceException e){ //OK, expected } }
/** {@inheritDoc} */ @SuppressWarnings("SimplifiableIfStatement") @Override public boolean enlistResource(final XAResource xaRes) throws RollbackException, IllegalStateException, SystemException { if (xaRes == null) return false; // final XAResource res = new IgniteOnePhaseXAResource(xaRes); Object ibmProxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {onePhaseXAResourceCls}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable { return mtd.invoke(xaRes, args); } }); return tx.enlistResource((XAResource)ibmProxy); }
@Override public AccountDataBean login(String userID, String password) throws RollbackException { AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID); if (profile == null) { throw new EJBException("No such user: " + userID); } entityManager.merge(profile); AccountDataBean account = profile.getAccount(); if (Log.doTrace()) { Log.trace("TradeSLSBBean:login", userID, password); } account.login(password); if (Log.doTrace()) { Log.trace("TradeSLSBBean:login(" + userID + "," + password + ") success" + account); } return account; }
/** * This test will publish set of messages through XA transaction and then rollback, then publish another set of * messages. All this time a consumer will be running on the particular Queue, and total of the consumed messages * should be equal to the total number of committed messages. * * @throws JMSConnectorException Error when sending messages through JMS transport connector. * @throws InterruptedException Interruption when thread sleep. * @throws JMSException Error when running the test message consumer. * @throws SystemException XA Transaction exceptions. * @throws NotSupportedException Transaction exceptions. * @throws RollbackException Transaction exceptions. * @throws HeuristicRollbackException Transaction exceptions. * @throws HeuristicMixedException Transaction exceptions. * @throws NoSuchFieldException Error when accessing the private field. * @throws IllegalAccessException Error when accessing the private field. */ @Test(groups = "jmsSending", description = "XA transacted queue sending tested case") public void queueSendingTestCase() throws JMSConnectorException, InterruptedException, JMSException, SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException, NoSuchFieldException, IllegalAccessException { // Run message consumer and publish messages performPublishAndConsume(jmsClientConnectorQueue, xaQueueName, false); JMSTestUtils.closeResources((JMSClientConnectorImpl) jmsClientConnectorQueue); Assert.assertEquals(receivedMsgCount, 5, "XA transacted queue sender expected message count " + 5 + " , received message count " + receivedMsgCount); }
/** * This test will publish set of messages through XA transaction and then rollback, then publish another set of * messages. All this time a consumer will be running on the particular Topic, and total of the consumed messages * should be equal to the total number of committed messages. * * @throws JMSConnectorException Error when sending messages through JMS transport connector. * @throws InterruptedException Interruption when thread sleep. * @throws JMSException Error when running the test message consumer. * @throws SystemException XA Transaction exceptions. * @throws NotSupportedException Transaction exceptions. * @throws RollbackException Transaction exceptions. * @throws HeuristicRollbackException Transaction exceptions. * @throws HeuristicMixedException Transaction exceptions. * @throws NoSuchFieldException Error when accessing the private field. * @throws IllegalAccessException Error when accessing the private field. */ @Test(groups = "jmsSending", description = "XA transacted topic sending tested case") public void topicSendingTestCase() throws JMSConnectorException, InterruptedException, JMSException, SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException, NoSuchFieldException, IllegalAccessException { // Run message consumer and publish messages performPublishAndConsume(jmsClientConnectorTopic, xaTopicName, true); JMSTestUtils.closeResources((JMSClientConnectorImpl) jmsClientConnectorTopic); Assert.assertEquals(receivedMsgCount, 5, "XA transacted topic sender expected message count " + 5 + " , received message count " + receivedMsgCount); }