类io.netty.util.DefaultAttributeMap源码实例Demo

下面列出了怎么用io.netty.util.DefaultAttributeMap的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: aws-sdk-java-v2   文件: FutureCancelHandlerTest.java
@Before
public void methodSetup() {
    requestContext = new RequestContext(channelPool,
                                        eventLoopGroup,
                                        AsyncExecuteRequest.builder().responseHandler(responseHandler).build(),
                                        null);

    DefaultAttributeMap attrMap = new DefaultAttributeMap();
    attrMap.attr(EXECUTION_ID_KEY).set(1L);
    attrMap.attr(REQUEST_CONTEXT_KEY).set(requestContext);

    when(ctx.channel()).thenReturn(channel);
    when(channel.attr(EXECUTION_ID_KEY)).thenReturn(attrMap.attr(EXECUTION_ID_KEY));
    when(channel.attr(REQUEST_CONTEXT_KEY)).thenReturn(attrMap.attr(REQUEST_CONTEXT_KEY));
}
 
@Before
public void before() {
    when(channelHandlerContext.channel()).thenReturn(channel);

    DefaultAttributeMap attributeMap = new DefaultAttributeMap();
    attributeMap.attr(ATTR_SSL_INFO).set(sslHandshakeInfo);
    when(channel.attr(any())).thenAnswer(arg -> attributeMap.attr((AttributeKey) arg.getArguments()[0]));

    headers = new DefaultHttpHeaders();
    when(msg.headers()).thenReturn(headers);
    headers.add(HttpHeaderNames.HOST, "netflix.com");
}
 
private void doHandoff(String ip, String matchingIp, HttpResponseStatus responseStatus, boolean isSuccess) throws UnsupportedEncodingException {
	if(StringUtils.isBlank(ip)) {
		EasyMock.expect(channel.remoteAddress()).andReturn(null).anyTimes();
	}else{
		EasyMock.expect(channel.remoteAddress()).andReturn(new InetSocketAddress(ip, 33213)).anyTimes();
	}
   SessionHandoff handoff = new SessionHandoff();
   handoff.setPersonId(UUID.randomUUID());
   handoff.setIp(matchingIp);
   
   Capture<Session> sessionRef = Capture.<Session>newInstance();
   
   EasyMock
      .expect(appHandoffDao.validate("token"))
      .andReturn(Optional.of(handoff));
   
   if(isSuccess) {
      EasyMock
         .expect(sessionDao.create(EasyMock.capture(sessionRef)))
         .andAnswer(() -> {
            SimpleSession value = (SimpleSession) sessionRef.getValue();
            value.setId("session-id");            
            return "session-id";
         });
      
      sessionDao.update(EasyMock.capture(sessionRef));
      EasyMock
         .expectLastCall()
         .times(3);
   }

   EasyMock
      .expect(sessionDao.readSession("session-id"))
      .andAnswer(() -> sessionRef.getValue())
      .anyTimes()
      ;
   Attribute<Client> attribMap = new DefaultAttributeMap().attr(Client.ATTR_CLIENT);
   EasyMock.expect(channel.attr(Client.ATTR_CLIENT)).andReturn(attribMap).times(2);
   
   replay();
   
   DefaultFullHttpRequest request = new DefaultFullHttpRequest(
         HttpVersion.HTTP_1_1, 
         HttpMethod.POST, 
         "http://localhost/client",
         Unpooled.wrappedBuffer("{token:\"token\"}".getBytes("UTF-8"))
   );
   
   FullHttpResponse response = authenticator.authenticateRequest(channel, request);
   assertEquals(responseStatus, response.getStatus());
   if(isSuccess) {
   	assertCookieSet(response);
   }else{
   	assertCookieCleared(response);
   }
   
   verify();
}
 
 类所在包
 类方法
 同包方法