import repository from arizona
[raven.git] / apps / gacks / testGacksQueue.py
1 import unittest
2 import xmlrpclib
3
4 from gacksqueue_mysql import *
5
6 class TestGacksQueue():
7     def setUp(self):
8         self.j1 = AsapJob(dict={"allocatorHRN": "foo", "consumerHRN": "fooslice", "resources": "cpu#10"})
9         self.j2 = AsapJob(dict={"allocatorHRN": "foo", "consumerHRN": "fooslice2", "resources": "cpu#15,disk#10"})
10         self.j3 = AsapJob(dict={"allocatorHRN": "bar", "consumerHRN": "barslice", "resources": "cpu#50"})
11         self.j4 = AsapJob(dict={"allocatorHRN": "bar", "consumerHRN": "barslice2", "resources": "cpu#15,disk#10"})
12
13     def testCreate(self):
14         c = self.createQueue()
15         c.reset()
16
17     def testAdd(self):
18         c = self.createQueue()
19         c.reset()
20         c.add(self.j1)
21         c.add(self.j2)
22         c.add(self.j3)
23         c.add(self.j4)
24
25     def testQuery(self):
26         c = self.createQueue()
27         c.reset()
28         c.add(self.j1)
29         c.add(self.j2)
30         c.add(self.j3)
31         c.add(self.j4)
32
33         jobs = c.query()
34         self.assertEqual(len(jobs), 4)
35
36         jobs = c.query(allocatorHRN = "foo")
37         self.assertEqual(len(jobs), 2)
38
39         jobs = c.query(consumerHRN = "fooslice")
40         self.assertEqual(len(jobs), 1)
41
42         jobs = c.query(consumerHRN = "fooslice2")
43         self.assertEqual(len(jobs), 1)
44
45         jobs = c.query(allocatorHRN = "foo", consumerHRN = "fooslice")
46         self.assertEqual(len(jobs), 1)
47
48         jobs2 = c.query(id = jobs[0].get_jobid())
49         self.assertEqual(len(jobs2), 1)
50         self.assertEqual(jobs[0].get_jobid(), jobs2[0].get_jobid())
51         self.assertEqual(jobs[0].get_consumer(), jobs2[0].get_consumer())
52         self.assertEqual(jobs[0].get_allocator(), jobs2[0].get_allocator())
53
54     def testDelete(self):
55         c = self.createQueue()
56         c.reset()
57         c.add(self.j1)
58         c.add(self.j2)
59         c.add(self.j3)
60         c.add(self.j4)
61
62         c.delete(allocatorHRN = "foo", consumerHRN = "fooslice")
63         jobs = c.query()
64         self.assertEqual(len(jobs), 3)
65
66         c.delete(consumerHRN = "barslice")
67         jobs = c.query()
68         self.assertEqual(len(jobs), 2)
69
70         c.delete(allocatorHRN = "bar")
71         jobs = c.query()
72         self.assertEqual(len(jobs), 1)
73
74     def testLocking(self):
75         c = self.createQueue()
76         c.lock()
77         c.unlock()
78         c.lock()
79         c.unlock()
80
81 class TestGacksMySQLQueue(unittest.TestCase, TestGacksQueue):
82     def setUp(self):
83         TestGacksQueue.setUp(self)
84
85     def createQueue(self):
86         return GacksMySQLQueue(tableName = "gacks_queue_test")
87
88 def junk():
89     queue = GacksMySQLQueue(tableName = "gacks_queue_test")
90     queue.reset();
91     j1 = AsapJob(dict={"allocatorHRN": "foo", "consumerHRN": "fooslice", "resources": "cpu#10"})
92     j2 = AsapJob(dict={"allocatorHRN": "foo", "consumerHRN": "fooslice2", "resources": "cpu#15,disk#10"})
93     j3 = AsapJob(dict={"allocatorHRN": "bar", "consumerHRN": "barslice", "resources": "cpu#50"})
94     j4 = AsapJob(dict={"allocatorHRN": "bar", "consumerHRN": "barslice2", "resources": "cpu#15,disk#10"})
95     queue.add(j1)
96     queue.add(j2)
97     queue.add(j3)
98     queue.add(j4)
99     queue.delete(allocatorHRN = "foo", consumerHRN = "fooslice")
100     jobs = queue.query()
101     print str(jobs)
102     queue.delete(consumerHRN = "barslice")
103     jobs = queue.query()
104     print str(jobs)
105
106 #if __name__ == "__main__":
107 #    junk()
108
109
110 if __name__ == "__main__":
111     unittest.main()