Exemple #1
0
    def test_ack_client_individual(self):
        destination = "/queue/ack-test-individual"

        # subscribe and send message
        self.listener.reset(2) ## expecting 2 messages
        self.subscribe_dest(self.conn, destination, None,
                            ack='client-individual',
                            headers={'prefetch-count': '10'})
        self.conn.send(destination, "test1")
        self.conn.send(destination, "test2")
        self.assertTrue(self.listener.wait(4), "Both initial messages not received")
        self.assertEquals(2, len(self.listener.messages))

        # disconnect without acks
        self.conn.disconnect()

        # now reconnect
        conn2 = self.create_connection()
        try:
            listener2 = base.WaitableListener()
            listener2.reset(2) ## expect 2 messages
            conn2.set_listener('', listener2)
            self.subscribe_dest(conn2, destination, None,
                                ack='client-individual',
                                headers={'prefetch-count': '10'})
            self.assertTrue(listener2.wait(2.5), "Did not receive 2 messages")
            self.assertEquals(2, len(listener2.messages), "Not exactly 2 messages received")

            # now ack only the 'test2' message - expecting individual behaviour
            nummsgs = len(listener2.messages)
            mid = None
            for ind in range(nummsgs):
                if listener2.messages[ind]['message']=="test2":
                    mid = listener2.messages[ind]['headers'][self.ack_id_source_header]
                    self.assertEquals(1, ind, 'Expecting test2 to be second message')
                    break
            self.assertTrue(mid, "Did not find test2 message id.")
            self.ack_message(conn2, mid, None)
        finally:
            conn2.disconnect()

        # now reconnect again, shouldn't see the message
        conn3 = self.create_connection()
        try:
            listener3 = base.WaitableListener()
            listener3.reset(2) ## expecting a single message, but wait for two
            conn3.set_listener('', listener3)
            self.subscribe_dest(conn3, destination, None)
            self.assertFalse(listener3.wait(2.5),
                             "Expected to see only one message. ACK not working?")
            self.assertEquals(1, len(listener3.messages), "Expecting exactly one message")
            self.assertEquals("test1", listener3.messages[0]['message'], "Unexpected message remains")
        finally:
            conn3.disconnect()
Exemple #2
0
    def test_ack_client(self):
        destination = "/queue/ack-test"

        # subscribe and send message
        self.listener.reset(2)  ## expecting 2 messages
        self.subscribe_dest(self.conn,
                            destination,
                            None,
                            ack='client',
                            headers={'prefetch-count': '10'})
        self.conn.send(destination, "test1")
        self.conn.send(destination, "test2")
        self.assertTrue(self.listener. await (4),
                        "initial message not received")
        self.assertEquals(2, len(self.listener.messages))

        # disconnect with no ack
        self.conn.disconnect()

        # now reconnect
        conn2 = self.create_connection()
        try:
            listener2 = base.WaitableListener()
            listener2.reset(2)
            conn2.set_listener('', listener2)
            self.subscribe_dest(conn2,
                                destination,
                                None,
                                ack='client',
                                headers={'prefetch-count': '10'})
            self.assertTrue(listener2. await (), "message not received again")
            self.assertEquals(2, len(listener2.messages))

            # now ack only the last message - expecting cumulative behaviour
            mid = listener2.messages[1]['headers'][self.ack_id_source_header]
            self.ack_message(conn2, mid, None)
        finally:
            conn2.disconnect()

        # now reconnect again, shouldn't see the message
        conn3 = self.create_connection()
        try:
            listener3 = base.WaitableListener()
            conn3.set_listener('', listener3)
            self.subscribe_dest(conn3, destination, None)
            self.assertFalse(listener3. await (3),
                             "unexpected message. ACK not working?")
        finally:
            conn3.disconnect()
Exemple #3
0
    def test_implicit_connect(self):
        ''' Implicit connect with receipt on first command '''
        self.conn.disconnect()
        test_util.enable_implicit_connect()
        listener = base.WaitableListener()
        new_conn = stomp.Connection(
            host_and_ports=[('localhost', int(os.environ["STOMP_PORT"]))])
        new_conn.set_listener('', listener)

        new_conn.transport.start()

        self.subscribe_dest(new_conn,
                            "/topic/implicit",
                            'sub_implicit',
                            receipt='implicit')

        try:
            self.assertTrue(listener.wait(5))
            self.assertEqual(1, len(listener.receipts),
                             'Missing receipt. Likely not connected')
            self.assertEqual('implicit',
                             listener.receipts[0]['headers']['receipt-id'])
        finally:
            new_conn.disconnect()
            test_util.disable_implicit_connect()
Exemple #4
0
    def test_redelivered(self):
        destination = "/queue/redelivered-test"

        # subscribe and send message
        self.subscribe_dest(self.conn, destination, None, ack='client')
        self.conn.send(destination, "test1")
        message_receive_timeout = 30
        self.assertTrue(self.listener.wait(message_receive_timeout), "Test message not received within {0} seconds".format(message_receive_timeout))
        self.assertEquals(1, len(self.listener.messages))
        self.assertEquals('false', self.listener.messages[0]['headers']['redelivered'])

        # disconnect with no ack
        self.conn.disconnect()

        # now reconnect
        conn2 = self.create_connection()
        try:
            listener2 = base.WaitableListener()
            listener2.reset(1)
            conn2.set_listener('', listener2)
            self.subscribe_dest(conn2, destination, None, ack='client')
            self.assertTrue(listener2.wait(), "message not received again")
            self.assertEquals(1, len(listener2.messages))
            self.assertEquals('true', listener2.messages[0]['headers']['redelivered'])
        finally:
            conn2.disconnect()
    def test_separate_ids(self):
        destination = '/topic/durable-separate'

        conn2 = self.create_connection()
        listener2 = base.WaitableListener()
        conn2.set_listener('', listener2)

        try:
            # ensure durable subscription exists for each ID
            self.__subscribe(destination)
            self.__assert_receipt()
            self.__subscribe(destination, conn2, "other.id")
            self.__assert_receipt(listener2)
            self.unsubscribe_dest(self.conn, destination, TestDurableSubscription.ID)
            self.unsubscribe_dest(conn2, destination, "other.id")

            self.listener.reset(101)
            listener2.reset(101) ## 100 messages and 1 receipt

            # send 100 messages
            for x in xrange(0, 100):
                self.conn.send(destination, "msg" + str(x))

            self.__subscribe(destination)
            self.__subscribe(destination, conn2, "other.id")

            for l in [self.listener, listener2]:
                self.assertTrue(l.await(20))
                self.assertEquals(100, len(l.messages))

        finally:
            conn2.disconnect()
Exemple #6
0
    def test_send_and_disconnect(self):
        ''' Test close socket after send does not lose messages '''
        destination = "/queue/reliability"
        pub_conn = self.create_connection()
        try:
            msg = "0" * (128)

            count = 10000

            listener = base.WaitableListener()
            listener.reset(count)
            self.conn.set_listener('', listener)
            self.subscribe_dest(self.conn, destination, None)

            for x in range(0, count):
                pub_conn.send(destination, msg + str(x))
            time.sleep(2.0)
            pub_conn.disconnect()

            if listener.wait(30):
                self.assertEquals(count, len(listener.messages))
            else:
                listener.print_state("Final state of listener:")
                self.fail("Did not receive %s messages in time" % count)
        finally:
            if pub_conn.is_connected():
                pub_conn.disconnect()
Exemple #7
0
    def test_ack_client_tx(self):
        destination = "/queue/ack-test-tx"

        # subscribe and send message
        self.listener.reset()
        self.subscribe_dest(self.conn, destination, None, ack='client')
        self.conn.send(destination, "test")
        self.assertTrue(self.listener. await (3),
                        "initial message not received")
        self.assertEquals(1, len(self.listener.messages))

        # disconnect with no ack
        self.conn.disconnect()

        # now reconnect
        conn2 = self.create_connection()
        try:
            tx = "abc"
            listener2 = base.WaitableListener()
            conn2.set_listener('', listener2)
            conn2.begin(transaction=tx)
            self.subscribe_dest(conn2, destination, None, ack='client')
            self.assertTrue(listener2. await (), "message not received again")
            self.assertEquals(1, len(listener2.messages))

            # now ack
            mid = listener2.messages[0]['headers'][self.ack_id_source_header]
            self.ack_message(conn2, mid, None, transaction=tx)

            #now commit
            conn2.commit(transaction=tx)
        finally:
            conn2.disconnect()

        # now reconnect again, shouldn't see the message
        conn3 = self.create_connection()
        try:
            listener3 = base.WaitableListener()
            conn3.set_listener('', listener3)
            self.subscribe_dest(conn3, destination, None)
            self.assertFalse(listener3. await (3),
                             "unexpected message. TX ACK not working?")
        finally:
            conn3.disconnect()
Exemple #8
0
    def test_ack_client_tx(self):
        d = "/queue/ack-test-tx"

        # subscribe and send message
        self.listener.reset()
        self.conn.subscribe(destination=d, ack='client')
        self.conn.send("test", destination=d)
        self.assertTrue(self.listener. await (3),
                        "initial message not received")
        self.assertEquals(1, len(self.listener.messages))

        # disconnect with no ack
        self.conn.disconnect()

        # now reconnect
        conn2 = self.create_connection()
        try:
            tx = "abc"
            listener2 = base.WaitableListener()
            conn2.set_listener('', listener2)
            conn2.begin(transaction=tx)
            conn2.subscribe(destination=d, ack='client')
            self.assertTrue(listener2. await (), "message not received again")
            self.assertEquals(1, len(listener2.messages))

            # now ack
            mid = listener2.messages[0]['headers']['message-id']
            conn2.ack({'message-id': mid, 'transaction': tx})

            #now commit
            conn2.commit(transaction=tx)
        finally:
            conn2.stop()

        # now reconnect again, shouldn't see the message
        conn3 = self.create_connection()
        try:
            listener3 = base.WaitableListener()
            conn3.set_listener('', listener3)
            conn3.subscribe(destination=d)
            self.assertFalse(listener3. await (3),
                             "unexpected message. TX ACK not working?")
        finally:
            conn3.stop()
 def bad_connect(self, new_conn, expected):
     self.conn.disconnect()
     listener = base.WaitableListener()
     new_conn.set_listener('', listener)
     try:
         new_conn.start()
         new_conn.connect()
         self.assertTrue(listener. await ())
         self.assertEquals(expected, listener.errors[0]['message'])
     finally:
         if new_conn.is_connected():
             new_conn.disconnect()
 def bad_connect(self, expected, user='******', passcode='guest', **kwargs):
     self.conn.disconnect()
     new_conn = self.create_connection_obj(**kwargs)
     listener = base.WaitableListener()
     new_conn.set_listener('', listener)
     try:
         new_conn.connect(user, passcode)
         self.assertTrue(listener.wait())
         self.assertEqual(expected, listener.errors[0]['message'])
     finally:
         if new_conn.is_connected():
             new_conn.disconnect()
 def test_default_user(self):
     ''' Default user connection '''
     self.conn.disconnect()
     test_util.enable_default_user()
     listener = base.WaitableListener()
     new_conn = stomp.Connection(
         host_and_ports=[('localhost', int(os.environ["STOMP_PORT"]))])
     new_conn.set_listener('', listener)
     new_conn.connect()
     try:
         self.assertFalse(listener.wait(3))  # no error back
         self.assertTrue(new_conn.is_connected())
     finally:
         new_conn.disconnect()
         test_util.disable_default_user()
Exemple #12
0
 def test_default_user(self):
     ''' Default user connection '''
     self.conn.disconnect()
     test_util.enable_default_user()
     listener = base.WaitableListener()
     new_conn = stomp.Connection()
     new_conn.set_listener('', listener)
     new_conn.start()
     new_conn.connect()
     try:
         self.assertFalse(listener. await (3))  # no error back
         self.assertTrue(new_conn.is_connected())
     finally:
         new_conn.disconnect()
         test_util.disable_default_user()
    def test_implicit_connect(self):
        ''' Implicit connect with receipt on first command '''
        self.conn.disconnect()
        listener = base.WaitableListener()
        new_conn = stomp.Connection(user="", passcode="")
        new_conn.set_listener('', listener)

        new_conn.start() # not going to issue connect
        new_conn.subscribe(destination="/topic/implicit", receipt='implicit')

        try:
            self.assertTrue(listener.await(5))
            self.assertEquals(1, len(listener.receipts),
                              'Missing receipt. Likely not connected')
            self.assertEquals('implicit', listener.receipts[0]['headers']['receipt-id'])
        finally:
            new_conn.disconnect()
Exemple #14
0
    def test_send_receive_in_other_conn(self):
        ''' Test send in one connection, receive in another '''
        d = '/queue/test2'

        # send
        self.conn.send("hello", destination=d)

        # now receive
        conn2 = self.create_connection()
        try:
            listener2 = base.WaitableListener()
            conn2.set_listener('', listener2)

            conn2.subscribe(destination=d)
            self.assertTrue(listener2. await (10), "no receive")
        finally:
            conn2.stop()
    def test_send_receive_in_other_conn(self):
        ''' Test send in one connection, receive in another '''
        destination = '/queue/test2'

        # send
        self.conn.send(destination, "hello")

        # now receive
        conn2 = self.create_connection()
        try:
            listener2 = base.WaitableListener()
            conn2.set_listener('', listener2)

            self.subscribe_dest(conn2, destination, None, ack="auto")
            self.assertTrue(listener2.await(10), "no receive")
        finally:
            conn2.disconnect()
    def test_send_receive_in_other_conn_with_disconnect(self):
        ''' Test send, disconnect, receive '''
        destination = '/queue/test3'

        # send
        self.conn.send(destination, "hello thar", receipt="foo")
        self.listener.await(3)
        self.conn.disconnect()

        # now receive
        conn2 = self.create_connection()
        try:
            listener2 = base.WaitableListener()
            conn2.set_listener('', listener2)

            self.subscribe_dest(conn2, destination, None, ack="auto")
            self.assertTrue(listener2.await(10), "no receive")
        finally:
            conn2.disconnect()
    def __test_conn(self, conn):
        try:
            listener = base.WaitableListener()

            conn.set_listener('', listener)

            d = "/topic/ssl.test"
            conn.subscribe(destination=d, ack="auto", id="ctag", receipt="sub")

            self.assertTrue(listener.wait(1))

            self.assertEquals("sub",
                              listener.receipts[0]['headers']['receipt-id'])

            listener.reset(1)
            conn.send(body="Hello SSL!", destination=d)

            self.assertTrue(listener.wait())

            self.assertEquals("Hello SSL!", listener.messages[0]['message'])
        finally:
            conn.disconnect()
    def test_send_and_disconnect(self):
        ''' Test close socket after send does not lose messages '''
        d = "/queue/reliability"
        pub_conn = self.create_connection()
        try:
            msg = "0" * (128)

            count = 10000

            listener = base.WaitableListener()
            listener.reset(count)
            self.conn.set_listener('', listener)
            self.conn.subscribe(destination=d)

            for x in range(0, count):
                pub_conn.send(msg + str(x), destination=d)
            time.sleep(2.0)
            pub_conn.close_socket()

            if listener. await (30):
                self.assertEquals(count, len(listener.messages))
            else:
Exemple #19
0
    def test_ssl_send_receive(self):
        conn = self.__ssl_connect()

        try:
            listener = base.WaitableListener()

            conn.set_listener('', listener)

            d = "/topic/ssl.test"
            conn.subscribe(destination=d, receipt="sub")

            self.assertTrue(listener. await (1))

            self.assertEquals("sub",
                              listener.receipts[0]['headers']['receipt-id'])

            listener.reset(1)
            conn.send("Hello SSL!", destination=d)

            self.assertTrue(listener. await ())

            self.assertEquals("Hello SSL!", listener.messages[0]['message'])
        finally:
            conn.disconnect()