Appy commented on HBASE-14734:

Gave a try at test after the chat, but now it seems that we actually can't test 
it. The problem is, we are dealing with ports over which we don't have full 
control. We can block a port and make sure that kdc setup fails, but we can't 
ensure an always available dedicated port  to test that kdc setup succeeds.
Here's the test, not committing it but putting here for posterity.

  void TestMiniKdcSetupBindException() throws Exception {
    HBaseTestingUtility hbt = new HBaseTestingUtility();
    ServerSocket socket = new ServerSocket(0);
    int port = socket.getLocalPort();

    boolean exception = false;
    try {
      hbt.setupMiniKdc(null, port);
    } catch (BindException e) {
      exception = true;
    assertTrue("setupMiniKdc didn't encounter exception even though port was 
not available.",

    // Close the socket and try again. Shouldn't get exception now.
    exception = false;
    try {
      hbt.setupMiniKdc(null, port);
    } catch (BindException e) {
      exception = true;
    // It's possible that port gets captured by some other service. So this 
test itself is flaky by
    // nature.
    assertTrue("setupMiniKdc encountered exception even though port was 
closed.", exception);

Chatted with stack, will commit current patch itself.

> BindException when setting up MiniKdc
> -------------------------------------
>                 Key: HBASE-14734
>                 URL: https://issues.apache.org/jira/browse/HBASE-14734
>             Project: HBase
>          Issue Type: Sub-task
>          Components: flakey, test
>            Reporter: stack
>            Assignee: Appy
>         Attachments: HBASE-14734.master.001.patch
> Root cause : Port for kdc service gets selected in the constructor, but we 
> bind to it later in MiniKdc.start()-->MiniKdc.initKDCServer() --> 
> KdcServer.start(). In meantime, some other service can capture the port which 
> results in BindException. The solution here is to catch the exception and 
> retry.
> From 
> https://builds.apache.org/view/H-L/view/HBase/job/HBase-1.2/330/jdk=latest1.7,label=Hadoop/testReport/junit/org.apache.hadoop.hbase.security.token/TestGenerateDelegationToken/org_apache_hadoop_hbase_security_token_TestGenerateDelegationToken/
> Error Message
> Address already in use
> Stacktrace
> java.net.BindException: Address already in use
>       at sun.nio.ch.Net.bind0(Native Method)
>       at sun.nio.ch.Net.bind(Net.java:444)
>       at sun.nio.ch.Net.bind(Net.java:436)
>       at 
> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
>       at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
>       at 
> org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:198)
>       at 
> org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:51)
>       at 
> org.apache.mina.core.polling.AbstractPollingIoAcceptor.registerHandles(AbstractPollingIoAcceptor.java:547)
>       at 
> org.apache.mina.core.polling.AbstractPollingIoAcceptor.access$400(AbstractPollingIoAcceptor.java:68)
>       at 
> org.apache.mina.core.polling.AbstractPollingIoAcceptor$Acceptor.run(AbstractPollingIoAcceptor.java:422)
>       at 
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
>       at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>       at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>       at java.lang.Thread.run(Thread.java:745)
> Can this utility be made to not fail if address taken? Try another?

This message was sent by Atlassian JIRA

Reply via email to