Exemple #1
0
 def set_job_servers(self, servers, pre_connect = False):
     # TODO: don't shut down dups and shut down old ones gracefully
     self.connections = []
     for serv in servers:
         connection = GearmanConnection(serv)
         if pre_connect:
             try:
                 connection.connect()
             except connection.ConnectionError:
                 pass # TODO: connection IS marked as dead but perhaps we don't want it at all
         self.connections.append( connection )
Exemple #2
0
 def set_job_servers(self, servers, pre_connect=False):
     # TODO: don't shut down dups. shut down old ones gracefully
     self.connections = []
     self.connections_by_hostport = {}
     for serv in servers:
         connection = GearmanConnection(serv, timeout=2)
         if pre_connect:
             try:
                 connection.connect()
             except connection.ConnectionError:
                 pass
         self.connections.append(connection)
         self.connections_by_hostport[connection.hostspec] = connection
Exemple #3
0
 def set_job_servers(self, servers, pre_connect=False):
     # TODO: don't shut down dups. shut down old ones gracefully
     self.connections = []
     self.connections_by_hostport = {}
     for serv in servers:
         connection = GearmanConnection(serv,timeout=2)
         if pre_connect:
             try:
                 connection.connect()
             except connection.ConnectionError:
                 pass
         self.connections.append(connection)
         self.connections_by_hostport[connection.hostspec] = connection
    def test_creating_with_host_port_pair_str(self, host_config):
        client = GearmanAdminClient(host_list=[host_config])
        assert len(client.connection_list) == 1

        _assert_gearman_connection_equal(conn1=GearmanConnection(
            host="localhost", port=4730),
                                         conn2=client.connection_list[0])
Exemple #5
0
class TestConnection(unittest.TestCase):
    def setUp(self):
        self.connection = GearmanConnection(job_servers[0])
        self.connection.connect()

    def testNoArgs(self):
        self.connection.send_command_blocking("echo_req")
        cmd = self.connection.recv_blocking()
        self.failUnlessEqual(cmd[0], "echo_res")

    def testWithArgs(self):
        self.connection.send_command_blocking("submit_job", dict(func="echo", uniq="", arg="tea"))
        cmd = self.connection.recv_blocking()
        self.failUnlessEqual(cmd[0], 'job_created')
Exemple #6
0
class TestConnection(GearmanTestCase):
    def setUp(self):
        self.start_server()
        self.connection = GearmanConnection(job_servers[0])
        self.connection.connect()

    def tearDown(self):
        self.stop_server()

    def testNoArgs(self):
        self.connection.send_command_blocking("echo_req")
        cmd = self.connection.recv_blocking()
        self.failUnlessEqual(cmd[0], "echo_res")

    def testWithArgs(self):
        self.connection.send_command_blocking("submit_job", dict(func="echo", uniq="", arg="tea"))
        cmd = self.connection.recv_blocking()
        self.failUnlessEqual(cmd[0], 'job_created')
    def test_creating_with_ssl_host(self):
        host_config = {
            "host": "localhost",
            "port": 5000,
            "keyfile": "key.txt",
            "certfile": "cert.txt",
            "ca_certs": "ca_certs.txt",
        }

        client = GearmanAdminClient(host_list=[host_config])
        assert len(client.connection_list) == 1

        _assert_gearman_connection_equal(conn1=GearmanConnection(
            host="localhost",
            port=5000,
            keyfile="key.txt",
            certfile="cert.txt",
            ca_certs="ca_certs.txt"),
                                         conn2=client.connection_list[0])
Exemple #8
0
 def start_server(self):
     self.server_pid = os.fork()
     if not self.server_pid:
         server = GearmanServer()
         server.start()
         sys.exit()
     connection = GearmanConnection(job_servers[0])
     for i in range(10):
         try:
             connection.connect()
         except GearmanConnection.ConnectionError:
             time.sleep(0.5)
         else:
             break
     connection.close()
Exemple #9
0
 def setUp(self):
     self.start_server()
     self.connection = GearmanConnection(job_servers[0])
     self.connection.connect()