Package io.reactivex.netty.contexts

Examples of io.reactivex.netty.contexts.ContextsContainerImpl


    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


    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

                    @Override
                    public String getContextValue(String key) {
                        return request.getHeaders().get(key);
                    }
                };
                ContextsContainer container = new ContextsContainerImpl(supplier);
                try {
                    String ctx1 = container.getContext(CTX_1_NAME);
                    TestContext ctx2 = container.getContext(CTX_2_NAME);
                    if (null != ctx1 && null != ctx2 && ctx1.equals(CTX_1_VAL) && ctx2.equals(CTX_2_VAL)) {
                        return response.writeStringAndFlush("Welcome!");
                    } else {
                        response.setStatus(HttpResponseStatus.BAD_REQUEST);
                        return response.writeStringAndFlush("Contexts not found or have wrong values.");
View Full Code Here

                RxContexts.<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", mockServer.getServerPort(),
                                                                  REQUEST_ID_HEADER_NAME,
                                                                  RxContexts.DEFAULT_CORRELATOR)
                          .withMaxConnections(1).enableWireLogging(LogLevel.ERROR)
                          .withIdleConnectionsTimeoutMillis(100000).build();
        ContextsContainer container = new ContextsContainerImpl(new MapBackedKeySupplier());
        container.addContext(CTX_1_NAME, CTX_1_VAL);
        container.addContext(CTX_2_NAME, CTX_2_VAL, new TestContextSerializer());

        String reqId = "testWithPooledConnections";
        RxContexts.DEFAULT_CORRELATOR.onNewServerRequest(reqId, container);

        invokeMockServer(testClient, reqId, false);
View Full Code Here

                                                                  REQUEST_ID_HEADER_NAME,
                                                                  RxContexts.DEFAULT_CORRELATOR)
                          .withMaxConnections(1).enableWireLogging(LogLevel.ERROR)
                          .withIdleConnectionsTimeoutMillis(100000).build();

        ContextsContainer container = new ContextsContainerImpl(new MapBackedKeySupplier());
        container.addContext(CTX_1_NAME, CTX_1_VAL);
        container.addContext(CTX_2_NAME, CTX_2_VAL, new TestContextSerializer());

        String reqId = "testNoStateLeakOnThreadReuse";
        RxContexts.DEFAULT_CORRELATOR.onNewServerRequest(reqId, container);

        try {
View Full Code Here

        return handler;
    }

    public void addSerializedContext(HttpMessage httpMessage, String ctxName, String strCtxValue)
    throws ContextSerializationException {
        ContextsContainer contextsContainer = new ContextsContainerImpl(keySupplier);
        contextsContainer.addContext(ctxName, strCtxValue);
        Map<String,String> serializedContexts = contextsContainer.getSerializedContexts();
        for (Map.Entry<String, String> entry : serializedContexts.entrySet()) {
            httpMessage.headers().add(entry.getKey(), entry.getValue());
        }
    }
View Full Code Here

        }
    }

    public <T> void addSerializedContext(HttpMessage httpMessage, String ctxName, T ctx,
                                     ContextSerializer<T> serializer) throws ContextSerializationException {
        ContextsContainer contextsContainer = new ContextsContainerImpl(keySupplier);
        contextsContainer.addContext(ctxName, ctx, serializer);
        Map<String,String> serializedContexts = contextsContainer.getSerializedContexts();
        for (Map.Entry<String, String> entry : serializedContexts.entrySet()) {
            httpMessage.headers().add(entry.getKey(), entry.getValue());
        }
    }
View Full Code Here

        holder.addSerializedContext(response, CTX_1_NAME, CTX_1_VAL, new BidirectionalTestContextSerializer());
        return response;
    }

    private static void sendRequestAndAssert(HandlerHolder holder) throws Exception {
        holder.correlator.onNewServerRequest(holder.requestId, new ContextsContainerImpl(holder.keySupplier));

        try {
            DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
            holder.addSerializedContext(request, CTX_1_NAME, CTX_1_VAL, new BidirectionalTestContextSerializer());
            holder.handler.write(holder.ctx, request, holder.ctx.newPromise());

            Assert.assertNotNull("Context container not set after request sent.",
                                 ContextAttributeStorageHelper.getContainer(holder.ctx, holder.requestId));

            ContextKeySupplier supplier = new HttpContextKeySupplier(request.headers());
            ContextsContainer container = new ContextsContainerImpl(supplier);

            Assert.assertEquals("Context not available in the container.", CTX_1_VAL, container.getContext(CTX_1_NAME));
            Assert.assertEquals("Request Id header not added.", holder.getRequestId(),
                                request.headers().get(holder.getProvider().getRequestIdContextKeyName()));
        } finally {
            holder.correlator.onServerProcessingEnd(holder.requestId);
            System.err.println("Sent server processing end callback to correlator.");
View Full Code Here

        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

        holder.handler.write(holder.ctx, response, holder.ctx.newPromise());

        ContextKeySupplier supplier = new HttpContextKeySupplier(response.headers());
        ContextsContainer containerToRead = new ContextsContainerImpl(supplier);
        Assert.assertEquals("Bi-directional context not written in response.", ctx2, containerToRead.getContext(
                ctx2Name));
    }
View Full Code Here

TOP

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

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.