activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbert...@apache.org
Subject [35/42] activemq-artemis git commit: ARTEMIS-463 Refactoring on Openwire https://issues.apache.org/jira/browse/ARTEMIS-463
Date Mon, 04 Apr 2016 16:09:44 GMT
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ddf486f/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java
index c4aea03..b87fc7d 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.tests.integration.openwire;
 
 import javax.jms.Connection;
 import javax.jms.Destination;
+import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
@@ -26,27 +27,24 @@ import javax.jms.Session;
 import javax.jms.TemporaryQueue;
 import javax.jms.TemporaryTopic;
 import javax.jms.TextMessage;
-import javax.jms.XAConnection;
-import javax.jms.XASession;
-import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
-import java.util.Collection;
-import java.util.LinkedList;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.ActiveMQSession;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
-import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 public class SimpleOpenWireTest extends BasicOpenWireTest {
 
+   @Rule
+   public ExpectedException thrown = ExpectedException.none();
+
    @Override
    @Before
    public void setUp() throws Exception {
@@ -55,158 +53,6 @@ public class SimpleOpenWireTest extends BasicOpenWireTest {
    }
 
    @Test
-   public void testSimple() throws Exception {
-      Connection connection = factory.createConnection();
-
-      Collection<Session> sessions = new LinkedList<>();
-
-      for (int i = 0; i < 10; i++) {
-         Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-         sessions.add(session);
-      }
-
-      connection.close();
-   }
-
-   @Test
-   public void testTransactionalSimple() throws Exception {
-      try (Connection connection = factory.createConnection()) {
-
-         Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-         Queue queue = session.createQueue(queueName);
-         System.out.println("Queue:" + queue);
-         MessageProducer producer = session.createProducer(queue);
-         MessageConsumer consumer = session.createConsumer(queue);
-         producer.send(session.createTextMessage("test"));
-         session.commit();
-
-         Assert.assertNull(consumer.receive(100));
-         connection.start();
-
-         TextMessage message = (TextMessage) consumer.receive(5000);
-         Assert.assertEquals("test", message.getText());
-
-         Assert.assertNotNull(message);
-
-         message.acknowledge();
-      }
-   }
-
-   @Test
-   public void testXASimple() throws Exception {
-      XAConnection connection = xaFactory.createXAConnection();
-
-      Collection<Session> sessions = new LinkedList<>();
-
-      for (int i = 0; i < 10; i++) {
-         XASession session = connection.createXASession();
-         session.getXAResource().start(newXID(), XAResource.TMNOFLAGS);
-         sessions.add(session);
-      }
-
-      connection.close();
-
-   }
-
-   @Test
-   public void testClientACK() throws Exception {
-      try {
-
-         Connection connection = factory.createConnection();
-
-         Collection<Session> sessions = new LinkedList<>();
-
-         Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-         Queue queue = session.createQueue(queueName);
-         System.out.println("Queue:" + queue);
-         MessageProducer producer = session.createProducer(queue);
-         MessageConsumer consumer = session.createConsumer(queue);
-         producer.send(session.createTextMessage("test"));
-
-         Assert.assertNull(consumer.receive(100));
-         connection.start();
-
-         TextMessage message = (TextMessage) consumer.receive(5000);
-
-         Assert.assertNotNull(message);
-
-         message.acknowledge();
-
-         connection.close();
-
-         System.err.println("Done!!!");
-      }
-      catch (Throwable e) {
-         e.printStackTrace();
-      }
-   }
-
-   @Test
-   public void testRollback() throws Exception {
-      try (Connection connection = factory.createConnection()) {
-         Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-         Queue queue = session.createQueue(queueName);
-         System.out.println("Queue:" + queue);
-         MessageProducer producer = session.createProducer(queue);
-         MessageConsumer consumer = session.createConsumer(queue);
-         producer.send(session.createTextMessage("test"));
-         producer.send(session.createTextMessage("test2"));
-         connection.start();
-         Assert.assertNull(consumer.receiveNoWait());
-         session.rollback();
-         producer.send(session.createTextMessage("test2"));
-         Assert.assertNull(consumer.receiveNoWait());
-         session.commit();
-         TextMessage msg = (TextMessage) consumer.receive(1000);
-
-         Assert.assertNotNull(msg);
-         Assert.assertEquals("test2", msg.getText());
-      }
-   }
-
-   @Test
-   public void testAutoAck() throws Exception {
-      Connection connection = factory.createConnection();
-
-      Collection<Session> sessions = new LinkedList<>();
-
-      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      Queue queue = session.createQueue(queueName);
-      System.out.println("Queue:" + queue);
-      MessageProducer producer = session.createProducer(queue);
-      MessageConsumer consumer = session.createConsumer(queue);
-      TextMessage msg = session.createTextMessage("test");
-      msg.setStringProperty("abc", "testAutoACK");
-      producer.send(msg);
-
-      Assert.assertNull(consumer.receive(100));
-      connection.start();
-
-      TextMessage message = (TextMessage) consumer.receive(5000);
-
-      Assert.assertNotNull(message);
-
-      connection.close();
-
-      System.err.println("Done!!!");
-   }
-
-   @Test
-   public void testProducerFlowControl() throws Exception {
-      ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlString);
-
-      factory.setProducerWindowSize(1024 * 64);
-
-      Connection connection = factory.createConnection();
-      Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-      Queue queue = session.createQueue(queueName);
-      MessageProducer producer = session.createProducer(queue);
-      producer.send(session.createTextMessage("test"));
-
-      connection.close();
-   }
-
-   @Test
    public void testSimpleQueue() throws Exception {
       connection.start();
       Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -242,11 +88,12 @@ public class SimpleOpenWireTest extends BasicOpenWireTest {
       session.close();
    }
 
-   //   @Test -- ignored for now
+
+   @Test
    public void testKeepAlive() throws Exception {
       connection.start();
 
-      Thread.sleep(30000);
+      Thread.sleep(125000);
 
       connection.createSession(false, 1);
    }
@@ -390,11 +237,9 @@ public class SimpleOpenWireTest extends BasicOpenWireTest {
       Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
       Queue queue = session.createQueue("foo");
 
-      try {
-         session.createProducer(queue);
-      }
-      catch (JMSException expected) {
-      }
+      thrown.expect(InvalidDestinationException.class);
+      thrown.expect(JMSException.class);
+      session.createProducer(queue);
       session.close();
    }
 
@@ -545,6 +390,7 @@ public class SimpleOpenWireTest extends BasicOpenWireTest {
 
    }
 
+
    /**
     * This is the example shipped with the distribution
     *
@@ -627,6 +473,7 @@ public class SimpleOpenWireTest extends BasicOpenWireTest {
 
    }
 
+
    // simple test sending openwire, consuming core
    @Test
    public void testMixedOpenWireExample2() throws Exception {
@@ -666,396 +513,5 @@ public class SimpleOpenWireTest extends BasicOpenWireTest {
       conn2.close();
    }
 
-   @Test
-   public void testXAConsumer() throws Exception {
-      Queue queue;
-      try (Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE))
{
-         queue = session.createQueue(queueName);
-         System.out.println("Queue:" + queue);
-         MessageProducer producer = session.createProducer(queue);
-         for (int i = 0; i < 10; i++) {
-            TextMessage msg = session.createTextMessage("test" + i);
-            msg.setStringProperty("myobj", "test" + i);
-            producer.send(msg);
-         }
-         session.close();
-      }
-
-      try (XAConnection xaconnection = xaFactory.createXAConnection()) {
-         Xid xid = newXID();
-
-         XASession session = xaconnection.createXASession();
-         session.getXAResource().start(xid, XAResource.TMNOFLAGS);
-         MessageConsumer consumer = session.createConsumer(queue);
-         xaconnection.start();
-         for (int i = 0; i < 5; i++) {
-            TextMessage message = (TextMessage) consumer.receive(5000);
-            Assert.assertNotNull(message);
-            Assert.assertEquals("test" + i, message.getText());
-         }
-         session.getXAResource().end(xid, XAResource.TMSUCCESS);
-         session.getXAResource().rollback(xid);
-         consumer.close();
-         xaconnection.close();
-      }
-
-      try (Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
-         connection.start();
-         MessageConsumer consumer = session.createConsumer(queue);
-         for (int i = 0; i < 10; i++) {
-            TextMessage message = (TextMessage) consumer.receive(5000);
-            Assert.assertNotNull(message);
-            //            Assert.assertEquals("test" + i, message.getText());
-            System.out.println("Message " + message.getText());
-         }
-         checkDuplicate(consumer);
-         System.out.println("Queue:" + queue);
-         session.close();
-      }
-
-      System.err.println("Done!!!");
-   }
-
-   @Test
-   public void testXASameConsumerRollback() throws Exception {
-      Queue queue;
-      try (Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE))
{
-         queue = session.createQueue(queueName);
-         System.out.println("Queue:" + queue);
-         MessageProducer producer = session.createProducer(queue);
-         for (int i = 0; i < 10; i++) {
-            TextMessage msg = session.createTextMessage("test" + i);
-            msg.setStringProperty("myobj", "test" + i);
-            producer.send(msg);
-         }
-         session.close();
-      }
-
-      try (XAConnection xaconnection = xaFactory.createXAConnection()) {
-         Xid xid = newXID();
-
-         XASession session = xaconnection.createXASession();
-         session.getXAResource().start(xid, XAResource.TMNOFLAGS);
-         MessageConsumer consumer = session.createConsumer(queue);
-         xaconnection.start();
-         for (int i = 0; i < 5; i++) {
-            TextMessage message = (TextMessage) consumer.receive(5000);
-            Assert.assertNotNull(message);
-            Assert.assertEquals("test" + i, message.getText());
-         }
-         session.getXAResource().end(xid, XAResource.TMSUCCESS);
-         session.getXAResource().rollback(xid);
-
-         xid = newXID();
-         session.getXAResource().start(xid, XAResource.TMNOFLAGS);
-
-         for (int i = 0; i < 10; i++) {
-            TextMessage message = (TextMessage) consumer.receive(5000);
-            Assert.assertNotNull(message);
-            Assert.assertEquals("test" + i, message.getText());
-         }
-
-         checkDuplicate(consumer);
-
-         session.getXAResource().end(xid, XAResource.TMSUCCESS);
-         session.getXAResource().commit(xid, true);
-      }
-   }
-
-   @Test
-   public void testXAPrepare() throws Exception {
-      try {
-
-         XAConnection connection = xaFactory.createXAConnection();
-
-         XASession xasession = connection.createXASession();
-
-         Xid xid = newXID();
-         xasession.getXAResource().start(xid, XAResource.TMNOFLAGS);
-         Queue queue = xasession.createQueue(queueName);
-         MessageProducer producer = xasession.createProducer(queue);
-         producer.send(xasession.createTextMessage("hello"));
-         producer.send(xasession.createTextMessage("hello"));
-         xasession.getXAResource().end(xid, XAResource.TMSUCCESS);
-
-         xasession.getXAResource().prepare(xid);
-
-         connection.close();
-
-         System.err.println("Done!!!");
-      }
-      catch (Exception e) {
-         e.printStackTrace();
-      }
-   }
-
-   @Test
-   public void testAutoSend() throws Exception {
-      connection.start();
-      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-      Queue queue = session.createQueue(queueName);
-      MessageConsumer consumer = session.createConsumer(queue);
-
-      MessageProducer producer = session.createProducer(queue);
-      for (int i = 0; i < 10; i++) {
-         producer.send(session.createTextMessage("testXX" + i));
-      }
-      connection.start();
-
-      for (int i = 0; i < 10; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-   }
-
-   @Test
-   public void testCommitCloseConsumerBefore() throws Exception {
-      testCommitCloseConsumer(true);
-   }
-
-   @Test
-   public void testCommitCloseConsumerAfter() throws Exception {
-      testCommitCloseConsumer(false);
-   }
-
-   private void testCommitCloseConsumer(boolean closeBefore) throws Exception {
-      connection.start();
-      Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-
-      Queue queue = session.createQueue(queueName);
-      MessageConsumer consumer = session.createConsumer(queue);
-
-      MessageProducer producer = session.createProducer(queue);
-      for (int i = 0; i < 10; i++) {
-         TextMessage msg = session.createTextMessage("testXX" + i);
-         msg.setStringProperty("count", "str " + i);
-         producer.send(msg);
-      }
-      session.commit();
-      connection.start();
-
-      for (int i = 0; i < 5; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-      if (closeBefore) {
-         consumer.close();
-      }
-
-      session.commit();
-
-      // we're testing two scenarios.
-      // closing the consumer before commit or after commit
-      if (!closeBefore) {
-         consumer.close();
-      }
-
-      consumer = session.createConsumer(queue);
-      //      Assert.assertNull(consumer.receiveNoWait());
-      for (int i = 5; i < 10; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      Assert.assertNull(consumer.receiveNoWait());
-
-   }
-
-   @Test
-   public void testRollbackWithAcked() throws Exception {
-      connection.start();
-      Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-
-      Queue queue = session.createQueue(queueName);
-      MessageConsumer consumer = session.createConsumer(queue);
-
-      MessageProducer producer = session.createProducer(queue);
-      for (int i = 0; i < 10; i++) {
-         TextMessage msg = session.createTextMessage("testXX" + i);
-         msg.setStringProperty("count", "str " + i);
-         producer.send(msg);
-      }
-      session.commit();
-      connection.start();
-
-      for (int i = 0; i < 5; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      session.rollback();
-
-      consumer.close();
-
-      consumer = session.createConsumer(queue);
-      //      Assert.assertNull(consumer.receiveNoWait());
-      for (int i = 0; i < 10; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         //         System.out.println("TXT::" + txt);
-         Assert.assertNotNull(txt);
-         System.out.println("TXT " + txt.getText());
-         //         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-      session.commit();
-
-      checkDuplicate(consumer);
-
-   }
-
-   @Test
-   public void testRollbackLocal() throws Exception {
-      connection.start();
-      Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-
-      Queue queue = session.createQueue(queueName);
-      MessageConsumer consumer = session.createConsumer(queue);
-
-      MessageProducer producer = session.createProducer(queue);
-      for (int i = 0; i < 10; i++) {
-         TextMessage msg = session.createTextMessage("testXX" + i);
-         msg.setStringProperty("count", "str " + i);
-         producer.send(msg);
-      }
-      session.commit();
-      connection.start();
-
-      for (int i = 0; i < 5; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(500);
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      session.rollback();
-
-      for (int i = 0; i < 10; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         Assert.assertNotNull(txt);
-         System.out.println("TXT " + txt.getText());
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      checkDuplicate(consumer);
-
-      session.commit();
-
-   }
-
-   private void checkDuplicate(MessageConsumer consumer) throws JMSException {
-      boolean duplicatedMessages = false;
-      while (true) {
-         TextMessage txt = (TextMessage) consumer.receiveNoWait();
-         if (txt == null) {
-            break;
-         }
-         else {
-            duplicatedMessages = true;
-            System.out.println("received in duplicate:" + txt.getText());
-         }
-      }
-
-      Assert.assertFalse("received messages in duplicate", duplicatedMessages);
-   }
-
-   @Test
-   public void testIndividualAck() throws Exception {
-      connection.start();
-      Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
-
-      Queue queue = session.createQueue(queueName);
-      MessageConsumer consumer = session.createConsumer(queue);
-
-      MessageProducer producer = session.createProducer(queue);
-      for (int i = 0; i < 10; i++) {
-         TextMessage msg = session.createTextMessage("testXX" + i);
-         msg.setStringProperty("count", "str " + i);
-         producer.send(msg);
-      }
-      connection.start();
-
-      for (int i = 0; i < 5; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         if (i == 4) {
-            txt.acknowledge();
-         }
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      consumer.close();
-
-      consumer = session.createConsumer(queue);
-      //      Assert.assertNull(consumer.receiveNoWait());
-      for (int i = 0; i < 4; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         txt.acknowledge();
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      for (int i = 5; i < 10; i++) {
-         TextMessage txt = (TextMessage) consumer.receive(5000);
-         txt.acknowledge();
-         Assert.assertEquals("testXX" + i, txt.getText());
-      }
-
-      checkDuplicate(consumer);
-
-      Assert.assertNull(consumer.receiveNoWait());
-
-   }
-
-   @Test
-   public void testCommitCloseConsumeXA() throws Exception {
-
-      Queue queue;
-      {
-         connection.start();
-         Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-
-         queue = session.createQueue(queueName);
-
-         MessageProducer producer = session.createProducer(queue);
-         for (int i = 0; i < 10; i++) {
-            TextMessage msg = session.createTextMessage("testXX" + i);
-            msg.setStringProperty("count", "str " + i);
-            producer.send(msg);
-         }
-         session.commit();
-      }
-
-      try (XAConnection xaconnection = xaFactory.createXAConnection()) {
-         xaconnection.start();
-
-         XASession xasession = xaconnection.createXASession();
-         Xid xid = newXID();
-         xasession.getXAResource().start(xid, XAResource.TMNOFLAGS);
-         MessageConsumer consumer = xasession.createConsumer(queue);
-
-         for (int i = 0; i < 5; i++) {
-            TextMessage txt = (TextMessage) consumer.receive(5000);
-            Assert.assertEquals("testXX" + i, txt.getText());
-         }
-
-         consumer.close();
-
-         xasession.getXAResource().end(xid, XAResource.TMSUCCESS);
-         xasession.getXAResource().prepare(xid);
-         xasession.getXAResource().commit(xid, false);
-
-         xaconnection.close();
-      }
-
-      {
-         connection.start();
-         Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-         try (MessageConsumer consumer = session.createConsumer(queue)) {
-            for (int i = 5; i < 10; i++) {
-               TextMessage txt = (TextMessage) consumer.receive(5000);
-               Assert.assertEquals("testXX" + i, txt.getText());
-            }
-         }
-
-      }
-
-   }
 
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ddf486f/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
index 805a6f5..a644718 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/BindingsImplTest.java
@@ -105,16 +105,6 @@ public class BindingsImplTest extends ActiveMQTestBase {
    private final class FakeTransaction implements Transaction {
 
       @Override
-      public Object getProtocolData() {
-         return null;
-      }
-
-      @Override
-      public void setProtocolData(Object data) {
-
-      }
-
-      @Override
       public void addOperation(final TransactionOperation sync) {
 
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6ddf486f/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java
b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java
index 78659d2..99d01e6 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java
@@ -42,11 +42,6 @@ public class FakeQueue implements Queue {
    }
 
    @Override
-   public void sendToDeadLetterAddress(Transaction tx, MessageReference ref) throws Exception
{
-
-   }
-
-   @Override
    public void deleteQueue(boolean removeConsumers) throws Exception {
    }
 


Mime
View raw message