コード例 #1
0
    def test_unsubscribe_1(self):
        """ Test that a no-interest packet will be send when all subscribes have unsubscdribed.
        """

        s = setup_story(3)

        s.do_remote_send(PEER1, LHOST,
                         packets.login(b'testname', False, False, False))
        s.expect_local_send(
            LHOST, PEER1,
            packets.session(b'testname', packets.SESSION_STATE_ACTIVE))

        s.do_remote_send(PEER2, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_INTEREST,
                             b'testtopic'))

        s.do_remote_send(PEER3, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.do_remote_send(PEER2, LHOST,
                         packets.unsubscribe(b'testname', b'testtopic'))
        s.do_remote_send(PEER3, LHOST,
                         packets.unsubscribe(b'testname', b'testtopic'))

        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_NOINTEREST,
                             b'testtopic'))

        with SysMock(s):
            main(['--nxtcp', ':9999'])
コード例 #2
0
    def test_subscriber_quit_1(self):
        """ Test if unexpected close of an client will result in an unsubscribe.
        """

        s = setup_story(2)

        s.do_remote_send(PEER1, LHOST,
                         packets.login(b'testname', False, False, False))
        s.expect_local_send(
            LHOST, PEER1,
            packets.session(b'testname', packets.SESSION_STATE_ACTIVE))

        s.do_remote_send(PEER2, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_INTEREST,
                             b'testtopic'))

        s.do_remote_close(PEER2, LHOST)
        s.expect_local_close(LHOST, PEER2)

        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_NOINTEREST,
                             b'testtopic'))

        with SysMock(s):
            main(['--nxtcp', ':9999'])
コード例 #3
0
    def test_interest(self):
        self.assertEncodePacket(
            InterestPacket(1234, InterestPacket.STATUS_INTEREST, b'thetopic'),
            packets.interest(1234, packets.INTEREST_STATUS_INTEREST,
                             b'thetopic'))

        self.assertEncodePacket(
            InterestPacket(1234, InterestPacket.STATUS_NO_INTEREST,
                           b'thetopic'),
            packets.interest(1234, packets.INTEREST_STATUS_NOINTEREST,
                             b'thetopic'))
コード例 #4
0
    def test_subscribe_post_1(self):
        """ Test if mulitple post on a topic will indeed result in multiple messages to all subscribers.
        """

        s = setup_story(3)

        s.do_remote_send(PEER1, LHOST,
                         packets.login(b'testname', False, False, False))
        s.expect_local_send(
            LHOST, PEER1,
            packets.session(b'testname', packets.SESSION_STATE_ACTIVE))

        s.do_remote_send(PEER2, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_INTEREST,
                             b'testtopic'))

        s.do_remote_send(PEER3, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.do_remote_send(PEER1, LHOST, packets.post(1, b'testpayload'))

        s.expect_local_send(
            LHOST, PEER2,
            packets.message(1234, packets.MESSAGE_STATUS_OK, b'testpayload'))
        s.expect_local_send(
            LHOST, PEER3,
            packets.message(1234, packets.MESSAGE_STATUS_OK, b'testpayload'))

        with SysMock(s):
            main(['--nxtcp', ':9999'])
コード例 #5
0
    def test_subscribe_2(self):
        """ Test that multiple subscries will still result in just one interest packet.
        """

        s = setup_story(3)

        s.do_remote_send(PEER1, LHOST,
                         packets.login(b'testname', False, False, False))
        s.expect_local_send(
            LHOST, PEER1,
            packets.session(b'testname', packets.SESSION_STATE_ACTIVE))

        s.do_remote_send(PEER2, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_INTEREST,
                             b'testtopic'))

        s.do_remote_send(PEER3, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))

        s.expect_local_wait(10.0)
        s.expect_local_send(LHOST, PEER1, packets.ping())
        s.expect_local_send(LHOST, PEER2, packets.ping())
        s.expect_local_send(LHOST, PEER3, packets.ping())

        with SysMock(s):
            main(['--nxtcp', ':9999'])
コード例 #6
0
    def test_subscribe_1(self):
        """ Test that a subscribe from c2 will result in a interest packet on c1.
        """

        s = setup_story(2)

        s.do_remote_send(PEER1, LHOST,
                         packets.login(b'testname', False, False, False))
        s.expect_local_send(
            LHOST, PEER1,
            packets.session(b'testname', packets.SESSION_STATE_ACTIVE))

        s.do_remote_send(PEER2, LHOST,
                         packets.subscribe(1234, b'testname', b'testtopic'))
        s.expect_local_send(
            LHOST, PEER1,
            packets.interest(1, packets.INTEREST_STATUS_INTEREST,
                             b'testtopic'))

        with SysMock(s):
            main(['--nxtcp', ':9999'])
コード例 #7
0
def test_interest_2(self):
    """ Test that a Interest verb is produced.
    """

    mock = Sysmock()
    mock.system.add_unused_local_address(CLIENT)

    downstream_handler = unittest.mock.Mock()

    with patch(mock):
        loop = Mainloop()

        mock.expect_tcp_syn(CLIENT, SERVER)
        mock.do_tcp_syn_ack(SERVER, CLIENT)
        mock.do_tcp_input(SERVER, CLIENT, packets.welcome())

        # send the packet
        mock.do_tcp_input(
            SERVER, CLIENT,
            packets.interest(
                postref=1234,
                name=b'thename',
                status=packets.INTEREST_STATUS_NOINTEREST,
                topic=b'topic',
            ))

        conn = NxtcpConnection(loop, SERVER.address)
        conn.set_downstream_handler(downstream_handler)

        mock.run_events(loop.run_once)

        # verify the verb
        downstream_handler.assert_called_once_with(
            verbs.InterestVerb(
                postref=1234,
                name=b'thename',
                status=verbs.InterestVerb.STATUS_NO_INTEREST,
                topic=b'topic',
            ))