Search in sources :

Example 1 with DefaultChannelFuture

use of org.jboss.netty.channel.DefaultChannelFuture in project opentsdb by OpenTSDB.

the class NettyMocks method mockChannelFuture.

/** @param the query to mock a future callback for */
public static void mockChannelFuture(final HttpQuery query) {
    final ChannelFuture future = new DefaultChannelFuture(query.channel(), false);
    when(query.channel().write(any(ChannelBuffer.class))).thenReturn(future);
    future.setSuccess();
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 2 with DefaultChannelFuture

use of org.jboss.netty.channel.DefaultChannelFuture in project bagheera by mozilla-metrics.

the class AccessFilterTest method setup.

@Before
public void setup() throws IOException {
    String[] namespaces = new String[] { "foo_*", "bar" };
    WildcardProperties props = new WildcardProperties();
    String propsFileStr = "foo_*.allow.delete.access=false\n" + "foo_*.id.validation=true\n" + "bar.allow.delete.access=true\n" + "bar.id.validation=false";
    InputStream is = new ByteArrayInputStream(propsFileStr.getBytes("UTF-8"));
    props.load(is);
    filter = new AccessFilter(new Validator(namespaces), props);
    remoteAddr = InetSocketAddress.createUnresolved("192.168.1.1", 51723);
    Channel channel = createMock(Channel.class);
    expect(channel.getCloseFuture()).andReturn(new DefaultChannelFuture(channel, false));
    expect(channel.getRemoteAddress()).andReturn(remoteAddr);
    OrderedMemoryAwareThreadPoolExecutor executor = new OrderedMemoryAwareThreadPoolExecutor(10, 0L, 0L);
    final ExecutionHandler handler = new ExecutionHandler(executor, true, true);
    ctx = new FakeChannelHandlerContext(channel, handler);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) WildcardProperties(com.mozilla.bagheera.util.WildcardProperties) Channel(org.jboss.netty.channel.Channel) ExecutionHandler(org.jboss.netty.handler.execution.ExecutionHandler) OrderedMemoryAwareThreadPoolExecutor(org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor) Validator(com.mozilla.bagheera.validation.Validator) FakeChannelHandlerContext(org.jboss.netty.channel.FakeChannelHandlerContext) Before(org.junit.Before)

Example 3 with DefaultChannelFuture

use of org.jboss.netty.channel.DefaultChannelFuture in project bagheera by mozilla-metrics.

the class AccessFilterTest method createMockEvent.

private MessageEvent createMockEvent(Channel channel, HttpVersion protocolVersion, HttpMethod method, String uri) {
    MessageEvent event = createMock(UpstreamMessageEvent.class);
    expect(event.getChannel()).andReturn(channel).anyTimes();
    expect(event.getFuture()).andReturn(new DefaultChannelFuture(channel, false)).anyTimes();
    expect(event.getRemoteAddress()).andReturn(remoteAddr);
    expect(event.getMessage()).andReturn(new BagheeraHttpRequest(protocolVersion, method, uri));
    replay(channel, event);
    return event;
}
Also used : UpstreamMessageEvent(org.jboss.netty.channel.UpstreamMessageEvent) MessageEvent(org.jboss.netty.channel.MessageEvent) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture)

Example 4 with DefaultChannelFuture

use of org.jboss.netty.channel.DefaultChannelFuture in project bagheera by mozilla-metrics.

the class ContentLengthFilterTest method createMockEvent.

private MessageEvent createMockEvent(Channel channel, HttpVersion protocolVersion, HttpMethod method, String uri, byte[] contentBytes) {
    MessageEvent event = createMock(UpstreamMessageEvent.class);
    expect(event.getChannel()).andReturn(channel).anyTimes();
    expect(event.getFuture()).andReturn(new DefaultChannelFuture(channel, false)).anyTimes();
    expect(event.getRemoteAddress()).andReturn(remoteAddr);
    HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    req.setChunked(false);
    req.setContent(ChannelBuffers.copiedBuffer(contentBytes));
    expect(event.getMessage()).andReturn(req);
    replay(channel, event);
    return event;
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) UpstreamMessageEvent(org.jboss.netty.channel.UpstreamMessageEvent) MessageEvent(org.jboss.netty.channel.MessageEvent) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest)

Example 5 with DefaultChannelFuture

use of org.jboss.netty.channel.DefaultChannelFuture in project bagheera by mozilla-metrics.

the class ContentLengthFilterTest method setup.

@Before
public void setup() {
    Channel channel = createMock(Channel.class);
    expect(channel.getCloseFuture()).andReturn(new DefaultChannelFuture(channel, false));
    expect(channel.getRemoteAddress()).andReturn(InetSocketAddress.createUnresolved("192.168.1.1", 51723));
    OrderedMemoryAwareThreadPoolExecutor executor = new OrderedMemoryAwareThreadPoolExecutor(10, 0L, 0L);
    final ExecutionHandler handler = new ExecutionHandler(executor, true, true);
    ctx = new FakeChannelHandlerContext(channel, handler);
}
Also used : DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) Channel(org.jboss.netty.channel.Channel) ExecutionHandler(org.jboss.netty.handler.execution.ExecutionHandler) OrderedMemoryAwareThreadPoolExecutor(org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor) FakeChannelHandlerContext(org.jboss.netty.channel.FakeChannelHandlerContext) Before(org.junit.Before)

Aggregations

DefaultChannelFuture (org.jboss.netty.channel.DefaultChannelFuture)5 Channel (org.jboss.netty.channel.Channel)2 FakeChannelHandlerContext (org.jboss.netty.channel.FakeChannelHandlerContext)2 MessageEvent (org.jboss.netty.channel.MessageEvent)2 UpstreamMessageEvent (org.jboss.netty.channel.UpstreamMessageEvent)2 ExecutionHandler (org.jboss.netty.handler.execution.ExecutionHandler)2 OrderedMemoryAwareThreadPoolExecutor (org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor)2 Before (org.junit.Before)2 WildcardProperties (com.mozilla.bagheera.util.WildcardProperties)1 Validator (com.mozilla.bagheera.validation.Validator)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)1 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)1