Exemplo n.º 1
0
class SystemCompositionsTest(unittest.TestCase):
    def setUp(self):
        self.single_host = [make_system_composition('192.168.1.10')]
        self.multi_host = [make_system_composition('192.168.1.11'),
                           make_system_composition('192.168.1.11')]
        self.job = Job(self.single_host + self.multi_host, [])

    def test_wrong_identifier(self):
        self.assertListEqual(self.job.compositions_for_node('baz'), [])

    def test_single_host_identifier(self):
        self.assertListEqual(self.job.compositions_for_node('192.168.1.10'),
                             self.single_host)

    def test_multi_host_identifier(self):
        self.assertListEqual(self.job.compositions_for_node('192.168.1.11'),
                             self.multi_host)

    def test_hash(self):
        c = make_system_composition()
        self.assertIn(c, set((c,)))

    def test_sha1hash(self):
        c = make_system_composition('localhost')
        c.jvm = JVM('path', 'options')
        h = sha1()
        update_hasher(h, c.jvm.hash())
        update_hasher(h, c.node_setting.hash())
        self.assertEqual(c.hash(), h.hexdigest())

    def test_equal(self):
        s1 = SystemComposition(JVM('java'),
                               NodeSetting('localhost', 22, 'dummy', '/', '/'))
        s2 = SystemComposition(JVM('java'),
                               NodeSetting('localhost', 22, 'dummy', '/', '/'))
        self.assertEqual(s1, s2)

    def test_not_equal(self):
        s1 = SystemComposition(JVM('java'),
                               NodeSetting('localhost', 22, 'dummy', '/', '/'))
        s2 = SystemComposition(JVM('java'),
                               NodeSetting('192.168.1.1', 22, 'dummy', '/',
        '/'))
        self.assertNotEqual(s1, s2)

        self.assertNotEqual(s1, SystemComposition(JVM('java'), 'no_setting'))

    def test_different_hashes(self):
        j1 = JVM('java')
        j2 = JVM('java')
        ns = NodeSetting('localhost', 22, 'dummy', '/', '/')
        s1 = SystemComposition(j1, ns)
        s2 = SystemComposition(j2, ns)

        self.assertEqual(s1.hash(), s2.hash())

        j1.workload = ScalaBench('fop')
        j2.workload = ScalaBench('batik')

        self.assertNotEqual(s1.hash(), s2.hash())
Exemplo n.º 2
0
 def test_client_cycle(self):
     c = make_system_composition()
     w = ScalaBench('jython')
     f = DacapoHarness()
     s = Send()
     r = Receive()
     p = Print()
     c.jvm.workload = w
     c.flow = [f >> f >> s]
     j = Job(c, [r >> p])
     self.assertFalse(j.check())
Exemplo n.º 3
0
 def test_wrapped_jvm(self):
     c = make_system_composition()
     c.jvm = ValgrindJVM('jvm')
     w = ScalaBench('jython')
     s = Send()
     r = Receive()
     p = Print()
     c.jvm.workload = w
     c.flow = [c.jvm >> ('valgrind_log', 'payload') >> s]
     j = Job(c,
             [r >> p])
     self.assertTrue(j.check())
Exemplo n.º 4
0
 def test_wrong_output(self):
     c = make_system_composition()
     w = ScalaBench('jython')
     f = DacapoHarness()
     s = Send()
     r = Receive()
     p = Print()
     c.jvm.workload = w
     c.flow = [w >> ('a', 'stderr') >> f >> s]
     j = Job(c,
             [r >> p])
     self.assertFalse(j.check())
Exemplo n.º 5
0
    def test_valid_job(self):
        c = make_system_composition()
        w = ScalaBench('jython')
        f = DacapoHarness()
        s = Send()
        r = Receive()
        p = Print()
        c.jvm.workload = w
        c.flow = [w >> f >> ('times', 'payload') >> s]
        j = Job(c,
                [r >> p])

        self.assertTrue(j.check())
Exemplo n.º 6
0
 def test_server_cycle(self):
     c = make_system_composition()
     w = ScalaBench('jython')
     f = DacapoHarness()
     s = Send()
     r = Receive()
     p = Print()
     m = MockPipelineElement()
     m.inputs = Types(('a', int))
     m.outputs = Types(('a', int))
     c.jvm.workload = w
     c.flow = [w >> f >> s]
     j = Job(c, [r >> m >> m >> p])
     self.assertFalse(j.check())
Exemplo n.º 7
0
    def test_correct_path(self):
        comp = make_system_composition()
        comp.flow = [Print() >> Print()]
        j = Job(comp,
                [Receive() >> Print()])

        path = j.visualize()
        self.assertTrue(os.path.exists(path))
        path_pdf = j.visualize('pdf')
        self.assertTrue(os.path.exists(path_pdf))
        self.assertTrue(path_pdf.endswith('.pdf'))

        self.assertFalse(os.path.exists(os.path.splitext(path)[0]))
        self.assertFalse(os.path.exists(os.path.splitext(path_pdf)[0]))
        os.remove(path)
        os.remove(path_pdf)
Exemplo n.º 8
0
class BuildEnvTest(unittest.TestCase):
    def setUp(self):
        self.job = Job(make_system_composition(), [])

    def test_empty_send_rcv(self):
        env = self.job._build_environment()
        self.assertDictEqual(env['receive'](), {})
        self.assertEqual(env['send']('data'), None)

    def test_set_send_rcv(self):
        receive = lambda: {'x' : 23}
        send = lambda data: 42
        self.job.receive = receive
        self.job.send = send
        env = self.job._build_environment()
        self.assertDictEqual(env['receive'](), {'x' : 23})
        self.assertEqual(env['send']('data'), 42)
Exemplo n.º 9
0
class JobServerElementsTest(unittest.TestCase):
    def setUp(self):
        super(JobServerElementsTest, self).setUp()
        self.composition = SystemComposition(JVM('foo'), 'pseudo_node')
        self.job = Job([self.composition], [])

    def test_empty_elements(self):
        self.assertSetEqual(self.job._get_server_dependencies(), set())
Exemplo n.º 10
0
class RunServerPipelineTest(unittest.TestCase):
    def setUp(self):
        self.receive = Receive()
        self.j = Job([], [Edge(self.receive, MockPipelineElement())])
        self.data = {'a': 1, 'b' : 2}
        self.j.receive = lambda: self.data

    def test_receive(self):
        self.assertDictEqual(self.receive.out, {})
        self.j.run_server_pipeline()
        self.assertDictEqual(self.receive.out, {'results' : self.data})

    def test_no_receivers(self):
        j = Job([], [DacapoHarness() >> Print()])
        with self.assertRaises(ValueError):
            j.run_server_pipeline()

    def test_empty_flow(self):
        j = Job([], [])
        self.assertEqual(j.run_server_pipeline(), None)
Exemplo n.º 11
0
 def setUp(self):
     super(JobClientElementsTest, self).setUp()
     self.jvm = JVM('foo')
     w = ScalaBench('scalac')
     self.jvm.workload = w
     t = HProf('')
     self.jvm.tool = t
     f = Print()
     self.config = SystemComposition(self.jvm, 'pseudo_node')
     self.config.flow = [Edge(w, f)]
     self.job = Job(self.config, [])
Exemplo n.º 12
0
class JobClientElementsTest(unittest.TestCase):

    def setUp(self):
        super(JobClientElementsTest, self).setUp()
        self.jvm = JVM('foo')
        w = ScalaBench('scalac')
        self.jvm.workload = w
        t = HProf('')
        self.jvm.tool = t
        f = Print()
        self.config = SystemComposition(self.jvm, 'pseudo_node')
        self.config.flow = [Edge(w, f)]
        self.job = Job(self.config, [])

    def test_empty_elements(self):
        self.job.client_flow = []
        self.assertSetEqual(self.job._get_client_dependencies(self.config),
                            ScalaBench.DEPENDENCIES.union(HProf.DEPENDENCIES))

    def test_full_client_elements(self):
        self.assertSetEqual(self.job._get_client_dependencies(self.config),
                            ScalaBench.DEPENDENCIES.union(HProf.DEPENDENCIES))

    def test_empty_tool(self):
        self.config.jvm.tool = None
        self.assertSetEqual(self.job._get_client_dependencies(self.config),
                            ScalaBench.DEPENDENCIES)

    def test_empty_workload(self):
        config = make_system_composition()
        config.jvm.tool = HProf('')
        self.assertSetEqual(Job(config, [], [])._get_client_dependencies(config),
                            HProf.DEPENDENCIES)

    def test_wrong_config(self):
        with self.assertRaises(ValueError):
            self.job._get_client_dependencies(SystemComposition(JVM('java'),
                                                                           'pseudo'))
Exemplo n.º 13
0
 def setUp(self):
     self.job = Job(make_system_composition(), [])
Exemplo n.º 14
0
 def setUp(self):
     self.single_host = [make_system_composition('192.168.1.10')]
     self.multi_host = [make_system_composition('192.168.1.11'),
                        make_system_composition('192.168.1.11')]
     self.job = Job(self.single_host + self.multi_host, [])
Exemplo n.º 15
0
 def setUp(self):
     super(JobServerElementsTest, self).setUp()
     self.composition = SystemComposition(JVM('foo'), 'pseudo_node')
     self.job = Job([self.composition], [])
Exemplo n.º 16
0
 def setUp(self):
     self.receive = Receive()
     self.j = Job([], [Edge(self.receive, MockPipelineElement())])
     self.data = {'a': 1, 'b' : 2}
     self.j.receive = lambda: self.data
Exemplo n.º 17
0
 def test_no_receivers(self):
     j = Job([], [DacapoHarness() >> Print()])
     with self.assertRaises(ValueError):
         j.run_server_pipeline()
Exemplo n.º 18
0
 def test_empty_flow(self):
     j = Job([], [])
     self.assertEqual(j.run_server_pipeline(), None)
Exemplo n.º 19
0
 def test_no_workload(self):
     c = make_system_composition()
     j = Job(c, [])
     self.assertFalse(j.check())