Package io.reactivex.netty.contexts

Examples of io.reactivex.netty.contexts.ContextsContainer


                    @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

                                           final HttpServerResponse<ByteBuf> serverResponse) {
                String reqId = getCurrentRequestId();
                if (null == reqId) {
                    return Observable.error(new AssertionError("Request Id not found at server."));
                }
                ContextsContainer container = getCurrentContextContainer();
                if (null == container) {
                    return Observable.error(new AssertionError("Context container not found by server."));
                }
                container.addContext(CTX_1_NAME, CTX_1_VAL);
                container.addContext(CTX_2_NAME, CTX_2_VAL, new TestContextSerializer());

                HttpClient<ByteBuf, ByteBuf> client =
                        RxContexts.<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", mockServer.getServerPort(),
                                                                          REQUEST_ID_HEADER_NAME,
                                                                          RxContexts.DEFAULT_CORRELATOR)
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

        HttpResponse response = createResponseWithCtxHeaders(holder);

        holder.handler.channelRead(holder.ctx, response);

        ContextsContainer container = ContextAttributeStorageHelper.getContainer(holder.ctx, holder.requestId);
        Assert.assertEquals("Context not available in client response", CTX_1_VAL, container.getContext(CTX_1_NAME));
    }
View Full Code Here

            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

        requestId = "ServerHandlerTest.testResponse";
        HandlerHolder holder = new HandlerHolder(true, requestId);
        readRequestAndAssert(holder);


        ContextsContainer container = ContextAttributeStorageHelper.getContainer(holder.ctx, holder.requestId);
        String ctx2Name = "ctx2";
        BidirectionalTestContext ctx2 = new BidirectionalTestContext(ctx2Name);

        container.addContext(ctx2Name, ctx2, new BidirectionalTestContextSerializer());

        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

    private static void readRequestAndAssert(HandlerHolder holder) throws Exception {
        DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
        holder.addSerializedContext(request, CTX_1_NAME, CTX_1_VAL);
        holder.handler.channelRead(holder.ctx, request);

        ContextsContainer container = ContextAttributeStorageHelper.getContainer(holder.ctx, holder.requestId);

        Assert.assertNotNull("Context container not set after request receive.", container);
        Assert.assertEquals("Context not available in the container.", CTX_1_VAL, container.getContext(CTX_1_NAME));
        Assert.assertEquals("Request Id header not added.", CTX_1_VAL, container.getContext(CTX_1_NAME));
    }
View Full Code Here

TOP

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

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.