Skip to content

Commit

Permalink
Handle different behaviour of UDP sockets on Linux and Mac OS X in Ud…
Browse files Browse the repository at this point in the history
…pTransportTest

It seems that Netty (or maybe the respective OS kernel) is handling datagrams larger than
the configured receive buffer differently on Linux and Mac OS X.

While on Mac OS X the data is completely discarded, the datagram is truncated on Linux.
  • Loading branch information
Jochen Schalanda committed May 11, 2015
1 parent 2a4f0e0 commit 13e5d5b
Showing 1 changed file with 24 additions and 1 deletion.
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.Callables;
import com.google.common.util.concurrent.Uninterruptibles;
import org.apache.commons.lang3.SystemUtils;
import org.graylog2.plugin.LocalMetricRegistry;
import org.graylog2.plugin.configuration.Configuration;
import org.graylog2.plugin.configuration.ConfigurationRequest;
Expand Down Expand Up @@ -50,6 +51,7 @@

import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -113,7 +115,9 @@ public Boolean call() throws Exception {
}

@Test
public void transportDiscardsDataLargerRecvBufferSize() throws Exception {
public void transportDiscardsDataLargerRecvBufferSizeOnMacOsX() throws Exception {
assumeTrue(SystemUtils.IS_OS_MAC_OSX);

final CountingChannelUpstreamHandler handler = new CountingChannelUpstreamHandler();
final UdpTransport transport = launchTransportForBootStrapTest(handler);

Expand All @@ -125,6 +129,25 @@ public void transportDiscardsDataLargerRecvBufferSize() throws Exception {
assertThat(handler.getBytesWritten()).isEmpty();
}

@Test
public void transportTruncatesDataLargerRecvBufferSizeOnLinux() throws Exception {
assumeTrue(SystemUtils.IS_OS_LINUX);

final CountingChannelUpstreamHandler handler = new CountingChannelUpstreamHandler();
final UdpTransport transport = launchTransportForBootStrapTest(handler);

sendUdpDatagram(BIND_ADDRESS, PORT, 2 * RECV_BUFFER_SIZE);
await().atMost(5, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return !handler.getBytesWritten().isEmpty();
}
});
transport.stop();

assertThat(handler.getBytesWritten()).containsExactly(RECV_BUFFER_SIZE);
}

private UdpTransport launchTransportForBootStrapTest(final ChannelHandler channelHandler) throws MisfireException {
final UdpTransport transport = new UdpTransport(CONFIGURATION, throughputCounter, new LocalMetricRegistry()) {
@Override
Expand Down

0 comments on commit 13e5d5b

Please sign in to comment.