示例#1
0
 def test_enqueue(self):
     self.relay._attempt(self.env, 0)
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     ret = q.enqueue(self.env)
     self.assertEqual(1, len(ret))
     self.assertEqual(2, len(ret[0]))
     self.assertEqual(self.env, ret[0][0])
     self.assertRegexpMatches(ret[0][1], r'[0-9a-fA-F]{32}')
 def test_enqueue(self):
     self.relay._attempt(self.env, 0)
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     ret = q.enqueue(self.env)
     self.assertEqual(1, len(ret))
     self.assertEqual(2, len(ret[0]))
     self.assertEqual(self.env, ret[0][0])
     self.assertRegexpMatches(ret[0][1], r"[0-9a-fA-F]{32}")
 def test_enqueue(self):
     self.relay._attempt(self.env, 0)
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     ret = q.enqueue(self.env)
     assert_equal(1, len(ret))
     assert_equal(2, len(ret[0]))
     assert_equal(self.env, ret[0][0])
     assert_regexp_matches(ret[0][1], r'[0-9a-fA-F]{32}')
 def test_enqueue_relayerror(self):
     err = PermanentRelayError("msg failure", Reply("550", "Not Ok"))
     self.relay._attempt(self.env, 0).AndRaise(err)
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     ret = q.enqueue(self.env)
     self.assertEqual(1, len(ret))
     self.assertEqual(2, len(ret[0]))
     self.assertEqual(self.env, ret[0][0])
     self.assertEqual(err, ret[0][1])
示例#5
0
 def test_enqueue_relayerror(self):
     err = PermanentRelayError('msg failure', Reply('550', 'Not Ok'))
     self.relay._attempt(self.env, 0).AndRaise(err)
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     ret = q.enqueue(self.env)
     self.assertEqual(1, len(ret))
     self.assertEqual(2, len(ret[0]))
     self.assertEqual(self.env, ret[0][0])
     self.assertEqual(err, ret[0][1])
 def test_enqueue_relayerror(self):
     err = PermanentRelayError('msg failure', Reply('550', 'Not Ok'))
     self.relay._attempt(self.env, 0).AndRaise(err)
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     ret = q.enqueue(self.env)
     assert_equal(1, len(ret))
     assert_equal(2, len(ret[0]))
     assert_equal(self.env, ret[0][0])
     assert_equal(err, ret[0][1])
 def test_add_policy_error(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     with self.assertRaises(NotImplementedError):
         q.add_policy("test")
 def test_flush_noop(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     q.flush()
 def test_start_noop(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     q.start()
示例#10
0
 def test_add_policy_error(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     with self.assertRaises(NotImplementedError):
         q.add_policy('test')
示例#11
0
 def test_flush_noop(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     q.flush()
示例#12
0
 def test_kill_noop(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     q.kill()
示例#13
0
 def test_start_noop(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     q.start()
 def test_kill_noop(self):
     self.mox.ReplayAll()
     q = ProxyQueue(self.relay)
     q.kill()
示例#15
0
 def _start_queue(self, name, options=None):
     if name in self.queues:
         return self.queues[name]
     if not options:
         options = getattr(self.cfg.queue, name)
     from .helpers import add_queue_policies, build_backoff_function
     new_queue = None
     relay_name = options.relay
     relay = self._start_relay(relay_name) if relay_name else None
     bounce_queue_name = options.get('bounce_queue', name)
     bounce_queue = self._start_queue(bounce_queue_name) \
                    if bounce_queue_name != name else None
     if options.type == 'memory':
         from slimta.queue import Queue
         from slimta.queue.dict import DictStorage
         store = DictStorage()
         backoff = build_backoff_function(options.retry)
         new_queue = Queue(store, relay, backoff=backoff,
                           bounce_queue=bounce_queue)
         new_queue.start()
     elif options.type == 'disk':
         from slimta.queue import Queue
         from slimta.diskstorage import DiskStorage
         env_dir = options.envelope_dir
         meta_dir = options.meta_dir
         tmp_dir = options.tmp_dir
         store = DiskStorage(env_dir, meta_dir, tmp_dir)
         backoff = build_backoff_function(options.retry)
         new_queue = Queue(store, relay, backoff=backoff,
                           bounce_queue=bounce_queue)
         new_queue.start()
     elif options.type == 'redis':
         from slimta.queue import Queue
         from slimta.redisstorage import RedisStorage
         kwargs = {}
         if 'host' in options:
             kwargs['host'] = options.host
         if 'port' in options:
             kwargs['port'] = int(options.port)
         if 'db' in options:
             kwargs['db'] = int(options.db)
         if 'password' in options:
             kwargs['password'] = options.password
         if 'socket_timeout' in options:
             kwargs['socket_timeout'] = float(options.socket_timeout)
         if 'prefix' in options:
             kwargs['prefix'] = options.prefix
         store = RedisStorage(**kwargs)
         backoff = build_backoff_function(options.retry)
         new_queue = Queue(store, relay, backoff=backoff,
                           bounce_queue=bounce_queue)
         new_queue.start()
     elif options.type == 'rackspace':
         from slimta.queue import Queue
         from slimta.cloudstorage import CloudStorage
         from slimta.cloudstorage.rackspace import RackspaceCloudAuth, \
                 RackspaceCloudFiles, RackspaceCloudQueues
         credentials = {'username': options.username}
         if 'password' in options:
             credentials['password'] = options.password
         if 'api_key' in options:
             credentials['api_key'] = options.api_key
         if 'tenant_id' in options:
             credentials['tenant_id'] = options.tenant_id
         auth_kwargs = {'region': options.region,
                        'timeout': 10.0}
         if 'endpoint' in options:
             auth_kwargs['endpoint'] = options.endpoint
         auth = RackspaceCloudAuth(credentials, **auth_kwargs)
         cloud_files = RackspaceCloudFiles(auth,
                 container=options.container_name, timeout=20.0)
         cloud_queues = None
         if 'queue_name' in options:
             cloud_queues = RackspaceCloudQueues(auth,
                     queue_name=options.queue_name, timeout=10.0)
         store = CloudStorage(cloud_files, cloud_queues)
         new_queue = Queue(store, relay, backoff=backoff,
                           bounce_queue=bounce_queue)
         new_queue.start()
     elif options.type == 'aws':
         from slimta.queue import Queue
         from slimta.cloudstorage import CloudStorage
         from slimta.cloudstorage.aws import SimpleStorageService, \
                 SimpleQueueService
         import boto
         if 'access_key_id' in options:
             from boto.s3.connection import S3Connection
             s3_conn = S3Connection(options.access_key_id,
                                    options.secret_access_key)
         else:
             s3_conn = boto.connect_s3()
         s3_bucket = s3_conn.get_bucket(options.bucket_name)
         s3 = SimpleStorageService(s3_bucket, timeout=20.0)
         sqs = None
         if 'queue_name' in options:
             from boto.sqs import connect_to_region
             region = options.get('queue_region', 'us-west-2')
             if 'access_key_id' in options:
                 sqs_conn = connect_to_region(region,
                         aws_access_key_id=options.access_key_id,
                         aws_secret_access_key=options.secret_access_key)
             else:
                 sqs_conn = connect_to_region(region)
             sqs_queue = sqs_conn.create_queue(options.queue_name)
             sqs = SimpleQueueService(sqs_queue, timeout=10.0)
         store = CloudStorage(s3, sqs)
         new_queue = Queue(store, relay, backoff=backoff,
                           bounce_queue=bounce_queue)
         new_queue.start()
     elif options.type == 'proxy':
         from slimta.queue.proxy import ProxyQueue
         new_queue = ProxyQueue(relay)
     elif options.type == 'custom':
         new_queue = custom_factory(options, relay)
     else:
         msg = 'queue type does not exist: '+options.type
         raise ConfigValidationError(msg)
     add_queue_policies(new_queue, options.get('policies', []))
     self.queues[name] = new_queue
     return new_queue