[ 
https://issues.apache.org/jira/browse/HADOOP-8982?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13506928#comment-13506928
 ] 

Xuan Gong commented on HADOOP-8982:
-----------------------------------

        The failure of this test case is, i think, because the partial write is 
handled differently by mac and windows. We actually write the bytes to 
channels, the Pipe.SinkChannel we are using here implements a interface 
WritableByteChannel, from Java Doc about write function of this interface, it 
said "Some types of channels, depending upon their state, may write only some 
of the bytes or possibly none at all." That is one reason why I think the 
differnet OS may cause the failure.
        Bacially, this test opens a pipe channel, and the sink will keep 
writing to the channel with 4192 bytes each time. When the channel is full, 
sink will do the parial write(write 3000 bytes to the channel, the channel is 
full, then the remaining bytes in the Bytebuffer is 1192) when the test is 
running on the mac environment, on the other hand, when we run this test on the 
windows environment, if the channel can not fit for the full Bytebuffer size, 
it will not allow us to write part of it. That means, when we try to write 4192 
bytes to the channel when the channel still has 3000 bytes empty size. We can 
not write at all. The remaining bytes in the Bytebuffer is still 4192. 
        When this partial wirte happens, we check the condition buf.capacity > 
buf.remaining or not, if yes, we will close the stream. So, that is why the 
stream is close on Mac environment, but still open in windows environment. So, 
the next time, when we try to write, we will not go expected "stream is close 
"exception at Windows environment. 
        So far, this is from my observations. So, the questions is whether the 
windows and mac handle parital write as I decribed previous ? If it is true, in 
order to fix this test failure. What we can do is add the function called 
tryToWriteOneByte() in SocketOutPutStream.java file, this function is only for 
test purpose.

public void tryToWriteOneByte(){
    try{
        write(1);
        writer.close();
    }catch(IOException e){
        //do nothing
    }
} 

        Calling this function will insert a byte to the channel, if we can do 
that, that means the channel is not full, and the partial write happens, so we 
need to close the stream. If we can not do that, we will catch a exception, 
that means last time we got the exception is not because the partial write is 
happened, is because the channel is full before we do the next 4192 bytes write.

        Since this test failure is happened on Windows, in the 
TestSocketIOWithTimeout.java, we can check whether the environment is Windows 
before we call this function. 
After doIO(null,out,TIMEOUT), we can do
if(System.getProperty("os.name").toLowerCase().indexOf("win")>=0){
        out.tryToWriteOneByte();
}
                
> TestSocketIOWithTimeout fails on Windows
> ----------------------------------------
>
>                 Key: HADOOP-8982
>                 URL: https://issues.apache.org/jira/browse/HADOOP-8982
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: net
>    Affects Versions: trunk-win
>            Reporter: Chris Nauroth
>            Assignee: Chris Nauroth
>
> This is a possible race condition or difference in socket handling on Windows.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to