Example usage for io.netty.util DefaultAttributeMap DefaultAttributeMap

List of usage examples for io.netty.util DefaultAttributeMap DefaultAttributeMap

Introduction

In this page you can find the example usage for io.netty.util DefaultAttributeMap DefaultAttributeMap.

Prototype

DefaultAttributeMap

Source Link

Usage

From source file:com.linecorp.armeria.server.metrics.MetricCollectingServiceCodecTest.java

License:Apache License

@SuppressWarnings("unchecked")
protected static void setupServer(ServerBuilder sb, ServiceInvocationHandler handler,
        final MetricConsumer consumer) throws Exception {
    ServiceCodec codec = Mockito.mock(ServiceCodec.class);
    DecodeResult decodeResult = Mockito.mock(DecodeResult.class);
    DefaultAttributeMap defaultAttributeMap = new DefaultAttributeMap();
    ServiceInvocationContext invocationContext = Mockito.mock(ServiceInvocationContext.class);

    when(decodeResult.type()).thenReturn(DecodeResultType.SUCCESS);
    when(decodeResult.invocationContext()).thenReturn(invocationContext);
    when(invocationContext.attr(any())).then(x -> defaultAttributeMap.attr(AttributeKey.valueOf("TEST")));
    when(invocationContext.method()).thenReturn("someMethod");

    when(codec.decodeRequest(any(), any(), any(), any(), any(), any(), any(), any(), any()))
            .thenReturn(decodeResult);//from w  w  w.j  ava 2  s .c  o m

    when(codec.encodeResponse(any(), any())).thenReturn(Unpooled.EMPTY_BUFFER);
    when(codec.encodeFailureResponse(any(), any())).thenReturn(Unpooled.EMPTY_BUFFER);

    sb.serviceAt("/", Service.of(new MetricCollectingServiceCodec(codec, consumer), handler));
}

From source file:io.moquette.parser.netty.ConnectDecoderTest.java

License:Open Source License

@Before
public void setUp() {
    m_msgdec = new ConnectDecoder();
    attrMap = new DefaultAttributeMap();
}

From source file:io.moquette.parser.netty.PublishDecoderTest.java

License:Open Source License

@Before
public void setUp() {
    m_msgdec = new PublishDecoder();
    m_results = new ArrayList<>();
    m_attrMap = new DefaultAttributeMap();
}

From source file:io.moquette.parser.netty.PubRelDecoderTest.java

License:Open Source License

@Before
public void setUp() {
    m_msgdec = new PubRelDecoder();
    attrMap = new DefaultAttributeMap();
}

From source file:io.reactivex.netty.contexts.http.HttpRequestIdProviderTest.java

License:Apache License

@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);
}

From source file:io.reactivex.netty.contexts.http.HttpRequestIdProviderTest.java

License:Apache License

@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());
}

From source file:io.reactivex.netty.contexts.http.HttpRequestIdProviderTest.java

License:Apache License

@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));
}

From source file:io.reactivex.netty.contexts.http.HttpRequestIdProviderTest.java

License:Apache License

@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);
}

From source file:io.reactivex.netty.contexts.http.HttpRequestIdProviderTest.java

License:Apache License

@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));
}

From source file:io.reactivex.netty.contexts.ThreadLocalRequestCorrelator.java

License:Apache License

@Override
public void onNewServerRequest(String requestId, ContextsContainer contextsContainer) {
    if (null == requestId) {
        throw new IllegalArgumentException("Request Id can not be null.");
    }//w ww .  j  a va2s . com
    if (null == contextsContainer) {
        throw new IllegalArgumentException("Context container can not be null.");
    }

    state.get().push(new DefaultAttributeMap());

    state.get().setRequestId(requestId);
    state.get().setContainer(contextsContainer);
}