-
Notifications
You must be signed in to change notification settings - Fork 24
Enhancement: Add Configurable Timeout to Socket Connection Methods #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
public class DefaultSocketFactoryImpl | ||
implements ORBSocketFactory | ||
{ | ||
private ORB orb; | ||
protected ORB orb; | ||
|
||
public void setORB(ORB orb) | ||
{ | ||
|
@@ -62,27 +62,6 @@ public ServerSocket createServerSocket(String type, | |
return serverSocket; | ||
} | ||
|
||
public Socket createSocket(String type, | ||
InetSocketAddress inetSocketAddress) | ||
throws IOException | ||
{ | ||
SocketChannel socketChannel = null; | ||
Socket socket = null; | ||
|
||
if (orb.getORBData().connectionSocketType().equals(ORBConstants.SOCKETCHANNEL)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha, here it is too ... type was unused, and it took the value from the orbdata ... why? |
||
socketChannel = ORBUtility.openSocketChannel(inetSocketAddress); | ||
socket = socketChannel.socket(); | ||
} else { | ||
socket = new Socket(inetSocketAddress.getHostName(), | ||
inetSocketAddress.getPort()); | ||
} | ||
|
||
// Disable Nagle's algorithm (i.e., always send immediately). | ||
socket.setTcpNoDelay(true); | ||
|
||
return socket; | ||
} | ||
|
||
public void setAcceptedSocketOptions(Acceptor acceptor, | ||
ServerSocket serverSocket, | ||
Socket socket) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
orbmain/src/test/java/com/sun/corba/ee/impl/transport/DefaultSocketFactoryImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.sun.corba.ee.impl.transport; | ||
|
||
import com.sun.corba.ee.spi.misc.ORBConstants; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.net.InetSocketAddress; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.net.SocketTimeoutException; | ||
import java.util.UUID; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class DefaultSocketFactoryImplTest { | ||
private static final String TEST_TYPE = ORBConstants.SOCKETCHANNEL; | ||
private static final int TEST_TIMEOUT = 1000; | ||
|
||
@Test | ||
public void testCreateSocketWithSocketChannelType() throws IOException { | ||
DefaultSocketFactoryImpl sf = new DefaultSocketFactoryImpl(); | ||
String testMessage = UUID.randomUUID().toString(); | ||
try (ServerSocket serverSocket = createServerSocket(testMessage)) { | ||
final InetSocketAddress address = new InetSocketAddress("localhost", serverSocket.getLocalPort()); | ||
Socket socket = sf.createSocket(TEST_TYPE, address, TEST_TIMEOUT); | ||
assertNotNull(socket); | ||
assertTrue(socket.getTcpNoDelay()); | ||
validateSocket(socket, testMessage); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateSocketWithOtherType() throws IOException { | ||
DefaultSocketFactoryImpl sf = new DefaultSocketFactoryImpl(); | ||
String testMessage = UUID.randomUUID().toString(); | ||
try (ServerSocket serverSocket = createServerSocket(testMessage)) { | ||
final InetSocketAddress address = new InetSocketAddress("localhost", serverSocket.getLocalPort()); | ||
Socket socket = sf.createSocket("otherType", address, TEST_TIMEOUT); | ||
assertNotNull(socket); | ||
assertTrue(socket.getTcpNoDelay()); | ||
validateSocket(socket, testMessage); | ||
} | ||
} | ||
|
||
@Test(expected = SocketTimeoutException.class) | ||
public void testCreateSocketWithTimeoutSocketChannelType() throws IOException { | ||
DefaultSocketFactoryImpl sf = new DefaultSocketFactoryImpl(); | ||
InetSocketAddress unreachableAddress = new InetSocketAddress("10.0.0.0", 8080); | ||
sf.createSocket(TEST_TYPE, unreachableAddress, TEST_TIMEOUT); | ||
} | ||
|
||
@Test(expected = SocketTimeoutException.class) | ||
public void testCreateSocketWithTimeoutOtherType() throws IOException { | ||
DefaultSocketFactoryImpl sf = new DefaultSocketFactoryImpl(); | ||
InetSocketAddress unreachableAddress = new InetSocketAddress("10.0.0.0", 8080); | ||
sf.createSocket("otherType", unreachableAddress, TEST_TIMEOUT); | ||
} | ||
|
||
private ServerSocket createServerSocket(String message) throws IOException { | ||
ServerSocket serverSocket = new ServerSocket(); | ||
serverSocket.bind(null); | ||
|
||
new Thread(() -> { | ||
try { | ||
Socket clientSocket = serverSocket.accept(); | ||
OutputStream out = clientSocket.getOutputStream(); | ||
out.write(message.getBytes()); | ||
out.flush(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}).start(); | ||
|
||
return serverSocket; | ||
} | ||
|
||
private void validateSocket(Socket socket, String expectedMessage) throws IOException { | ||
InputStream in = socket.getInputStream(); | ||
byte[] buffer = new byte[expectedMessage.length()]; | ||
int read = in.read(buffer); | ||
assertEquals(expectedMessage, new String(buffer, 0, read)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet one question - why you replaced the
socketType
parameter withorb.getORBData().connectionSocketType()
? It seems it did not change anything in test results, but ...