2017-01-19 17:31:34 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
package io.netty.channel.kqueue;
|
|
|
|
|
2017-09-17 02:20:01 +02:00
|
|
|
import io.netty.bootstrap.Bootstrap;
|
2017-01-19 17:31:34 +01:00
|
|
|
import io.netty.channel.ChannelException;
|
2017-09-17 02:20:01 +02:00
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
|
|
import io.netty.channel.ChannelOption;
|
|
|
|
import io.netty.channel.EventLoopGroup;
|
2017-01-19 17:31:34 +01:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2017-09-17 02:20:01 +02:00
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
2017-01-19 17:31:34 +01:00
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
|
|
public class KQueueChannelConfigTest {
|
|
|
|
@Before
|
|
|
|
public void before() {
|
|
|
|
KQueue.ensureAvailability();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testOptionGetThrowsChannelException() throws Exception {
|
|
|
|
KQueueSocketChannel channel = new KQueueSocketChannel();
|
|
|
|
channel.config().getSoLinger();
|
|
|
|
channel.fd().close();
|
|
|
|
try {
|
|
|
|
channel.config().getSoLinger();
|
|
|
|
fail();
|
|
|
|
} catch (ChannelException e) {
|
|
|
|
// expected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testOptionSetThrowsChannelException() throws Exception {
|
|
|
|
KQueueSocketChannel channel = new KQueueSocketChannel();
|
|
|
|
channel.config().setKeepAlive(true);
|
|
|
|
channel.fd().close();
|
|
|
|
try {
|
|
|
|
channel.config().setKeepAlive(true);
|
|
|
|
fail();
|
|
|
|
} catch (ChannelException e) {
|
|
|
|
// expected
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 02:20:01 +02:00
|
|
|
|
|
|
|
// See https://github.com/netty/netty/issues/7159
|
|
|
|
@Test
|
|
|
|
public void testSoLingerNoAssertError() throws Exception {
|
|
|
|
EventLoopGroup group = new KQueueEventLoopGroup(1);
|
|
|
|
|
|
|
|
try {
|
|
|
|
Bootstrap bootstrap = new Bootstrap();
|
|
|
|
KQueueSocketChannel ch = (KQueueSocketChannel) bootstrap.group(group)
|
|
|
|
.channel(KQueueSocketChannel.class)
|
|
|
|
.option(ChannelOption.SO_LINGER, 10)
|
|
|
|
.handler(new ChannelInboundHandlerAdapter())
|
|
|
|
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
|
|
|
|
ch.close().syncUninterruptibly();
|
|
|
|
} finally {
|
|
|
|
group.shutdownGracefully();
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 17:31:34 +01:00
|
|
|
}
|