@Override
    public void unaryCall(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) {
        final ServerCallStreamObserver<SimpleResponse> obs =
                (ServerCallStreamObserver<SimpleResponse>) responseObserver;
        final SimpleResponse.Builder responseBuilder = SimpleResponse.newBuilder();
        try {
            switch (req.getResponseCompression()) {
                case DEFLATE:
                    // fallthrough, just use gzip
                case GZIP:
                    obs.setCompression("gzip");
                    break;
                case NONE:
                    obs.setCompression("identity");
                    break;
                case UNRECOGNIZED:
                    // fallthrough
                default:
                    obs.onError(Status.INVALID_ARGUMENT
                                        .withDescription("Unknown: " + req.getResponseCompression())
                                        .asRuntimeException());
                    return;
            }
        } catch (IllegalArgumentException e) {
            obs.onError(Status.UNIMPLEMENTED
                                .withDescription("compression not supported.")
                                .withCause(e)
                                .asRuntimeException());
            return;
        }

        if (req.getResponseSize() != 0) {
            final boolean compressable = compressableResponse(req.getResponseType());
            final ByteString dataBuffer = compressable ? compressableBuffer : uncompressableBuffer;
            // For consistency with the c++ TestServiceImpl, use a random offset for unary calls.
            // TODO(wonderfly): whether or not this is a good approach needs further discussion.
            final int offset = random.nextInt(
                    compressable ? compressableBuffer.size() : uncompressableBuffer.size());
            final ByteString payload = generatePayload(dataBuffer, offset, req.getResponseSize());
            responseBuilder.getPayloadBuilder()
                           .setType(compressable ? PayloadType.COMPRESSABLE : PayloadType.UNCOMPRESSABLE)
                           .setBody(payload);
        }

        if (req.hasResponseStatus()) {
            obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode())
                              .withDescription(req.getResponseStatus().getMessage())
                              .asRuntimeException());
            return;
        }

        responseObserver.onNext(responseBuilder.build());
        responseObserver.onCompleted();
    }
Immediately responds with a payload of the type and size specified in the request.
grpc/src/test/java/com/linecorp/armeria/internal/common/grpc/TestServiceImpl.java