public function testParsing() { $cnt = count($this->prot_parseable); for ($i = 0; $i < $cnt; $i++) { try { //print($i . " " . ($this->prot_parseable[$i]?"true":"false") . " \n"); $prot = AvroProtocol::parse($this->prot_data[$i]); } catch (AvroSchemaParseException $x) { // exception ok if we expected this protocol spec to be unparseable $this->assertEquals(false, $this->prot_parseable[$i]); } } }
public function write($input_filename, $output_folder, $namespace_prefix, $java_string) { $protocol_json = file_get_contents($input_filename); $protocol = \AvroProtocol::parse($protocol_json); $working_tpl = $this->protocol_tpl; $filename = $this->getFilename($protocol); $subdirectory = $this->getSubdirectory($protocol); $working_tpl = $this->generate($protocol, $protocol_json, $namespace_prefix, $working_tpl, $java_string); if (!file_exists($output_folder . $subdirectory)) { mkdir($output_folder . $subdirectory, 0755, true); } file_put_contents($output_folder . $subdirectory . "/" . $filename, $working_tpl); }
{ echo $local_message->name . ":" . json_encode($request) . "\n"; switch ($local_message->name) { case "testSimpleRequestResponse": if ($request["message"]["subject"] == "ping") { return array("response" => "pong"); } else { if ($request["message"]["subject"] == "pong") { return array("response" => "ping"); } } break; case "testSimpleRequestWithoutParameters": return array("response" => "no incoming parameters"); break; case "testNotification": break; case "testRequestResponseException": if ($request["exception"]["cause"] == "callback") { throw new AvroRemoteException(array("exception" => "raised on callback cause")); } else { throw new AvroRemoteException("System exception"); } break; default: throw new AvroRemoteException("Method unknown"); } } } $server = new SocketServer('127.0.0.1', 1411, new TestProtocolResponder(AvroProtocol::parse($protocol)), true); $server->start();
public function testRequestResponseException() { $server = new TestServer(new TestProtocolResponder(AvroProtocol::parse($this->protocol))); $client = TestTransceiver::getTestClient($server); $requestor = new Requestor(AvroProtocol::parse($this->protocol), $client); $exception_raised = false; try { $response = $requestor->request('testRequestResponseException', array("exception" => array("cause" => "callback"))); } catch (AvroRemoteException $e) { $exception_raised = true; $exception_datum = $e->getDatum(); $this->assertEquals("raised on callback cause", $exception_datum["exception"]); } $this->assertTrue($exception_raised); $exception_raised = false; try { $response = $requestor->request('testRequestResponseException', array("exception" => array("cause" => "system"))); } catch (AvroRemoteException $e) { $exception_raised = true; $exception_datum = $e->getDatum(); $this->assertEquals("System exception", $exception_datum); } $this->assertTrue($exception_raised); }
protected function set_remote($handshake_response) { $this->remote_protocol[$this->transceiver->remote_name()] = AvroProtocol::parse($handshake_response["serverProtocol"]); if (!isset($this->remote_hash[$this->transceiver->remote_name()])) { $this->remote_hash[$this->transceiver->remote_name()] = $handshake_response["serverHash"]; } }
"testNotification": { "doc" : "Notification : one-way message", "request": [{"name": "notification", "type": "Notification"}], "one-way": true }, "testRequestResponseException": { "doc" : "Request Response with Exception", "request": [{"name": "exception", "type": "RaiseException"}], "response" : "NeverSend", "errors" : ["AlwaysRaised"] } } } PROTO; $client = NettyFramedSocketTransceiver::create('127.0.0.1', 1411); $requestor = new Requestor(AvroProtocol::parse($protocol), $client); try { $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "pong"))); echo "Response received: " . json_encode($response) . "\n"; $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "ping"))); echo "Response received: " . json_encode($response) . "\n"; } catch (AvroRemoteException $e) { echo "Exception received: " . json_encode($e->getDatum()) . "\n"; } try { $response = $requestor->request('testSimpleRequestWithoutParameters', array()); echo "Response received: " . json_encode($response) . "\n"; } catch (AvroRemoteException $e) { echo "Exception received: " . json_encode($e->getDatum()) . "\n"; } try {
public function __construct($host, $port) { $client = \NettyFramedSocketTransceiver::create($host, $port); parent::__construct(\AvroProtocol::parse(self::$json_protocol), $client); }