def testErrorInPythonCallback(self): with clientserver_example_app_process(): client_server = ClientServer( JavaParameters(), PythonParameters(propagate_java_exceptions=True)) example = client_server.entry_point.getNewExample() try: example.callHello( IHelloFailingImpl( ValueError('My interesting Python exception'))) self.fail() except Py4JJavaError as e: self.assertTrue( is_instance_of(client_server, e.java_exception, 'py4j.Py4JException')) self.assertTrue('interesting Python exception' in str(e)) try: example.callHello( IHelloFailingImpl( Py4JJavaError( '', client_server.jvm.java.lang.IllegalStateException( 'My IllegalStateException')))) self.fail() except Py4JJavaError as e: self.assertTrue( is_instance_of(client_server, e.java_exception, 'java.lang.IllegalStateException')) client_server.shutdown()
def testProxyError(self): sleep() example = self.gateway.entry_point.getNewExample() try: example.callHello(IHelloFailingImpl( Py4JJavaError( '', self.gateway.jvm.java.lang.IllegalStateException( 'My IllegalStateException')))) self.fail() except Py4JJavaError as e: self.assertTrue(is_instance_of( self.gateway, e.java_exception, 'py4j.Py4JException')) self.assertIn('My IllegalStateException', str(e))
def zip(self, other): if self.count() != other.count(): raise Py4JJavaError( "Can only zip RDDs with same number of elements in each partition", JavaException('')) other_flat = [o for p in other.partitions for o in p] zipped = [] idx = 0 for p in self.partitions: zipped_p = [] for r in p: zipped_p.append((r, other_flat[idx])) idx += 1 zipped.append(zipped_p) return self._toRDD(zipped)
def get(self): if failure_reason: return "failure-reason" else: raise Py4JJavaError("msg", JavaException())