-
Notifications
You must be signed in to change notification settings - Fork 497
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
[Wisp] Fix initialization problem between JavaNetSocketAccess and its usage #443
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import java.dyn.CoroutineExitException; | ||
import java.dyn.CoroutineSupport; | ||
import java.io.IOException; | ||
import java.net.Socket; | ||
import java.nio.channels.SelectableChannel; | ||
import java.nio.channels.SelectionKey; | ||
import java.util.*; | ||
|
@@ -148,6 +149,7 @@ private static void initializeClasses() { | |
Class.forName(ShutdownEngine.class.getName()); | ||
Class.forName(AbstractShutdownTask.class.getName()); | ||
Class.forName(ShutdownControlGroup.class.getName()); | ||
Class.forName(Socket.class.getName()); | ||
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.
|
||
if (WispConfiguration.WISP_PROFILE) { | ||
Class.forName(WispPerfCounterMonitor.class.getName()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,43 @@ | |
* @summary Test ServerSocket isConnected() method | ||
* @requires os.family == "linux" | ||
* @library /lib/testlibrary | ||
* @build SimpleClient | ||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableCoroutine -XX:+UseWispMonitor -Dcom.alibaba.wisp.transparentWispSwitch=true ServerSocketConnectionTest | ||
*/ | ||
|
||
import java.io.IOException; | ||
import java.net.*; | ||
import static jdk.testlibrary.Asserts.assertTrue; | ||
import static jdk.testlibrary.Asserts.assertFalse; | ||
|
||
import static jdk.testlibrary.Asserts.*; | ||
|
||
|
||
public class ServerSocketConnectionTest { | ||
|
||
private static final String CLIENT = "SimpleClient"; | ||
private static final String PORT = "4039"; | ||
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. IMHO, using a random port makes the test more stable. 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. use 0
|
||
|
||
public static void testJavaNetSocketAccessInitialization() throws Exception { | ||
ServerSocket ss = null; | ||
try { | ||
ss = new ServerSocket(Integer.parseInt(PORT)); | ||
// We should avoid using the Socket class here to reproduce this issue. | ||
// So we use another process here. | ||
ProcessBuilder pb = jdk.testlibrary.ProcessTools.createJavaProcessBuilder( | ||
CLIENT, | ||
PORT // port | ||
); | ||
pb.start(); | ||
ss.accept(); | ||
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. accept after started? is this intentional? |
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
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. Use 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. done. |
||
fail("Test Failed!"); | ||
} finally { | ||
if (ss != null) { | ||
ss.close(); | ||
} | ||
} | ||
} | ||
|
||
private static void testIsConnectedAfterClosing() throws Exception { | ||
ServerSocket ss = null; | ||
Socket s1 = null; | ||
|
@@ -48,7 +74,7 @@ private static void testIsConnectedAfterClosing() throws Exception { | |
s1.connect(isa); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException("Test Failed!"); | ||
fail("Test Failed!"); | ||
} finally { | ||
// close this socket | ||
if (s1 != null) { | ||
|
@@ -74,7 +100,7 @@ private static void testIsConnectedAfterConnectionFailure() throws Exception { | |
s1.connect(isa, -1); // exception here | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException("Test Failed!"); | ||
fail("Test Failed!"); | ||
} catch (IllegalArgumentException e) { | ||
// we shall go here. | ||
assertFalse(s1.isConnected()); | ||
|
@@ -93,7 +119,7 @@ private static void testIsConnectedAfterAcception() throws Exception { | |
s1 = ss.accept(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException("Test Failed!"); | ||
fail("Test Failed!"); | ||
} finally { | ||
if (s1 != null) { | ||
assertTrue(s1.isConnected()); | ||
|
@@ -105,6 +131,7 @@ private static void testIsConnectedAfterAcception() throws Exception { | |
} | ||
|
||
public static void main(String args[]) throws Exception { | ||
testJavaNetSocketAccessInitialization(); | ||
testIsConnectedAfterClosing(); | ||
testIsConnectedAfterConnectionFailure(); | ||
testIsConnectedAfterAcception(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.*; | ||
import java.net.Socket; | ||
|
||
public class SimpleClient { | ||
|
||
public static void main(String[] args) throws Exception { | ||
Socket socket = new Socket(); | ||
socket.connect(new InetSocketAddress(InetAddress.getLocalHost(), Integer.parseInt(args[0]))); | ||
System.out.println(socket.getRemoteSocketAddress()); | ||
} | ||
|
||
} |
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.
Please add some comments to explain why we need this.