Ejemplo n.º 1
0
 def test_release_empty_queue(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     self.mock_redis_conn.get.return_value = 0
     l1, l2 = queue.release(qname, self.uuid)
     self.assertEqual(0, l1)
     self.assertEqual(0, l2)
Ejemplo n.º 2
0
 def test_release_empty_queue(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     self.mock_redis_conn.get.return_value = 0
     l1, l2 = queue.release(qname, self.uuid)
     self.assertEqual(0, l1)
     self.assertEqual(0, l2)
Ejemplo n.º 3
0
 def test_dequeue_pipeline_connection_error(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     self.mock_redis_conn.pipeline.return_value.execute.side_effect =\
         ConnectionError
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ConnectionError) as ar:
         queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, ConnectionError)
Ejemplo n.º 4
0
 def test_dequeue_not_found(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5("None" + "_queue").hexdigest()
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         None, None
     with self.assertRaises(ERedisKeyNotFound) as ar:
         k, data = queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, ERedisKeyNotFound)
Ejemplo n.º 5
0
 def test_enqueue(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         1, 1, 11, 11
     r = queue.enqueue(qname, self.uuid, self.data)
     self.assertIsNone(r)
Ejemplo n.º 6
0
 def test_dequeue_pipeline_timeout_error(self):
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.pipeline.return_value.execute.side_effect =\
         TimeoutError
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(TimeoutError) as ar:
         queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, TimeoutError)
Ejemplo n.º 7
0
 def test_release_pipeline_connection_error(self):
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.hget.side_effect = ConnectionError
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ConnectionError) as ar:
         queue.release(qname, self.uuid)
     self.assertIsInstance(ar.exception, ConnectionError)
Ejemplo n.º 8
0
 def test_dequeue_pipeline_timeout_error(self):
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.pipeline.return_value.execute.side_effect =\
         TimeoutError
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(TimeoutError) as ar:
         queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, TimeoutError)
Ejemplo n.º 9
0
 def test_enqueue_queue_full(self):
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.get.return_value = '1024'
     self.assertEqual(len(queue), 1024)
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ERedisQueueFull) as ar:
         queue.enqueue(qname, self.uuid, self.data)
     self.assertIsInstance(ar.exception, ERedisQueueFull)
Ejemplo n.º 10
0
 def test_enqueue_pipeline_connection_error(self):
     self.mock_redis_conn.get.return_value = None
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.pipeline.side_effect = ConnectionError
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ConnectionError) as ar:
         queue.enqueue(qname, self.uuid, self.data)
     self.assertIsInstance(ar.exception, ConnectionError)
Ejemplo n.º 11
0
 def test_dequeue_pipeline_connection_error(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     self.mock_redis_conn.pipeline.return_value.execute.side_effect =\
         ConnectionError
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ConnectionError) as ar:
         queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, ConnectionError)
Ejemplo n.º 12
0
 def test_dequeue_not_found(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5("None" + "_queue").hexdigest()
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         None, None
     with self.assertRaises(ERedisKeyNotFound) as ar:
         k, data = queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, ERedisKeyNotFound)
Ejemplo n.º 13
0
 def test_enqueue(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         1, 1, 11, 11
     r = queue.enqueue(qname, self.uuid, self.data)
     self.assertIsNone(r)
Ejemplo n.º 14
0
 def test_enqueue_pipeline_connection_error(self):
     self.mock_redis_conn.get.return_value = None
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.pipeline.side_effect = ConnectionError
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ConnectionError) as ar:
         queue.enqueue(qname, self.uuid, self.data)
     self.assertIsInstance(ar.exception, ConnectionError)
Ejemplo n.º 15
0
 def test_enqueue_queue_full(self):
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.get.return_value = '1024'
     self.assertEqual(len(queue), 1024)
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ERedisQueueFull) as ar:
         queue.enqueue(qname, self.uuid, self.data)
     self.assertIsInstance(ar.exception, ERedisQueueFull)
Ejemplo n.º 16
0
 def test_release_pipeline_connection_error(self):
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.hget.side_effect = ConnectionError
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     with self.assertRaises(ConnectionError) as ar:
         queue.release(qname, self.uuid)
     self.assertIsInstance(ar.exception, ConnectionError)
Ejemplo n.º 17
0
 def test_dequeue_data_missing(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         None, job
     with self.assertRaises(ERedisDataMissing) as ar:
         k, data = queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, ERedisDataMissing)
Ejemplo n.º 18
0
 def test_dequeue(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         self.data, job
     k, data = queue.dequeue(qname, self.uuid)
     self.assertEqual(k, self.uuid)
     self.assertEqual(data, self.data)
Ejemplo n.º 19
0
 def test_proxy(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=False)
     self.mock_redis_conn.get.return_value = 10
     queue.redis.pipeline.return_value.execute.side_effect = ConnectionError
     qname = md5(self.user_id + "_queue").hexdigest()
     try:
         queue.enqueue(qname, self.uuid, self.data)
     except Exception as e:
         self.assertIsInstance(e, ConnectionError)
Ejemplo n.º 20
0
 def test_release_undequeued_job(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.hget.return_value = job
     with self.assertRaises(ERedisReleaseError) as ar:
         queue.release(qname, self.uuid)
     self.assertIsInstance(ar.exception, ERedisReleaseError)
Ejemplo n.º 21
0
 def test_dequeue(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         self.data, job
     k, data = queue.dequeue(qname, self.uuid)
     self.assertEqual(k, self.uuid)
     self.assertEqual(data, self.data)
Ejemplo n.º 22
0
 def test_release_undequeued_job(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.hget.return_value = job
     with self.assertRaises(ERedisReleaseError) as ar:
         queue.release(qname, self.uuid)
     self.assertIsInstance(ar.exception, ERedisReleaseError)
Ejemplo n.º 23
0
 def test_dequeue_data_missing(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         None, job
     with self.assertRaises(ERedisDataMissing) as ar:
         k, data = queue.dequeue(qname, self.uuid)
     self.assertIsInstance(ar.exception, ERedisDataMissing)
Ejemplo n.º 24
0
 def test_proxy(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=False)
     self.mock_redis_conn.get.return_value = 10
     queue.redis.pipeline.return_value.execute.side_effect = ConnectionError
     qname = md5(self.user_id + "_queue").hexdigest()
     try:
         queue.enqueue(qname, self.uuid, self.data)
     except Exception as e:
         self.assertIsInstance(e, ConnectionError)
Ejemplo n.º 25
0
 def test_queue_stats(self):
     self.mock_redis_conn.get.return_value = '20'
     self.mock_redis_conn.hget.return_value = '10'
     queue = HashQueue(self.mock_redis_conn)
     qname = md5(self.user_id + "_queue").hexdigest()
     stat = queue.stats(qname)
     self.assertEqual(1024, stat['size'])
     self.assertEqual(20, stat['length'])
     self.assertEqual('10', stat[qname])
     self.mock_redis_conn.hget.return_value = None
     stat = queue.stats(qname)
     self.assertEqual(None, stat[qname])
Ejemplo n.º 26
0
 def test_queue_stats(self):
     self.mock_redis_conn.get.return_value = '20'
     self.mock_redis_conn.hget.return_value = '10'
     queue = HashQueue(self.mock_redis_conn)
     qname = md5(self.user_id + "_queue").hexdigest()
     stat = queue.stats(qname)
     self.assertEqual(1024, stat['size'])
     self.assertEqual(20, stat['length'])
     self.assertEqual('10', stat[qname])
     self.mock_redis_conn.hget.return_value = None
     stat = queue.stats(qname)
     self.assertEqual(None, stat[qname])
Ejemplo n.º 27
0
 def test_release(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     job = pickle.loads(job)
     job.change_state(JOB_DEQUEUED)
     job = pickle.dumps(job)
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.hget.return_value = job
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         1, 1, 9, 9
     l1, l2 = queue.release(qname, self.uuid)
     self.assertEqual(9, l1)
     self.assertEqual(9, l2)
Ejemplo n.º 28
0
 def test_release(self):
     queue = HashQueue(self.mock_redis_conn, has_proxy=True)
     qname = md5(self.user_id + "_queue").hexdigest()
     job = pickle.dumps(Job(self.uuid))
     job = pickle.loads(job)
     job.change_state(JOB_DEQUEUED)
     job = pickle.dumps(job)
     self.mock_redis_conn.get.return_value = 10
     self.mock_redis_conn.hget.return_value = job
     self.mock_redis_conn.pipeline.return_value.execute.return_value =\
         1, 1, 9, 9
     l1, l2 = queue.release(qname, self.uuid)
     self.assertEqual(9, l1)
     self.assertEqual(9, l2)
Ejemplo n.º 29
0
 def test_queue_length(self):
     queue = HashQueue(self.mock_redis_conn)
     self.mock_redis_conn.get.return_value = None
     self.assertEqual(0, len(queue))
     self.mock_redis_conn.reset_mock()
     self.mock_redis_conn.get.return_value = '1024'
     self.assertEqual(1024, len(queue))
Ejemplo n.º 30
0
    def test_release_pipeline_timeout_error(self):
        self.mock_redis_conn.get.return_value = 10
        self.mock_redis_conn.hget.side_effect = TimeoutError
        queue = HashQueue(self.mock_redis_conn)
        qname = md5(self.user_id + "_queue").hexdigest()
        with self.assertRaises(TimeoutError) as ar:
            queue.release(qname, self.uuid)
        self.assertIsInstance(ar.exception, TimeoutError)

        self.mock_redis_conn.reset_mock()
        self.mock_redis_conn.get.side_effect = TimeoutError
        with self.assertRaises(TimeoutError) as ar:
            queue.release(qname, self.uuid)
        self.assertIsInstance(ar.exception, TimeoutError)

        self.mock_redis_conn.reset_mock()
        self.mock_redis_conn.get.return_value = 10
        self.mock_redis_conn.hget.return_value = pickle.dumps(Job(self.uuid))
        self.mock_redis_conn.pipeline.return_value.execute.side_effect =\
            TimeoutError
        with self.assertRaises(TimeoutError) as ar:
            queue.release(qname, self.uuid)
        self.assertIsInstance(ar.exception, TimeoutError)
Ejemplo n.º 31
0
    def test_release_pipeline_timeout_error(self):
        self.mock_redis_conn.get.return_value = 10
        self.mock_redis_conn.hget.side_effect = TimeoutError
        queue = HashQueue(self.mock_redis_conn)
        qname = md5(self.user_id + "_queue").hexdigest()
        with self.assertRaises(TimeoutError) as ar:
            queue.release(qname, self.uuid)
        self.assertIsInstance(ar.exception, TimeoutError)

        self.mock_redis_conn.reset_mock()
        self.mock_redis_conn.get.side_effect = TimeoutError
        with self.assertRaises(TimeoutError) as ar:
            queue.release(qname, self.uuid)
        self.assertIsInstance(ar.exception, TimeoutError)

        self.mock_redis_conn.reset_mock()
        self.mock_redis_conn.get.return_value = 10
        self.mock_redis_conn.hget.return_value = pickle.dumps(Job(self.uuid))
        self.mock_redis_conn.pipeline.return_value.execute.side_effect =\
            TimeoutError
        with self.assertRaises(TimeoutError) as ar:
            queue.release(qname, self.uuid)
        self.assertIsInstance(ar.exception, TimeoutError)