Example usage for io.netty.util DefaultAttributeMap attr

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

Introduction

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

Prototype

@SuppressWarnings("unchecked")
    @Override
    public <T> Attribute<T> attr(AttributeKey<T> key) 

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);//w  w w . j a v  a  2s .co 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));
}