Search in sources :

Example 1 with PerfStreamWriter

use of test.r2.perf.PerfStreamWriter in project rest.li by linkedin.

the class AbstractPerfServerFactory method createPureStreamServer.

public Server createPureStreamServer(int port, URI echoUri, final int msg_size, int numHeaders, int headerSize) {
    String headerContent = new StringGenerator(headerSize).nextMessage();
    StreamRequestHandler handler = new StreamRequestHandler() {

        @Override
        public void handleRequest(StreamRequest request, RequestContext requestContext, final Callback<StreamResponse> callback) {
            request.getEntityStream().setReader(new PerfStreamReader<>(new Callback<None>() {

                @Override
                public void onError(Throwable e) {
                    callback.onError(e);
                }

                @Override
                public void onSuccess(None result) {
                    StreamResponseBuilder builder = new StreamResponseBuilder();
                    for (int i = 0; i < numHeaders; i++) {
                        builder.setHeader(STATIC_HEADER_PREFIX + i, headerContent);
                    }
                    callback.onSuccess(builder.build(EntityStreams.newEntityStream(new PerfStreamWriter(msg_size))));
                }
            }, None.none()));
        }
    };
    final TransportDispatcher dispatcher = new TransportDispatcherBuilder().addStreamHandler(echoUri, handler).build();
    return createServer(port, dispatcher, true);
}
Also used : StreamResponseBuilder(com.linkedin.r2.message.stream.StreamResponseBuilder) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) PerfStreamWriter(test.r2.perf.PerfStreamWriter) StreamRequestHandler(com.linkedin.r2.transport.common.StreamRequestHandler) Callback(com.linkedin.common.callback.Callback) StringGenerator(test.r2.perf.StringGenerator) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Example 2 with PerfStreamWriter

use of test.r2.perf.PerfStreamWriter in project rest.li by linkedin.

the class StreamRequestGenerator method nextMessage.

@Override
public StreamRequest nextMessage() {
    if (_msgCounter.getAndDecrement() > 0) {
        StreamRequestBuilder builder = new StreamRequestBuilder(_uri);
        builder.setMethod(HTTP_POST_METHOD);
        for (int i = 0; i < _numHeaders; i++) {
            builder.setHeader(STATIC_HEADER_PREFIX + i, _headerContent);
        }
        return builder.build(EntityStreams.newEntityStream(new PerfStreamWriter(_msgSize)));
    } else {
        return null;
    }
}
Also used : StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) PerfStreamWriter(test.r2.perf.PerfStreamWriter)

Aggregations

PerfStreamWriter (test.r2.perf.PerfStreamWriter)2 Callback (com.linkedin.common.callback.Callback)1 None (com.linkedin.common.util.None)1 RequestContext (com.linkedin.r2.message.RequestContext)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)1 StreamResponseBuilder (com.linkedin.r2.message.stream.StreamResponseBuilder)1 StreamRequestHandler (com.linkedin.r2.transport.common.StreamRequestHandler)1 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)1 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)1 StringGenerator (test.r2.perf.StringGenerator)1