Search in sources :

Example 11 with MessageEvent

use of org.jboss.netty.channel.MessageEvent 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 12 with MessageEvent

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

the class DummyProducer method testMessage.

// Ensure that one invocation of the message results in the specified number of deletes and creates
// and that two invocations results in double those numbers.
private void testMessage(String id, boolean doDelete, int expectedDeletes, int expectedCreates, String... deletes) throws Exception {
    SubmissionHandler handler = new SubmissionHandler(validator, producer, channelGroup, manager);
    ChannelHandlerContext context = Mockito.mock(ChannelHandlerContext.class);
    MessageEvent messageEvent = Mockito.mock(MessageEvent.class);
    Mockito.when(messageEvent.getChannel()).thenReturn(mockChannel);
    BagheeraHttpRequest mockMessage = getMockMessage(HttpMethod.POST, id, doDelete, deletes);
    Mockito.when(messageEvent.getMessage()).thenReturn(mockMessage);
    testTwoInvocations(expectedDeletes, expectedCreates, handler, context, messageEvent);
    producer.reset();
}
Also used : MessageEvent(org.jboss.netty.channel.MessageEvent) ChannelHandlerContext(org.jboss.netty.channel.ChannelHandlerContext)

Example 13 with MessageEvent

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

the class DummyProducer method testDelete.

@Test
public void testDelete() throws Exception {
    // Test an actual delete (as opposed to a POST message with an X-Obsolete-Doc header).
    SubmissionHandler handler = new SubmissionHandler(validator, producer, channelGroup, manager);
    ChannelHandlerContext context = Mockito.mock(ChannelHandlerContext.class);
    MessageEvent messageEvent = Mockito.mock(MessageEvent.class);
    Mockito.when(messageEvent.getChannel()).thenReturn(mockChannel);
    BagheeraHttpRequest mockMessage = getMockMessage(HttpMethod.DELETE, "delete-id", false);
    Mockito.when(messageEvent.getMessage()).thenReturn(mockMessage);
    testTwoInvocations(1, 0, handler, context, messageEvent);
    producer.reset();
}
Also used : MessageEvent(org.jboss.netty.channel.MessageEvent) ChannelHandlerContext(org.jboss.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 14 with MessageEvent

use of org.jboss.netty.channel.MessageEvent 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)

Aggregations

MessageEvent (org.jboss.netty.channel.MessageEvent)14 ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)4 Test (org.junit.Test)4 Event (com.nabalive.common.server.Event)3 Channel (org.jboss.netty.channel.Channel)3 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 ChannelBufferOutputStream (org.jboss.netty.buffer.ChannelBufferOutputStream)2 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 DefaultChannelFuture (org.jboss.netty.channel.DefaultChannelFuture)2 UpstreamMessageEvent (org.jboss.netty.channel.UpstreamMessageEvent)2 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)2 BagheeraMessage (com.mozilla.bagheera.BagheeraProto.BagheeraMessage)1 Jid (com.nabalive.server.jabber.util.Jid)1 URI (java.net.URI)1 ByteBuffer (java.nio.ByteBuffer)1 ClientRequest (org.adbcj.mysql.codec.ClientRequest)1 AbstractFrontendMessage (org.adbcj.postgresql.codec.frontend.AbstractFrontendMessage)1