当前位置: 首页>>代码示例>>Python>>正文


Python JavaGateway.shutdown方法代码示例

本文整理汇总了Python中py4j.java_gateway.JavaGateway.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.shutdown方法的具体用法?Python JavaGateway.shutdown怎么用?Python JavaGateway.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py4j.java_gateway.JavaGateway的用法示例。


在下文中一共展示了JavaGateway.shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_all_regular_signals_auto_start

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
 def test_all_regular_signals_auto_start(self):
     listener = MockListener(self)
     with gateway_example_app_process(None):
         server_started.connect(listener.started)
         gateway = JavaGateway(
             gateway_parameters=GatewayParameters(),
             callback_server_parameters=CallbackServerParameters())
         server_stopped.connect(
             listener.stopped, sender=gateway.get_callback_server())
         server_connection_started.connect(
             listener.connection_started,
             sender=gateway.get_callback_server())
         server_connection_stopped.connect(
             listener.connection_stopped,
             sender=gateway.get_callback_server())
         pre_server_shutdown.connect(
             listener.pre_shutdown, sender=gateway.get_callback_server())
         post_server_shutdown.connect(
             listener.post_shutdown, sender=gateway.get_callback_server())
         example = gateway.entry_point.getNewExample()
         impl = IHelloImpl()
         self.assertEqual("This is Hello!", example.callHello(impl))
         gateway.shutdown()
     self.assertEqual(1, listener.received["started"])
     self.assertEqual(1, listener.received["stopped"])
     self.assertEqual(1, listener.received["pre_shutdown"])
     self.assertEqual(1, listener.received["post_shutdown"])
     self.assertEqual(1, listener.received["connection_started"])
     self.assertEqual(1, listener.received["connection_stopped"])
开发者ID:DiamondLightSource,项目名称:py4j,代码行数:31,代码来源:py4j_signals_test.py

示例2: testBadRetryFromJava

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
    def testBadRetryFromJava(self):
        """Should not retry from Java to Python.
        Similar use case as testBadRetry, but from Java: Java calls a long
        Python operation.

        If there is a bug, Java will call Python, then read will fail, then it
        will call Python again.

        If there is no bug, Java will call Python, read will fail, then Java
        will raise an Exception that will be received as a Py4JError on the
        Python side.
        """
        self.p = start_short_timeout_app_process()
        gateway = JavaGateway(
            callback_server_parameters=CallbackServerParameters())
        try:
            operator = WaitOperator(0.5)
            opExample = gateway.jvm.py4j.examples.OperatorExample()

            opExample.randomBinaryOperator(operator)
            self.fail(
                "Should never retry once the first command went through."
                " number of calls made: {0}".format(operator.callCount))
        except Py4JJavaError:
            self.assertTrue(True)
        finally:
            gateway.shutdown()
            self.p.join()
开发者ID:bartdag,项目名称:py4j,代码行数:30,代码来源:java_gateway_test.py

示例3: testGC

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
    def testGC(self):
        with gateway_example_app_process("nomem"):
            # This will only work with some JVM.
            gateway = JavaGateway(
                callback_server_parameters=CallbackServerParameters())
            sleep()
            example = gateway.entry_point.getNewExample()
            impl = IHelloImpl()
            self.assertEqual("This is Hello!", example.callHello(impl))
            self.assertEqual(
                "This is Hello;\n10MyMy!\n;",
                example.callHello2(impl))
            self.assertEqual(2, len(gateway.gateway_property.pool))

            # Make sure that finalizers do not block
            impl2 = IHelloImpl()
            self.assertEqual("This is Hello!", example.callHello(impl2))
            self.assertEqual(3, len(gateway.gateway_property.pool))

            gateway.jvm.java.lang.System.gc()

            # Leave time for sotimeout
            sleep(3)
            # Make sure the three objects have not been removed from the pool
            # because the Java side should not send gc request.
            self.assertEqual(len(gateway.gateway_property.pool), 3)
            gateway.shutdown()
开发者ID:DiamondLightSource,项目名称:py4j,代码行数:29,代码来源:java_callback_test.py

示例4: testGoodRetryFromJava

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
    def testGoodRetryFromJava(self):
        """Should retry from Java to Python.
        Similar use case as testGoodRetry, but from Java: Python calls Java,
        which calls Python back two times in a row. Then python waits for a
        while. Python then calls Java, which calls Python.

        Because Python Callback server has been waiting for too much time, the
        receiving socket has closed so the call from Java to Python will fail
        on send, and Java must retry by creating a new connection
        (CallbackConnection).
        """
        self.p = start_example_app_process()
        gateway = JavaGateway(callback_server_parameters=CallbackServerParameters(read_timeout=0.250))
        try:
            operator = WaitOperator(0)
            opExample = gateway.jvm.py4j.examples.OperatorExample()
            opExample.randomBinaryOperator(operator)
            str_connection = str(list(gateway._callback_server.connections)[0])

            opExample.randomBinaryOperator(operator)
            str_connection2 = str(list(gateway._callback_server.connections)[0])

            sleep(0.5)

            opExample.randomBinaryOperator(operator)
            str_connection3 = str(list(gateway._callback_server.connections)[0])

            self.assertEqual(str_connection, str_connection2)
            self.assertNotEqual(str_connection, str_connection3)
        except Py4JJavaError:
            self.fail("Java callbackclient did not retry.")
        finally:
            gateway.shutdown()
            self.p.join()
开发者ID:bartdag,项目名称:py4j,代码行数:36,代码来源:java_gateway_test.py

示例5: Test

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class Test(unittest.TestCase):
    def setUp(self):
#        logger = logging.getLogger("py4j")
#        logger.setLevel(logging.DEBUG)
#        logger.addHandler(logging.StreamHandler())
        self.p = start_example_app_process()
        time.sleep(0.5)
        self.gateway = JavaGateway()

    def tearDown(self):
        self.p.terminate()
        self.gateway.shutdown()
        time.sleep(0.5)

    def equal_maps(self, m1, m2):
        if len(m1) == len(m2):
            equal = True
            for k in m1:
                equal = m1[k] == m2[k]
                if not equal:
                    break
            return equal
        else:
            return False

    def testMap(self):
        dp0 = {}
        dp = get_map()
        dj = self.gateway.jvm.java.util.HashMap()
        self.equal_maps(dj, dp0)
        dj["a"] = 1
        dj["b"] = 2.0
        dj["c"] = "z"
        self.equal_maps(dj, dp)

        del(dj["a"])
        del(dp["a"])

        dj2 = self.gateway.jvm.java.util.HashMap()
        dj2["b"] = 2.0
        dj2["c"] = "z"

        dj3 = self.gateway.jvm.java.util.HashMap()
        dj3["a"] = 1
        dj3["b"] = 2.0
        dj3["c"] = "z"

        self.equal_maps(dj, dp)
        self.assertTrue(dj == dj)
        self.assertTrue(dj == dj2)
        # Does not always work for some reason...
        # Probably not worth supporting for now...
        # self.assertTrue(dj < dj3)
        self.assertTrue(dj != dp)

        dps = {1: 1, 2: 2}
        djs = self.gateway.jvm.java.util.HashMap()
        djs[1] = 1
        djs[2] = 2
        self.assertEqual(str(djs), str(dps))
开发者ID:pellis10asee,项目名称:sharkhunter-shb,代码行数:62,代码来源:java_map_test.py

示例6: shutdown_gateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
    def shutdown_gateway(event, gateway: JavaGateway, resource_name: str, shutdown_jvm: bool):
        if shutdown_jvm:
            gateway.shutdown()
        else:
            gateway.close()

        logger.info('Py4J gateway (%s) shut down', resource_name)
开发者ID:asphalt-framework,项目名称:asphalt-py4j,代码行数:9,代码来源:component.py

示例7: IntegrationTest

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class IntegrationTest(unittest.TestCase):
    def setUp(self):
        self.p = start_echo_server_process()
        # This is to ensure that the server is started before connecting to it!
        time.sleep(1)

    def tearDown(self):
        # Safety check in case there was an exception...
        safe_shutdown(self)
        self.p.join()

    def testIntegration(self):
        try:
            testSocket = get_test_socket()
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('yro0\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('ysHello World\n'.encode('utf-8'))
#            testSocket.sendall('yo\n'.encode('utf-8')) # No need because getNewExampe is in cache now!
            testSocket.sendall('yro1\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('ysHello World2\n'.encode('utf-8'))
            testSocket.close()
            time.sleep(1)

            self.gateway = JavaGateway(auto_field=True)
            ex = self.gateway.getNewExample()
            response = ex.method3(1, True)
            self.assertEqual('Hello World', response)
            ex2 = self.gateway.entry_point.getNewExample()
            response = ex2.method3(1, True)
            self.assertEqual('Hello World2', response)
            self.gateway.shutdown()
        except Exception as e:
            print('Error has occurred', e)
            self.fail('Problem occurred')

    def testException(self):
        try:
            testSocket = get_test_socket()
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('yro0\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall(b'x\n')
            testSocket.close()
            time.sleep(1)

            self.gateway = JavaGateway(auto_field=True)
            ex = self.gateway.getNewExample()

            try:
                ex.method3(1, True)
                self.fail('Should have failed!')
            except Py4JError:
                self.assertTrue(True)
            self.gateway.shutdown()
        except Exception as e:
            print('Error has occurred', e)
            self.fail('Problem occurred')
开发者ID:pellis10asee,项目名称:sharkhunter-shb,代码行数:61,代码来源:java_gateway_test.py

示例8: ProtocolTest

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class ProtocolTest(unittest.TestCase):
    def tearDown(self):
        # Safety check in case there was an exception...
        safe_shutdown(self)

    def testEscape(self):
        self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line(
            escape_new_line("Hello\t\rWorld\n\\")))
        self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line(
            escape_new_line("Hello\t\rWorld\n\\")))

    def testProtocolSend(self):
        testConnection = TestConnection()
        self.gateway = JavaGateway(testConnection, False)
        e = self.gateway.getExample()
        self.assertEqual('c\nt\ngetExample\ne\n', testConnection.last_message)
        e.method1(1, True, 'Hello\nWorld', e, None, 1.5)
        self.assertEqual(
                'c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n',
                testConnection.last_message)
        del(e)

    def testProtocolReceive(self):
        p = start_echo_server_process()
        time.sleep(1)
        try:
            testSocket = get_socket()
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('yro0\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('ysHello World\n'.encode('utf-8'))
            # No extra echange (method3) because it is already cached.
            testSocket.sendall('yi123\n'.encode('utf-8'))
            testSocket.sendall('yd1.25\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('yn\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('ybTrue\n'.encode('utf-8'))
            testSocket.sendall('yo\n'.encode('utf-8'))
            testSocket.sendall('yL123\n'.encode('utf-8'))
            testSocket.close()
            time.sleep(1)

            self.gateway = JavaGateway(auto_field=True)
            ex = self.gateway.getNewExample()
            self.assertEqual('Hello World', ex.method3(1, True))
            self.assertEqual(123, ex.method3())
            self.assertAlmostEqual(1.25, ex.method3())
            self.assertTrue(ex.method2() is None)
            self.assertTrue(ex.method4())
            self.assertEqual(long(123), ex.method8())
            self.gateway.shutdown()

        except Exception as e:
            print('Error has occurred', e)
            print_exc()
            self.fail('Problem occurred')
        p.join()
开发者ID:Isb1009,项目名称:py4j,代码行数:60,代码来源:java_gateway_test.py

示例9: TestIntegration

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class TestIntegration(unittest.TestCase):
    def setUp(self):
        #        logger = logging.getLogger("py4j")
        #        logger.setLevel(logging.DEBUG)
        #        logger.addHandler(logging.StreamHandler())
        self.p = start_example_app_process()
        self.gateway = JavaGateway(callback_server_parameters=CallbackServerParameters())

    def tearDown(self):
        safe_shutdown(self)
        self.p.join()
        sleep()

    #    Does not work when combined with other tests... because of TCP_WAIT
    def testShutdown(self):
        example = self.gateway.entry_point.getNewExample()
        impl = IHelloImpl()
        self.assertEqual("This is Hello!", example.callHello(impl))
        self.assertEqual("This is Hello;\n10MyMy!\n;", example.callHello2(impl))
        self.gateway.shutdown()
        self.assertEqual(0, len(self.gateway.gateway_property.pool))

    def testProxy(self):
        #        self.gateway.jvm.py4j.GatewayServer.turnLoggingOn()
        sleep()
        example = self.gateway.entry_point.getNewExample()
        impl = IHelloImpl()
        self.assertEqual("This is Hello!", example.callHello(impl))
        self.assertEqual("This is Hello;\n10MyMy!\n;", example.callHello2(impl))

    def testGC(self):
        # This will only work with some JVM.
        sleep()
        example = self.gateway.entry_point.getNewExample()
        impl = IHelloImpl()
        self.assertEqual("This is Hello!", example.callHello(impl))
        self.assertEqual("This is Hello;\n10MyMy!\n;", example.callHello2(impl))
        self.assertEqual(2, len(self.gateway.gateway_property.pool))
        self.gateway.jvm.java.lang.System.gc()
        sleep(1)
        self.assertTrue(len(self.gateway.gateway_property.pool) < 2)

    def testDoubleCallbackServer(self):
        try:
            self.gateway2 = JavaGateway(callback_server_parameters=CallbackServerParameters())
            self.fail()
        except Exception:
            self.assertTrue(True)

    def testMethodConstructor(self):
        sleep()
        goodAddition = GoodAddition()
        oe1 = self.gateway.jvm.py4j.examples.OperatorExample()
        # Test method
        oe1.randomBinaryOperator(goodAddition)
        # Test constructor
        oe2 = self.gateway.jvm.py4j.examples.OperatorExample(goodAddition)
        self.assertTrue(oe2 is not None)
开发者ID:DawnScience,项目名称:py4j,代码行数:60,代码来源:java_callback_test.py

示例10: ProtocolTest

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class ProtocolTest(unittest.TestCase):
    def tearDown(self):
        # Safety check in case there was an exception...
        safe_shutdown(self)

    def testEscape(self):
        self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\")))
        self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\")))

    def testProtocolSend(self):
        testConnection = TestConnection()
        self.gateway = JavaGateway()

        # Replace gateway client by test connection
        self.gateway.set_gateway_client(testConnection)

        e = self.gateway.getExample()
        self.assertEqual("c\nt\ngetExample\ne\n", testConnection.last_message)
        e.method1(1, True, "Hello\nWorld", e, None, 1.5)
        self.assertEqual("c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n", testConnection.last_message)
        del (e)

    def testProtocolReceive(self):
        p = start_echo_server_process()
        try:
            testSocket = get_socket()
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!yro0\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!ysHello World\n".encode("utf-8"))
            # No extra echange (method3) because it is already cached.
            testSocket.sendall("!yi123\n".encode("utf-8"))
            testSocket.sendall("!yd1.25\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!yn\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!ybTrue\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!yL123\n".encode("utf-8"))
            testSocket.sendall("!ydinf\n".encode("utf-8"))
            testSocket.close()
            sleep()

            self.gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_field=True))
            ex = self.gateway.getNewExample()
            self.assertEqual("Hello World", ex.method3(1, True))
            self.assertEqual(123, ex.method3())
            self.assertAlmostEqual(1.25, ex.method3())
            self.assertTrue(ex.method2() is None)
            self.assertTrue(ex.method4())
            self.assertEqual(long(123), ex.method8())
            self.assertEqual(float("inf"), ex.method8())
            self.gateway.shutdown()

        except Exception:
            print_exc()
            self.fail("Problem occurred")
        p.join()
开发者ID:bartdag,项目名称:py4j,代码行数:60,代码来源:java_gateway_test.py

示例11: gateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
def gateway(*args, **kwargs):
    g = JavaGateway(gateway_parameters=GatewayParameters(*args, auto_convert=True, **kwargs))
    time = g.jvm.System.currentTimeMillis()
    try:
        yield g
        # Call a dummy method to make sure we haven't corrupted the streams
        assert time <= g.jvm.System.currentTimeMillis()
    finally:
        g.shutdown()
开发者ID:bartdag,项目名称:py4j,代码行数:11,代码来源:java_gateway_test.py

示例12: gateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
def gateway(*args, **kwargs):
    g = JavaGateway(gateway_parameters=GatewayParameters(*args, auto_convert=True, **kwargs))
    lineSep = g.jvm.System.lineSeparator()
    try:
        yield g
        # Call a dummy method to make sure we haven't corrupted the streams
        assert lineSep == g.jvm.System.lineSeparator()
    finally:
        g.shutdown()
开发者ID:shobull,项目名称:hue,代码行数:11,代码来源:java_dir_test.py

示例13: ArrayTest

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class ArrayTest(unittest.TestCase):
    def setUp(self):
        self.p = start_example_app_process()
        time.sleep(0.5)
        self.gateway = JavaGateway()

    def tearDown(self):
        self.p.terminate()
        self.gateway.shutdown()
        time.sleep(0.5)

    def testArray(self):
        example = self.gateway.entry_point.getNewExample()
        array1 = example.getStringArray()
        array2 = example.getIntArray()
        self.assertEqual(3, len(array1))
        self.assertEqual(4, len(array2))

        self.assertEqual("333", array1[2])
        self.assertEqual(5, array2[1])

        array1[2] = "aaa"
        array2[1] = 6
        self.assertEqual("aaa", array1[2])
        self.assertEqual(6, array2[1])

        new_array = array2[1:3]
        self.assertEqual(2, len(new_array))
        self.assertEqual(1, new_array[1])

    def testCreateArray(self):
        int_class = self.gateway.jvm.int
        string_class = self.gateway.jvm.java.lang.String
        int_array = self.gateway.new_array(int_class, 2)
        string_array = self.gateway.new_array(string_class, 3, 5)
        self.assertEqual(2, len(int_array))
        self.assertEqual(3, len(string_array))
        self.assertEqual(5, len(string_array[0]))

    def testDoubleArray(self):
        double_class = self.gateway.jvm.double
        double_array = self.gateway.new_array(double_class, 2)
        double_array[0] = 2.2
        self.assertAlmostEqual(double_array[0], 2.2)

    def testFloatArray(self):
        float_class = self.gateway.jvm.float
        float_array = self.gateway.new_array(float_class, 2)
        float_array[0] = 2.2
        self.assertAlmostEqual(float_array[0], 2.2)

    def testCharArray(self):
        char_class = self.gateway.jvm.char
        char_array = self.gateway.new_array(char_class, 2)
        char_array[0] = "a"
        self.assertAlmostEqual(char_array[0], "a")
开发者ID:davidcsterratt,项目名称:py4j,代码行数:58,代码来源:java_array_test.py

示例14: IntegrationTest

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class IntegrationTest(unittest.TestCase):
    def setUp(self):
        self.p = start_echo_server_process()
        # This is to ensure that the server is started before connecting to it!

    def tearDown(self):
        # Safety check in case there was an exception...
        safe_shutdown(self)
        self.p.join()

    def testIntegration(self):
        try:
            testSocket = get_socket()
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!yro0\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!ysHello World\n".encode("utf-8"))
            testSocket.sendall("!yro1\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!ysHello World2\n".encode("utf-8"))
            testSocket.close()
            sleep()

            self.gateway = JavaGateway(
                gateway_parameters=GatewayParameters(auto_field=True))
            ex = self.gateway.getNewExample()
            response = ex.method3(1, True)
            self.assertEqual("Hello World", response)
            ex2 = self.gateway.entry_point.getNewExample()
            response = ex2.method3(1, True)
            self.assertEqual("Hello World2", response)
            self.gateway.shutdown()
        except Exception:
            self.fail("Problem occurred")

    def testException(self):
        try:
            testSocket = get_socket()
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall("!yro0\n".encode("utf-8"))
            testSocket.sendall("!yo\n".encode("utf-8"))
            testSocket.sendall(b"!x\n")
            testSocket.close()
            sleep()

            self.gateway = JavaGateway(
                gateway_parameters=GatewayParameters(auto_field=True))
            ex = self.gateway.getNewExample()

            self.assertRaises(Py4JError, lambda: ex.method3(1, True))
            self.gateway.shutdown()
        except Exception:
            self.fail("Problem occurred")
开发者ID:bartdag,项目名称:py4j,代码行数:55,代码来源:java_gateway_test.py

示例15: TestIntegration

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown [as 别名]
class TestIntegration(unittest.TestCase):
    def setUp(self):
#        logger = logging.getLogger("py4j")
#        logger.setLevel(logging.DEBUG)
#        logger.addHandler(logging.StreamHandler())
        time.sleep(1)
        self.p = start_example_app_process()
        time.sleep(1)
        self.gateway = JavaGateway(start_callback_server=True)

    def tearDown(self):
        safe_shutdown(self)
        self.p.join()
        time.sleep(1)

#    Does not work when combined with other tests... because of TCP_WAIT
    def testShutdown(self):
        example = self.gateway.entry_point.getNewExample()
        impl = IHelloImpl()
        self.assertEqual('This is Hello!', example.callHello(impl))
        self.assertEqual('This is Hello;\n10MyMy!\n;',
                example.callHello2(impl))
        self.gateway.shutdown()
        self.assertEqual(0, len(self.gateway.gateway_property.pool))

    def testProxy(self):
#        self.gateway.jvm.py4j.GatewayServer.turnLoggingOn()
        time.sleep(1)
        example = self.gateway.entry_point.getNewExample()
        impl = IHelloImpl()
        self.assertEqual('This is Hello!', example.callHello(impl))
        self.assertEqual('This is Hello;\n10MyMy!\n;',
                example.callHello2(impl))

    def testGC(self):
        # This will only work with some JVM.
        time.sleep(1)
        example = self.gateway.entry_point.getNewExample()
        impl = IHelloImpl()
        self.assertEqual('This is Hello!', example.callHello(impl))
        self.assertEqual('This is Hello;\n10MyMy!\n;',
                example.callHello2(impl))
        self.assertEqual(2, len(self.gateway.gateway_property.pool))
        self.gateway.jvm.java.lang.System.gc()
        time.sleep(2)
        self.assertTrue(len(self.gateway.gateway_property.pool) < 2)

    def testDoubleCallbackServer(self):
        try:
            self.gateway2 = JavaGateway(start_callback_server=True)
            self.fail()
        except Exception:
            self.assertTrue(True)
开发者ID:gdw2,项目名称:py4j,代码行数:55,代码来源:java_callback_test.py


注:本文中的py4j.java_gateway.JavaGateway.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。