Beispiel #1
0
class SMPPClientManagerPBTestCase(HttpServerTestCase):
    @defer.inlineCallbacks
    def setUp(self):
        HttpServerTestCase.setUp(self)
        
        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        AMQPServiceConfigInstance = AmqpConfig()
        AMQPServiceConfigInstance.reconnectOnConnectionLoss = False

        # Launch AMQP Broker
        self.amqpBroker = AmqpFactory(AMQPServiceConfigInstance)
        self.amqpBroker.preConnect()
        self.amqpClient = reactor.connectTCP(AMQPServiceConfigInstance.host, AMQPServiceConfigInstance.port, self.amqpBroker)
        
        # Wait for AMQP Broker connection to get ready
        yield self.amqpBroker.getChannelReadyDeferred()
        
        # Add the broker to the RouterPB
        yield self.pbRoot_f.addAmqpBroker(self.amqpBroker)
        
        # Setup smpp client manager pb
        yield self.clientManager_f.addAmqpBroker(self.amqpBroker)
        p = portal.Portal(JasminPBRealm(self.clientManager_f))
        p.registerChecker(AllowAnonymousAccess())
        jPBPortalRoot = JasminPBPortalRoot(p)
        self.CManagerServer = reactor.listenTCP(0, pb.PBServerFactory(jPBPortalRoot))
        self.CManagerPort = self.CManagerServer.getHost().port
        
        # Start DLRThrower
        DLRThrowerConfigInstance = DLRThrowerConfig()
        self.DLRThrower = DLRThrower()
        self.DLRThrower.setConfig(DLRThrowerConfigInstance)
        yield self.DLRThrower.addAmqpBroker(self.amqpBroker)
        
        # Connect to redis server
        RedisForJasminConfigInstance = RedisForJasminConfig()
        self.redisClient = yield ConnectionWithConfiguration(RedisForJasminConfigInstance)
        # Authenticate and select db
        if RedisForJasminConfigInstance.password is not None:
            yield self.redisClient.auth(RedisForJasminConfigInstance.password)
            yield self.redisClient.select(RedisForJasminConfigInstance.dbid)
        # Connect CM with RC:
        self.clientManager_f.addRedisClient(self.redisClient)
        
        # Set a smpp client manager proxy instance
        self.SMPPClientManagerPBProxy = SMPPClientManagerPBProxy()
    
    @defer.inlineCallbacks
    def tearDown(self):
        yield HttpServerTestCase.tearDown(self)
        
        if self.SMPPClientManagerPBProxy.isConnected:
            yield self.SMPPClientManagerPBProxy.disconnect()
        yield self.CManagerServer.stopListening()
        yield self.amqpClient.disconnect()
        yield self.redisClient.disconnect()
Beispiel #2
0
class SMPPClientManagerPBTestCase(HttpServerTestCase):
    @defer.inlineCallbacks
    def setUp(self):
        HttpServerTestCase.setUp(self)

        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        AMQPServiceConfigInstance = AmqpConfig()
        AMQPServiceConfigInstance.reconnectOnConnectionLoss = False

        # Launch AMQP Broker
        self.amqpBroker = AmqpFactory(AMQPServiceConfigInstance)
        self.amqpBroker.preConnect()
        self.amqpClient = reactor.connectTCP(AMQPServiceConfigInstance.host,
                                             AMQPServiceConfigInstance.port,
                                             self.amqpBroker)

        # Wait for AMQP Broker connection to get ready
        yield self.amqpBroker.getChannelReadyDeferred()

        # Add the broker to the RouterPB
        yield self.pbRoot_f.addAmqpBroker(self.amqpBroker)

        # Setup smpp client manager pb
        yield self.clientManager_f.addAmqpBroker(self.amqpBroker)
        p = portal.Portal(JasminPBRealm(self.clientManager_f))
        p.registerChecker(AllowAnonymousAccess())
        jPBPortalRoot = JasminPBPortalRoot(p)
        self.CManagerServer = reactor.listenTCP(
            0, pb.PBServerFactory(jPBPortalRoot))
        self.CManagerPort = self.CManagerServer.getHost().port

        # Start DLRThrower
        DLRThrowerConfigInstance = DLRThrowerConfig()
        self.DLRThrower = DLRThrower()
        self.DLRThrower.setConfig(DLRThrowerConfigInstance)
        yield self.DLRThrower.addAmqpBroker(self.amqpBroker)

        # Connect to redis server
        RedisForJasminConfigInstance = RedisForJasminConfig()
        self.redisClient = yield ConnectionWithConfiguration(
            RedisForJasminConfigInstance)
        # Authenticate and select db
        if RedisForJasminConfigInstance.password is not None:
            yield self.redisClient.auth(RedisForJasminConfigInstance.password)
            yield self.redisClient.select(RedisForJasminConfigInstance.dbid)
        # Connect CM with RC:
        self.clientManager_f.addRedisClient(self.redisClient)

        # Set a smpp client manager proxy instance
        self.SMPPClientManagerPBProxy = SMPPClientManagerPBProxy()

    @defer.inlineCallbacks
    def tearDown(self):
        yield HttpServerTestCase.tearDown(self)

        if self.SMPPClientManagerPBProxy.isConnected:
            yield self.SMPPClientManagerPBProxy.disconnect()
        yield self.CManagerServer.stopListening()
        yield self.amqpClient.disconnect()
        yield self.redisClient.disconnect()