tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1402018 - in /tomcat/trunk/test/org/apache/catalina: connector/ filters/ startup/ tribes/test/transport/
Date Thu, 25 Oct 2012 08:29:23 GMT
Author: markt
Date: Thu Oct 25 08:29:22 2012
New Revision: 1402018

URL: http://svn.apache.org/viewvc?rev=1402018&view=rev
Log:
Fix Eclipse warnings in unit tests

Modified:
    tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
    tomcat/trunk/test/org/apache/catalina/filters/TesterResponse.java
    tomcat/trunk/test/org/apache/catalina/startup/BytesStreamer.java
    tomcat/trunk/test/org/apache/catalina/startup/TestListener.java
    tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java
    tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java
    tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java
    tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java

Modified: tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestSendFile.java Thu Oct 25 08:29:22
2012
@@ -131,20 +131,21 @@ public class TestSendFile extends Tomcat
                 req.setAttribute(Globals.SENDFILE_FILE_END_ATTR, new Long(f.length()));
             } else {
                 byte[] c = new byte[8192];
-                BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
-                int len = 0;
-                int written = 0;
-                long start = System.currentTimeMillis();
-                do {
-                    len = in.read(c);
-                    if (len>0) {
-                        resp.getOutputStream().write(c,0,len);
-                        written += len;
-                    }
-                } while (len > 0);
-                System.out.println("Server Wrote "+written + " bytes in "+(System.currentTimeMillis()-start)+"
ms.");
+                try (BufferedInputStream in = new BufferedInputStream(
+                        new FileInputStream(f))) {
+                    int len = 0;
+                    int written = 0;
+                    long start = System.currentTimeMillis();
+                    do {
+                        len = in.read(c);
+                        if (len>0) {
+                            resp.getOutputStream().write(c,0,len);
+                            written += len;
+                        }
+                    } while (len > 0);
+                    System.out.println("Server Wrote "+written + " bytes in "+(System.currentTimeMillis()-start)+"
ms.");
+                }
             }
-
         }
     }
 

Modified: tomcat/trunk/test/org/apache/catalina/filters/TesterResponse.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/filters/TesterResponse.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/filters/TesterResponse.java (original)
+++ tomcat/trunk/test/org/apache/catalina/filters/TesterResponse.java Thu Oct 25 08:29:22
2012
@@ -82,15 +82,12 @@ public class TesterResponse
     public void setError() {/* NOOP */}
     public boolean isError() { return false; }
     /**
-     *
-     * @return
      * @throws IOException
      */
     public ServletOutputStream createOutputStream() throws IOException {
         return null;
     }
     /**
-     *
      * @throws IOException
      */
     public void finishResponse() throws IOException {/* NOOP */}
@@ -100,7 +97,6 @@ public class TesterResponse
     public PrintWriter getReporter() { return null; }
     public void recycle() {/* NOOP */}
     /**
-     *
      * @param b
      * @throws IOException
      */
@@ -108,7 +104,6 @@ public class TesterResponse
         // NOOP
     }
     /**
-     *
      * @param b
      * @throws IOException
      */
@@ -116,7 +111,6 @@ public class TesterResponse
         // NOOP
     }
     /**
-     *
      * @param b
      * @param off
      * @param len

Modified: tomcat/trunk/test/org/apache/catalina/startup/BytesStreamer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/BytesStreamer.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/BytesStreamer.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/BytesStreamer.java Thu Oct 25 08:29:22 2012
@@ -24,22 +24,20 @@ package org.apache.catalina.startup;
  */
 public interface BytesStreamer {
     /**
-     * Returns the length of the content about to be streamed.
-     * Return -1 if length is unknown and chunked encoding should be used
-     * @return the length if known - otherwise -1
+     * Get the length of the content about to be streamed.
+     *
+     * @return the length if known, else -1 and chucked encoding should be used
      */
     int getLength();
 
     /**
-     * return the number of bytes available in next chunk
-     * @return
+     * @return  the number of bytes available in next chunk
      */
     int available();
 
     /**
-     * returns the next byte to write.
-     * if {@link #available()} method returns >0
-     * @return
+     * @return  returns the next byte to write if {@link #available()} returns
+     *          > 0
      */
     byte[] next();
 }

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestListener.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestListener.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestListener.java Thu Oct 25 08:29:22 2012
@@ -52,7 +52,7 @@ public class TestListener extends Tomcat
 
     /**
      * Check that a {@link ServletContextListener} cannot install a
-     * {@link ServletContextInitializer}.
+     * {@link ServletContainerInitializer}.
      * @throws Exception
      */
     @Test

Modified: tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java (original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java Thu Oct
25 08:29:22 2012
@@ -35,47 +35,54 @@ public class SocketReceive {
 
     public static void main(String[] args) throws Exception {
 
-        ServerSocket srvSocket = new ServerSocket(9999);
-        System.out.println("Listening on 9999");
-        Socket socket = srvSocket.accept();
-        socket.setReceiveBufferSize(43800);
-        InputStream in = socket.getInputStream();
-        Thread t = new Thread() {
-            @Override
-            public void run() {
-                while ( true ) {
-                    try {
-                        Thread.sleep(1000);
-                        printStats(start, mb, count, df, total);
-                    }catch ( Exception x ) {
-                        // Ignore
+        try (ServerSocket srvSocket = new ServerSocket(9999)) {
+            System.out.println("Listening on 9999");
+            Socket socket = srvSocket.accept();
+            socket.setReceiveBufferSize(43800);
+            InputStream in = socket.getInputStream();
+            Thread t = new Thread() {
+                @Override
+                public void run() {
+                    while ( true ) {
+                        try {
+                            Thread.sleep(1000);
+                            printStats(start, mb, count, df, total);
+                        }catch ( Exception x ) {
+                            // Ignore
+                        }
                     }
                 }
-            }
-        };
-        t.setDaemon(true);
-        t.start();
+            };
+            t.setDaemon(true);
+            t.start();
 
-        while ( true ) {
-            if ( first ) { first = false; start = System.currentTimeMillis();}
-            int len = in.read(buf);
-            if ( len == -1 ) {
-                printStats(start, mb, count, df, total);
-                System.exit(1);
-            }
-            if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len);
-            total = total.add(bytes);
-            mb += ( (double) len) / 1024 / 1024;
-            if ( ((++count) % 10000) == 0 ) {
-                printStats(start, mb, count, df, total);
+            while ( true ) {
+                if ( first ) {
+                    first = false; start = System.currentTimeMillis();
+                }
+                int len = in.read(buf);
+                if ( len == -1 ) {
+                    printStats(start, mb, count, df, total);
+                    System.exit(1);
+                }
+                if ( bytes.intValue() != len ) {
+                    bytes = new BigDecimal((double)len);
+                }
+                total = total.add(bytes);
+                mb += ( (double) len) / 1024 / 1024;
+                if ( ((++count) % 10000) == 0 ) {
+                    printStats(start, mb, count, df, total);
+                }
             }
         }
-
     }
 
-    private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal
total) {
+    private static void printStats(long start, double mb, int count,
+            DecimalFormat df, BigDecimal total) {
         long time = System.currentTimeMillis();
         double seconds = ((double)(time-start))/1000;
-        System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+",
total "+mb+" MB, total "+total+" bytes.");
+        System.out.println("Throughput " + df.format(mb/seconds) +
+                " MB/seconds messages " + count + ", total " + mb +
+                " MB, total " + total + " bytes.");
     }
 }
\ No newline at end of file

Modified: tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java (original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java Thu Oct 25
08:29:22 2012
@@ -43,28 +43,32 @@ public class SocketSend {
         System.out.println("Message size:"+len+" bytes");
         BigDecimal total = new BigDecimal((double)0);
         BigDecimal bytes = new BigDecimal((double)len);
-        Socket socket = new Socket("localhost",9999);
-        System.out.println("Writing to 9999");
-        OutputStream out = socket.getOutputStream();
-        long start = 0;
-        double mb = 0;
-        boolean first = true;
-        int count = 0;
-        DecimalFormat df = new DecimalFormat("##.00");
-        while ( count<1000000 ) {
-            if ( first ) { first = false; start = System.currentTimeMillis();}
-            out.write(buf,0,buf.length);
-            mb += ( (double) buf.length) / 1024 / 1024;
-            total = total.add(bytes);
-            if ( ((++count) % 10000) == 0 ) {
-                long time = System.currentTimeMillis();
-                double seconds = ((double)(time-start))/1000;
-                System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages
"+count+", total "+mb+" MB, total "+total+" bytes.");
+        try (Socket socket = new Socket("localhost",9999)) {
+            System.out.println("Writing to 9999");
+            OutputStream out = socket.getOutputStream();
+            long start = 0;
+            double mb = 0;
+            boolean first = true;
+            int count = 0;
+            DecimalFormat df = new DecimalFormat("##.00");
+            while ( count<1000000 ) {
+                if ( first ) {
+                    first = false; start = System.currentTimeMillis();
+                }
+                out.write(buf,0,buf.length);
+                mb += ( (double) buf.length) / 1024 / 1024;
+                total = total.add(bytes);
+                if ( ((++count) % 10000) == 0 ) {
+                    long time = System.currentTimeMillis();
+                    double seconds = ((double)(time-start))/1000;
+                    System.out.println("Throughput " + df.format(mb/seconds) +
+                            " MB/seconds messages " + count + ", total " + mb +
+                            " MB, total " + total + " bytes.");
+                }
             }
+            out.flush();
+            System.out.println("Complete, sleeping 5 seconds");
+            Thread.sleep(5000);
         }
-        out.flush();
-        System.out.println("Complete, sleeping 5 seconds");
-        Thread.sleep(5000);
-
     }
 }

Modified: tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java (original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java Thu
Oct 25 08:29:22 2012
@@ -38,52 +38,65 @@ public class SocketTribesReceive {
 
     public static void main(String[] args) throws Exception {
         int size = 43800;
-        if (args.length > 0 ) try {size=Integer.parseInt(args[0]);}catch(Exception x){
/* Ignore */ }
+        if (args.length > 0 ) {
+            try {
+                size = Integer.parseInt(args[0]);
+            } catch (Exception e){
+                /* Ignore */
+            }
+        }
         XByteBuffer xbuf = new XByteBuffer(43800,true);
-        ServerSocket srvSocket = new ServerSocket(9999);
-        System.out.println("Listening on 9999");
-        Socket socket = srvSocket.accept();
-        socket.setReceiveBufferSize(size);
-        InputStream in = socket.getInputStream();
-        Thread t = new Thread() {
-            @Override
-            public void run() {
-                while ( true ) {
-                    try {
-                        Thread.sleep(1000);
-                        printStats(start, mb, count, df, total);
-                    }catch ( Exception x ) { /* Ignore */ }
+        try (ServerSocket srvSocket = new ServerSocket(9999)) {
+            System.out.println("Listening on 9999");
+            Socket socket = srvSocket.accept();
+            socket.setReceiveBufferSize(size);
+            InputStream in = socket.getInputStream();
+            Thread t = new Thread() {
+                @Override
+                public void run() {
+                    while ( true ) {
+                        try {
+                            Thread.sleep(1000);
+                            printStats(start, mb, count, df, total);
+                        }catch ( Exception x ) { /* Ignore */ }
+                    }
                 }
-            }
-        };
-        t.setDaemon(true);
-        t.start();
+            };
+            t.setDaemon(true);
+            t.start();
 
-        while ( true ) {
-            if ( first ) { first = false; start = System.currentTimeMillis();}
-            int len = in.read(buf);
-            if ( len == -1 ) {
-                printStats(start, mb, count, df, total);
-                System.exit(1);
-            }
-            xbuf.append(buf,0,len);
-            if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len);
-            total = total.add(bytes);
-            while ( xbuf.countPackages(true) > 0 ) {
-                xbuf.extractPackage(true);
-                count++;
-            }
-            mb += ( (double) len) / 1024 / 1024;
-            if ( ((count) % 10000) == 0 ) {
-                printStats(start, mb, count, df, total);
+            while ( true ) {
+                if ( first ) {
+                    first = false; start = System.currentTimeMillis();
+                }
+                int len = in.read(buf);
+                if ( len == -1 ) {
+                    printStats(start, mb, count, df, total);
+                    System.exit(1);
+                }
+                xbuf.append(buf,0,len);
+                if ( bytes.intValue() != len ) {
+                    bytes = new BigDecimal((double)len);
+                }
+                total = total.add(bytes);
+                while ( xbuf.countPackages(true) > 0 ) {
+                    xbuf.extractPackage(true);
+                    count++;
+                }
+                mb += ( (double) len) / 1024 / 1024;
+                if ( ((count) % 10000) == 0 ) {
+                    printStats(start, mb, count, df, total);
+                }
             }
         }
-
     }
 
-    private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal
total) {
+    private static void printStats(long start, double mb, int count,
+            DecimalFormat df, BigDecimal total) {
         long time = System.currentTimeMillis();
         double seconds = ((double)(time-start))/1000;
-        System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+",
total "+mb+" MB, total "+total+" bytes.");
+        System.out.println("Throughput " + df.format(mb/seconds) +
+                " MB/seconds messages " + count + ", total " + mb +
+                " MB, total " + total + " bytes.");
     }
 }
\ No newline at end of file

Modified: tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java?rev=1402018&r1=1402017&r2=1402018&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java
(original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java
Thu Oct 25 08:29:22 2012
@@ -37,49 +37,56 @@ public class SocketValidateReceive {
         int size = 43800;
         if (args.length > 0 ) try {size=Integer.parseInt(args[0]);}catch(Exception x){
/* Ignore */ }
 
-        ServerSocket srvSocket = new ServerSocket(9999);
-        System.out.println("Listening on 9999");
-        Socket socket = srvSocket.accept();
-        socket.setReceiveBufferSize(size);
-        InputStream in = socket.getInputStream();
-        MyDataReader reader = new MyDataReader(50000);
-        Thread t = new Thread() {
-            @Override
-            public void run() {
-                while ( true ) {
-                    try {
-                        Thread.sleep(1000);
-                        printStats(start, mb, count, df, total);
-                    }catch ( Exception x ) { /* Ignore */ }
+        try(ServerSocket srvSocket = new ServerSocket(9999)) {
+            System.out.println("Listening on 9999");
+            Socket socket = srvSocket.accept();
+            socket.setReceiveBufferSize(size);
+            InputStream in = socket.getInputStream();
+            MyDataReader reader = new MyDataReader(50000);
+            Thread t = new Thread() {
+                @Override
+                public void run() {
+                    while ( true ) {
+                        try {
+                            Thread.sleep(1000);
+                            printStats(start, mb, count, df, total);
+                        }catch ( Exception x ) { /* Ignore */ }
+                    }
                 }
-            }
-        };
-        t.setDaemon(true);
-        t.start();
-
-        while ( true ) {
-            if ( first ) { first = false; start = System.currentTimeMillis();}
-            int len = in.read(buf);
-            if ( len == -1 ) {
-                printStats(start, mb, count, df, total);
-                System.exit(1);
-            }
-            count += reader.append(buf,0,len);
+            };
+            t.setDaemon(true);
+            t.start();
+
+            while ( true ) {
+                if ( first ) {
+                    first = false; start = System.currentTimeMillis();
+                }
+                int len = in.read(buf);
+                if ( len == -1 ) {
+                    printStats(start, mb, count, df, total);
+                    System.exit(1);
+                }
+                count += reader.append(buf,0,len);
 
-            if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len);
-            total = total.add(bytes);
-            mb += ( (double) len) / 1024 / 1024;
-            if ( ((count) % 10000) == 0 ) {
-                printStats(start, mb, count, df, total);
+                if ( bytes.intValue() != len ) {
+                    bytes = new BigDecimal((double)len);
+                }
+                total = total.add(bytes);
+                mb += ( (double) len) / 1024 / 1024;
+                if ( ((count) % 10000) == 0 ) {
+                    printStats(start, mb, count, df, total);
+                }
             }
         }
-
     }
 
-    private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal
total) {
+    private static void printStats(long start, double mb, int count,
+            DecimalFormat df, BigDecimal total) {
         long time = System.currentTimeMillis();
         double seconds = ((double)(time-start))/1000;
-        System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+",
total "+mb+" MB, total "+total+" bytes.");
+        System.out.println("Throughput " + df.format(mb/seconds) +
+                " MB/seconds messages " + count + ", total " + mb +
+                " MB, total " + total + " bytes.");
     }
 
     public static class MyDataReader {



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


Mime
View raw message