Exemple #1
0
 def test_assert_right_proto_type(self):
     'should return True if the msg if matched the reg of  given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
        'proto' : 'content'
         }, clear=True):
         msg = 'content'
         self.assertTrue(Protocol.assert_protocol_type(msg, 'proto'))
Exemple #2
0
 def test_protocol_regular_in_table(self):
     'should return the proto regular if in protocol table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
        'proto' : 'content'
         }, clear=True):
         self.assertEqual(Protocol.protocol_regular('proto'), 
         	re.compile('content'))
Exemple #3
0
 def test_nonexist_proto(self):
     'should return False if proto not in table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
         'proto' : 'content'
           }, clear=True):
         msg = 'content'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'nonexist'))        
Exemple #4
0
 def test_not_matched(self):
     'should return the un-matched part of message'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
         'proto' : 'content'
           }, clear=True):
         msg = 'content_not_matched'
         self.assertEqual(Protocol.not_matched('proto', msg), '_not_matched')
Exemple #5
0
 def test_assert_wrong_proto_type(self):
     'should return False if msg not matched the reg of given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
         'proto' : 'content'
           }, clear=True):
         msg = 'somemsg'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'proto'))
Exemple #6
0
 def test_not_matched(self):
     'should return the un-matched part of message'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'content_not_matched'
         self.assertEqual(Protocol.not_matched('proto', msg),
                          '_not_matched')
Exemple #7
0
    def _process_info(self, info):
        '''\
        process server infomation message;

        Params:
        =====
        info: nats server information
        '''
        server_info = json.loads(info)
        if server_info["auth_required"]:
            conn_opts = self.conn.get_connection_options()
            self.conn.send_command(Protocol.connect_command(conn_opts), True)
Exemple #8
0
    def _process_info(self, info):
        '''\
        process server infomation message;

        Params:
        =====
        info: nats server information
        '''
        server_info = json.loads(info)
        if server_info["auth_required"]:
            conn_opts = self.conn.get_connection_options()
            self.conn.send_command(Protocol.connect_command(conn_opts),
                True)
Exemple #9
0
 def test_protocol_regular_in_table(self):
     'should return the proto regular if in protocol table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         self.assertEqual(Protocol.protocol_regular('proto'),
                          re.compile('content'))
Exemple #10
0
 def test_version(self):
     'should return the protocol version'
     #with patch.dict(Protocol, PROTOCOL_VERSION='0-0-0-0'):
     version = Protocol.version()
     self.assertEqual(version, '0.5.0.beta.12')
Exemple #11
0
 def test_connect_command(self):
     'should return the connect command'
     opts = {'user': '******', 'pass': '******'}
     self.assertEqual(Protocol.connect_command(opts),
                      'CONNECT {"user": "******", "pass": "******"}\r\n')
Exemple #12
0
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
Exemple #13
0
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
Exemple #14
0
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
Exemple #15
0
 def test_nonexist_proto(self):
     'should return False if proto not in table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'content'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'nonexist'))
Exemple #16
0
 def test_assert_right_proto_type(self):
     'should return True if the msg if matched the reg of  given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'content'
         self.assertTrue(Protocol.assert_protocol_type(msg, 'proto'))
Exemple #17
0
 def test_connect_command(self):
     'should return the connect command'
     opts = {'user' : 'a', 'pass' : 'b'}
     self.assertEqual(Protocol.connect_command(opts), 
      	'CONNECT {"user": "******", "pass": "******"}\r\n')
Exemple #18
0
 def test_version(self):
     'should return the protocol version' 
     #with patch.dict(Protocol, PROTOCOL_VERSION='0-0-0-0'):
     version = Protocol.version()
     self.assertEqual(version, '0.5.0.beta.12')
Exemple #19
0
 def test_assert_wrong_proto_type(self):
     'should return False if msg not matched the reg of given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'somemsg'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'proto'))
Exemple #20
0
 def send_ping(self):
     "send ping request to nats server"
     self.pings_outstanding += 1
     self.conn.send_command(Protocol.ping_request())
     self.queue_server_rt(self.process_pong)
     self.conn.flush_pending()
Exemple #21
0
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
Exemple #22
0
 def queue_server_rt(self, blk):
     'queue server response'
     if not blk:
         return None
     self.pongs.put(blk)
     self.conn.send_command(Protocol.ping_request())
Exemple #23
0
 def send_ping(self):
     "send ping request to nats server"
     self.pings_outstanding += 1
     self.conn.send_command(Protocol.ping_request())
     self.queue_server_rt(self.process_pong)
     self.conn.flush_pending()
Exemple #24
0
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')
Exemple #25
0
 def queue_server_rt(self, blk):
     'queue server response'
     if not blk:
         return None
     self.pongs.put(blk)
     self.conn.send_command(Protocol.ping_request())
Exemple #26
0
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')