Package io.reactivex.netty.contexts

Examples of io.reactivex.netty.contexts.RequestIdProvider


        }
    }

    @Test
    public void testOnServerRequest() throws Exception {
        RequestIdProvider provider = new HttpRequestIdProvider(REQUEST_ID_HEADER_NAME, CORRELATOR);
        MapBackedKeySupplier keySupplier = new MapBackedKeySupplier(new HashMap<String, String>());
        AttributeMap attributeMap = new DefaultAttributeMap();
        String requestId = provider.onServerRequest(keySupplier, attributeMap);
        Assert.assertNull("Request Id should be null.", requestId);

        String expectedId = "hellothere";
        keySupplier.put(REQUEST_ID_HEADER_NAME, expectedId);

        requestId = provider.onServerRequest(keySupplier, attributeMap);

        Assert.assertEquals("Unexpected request id.", expectedId, requestId);
    }
View Full Code Here


        Assert.assertEquals("Unexpected request id.", expectedId, requestId);
    }

    @Test
    public void testNewRequestId() throws Exception {
        RequestIdProvider provider = new HttpRequestIdProvider("request_id", CORRELATOR);
        ContextKeySupplier keySupplier = new MapBackedKeySupplier(new HashMap<String, String>());
        AttributeMap attributeMap = new DefaultAttributeMap();
        String requestId = provider.newRequestId(keySupplier, attributeMap);
        ConcurrentLinkedQueue<String> ids = attributeMap.attr(HttpRequestIdProvider.REQUEST_IDS_KEY).get();
        Assert.assertNotNull("Request Id not added to context.", ids);
        Assert.assertNotNull("Request Id not added to context.", ids.peek());
        Assert.assertSame("Unexpected request Id in the context.", requestId, ids.poll());
    }
View Full Code Here

        Assert.assertSame("Unexpected request Id in the context.", requestId, ids.poll());
    }

    @Test
    public void testBeforeServerResponse() throws Exception {
        RequestIdProvider provider = new HttpRequestIdProvider(REQUEST_ID_HEADER_NAME, CORRELATOR);
        AttributeMap attributeMap = new DefaultAttributeMap();
        MapBackedKeySupplier keySupplier = new MapBackedKeySupplier(new HashMap<String, String>());
        String expectedId1 = "hellothere1";
        String expectedId2 = "hellothere2";
        String expectedId3 = "hellothere3";

        // Simulate HTTP pipelining
        onServerRequest(provider, attributeMap, keySupplier, expectedId1);
        onServerRequest(provider, attributeMap, keySupplier, expectedId2);
        onServerRequest(provider, attributeMap, keySupplier, expectedId3);

        Assert.assertSame("Unexpected 1st request Id", expectedId1,
                          provider.beforeServerResponse(keySupplier, attributeMap));
        Assert.assertSame("Unexpected 2nd request Id", expectedId2,
                          provider.beforeServerResponse(keySupplier, attributeMap));
        Assert.assertSame("Unexpected 3rd request Id", expectedId3,
                          provider.beforeServerResponse(keySupplier, attributeMap));
    }
View Full Code Here

                          provider.beforeServerResponse(keySupplier, attributeMap));
    }

    @Test
    public void testBeforeClientRequest() throws Exception {
        RequestIdProvider provider = new HttpRequestIdProvider(REQUEST_ID, CORRELATOR);
        AttributeMap attributeMap = new DefaultAttributeMap();
        ContextKeySupplier keySupplier = new MapBackedKeySupplier(new HashMap<String, String>());
        String expectedId = "daah";
        CORRELATOR.onNewServerRequest(expectedId, new ContextsContainerImpl(keySupplier));
        String requestId = provider.beforeClientRequest(attributeMap);

        Assert.assertSame("Unexpected request Id", expectedId, requestId);
    }
View Full Code Here

        Assert.assertSame("Unexpected request Id", expectedId, requestId);
    }

    @Test
    public void testOnClientResponse() throws Exception {
        RequestIdProvider provider = new HttpRequestIdProvider("request_id", CORRELATOR);
        AttributeMap attributeMap = new DefaultAttributeMap();
        ContextKeySupplier keySupplier = new MapBackedKeySupplier(new HashMap<String, String>());
        String expectedId = "daah";
        CORRELATOR.onNewServerRequest(expectedId, new ContextsContainerImpl(keySupplier));
        String requestId = provider.beforeClientRequest(attributeMap);
        Assert.assertSame("Unexpected request Id", expectedId, requestId);
        Assert.assertSame("Unexpected request Id on client response.", expectedId, provider.onClientResponse(attributeMap));
    }
View Full Code Here

TOP

Related Classes of io.reactivex.netty.contexts.RequestIdProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.