Re: svn commit: r1823392 - /tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java

2018-02-06 Thread Konstantin Kolinko
2018-02-07 0:00 GMT+03:00  :
> Author: markt
> Date: Tue Feb  6 21:00:52 2018
> New Revision: 1823392
>
> URL: http://svn.apache.org/viewvc?rev=1823392=rev
> Log:
> Make test more robust
>
> Modified:
> 
> tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java
>
> Modified: 
> tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java?rev=1823392=1823391=1823392=diff
> ==
> --- 
> tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java 
> (original)
> +++ 
> tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java 
> Tue Feb  6 21:00:52 2018
> @@ -33,6 +33,9 @@ import org.junit.Test;
>   */
>  public class TestSocketServerAnyLocalAddress extends AbstractJniTest {
>
> +// Excessive but allows for slow systems
> +private static final int TIMEOUT_MICROSECONDS = 10 * 1000 * 1000;
> +
>  private long serverSocket = 0;
>  private long clientSocket = 0;
>
> @@ -80,8 +83,8 @@ public class TestSocketServerAnyLocalAdd
>  /* Accept the client connection */
>  clientSocket = Socket.accept(serverSocket);
>
> -/* Configure a 2ms timeout for reading from client */
> -Socket.timeoutSet(clientSocket, 1);
> +/* Configure a 1s timeout for reading from client */
> +Socket.timeoutSet(clientSocket, TIMEOUT_MICROSECONDS);

The above comment is wrong. The constant value is 10 seconds.

(The old comment was wrong as well.)

Constant name is ok.  JNI Socket method expects microseconds (10^-6 second)
http://tomcat.apache.org/tomcat-9.0-doc/api/org/apache/tomcat/jni/Socket.html#timeoutSet-long-long-

https://en.wikipedia.org/wiki/Microsecond
(Looking up. To be sure I count the zeros correctly).

APR api called here:
http://apr.apache.org/docs/apr/1.6/group__apr__network__io.html#ga945bdbe807ec5635d65a6fd9ddb78c29
http://apr.apache.org/docs/apr/1.6/group__apr__time.html#gaae2129185a395cc393f76fabf4f43e47

>  byte [] buf = new byte[1];
>  while (Socket.recv(clientSocket, buf, 0, 1) == 1) {
> @@ -122,8 +125,8 @@ public class TestSocketServerAnyLocalAdd
>  try {
>  InetSocketAddress connectAddress = 
> getConnectAddress(serverSocket);
>  java.net.Socket sock = new java.net.Socket();
> -sock.connect(connectAddress, 1);
> -sock.setSoTimeout(1);
> +sock.connect(connectAddress, TIMEOUT_MICROSECONDS);
> +sock.setSoTimeout(TIMEOUT_MICROSECONDS);

The above is 1000 times more than expected.

https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#connect(java.net.SocketAddress,%20int)
https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#setSoTimeout(int)

java.net.Socket here expects milliseconds (10^-3 second)


>  OutputStream ou = sock.getOutputStream();
>  InputStream in =  sock.getInputStream();
>  ou.write('A');
> @@ -135,8 +138,8 @@ public class TestSocketServerAnyLocalAdd
>  }
>
>  sock = new java.net.Socket();

Again, a JRE Socket here. Milliseconds (10^-3).

> -sock.connect(connectAddress, 1);
> -sock.setSoTimeout(1);
> +sock.connect(connectAddress, TIMEOUT_MICROSECONDS);
> +sock.setSoTimeout(TIMEOUT_MICROSECONDS);
>  ou = sock.getOutputStream();
>  ou.write('E');
>  ou.flush();

Best regards,
Konstantin Kolinko

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



svn commit: r1823392 - /tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java

2018-02-06 Thread markt
Author: markt
Date: Tue Feb  6 21:00:52 2018
New Revision: 1823392

URL: http://svn.apache.org/viewvc?rev=1823392=rev
Log:
Make test more robust

Modified:
tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java

Modified: 
tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java?rev=1823392=1823391=1823392=diff
==
--- 
tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java 
(original)
+++ 
tomcat/trunk/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java 
Tue Feb  6 21:00:52 2018
@@ -33,6 +33,9 @@ import org.junit.Test;
  */
 public class TestSocketServerAnyLocalAddress extends AbstractJniTest {
 
+// Excessive but allows for slow systems
+private static final int TIMEOUT_MICROSECONDS = 10 * 1000 * 1000;
+
 private long serverSocket = 0;
 private long clientSocket = 0;
 
@@ -80,8 +83,8 @@ public class TestSocketServerAnyLocalAdd
 /* Accept the client connection */
 clientSocket = Socket.accept(serverSocket);
 
-/* Configure a 2ms timeout for reading from client */
-Socket.timeoutSet(clientSocket, 1);
+/* Configure a 1s timeout for reading from client */
+Socket.timeoutSet(clientSocket, TIMEOUT_MICROSECONDS);
 
 byte [] buf = new byte[1];
 while (Socket.recv(clientSocket, buf, 0, 1) == 1) {
@@ -122,8 +125,8 @@ public class TestSocketServerAnyLocalAdd
 try {
 InetSocketAddress connectAddress = 
getConnectAddress(serverSocket);
 java.net.Socket sock = new java.net.Socket();
-sock.connect(connectAddress, 1);
-sock.setSoTimeout(1);
+sock.connect(connectAddress, TIMEOUT_MICROSECONDS);
+sock.setSoTimeout(TIMEOUT_MICROSECONDS);
 OutputStream ou = sock.getOutputStream();
 InputStream in =  sock.getInputStream();
 ou.write('A');
@@ -135,8 +138,8 @@ public class TestSocketServerAnyLocalAdd
 }
 
 sock = new java.net.Socket();
-sock.connect(connectAddress, 1);
-sock.setSoTimeout(1);
+sock.connect(connectAddress, TIMEOUT_MICROSECONDS);
+sock.setSoTimeout(TIMEOUT_MICROSECONDS);
 ou = sock.getOutputStream();
 ou.write('E');
 ou.flush();



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org