List of usage examples for io.netty.util Attribute getAndRemove
@Deprecated T getAndRemove();
From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java
License:Apache License
@Test public void testSetRemove() { AttributeKey<Integer> key = AttributeKey.valueOf("key"); Attribute<Integer> attr = map.attr(key); attr.set(1);/* w ww .jav a 2 s. c o m*/ assertSame(1, attr.getAndRemove()); Attribute<Integer> attr2 = map.attr(key); attr2.set(2); assertSame(2, attr2.get()); assertNotSame(attr, attr2); }
From source file:org.ebayopensource.scc.filter.NettyResponseProxyFilterTest.java
License:Apache License
@Test public void testFilterFullHttpResponse() { PolicyManager policyManager = mock(PolicyManager.class); AppConfiguration appConfig = mock(AppConfiguration.class); when(appConfig.getBoolean(AppConfiguration.KEY_DEBUG_INFO)).thenReturn(true); NettyResponseProxyFilter filter = new NettyResponseProxyFilter(policyManager, Executors.newCachedThreadPool()); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); when(ctx.attr(any(AttributeKey.class))).thenReturn(mock(Attribute.class)); Attribute cachable = mock(Attribute.class); when(ctx.attr(NettyRequestProxyFilter.IS_CACHABLE)).thenReturn(cachable); when(cachable.get()).thenReturn(Boolean.FALSE); assertNull(filter.filterResponse(null, ctx)); when(cachable.get()).thenReturn(Boolean.TRUE); assertNull(filter.filterResponse(null, ctx)); HttpResponse resp = mock(HttpResponse.class); when(resp.getStatus()).thenReturn(HttpResponseStatus.OK); assertEquals(resp, filter.filterResponse(resp, ctx)); resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND); assertEquals(resp, filter.filterResponse(resp, ctx)); resp.setStatus(HttpResponseStatus.OK); assertEquals(resp, filter.filterResponse(resp, ctx)); Attribute cacheKey = mock(Attribute.class); when(ctx.attr(NettyRequestProxyFilter.CACHE_KEY)).thenReturn(cacheKey); when(cacheKey.getAndRemove()).thenReturn("key"); when(policyManager.getCacheManager()).thenReturn(mock(CacheManager.class)); assertEquals(resp, filter.filterResponse(resp, ctx)); when(cacheKey.get()).thenReturn("key"); assertEquals(resp, filter.filterResponse(resp, ctx)); }