예제 #1
0
	def test_is_singleton(self):
		i1 = SMPPClientStatsCollector()
		i2 = SMPPClientStatsCollector()
		self.assertEqual(i1, i2)

		i1.get(cid = 'testing').set('last_seqNum', 100)

		self.assertEqual(i1.get(cid = 'testing').get('last_seqNum'),
						 i2.get(cid = 'testing').get('last_seqNum'),
						 )
예제 #2
0
    def smppcs(self, arg, opts):
        sc = SMPPClientStatsCollector()
        headers = [
            "#Connector id", "Connected at", "Bound at", "Disconnected at",
            "Submits", "Delivers", "QoS errs", "Other errs"
        ]

        table = []
        connectors = self.pb['smppcm'].perspective_connector_list()
        for connector in connectors:
            row = []
            row.append('#%s' % connector['id'])
            row.append(
                formatDateTime(sc.get(connector['id']).get('connected_at')))
            row.append(formatDateTime(sc.get(connector['id']).get('bound_at')))
            row.append(
                formatDateTime(sc.get(connector['id']).get('disconnected_at')))
            row.append('%s/%s' %
                       (sc.get(connector['id']).get('submit_sm_request_count'),
                        sc.get(connector['id']).get('submit_sm_count')))
            row.append('%s/%s' %
                       (sc.get(connector['id']).get('deliver_sm_count'),
                        sc.get(connector['id']).get('data_sm_count')))
            row.append(sc.get(connector['id']).get('throttling_error_count'))
            row.append(sc.get(connector['id']).get('other_submit_error_count'))

            table.append(row)

        self.protocol.sendData(tabulate(table,
                                        headers,
                                        tablefmt="plain",
                                        numalign="left").encode('ascii'),
                               prompt=False)
        self.protocol.sendData('Total connectors: %s' % (len(table)))
예제 #3
0
	def test_get_will_reuse_existent_connector(self):
		c = SMPPClientStatsCollector()
		self.assertTrue('test_get_will_reuse_existent_connector' not in c.connectors)

		i1 = c.get(cid = 'test_get_will_reuse_existent_connector')
		i2 = c.get(cid = 'test_get_will_reuse_existent_connector')
		self.assertEqual(i1, i2)
예제 #4
0
    def test_stats(self):
        stats = SMPPClientStatsCollector().get(cid='test_stats')

        self.assertEqual(
            stats._stats, {
                'bound_at': 0,
                'bound_count': 0,
                'connected_at': 0,
                'connected_count': 0,
                'created_at': 0,
                'data_sm_count': 0,
                'deliver_sm_count': 0,
                'disconnected_at': 0,
                'disconnected_count': 0,
                'elink_count': 0,
                'interceptor_count': 0,
                'interceptor_error_count': 0,
                'last_received_elink_at': 0,
                'last_received_pdu_at': 0,
                'last_sent_elink_at': 0,
                'last_sent_pdu_at': 0,
                'last_seqNum': None,
                'last_seqNum_at': 0,
                'other_submit_error_count': 0,
                'submit_sm_count': 0,
                'submit_sm_request_count': 0,
                'throttling_error_count': 0,
            })
예제 #5
0
    def __init__(self, config, msgHandler=None):
        self.reconnectTimer = None
        self.smpp = None
        self.connectionRetry = True
        self.config = config

        # Setup statistics collector
        self.stats = SMPPClientStatsCollector().get(cid=self.config.id)
        self.stats.set('created_at', datetime.now())

        # Set up a dedicated logger
        self.log = logging.getLogger(LOG_CATEGORY_CLIENT_BASE +
                                     ".%s" % config.id)
        if len(self.log.handlers) != 1:
            self.log.setLevel(self.config.log_level)
            _when = self.config.log_rotate if hasattr(
                self.config, 'log_rotate') else 'midnight'
            if 'stdout' in self.config.log_file:
                handler = logging.StreamHandler(sys.stdout)
            else:
                handler = TimedRotatingFileHandler(
                    filename=self.config.log_file, when=_when)
            formatter = logging.Formatter(self.config.log_format,
                                          self.config.log_date_format)
            handler.setFormatter(formatter)
            self.log.addHandler(handler)
            self.log.propagate = False

        if msgHandler is None:
            self.msgHandler = self.msgHandlerStub
        else:
            self.msgHandler = msgHandler
예제 #6
0
    def smppcs(self, arg, opts):
        sc = SMPPClientStatsCollector()
        headers = [
            "#Connector id", "Bound count", "Connected at", "Bound at",
            "Disconnected at", "Sent elink at", "Received elink at"
        ]

        table = []
        connectors = self.pb['smppcm'].perspective_connector_list()
        for connector in connectors:
            row = []
            row.append('#%s' % connector['id'])
            row.append(sc.get(connector['id']).get('bound_count'))
            row.append(
                formatDateTime(sc.get(connector['id']).get('connected_at')))
            row.append(formatDateTime(sc.get(connector['id']).get('bound_at')))
            row.append(
                formatDateTime(sc.get(connector['id']).get('disconnected_at')))
            row.append(
                formatDateTime(
                    sc.get(connector['id']).get('last_sent_elink_at')))
            row.append(
                formatDateTime(
                    sc.get(connector['id']).get('last_received_elink_at')))

            table.append(row)

        self.protocol.sendData(tabulate(table,
                                        headers,
                                        tablefmt="plain",
                                        numalign="left").encode('ascii'),
                               prompt=False)
        self.protocol.sendData('Total connectors: %s' % (len(table)))
예제 #7
0
	def test_exceptions(self):
		stats = SMPPClientStatsCollector().get(cid = 'test_exceptions')
		self.assertRaises(KeyNotFound, stats.get, 'anything')
		self.assertRaises(KeyNotFound, stats.set, 'anything', 22)
		self.assertRaises(KeyNotFound, stats.inc, 'anything')

		stats.set('created_at', datetime.now())
		self.assertRaises(KeyNotIncrementable, stats.inc, 'created_at')
예제 #8
0
	def test_stats_inc(self):
		stats = SMPPClientStatsCollector().get(cid = 'test_stats_inc')
		self.assertEqual(stats.get('bound_count'), 0)

		stats.inc('bound_count')
		self.assertEqual(stats.get('bound_count'), 1)

		stats.inc('bound_count', 5)
		self.assertEqual(stats.get('bound_count'), 6)
    def prepareRoutingsAndStartConnector(self):
        yield SubmitSmTestCaseTools.prepareRoutingsAndStartConnector(self)

        # Add a MO Route to a SmppServerSystemIdConnector
        c2_destination = SmppServerSystemIdConnector(system_id=self.smppc_factory.config.username)
        # Set the route
        yield self.moroute_add(DefaultRoute(c2_destination), 0)

        # Get stats singletons
        self.stats_smppc = SMPPClientStatsCollector().get(self.c1.cid)
예제 #10
0
    def smppc(self, arg, opts):
        sc = SMPPClientStatsCollector()
        headers = ["#Item", "Value"]

        table = []
        for k, v in sc.get(opts.smppc).getStats().iteritems():
            row = []
            row.append('#%s' % k)
            if k[-3:] == '_at':
                row.append(formatDateTime(v))
            else:
                row.append(v)

            table.append(row)

        self.protocol.sendData(
            tabulate(table, headers, tablefmt="plain", numalign="left").encode('ascii'))
예제 #11
0
	def test_stats(self):
		stats = SMPPClientStatsCollector().get(cid = 'test_stats')

		self.assertEqual(stats._stats, {
			'created_at': 0,
			'last_received_pdu_at': 0,
			'last_sent_pdu_at': 0,
			'last_received_elink_at': 0,
			'last_sent_elink_at': 0,
			'last_seqNum_at': 0,
			'last_seqNum': None,
			'connected_at': 0,
			'bound_at': 0,
			'disconnected_at': 0,
			'connected_count': 0,
			'bound_count': 0,
			'disconnected_count': 0,
		})
예제 #12
0
	def test_stats_set(self):
		stats = SMPPClientStatsCollector().get(cid = 'test_stats_set')
		self.assertEqual(stats.get('last_seqNum'), None)

		stats.set('last_seqNum', 2)
		self.assertEqual(stats.get('last_seqNum'), 2)
예제 #13
0
	def test_get_will_create_connector(self):
		c = SMPPClientStatsCollector()
		self.assertTrue('test_get_will_create_connector' not in c.connectors)

		c.get(cid = 'test_get_will_create_connector')
		self.assertTrue('test_get_will_create_connector' in c.connectors)