Search in sources :

Example 1 with StreamFilter

use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.

the class StreamFilterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    _filter = new StreamFilter() {
    };
    _beforeFilter = new StreamCountFilter();
    _afterFilter = new StreamCountFilter();
    _fc = FilterChains.createStreamChain(_beforeFilter, _filter, _afterFilter);
}
Also used : StreamCountFilter(com.linkedin.r2.testutils.filter.StreamCountFilter) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with StreamFilter

use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.

the class TestRequestCompression method requestCompressionData.

@DataProvider
public Object[][] requestCompressionData() {
    StreamEncodingType[] encodings = new StreamEncodingType[] { StreamEncodingType.GZIP, StreamEncodingType.DEFLATE, StreamEncodingType.SNAPPY_FRAMED, StreamEncodingType.BZIP2 };
    String[] protocols = new String[] { HttpProtocolVersion.HTTP_1_1.name(), HttpProtocolVersion.HTTP_2.name() };
    Object[][] args = new Object[encodings.length * protocols.length][2];
    int cur = 0;
    for (StreamEncodingType requestEncoding : encodings) {
        for (String protocol : protocols) {
            StreamFilter clientCompressionFilter = new ClientStreamCompressionFilter(requestEncoding, new CompressionConfig(THRESHOLD), null, new CompressionConfig(THRESHOLD), Arrays.asList(new String[] { "*" }), _executor);
            TransportClientFactory factory = new HttpClientFactory.Builder().setFilterChain(FilterChains.createStreamChain(clientCompressionFilter)).build();
            HashMap<String, String> properties = new HashMap<>();
            properties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocol);
            Client client = new TransportClientAdapter(factory.getClient(properties), true);
            args[cur][0] = client;
            args[cur][1] = URI.create("/" + requestEncoding.getHttpName());
            cur++;
            _clientFactories.add(factory);
            _clients.add(client);
        }
    }
    return args;
}
Also used : HashMap(java.util.HashMap) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) ByteString(com.linkedin.data.ByteString) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) StreamEncodingType(com.linkedin.r2.filter.compression.streaming.StreamEncodingType) ClientStreamCompressionFilter(com.linkedin.r2.filter.compression.ClientStreamCompressionFilter) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) Client(com.linkedin.r2.transport.common.Client) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) CompressionConfig(com.linkedin.r2.filter.CompressionConfig) DataProvider(org.testng.annotations.DataProvider)

Example 3 with StreamFilter

use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.

the class TestServerRetryFilter method testStreamRetryFilter.

@Test
public void testStreamRetryFilter() {
    String retryMessage = "this is a retry";
    ServerRetryFilter retryFilter = new ServerRetryFilter();
    StreamFilter captureFilter = new StreamFilter() {

        @Override
        public void onStreamError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
            Assert.assertEquals(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY), retryMessage);
        }
    };
    FilterChain filterChain = FilterChains.createStreamChain(captureFilter, retryFilter);
    FilterUtil.fireRestError(filterChain, new StreamException(null, new RetriableRequestException(retryMessage)), new HashMap<String, String>());
}
Also used : RetriableRequestException(com.linkedin.r2.RetriableRequestException) ServerRetryFilter(com.linkedin.r2.filter.transport.ServerRetryFilter) NextFilter(com.linkedin.r2.filter.NextFilter) FilterChain(com.linkedin.r2.filter.FilterChain) RequestContext(com.linkedin.r2.message.RequestContext) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) HashMap(java.util.HashMap) Map(java.util.Map) StreamException(com.linkedin.r2.message.stream.StreamException) Test(org.testng.annotations.Test)

Example 4 with StreamFilter

use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.

the class TestFilterChainImpl method testNullFilterInList.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullFilterInList() {
    List<RestFilter> restFilters = new ArrayList<RestFilter>();
    restFilters.add(new RestCountFilter());
    restFilters.add(null);
    FilterChains.create(restFilters, Collections.<StreamFilter>emptyList());
}
Also used : RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) ArrayList(java.util.ArrayList) RestCountFilter(com.linkedin.r2.testutils.filter.RestCountFilter) Test(org.testng.annotations.Test)

Example 5 with StreamFilter

use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.

the class TestCompressionEcho method compressionEchoData.

@DataProvider
public Object[][] compressionEchoData() {
    StreamEncodingType[] encodings = new StreamEncodingType[] { StreamEncodingType.GZIP, StreamEncodingType.DEFLATE, StreamEncodingType.SNAPPY_FRAMED, StreamEncodingType.BZIP2, StreamEncodingType.IDENTITY };
    Object[][] args = new Object[2 * encodings.length * encodings.length][2];
    int cur = 0;
    for (StreamEncodingType requestEncoding : encodings) {
        for (StreamEncodingType acceptEncoding : encodings) {
            StreamFilter clientCompressionFilter = new ClientStreamCompressionFilter(requestEncoding, new CompressionConfig(THRESHOLD), new StreamEncodingType[] { acceptEncoding }, new CompressionConfig(THRESHOLD), Arrays.asList(new String[] { "*" }), _executor);
            TransportClientFactory factory = new HttpClientFactory.Builder().setFilterChain(FilterChains.createStreamChain(clientCompressionFilter)).build();
            Client client = new TransportClientAdapter(factory.getClient(getClientProperties()), true);
            args[cur][0] = client;
            args[cur][1] = LARGE_BYTES_NUM;
            cur++;
            _clientFactories.add(factory);
            _clients.add(client);
        }
    }
    // test data that won't trigger compression
    for (StreamEncodingType requestEncoding : encodings) {
        for (StreamEncodingType acceptEncoding : encodings) {
            StreamFilter clientCompressionFilter = new ClientStreamCompressionFilter(requestEncoding, new CompressionConfig(THRESHOLD), new StreamEncodingType[] { acceptEncoding }, new CompressionConfig(THRESHOLD), Arrays.asList(new String[] { "*" }), _executor);
            TransportClientFactory factory = new HttpClientFactory.Builder().setFilterChain(FilterChains.createStreamChain(clientCompressionFilter)).build();
            Client client = new TransportClientAdapter(factory.getClient(getClientProperties()), true);
            args[cur][0] = client;
            args[cur][1] = SMALL_BYTES_NUM;
            cur++;
            _clientFactories.add(factory);
            _clients.add(client);
        }
    }
    return args;
}
Also used : StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) StreamResponseBuilder(com.linkedin.r2.message.stream.StreamResponseBuilder) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) StreamEncodingType(com.linkedin.r2.filter.compression.streaming.StreamEncodingType) ClientStreamCompressionFilter(com.linkedin.r2.filter.compression.ClientStreamCompressionFilter) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) Client(com.linkedin.r2.transport.common.Client) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) CompressionConfig(com.linkedin.r2.filter.CompressionConfig) DataProvider(org.testng.annotations.DataProvider)

Aggregations

StreamFilter (com.linkedin.r2.filter.message.stream.StreamFilter)6 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)3 ClientStreamCompressionFilter (com.linkedin.r2.filter.compression.ClientStreamCompressionFilter)3 StreamEncodingType (com.linkedin.r2.filter.compression.streaming.StreamEncodingType)3 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)3 Client (com.linkedin.r2.transport.common.Client)3 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)3 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)3 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)3 HashMap (java.util.HashMap)3 DataProvider (org.testng.annotations.DataProvider)3 Test (org.testng.annotations.Test)3 ByteString (com.linkedin.data.ByteString)2 FilterChain (com.linkedin.r2.filter.FilterChain)2 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)2 ArrayList (java.util.ArrayList)2 RetriableRequestException (com.linkedin.r2.RetriableRequestException)1 NextFilter (com.linkedin.r2.filter.NextFilter)1 ServerRetryFilter (com.linkedin.r2.filter.transport.ServerRetryFilter)1 RequestContext (com.linkedin.r2.message.RequestContext)1