Util.jsonToGenericDatum(expectedMessage.getResponse(), data.value(opts)); } else if (file.value(opts) != null) { this.response = Util.datumFromFile(expectedMessage.getResponse(), file.value(opts)); } else {
new GenericRequestor(protocol, Ipc.createTransceiver(uri)); Object response = client.request(message.getName(), datum); dumpJson(out, message.getResponse(), response); return 0;
private Protocol addStringType(Protocol p) { if (stringType != StringType.String) return p; Protocol newP = new Protocol(p.getName(), p.getDoc(), p.getNamespace()); Map<Schema,Schema> types = new LinkedHashMap<>(); for (Map.Entry<String, Object> a : p.getObjectProps().entrySet()) { newP.addProp(a.getKey(), a.getValue()); } // annotate types Collection<Schema> namedTypes = new LinkedHashSet<>(); for (Schema s : p.getTypes()) namedTypes.add(addStringType(s, types)); newP.setTypes(namedTypes); // annotate messages Map<String,Message> newM = newP.getMessages(); for (Message m : p.getMessages().values()) newM.put(m.getName(), m.isOneWay() ? newP.createMessage(m, addStringType(m.getRequest(), types)) : newP.createMessage(m, addStringType(m.getRequest(), types), addStringType(m.getResponse(), types), addStringType(m.getErrors(), types))); return newP; }
out.writeBoolean(error != null); if (error == null) writeResponse(m.getResponse(), response, out); else writeError(m.getErrors(), error, out);
dumpJson(out, message.getResponse(), response); return 0;
new GenericRequestor(protocol, Ipc.createTransceiver(uri)); Object response = client.request(message.getName(), datum); dumpJson(out, message.getResponse(), response); return 0;
dumpJson(out, message.getResponse(), response); return 0;
Util.jsonToGenericDatum(expectedMessage.getResponse(), data.value(opts)); } else if (file.value(opts) != null) { this.response = Util.datumFromFile(expectedMessage.getResponse(), file.value(opts)); } else {
Util.jsonToGenericDatum(expectedMessage.getResponse(), data.value(opts)); } else if (file.value(opts) != null) { this.response = Util.datumFromFile(expectedMessage.getResponse(), file.value(opts)); } else {
Object response = readResponse(rm.getResponse(), lm.getResponse(), in); context.setResponse(response); for (RPCPlugin plugin : rpcMetaPlugins) {
private OutputFile compileInterface(Protocol protocol) { OutputFile outputFile = new OutputFile(); String mangledName = mangle(protocol.getName()); outputFile.path = makePath(mangledName, protocol.getNamespace()); StringBuilder out = new StringBuilder(); header(out, protocol.getNamespace()); doc(out, 1, protocol.getDoc()); line(out, 0, "public interface " + mangledName + " {"); line(out, 1, "public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse(\"" +esc(protocol)+"\");"); for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) { String name = e.getKey(); Message message = e.getValue(); Schema request = message.getRequest(); String response = message.isOneWay() ? "void" : unbox(message.getResponse()); doc(out, 1, e.getValue().getDoc()); line(out, 1, response+" "+ mangle(name)+"("+params(request)+")" + (message.isOneWay() ? "" : (" throws org.apache.avro.ipc.AvroRemoteException" +errors(message.getErrors()))) +";"); } line(out, 0, "}"); outputFile.contents = out.toString(); return outputFile; }
private OutputFile compileInterface(Protocol protocol) { OutputFile outputFile = new OutputFile(); String mangledName = mangle(protocol.getName()); outputFile.path = makePath(mangledName, protocol.getNamespace()); StringBuilder out = new StringBuilder(); header(out, protocol.getNamespace()); doc(out, 1, protocol.getDoc()); line(out, 0, "public interface " + mangledName + " {"); line(out, 1, "public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse(\"" +esc(protocol)+"\");"); for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) { String name = e.getKey(); Message message = e.getValue(); Schema request = message.getRequest(); Schema response = message.getResponse(); doc(out, 1, e.getValue().getDoc()); line(out, 1, unbox(response)+" "+ mangle(name)+"("+params(request)+")"); line(out, 2,"throws org.apache.avro.ipc.AvroRemoteException"+errors(message.getErrors())+";"); } line(out, 0, "}"); outputFile.contents = out.toString(); return outputFile; }
writeResponse(m.getResponse(), response, out); else try {
Object response = readResponse(rm.getResponse(), lm.getResponse(), in); context.setResponse(response); for (RPCPlugin plugin : rpcMetaPlugins) {
} else { Schema request = resolve(replacements, value.getRequest(), protocol); Schema response = resolve(replacements, value.getResponse(), protocol); Schema errors = resolve(replacements, value.getErrors(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(),
BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(outputStream, null); out.writeBoolean(false); new SpecificDatumWriter(message.getResponse()).write(response, out); out.flush(); written = outputStream.getWrittenCount();
@Override public Object parse(InputStream stream) { try { if (message.isOneWay()) return null; BinaryDecoder in = DECODER_FACTORY.binaryDecoder(stream, null); if (!in.readBoolean()) { Object response = new SpecificDatumReader(message.getResponse()).read(null, in); return response; } else { Object value = new SpecificDatumReader(message.getErrors()).read(null, in); if (value instanceof Exception) { return value; } return new AvroRuntimeException(value.toString()); } } catch (IOException e) { throw Status.INTERNAL.withCause(e). withDescription("Error deserializing avro response").asRuntimeException(); } finally { AvroGrpcUtils.skipAndCloseQuietly(stream); } }
@Test public void testP1() throws Exception { Protocol p1 = ReflectData.get().getProtocol(P1.class); Protocol.Message message = p1.getMessages().get("foo"); // check response schema is union Schema response = message.getResponse(); assertEquals(Schema.Type.UNION, response.getType()); assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType()); // check request schema is union Schema request = message.getRequest(); Field field = request.getField("s"); assertNotNull("field 's' should not be null", field); Schema param = field.schema(); assertEquals(Schema.Type.UNION, param.getType()); assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType()); // check union erasure assertEquals(String.class, ReflectData.get().getClass(response)); assertEquals(String.class, ReflectData.get().getClass(param)); }
@Test public void testP0() throws Exception { Protocol p0 = ReflectData.get().getProtocol(P0.class); Protocol.Message message = p0.getMessages().get("foo"); // check response schema is union Schema response = message.getResponse(); assertEquals(Schema.Type.UNION, response.getType()); assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType()); // check request schema is union Schema request = message.getRequest(); Field field = request.getField("s"); assertNotNull("field 's' should not be null", field); Schema param = field.schema(); assertEquals(Schema.Type.UNION, param.getType()); assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType()); // check union erasure assertEquals(String.class, ReflectData.get().getClass(response)); assertEquals(String.class, ReflectData.get().getClass(param)); }
@Test public void testP4() throws Exception { Protocol p = ReflectData.get().getProtocol(P4.class); Protocol.Message message = p.getMessages().get("foo"); assertEquals(Schema.Type.INT, message.getResponse().getType()); Field field = message.getRequest().getField("x"); assertEquals(Schema.Type.INT, field.schema().getType()); }