Search in sources :

Example 6 with StreamFilter

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

the class TestRequestCompression method noCompressionData.

@DataProvider
public Object[][] noCompressionData() {
    StreamEncodingType[] encodings = new StreamEncodingType[] { StreamEncodingType.GZIP, StreamEncodingType.DEFLATE, StreamEncodingType.SNAPPY_FRAMED, StreamEncodingType.BZIP2, StreamEncodingType.IDENTITY };
    String[] protocols = new String[] { HttpProtocolVersion.HTTP_1_1.name(), HttpProtocolVersion.HTTP_2.name() };
    Object[][] args = new Object[encodings.length * protocols.length][1];
    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(Collections.<String, String>emptyMap()), 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 7 with StreamFilter

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

the class TestFilterChainImpl method testFilterOrderTwoChains.

@Test
public void testFilterOrderTwoChains() {
    AtomicInteger count = new AtomicInteger(0);
    CheckOrderFilter filter1 = new CheckOrderFilter(count);
    CheckOrderFilter filter2 = new CheckOrderFilter(count);
    List<RestFilter> restFilters = new ArrayList<RestFilter>();
    restFilters.add(filter1);
    restFilters.add(filter2);
    List<StreamFilter> streamFilters = new ArrayList<StreamFilter>();
    streamFilters.add(filter1);
    streamFilters.add(filter2);
    final FilterChain fc = FilterChains.create(restFilters, streamFilters);
    fireRestRequest(fc);
    Assert.assertEquals(filter1.getOrder(), 1);
    Assert.assertEquals(filter2.getOrder(), 2);
    fireRestResponse(fc);
    Assert.assertEquals(filter1.getOrder(), 4);
    Assert.assertEquals(filter2.getOrder(), 3);
    fireRestError(fc);
    Assert.assertEquals(filter1.getOrder(), 6);
    Assert.assertEquals(filter2.getOrder(), 5);
    count.set(0);
    fireStreamRequest(fc);
    Assert.assertEquals(filter1.getOrder(), 1);
    Assert.assertEquals(filter2.getOrder(), 2);
    fireStreamResponse(fc);
    Assert.assertEquals(filter1.getOrder(), 4);
    Assert.assertEquals(filter2.getOrder(), 3);
    fireStreamError(fc);
    Assert.assertEquals(filter1.getOrder(), 6);
    Assert.assertEquals(filter2.getOrder(), 5);
}
Also used : RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterChain(com.linkedin.r2.filter.FilterChain) ArrayList(java.util.ArrayList) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) Test(org.testng.annotations.Test)

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