[jscover] 65/69: Fix some logging statements. Minor tidying.

Sylvestre Ledru sylvestre at moszumanska.debian.org
Fri Aug 22 05:54:09 UTC 2014


This is an automated email from the git hooks/post-receive script.

sylvestre pushed a commit to branch master
in repository jscover.

commit 2e0d9f2cc4015b33820ce4ee56de1ea07a7c29b1
Author: tntim96 <tntim96 at gmail.com>
Date:   Fri Aug 15 18:44:19 2014 +1000

    Fix some logging statements. Minor tidying.
---
 src/main/java/jscover/report/Main.java             |  7 +--
 src/main/java/jscover/server/ProxyService.java     | 16 +++---
 .../java/jscover/server/PersistentProxyTest.java   | 66 ++++++----------------
 .../jscover/server/PersistentStaticHttpServer.java | 33 +----------
 src/test/java/jscover/server/ProxyServiceTest.java | 24 ++++----
 5 files changed, 42 insertions(+), 104 deletions(-)

diff --git a/src/main/java/jscover/report/Main.java b/src/main/java/jscover/report/Main.java
index e69c3a2..3952edd 100644
--- a/src/main/java/jscover/report/Main.java
+++ b/src/main/java/jscover/report/Main.java
@@ -354,7 +354,6 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Properties;
 import java.util.SortedMap;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import static java.util.logging.Level.INFO;
@@ -427,10 +426,10 @@ public class Main {
         for (int i = 0; i < config.getMergeDirs().size(); i++) {
             File jsOriginalSrc = new File(config.getMergeDirs().get(i), jscover.Main.reportSrcSubDir);
             if (jsOriginalSrc.exists()) {
-                logger.log(INFO, "Merging source from '%s'", jsOriginalSrc.getPath());
+                logger.log(INFO, "Merging source from ''{0}''", jsOriginalSrc.getPath());
                 ioUtils.copyDir(jsOriginalSrc, srcDir);
             } else
-                logger.info(String.format("Couldn't find directory '%s' to merge", jsOriginalSrc));
+                logger.log(INFO, "Couldn''t find directory ''{0}'' to merge", jsOriginalSrc);
         }
     }
 
@@ -438,7 +437,7 @@ public class Main {
         String[] data = new String[config.getMergeDirs().size()];
         for (int i = 0; i < data.length; i++) {
             File dataFile = new File(config.getMergeDirs().get(i), "jscoverage.json");
-            logger.log(INFO, "Merging JSON from '%s'", dataFile.getPath());
+            logger.log(INFO, "Merging JSON from ''{0}''", dataFile.getPath());
             data[i] = ioUtils.loadFromFileSystem(dataFile);
         }
         SortedMap<String, FileData> mergedMap = jsonDataMerger.mergeJSONCoverageStrings(data);
diff --git a/src/main/java/jscover/server/ProxyService.java b/src/main/java/jscover/server/ProxyService.java
index 9cb7e83..6eee216 100644
--- a/src/main/java/jscover/server/ProxyService.java
+++ b/src/main/java/jscover/server/ProxyService.java
@@ -414,9 +414,9 @@ public class ProxyService {
             ioUtils.closeQuietly(socket);
         }
     }
-    
+
     protected void sendMethodAndHeaders(HttpRequest request, InputStream is, OutputStream remoteOutputStream) throws IOException {
-        
+
         // read ahead to see the method and headers
         logger.log(FINE, "Bytes available on stream {0}", is.available());
         int bufSize = Math.min(is.available(), HttpServer.HEADER_SIZE);
@@ -426,7 +426,7 @@ public class ProxyService {
         int read = pbis.read(headerBytes);
         int firstLineIndex = ioUtils.getNewLineIndex(headerBytes, UTF8);
         int dataIndex = ioUtils.getDataIndex(headerBytes, UTF8);
-        
+
         // back up to the start of data
         pbis.unread(headerBytes, dataIndex, read - dataIndex);
 
@@ -437,18 +437,18 @@ public class ProxyService {
         header = header.replaceFirst(Pattern.quote(url.toExternalForm()), getRawURI(url));
         header = header.replaceFirst("HTTP/1.1", "HTTP/1.0");
         logger.log(FINEST, "Header after {0}", header);
-        
+
         // write method and filtered headers to intermediate buffer
         PrintWriter remotePrintWriter = new PrintWriter(new OutputStreamWriter(baos, UTF8));
         remotePrintWriter.write(header);
         remotePrintWriter.write("\r\n");
         sendHeaders(request, remotePrintWriter);
         byte[] methodAndHeaderBytes = baos.toByteArray();
-        
+
         // push method and headers in front of response data
         PushbackInputStream requestInputStream = new PushbackInputStream(pbis, methodAndHeaderBytes.length);
         requestInputStream.unread(methodAndHeaderBytes);
-        
+
         // now copy the whole thing
         int toSend = methodAndHeaderBytes.length + request.getContentLength();
         ioUtils.copyNoClose(requestInputStream, remoteOutputStream, toSend);
@@ -461,7 +461,7 @@ public class ProxyService {
         }
         return uri;
     }
-    
+
     private void sendHeaders(HttpRequest request, PrintWriter remotePrintWriter) {
         Map<String, List<String>> clientHeaders = request.getHeaders();
         for (String header : clientHeaders.keySet()) {
@@ -475,7 +475,7 @@ public class ProxyService {
         remotePrintWriter.print("\r\n");
         remotePrintWriter.flush();
     }
-    
+
     protected boolean shouldSendHeader(String header) {
         header = header.toLowerCase();
         // don't allow keep-alive headers to override HTTP/1.0 default of non-persistent
diff --git a/src/test-acceptance/java/jscover/server/PersistentProxyTest.java b/src/test-acceptance/java/jscover/server/PersistentProxyTest.java
index 111700a..b8caf6d 100644
--- a/src/test-acceptance/java/jscover/server/PersistentProxyTest.java
+++ b/src/test-acceptance/java/jscover/server/PersistentProxyTest.java
@@ -339,8 +339,8 @@ consider it more useful to permit linking proprietary applications with the
 library.  If this is what you want to do, use the GNU Lesser General
 Public License instead of this License.
  */
- 
- package jscover.server;
+
+package jscover.server;
 
 import java.io.IOException;
 import java.net.ServerSocket;
@@ -351,10 +351,8 @@ import jscover.Main;
 import jscover.util.IoUtils;
 
 import org.junit.AfterClass;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.gargoylesoftware.htmlunit.HttpMethod;
@@ -363,23 +361,23 @@ import com.gargoylesoftware.htmlunit.ProxyConfig;
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.WebRequest;
 
-public class PersistentProxyTest  {
+import static org.junit.Assert.assertEquals;
+
+public class PersistentProxyTest {
     private static Thread webServer;
     private static Thread proxyServer;
     private static Main main = new Main();
     private static ServerSocket serverSocket;
     private static int proxyPort = 3129;
-    
-    private static boolean forceKeepAlive;
-    
+
     protected WebClient webClient = new WebClient();
     protected IoUtils ioUtils = IoUtils.getInstance();
-    
+
     private static String CONTENT = "Some content";
 
     private static String[] args = new String[]{
             "-ws",
-            "--port="+proxyPort,
+            "--port=" + proxyPort,
             "--proxy",
             "--no-branch",
             "--no-function",
@@ -400,7 +398,7 @@ public class PersistentProxyTest  {
                     serverSocket = new ServerSocket(9001);
                     while (true) {
                         final Socket socket = serverSocket.accept();
-                        new Thread(new PersistentStaticHttpServer(socket, CONTENT, forceKeepAlive)).start();
+                        new Thread(new PersistentStaticHttpServer(socket, CONTENT)).start();
                     }
                 } catch (IOException e) {
                     //throw new RuntimeException(e);
@@ -427,65 +425,33 @@ public class PersistentProxyTest  {
     protected String getTestUrl() {
         return "http://localhost:9001/anything";
     }
-    
+
     protected void doTestRequests(HttpMethod... methods) throws Exception {
         URL testURL = new URL(getTestUrl());
-        for( HttpMethod method: methods ) {
+        for (HttpMethod method : methods) {
             WebRequest request = new WebRequest(testURL, method);
             Page page = webClient.getPage(request);
-            Assert.assertEquals("Unexpected response", CONTENT, page.getWebResponse().getContentAsString());
+            assertEquals("Unexpected response", CONTENT, page.getWebResponse().getContentAsString());
         }
     }
-    
+
     @Test
     public void testSingleGet() throws Exception {
-        forceKeepAlive = false;
         doTestRequests(HttpMethod.GET);
     }
-    
-    @Test
-    @Ignore("No forced keep-alives")
-    public void testSingleGetKeepAlive() throws Exception {
-        forceKeepAlive = true;
-        doTestRequests(HttpMethod.GET);
-    }
-    
+
     @Test
     public void testSinglePost() throws Exception {
-        forceKeepAlive = false;
         doTestRequests(HttpMethod.POST);
     }
-    
-    @Test
-    @Ignore("No forced keep-alives")
-    public void testSinglePostKeepAlive() throws Exception {
-        forceKeepAlive = true;
-        doTestRequests(HttpMethod.POST);
-    }
-    
+
     @Test
     public void testConsecutiveGets() throws Exception {
-        forceKeepAlive = false;
-        doTestRequests(HttpMethod.GET, HttpMethod.GET);
-    }
-    
-    @Test
-    @Ignore("No forced keep-alives")
-    public void testConsecutiveGetsKeepAlive() throws Exception {
-        forceKeepAlive = true;
         doTestRequests(HttpMethod.GET, HttpMethod.GET);
     }
-    
+
     @Test
     public void testConsecutivePosts() throws Exception {
-        forceKeepAlive = false;
-        doTestRequests(HttpMethod.POST, HttpMethod.POST);
-    }
-    
-    @Test
-    @Ignore("No forced keep-alives")
-    public void testConsecutivePostsKeepAlive() throws Exception {
-        forceKeepAlive = true;
         doTestRequests(HttpMethod.POST, HttpMethod.POST);
     }
 }
diff --git a/src/test-acceptance/java/jscover/server/PersistentStaticHttpServer.java b/src/test-acceptance/java/jscover/server/PersistentStaticHttpServer.java
index 4e59518..0a6ec07 100644
--- a/src/test-acceptance/java/jscover/server/PersistentStaticHttpServer.java
+++ b/src/test-acceptance/java/jscover/server/PersistentStaticHttpServer.java
@@ -374,18 +374,11 @@ public class PersistentStaticHttpServer implements Runnable {
     
     protected final Socket socket;
     protected String content;
-    /** To force the connection to be persistent regardless of headers. */
-    protected boolean forceKeepAlive;
-    
-    public PersistentStaticHttpServer(Socket socket) {
-        this(socket, "Some content", false);
-    }
-    
-    public PersistentStaticHttpServer(Socket socket, String content, boolean forceKeepAlive) {
+
+    public PersistentStaticHttpServer(Socket socket, String content) {
         if( socket == null ) throw new NullPointerException("socket is null");
         this.socket = socket;
         this.content = content;
-        this.forceKeepAlive = forceKeepAlive;
     }
     
     public void run() {
@@ -398,7 +391,7 @@ public class PersistentStaticHttpServer implements Runnable {
                     // fully read the request, whatever it is
                     HttpRequest request = conn.receiveRequestHeader();
                     logger.log(FINE, "Received request: {0}", request);
-                    keepAlive = forceKeepAlive || isKeepAlive(request);
+                    keepAlive = isKeepAlive(request);
                     
                     if (request instanceof HttpEntityEnclosingRequest) {
                         conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
@@ -468,24 +461,4 @@ public class PersistentStaticHttpServer implements Runnable {
         conn.flush();
         logger.log(FINE, "Sent 405 Method Not Allowed");
     }
-    
-    public String getContent() {
-        return content;
-    }
-    
-    public void setContent(String content) {
-        this.content = content;
-    }
-    
-    public Socket getSocket() {
-        return socket;
-    }
-    
-    public void setForceKeepAlive(boolean forceKeepAlive) {
-        this.forceKeepAlive = forceKeepAlive;
-    }
-    
-    public boolean isForceKeepAlive() {
-        return forceKeepAlive;
-    }
 }
diff --git a/src/test/java/jscover/server/ProxyServiceTest.java b/src/test/java/jscover/server/ProxyServiceTest.java
index 3cb2f5a..6e0b343 100644
--- a/src/test/java/jscover/server/ProxyServiceTest.java
+++ b/src/test/java/jscover/server/ProxyServiceTest.java
@@ -340,7 +340,7 @@ library.  If this is what you want to do, use the GNU Lesser General
 Public License instead of this License.
  */
 
- package jscover.server;
+package jscover.server;
 
 import jscover.util.IoUtils;
 
@@ -387,7 +387,7 @@ public class ProxyServiceTest {
 
         proxyService.copyHeadersExceptEncoding(request, conn);
 
-        verify(conn).addRequestProperty("Cookie","123");
+        verify(conn).addRequestProperty("Cookie", "123");
         verify(conn).addRequestProperty("Cookie", "456");
     }
 
@@ -428,22 +428,22 @@ public class ProxyServiceTest {
         headers.put("Content-Length", Collections.singletonList("0"));
         String url = "http://somehost/someURL";
         String requestString = "POST " + url + " HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
-        
+
         String result = sendMethodAndHeaders(url, requestString, headers).toString("UTF-8");
         assertThat(result, startsWith("POST /someURL HTTP/1.0"));
     }
-    
+
     @Test
     public void shouldChangeURLToPath() throws Exception {
         Map<String, List<String>> headers = new HashMap<String, List<String>>();
         headers.put("Content-Length", Collections.singletonList("0"));
         String url = "http://somehost/someURL";
         String requestString = "POST " + url + " HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
-        
+
         String result = sendMethodAndHeaders(url, requestString, headers).toString("UTF-8");
         assertThat(result, startsWith("POST /someURL"));
     }
-    
+
     @Test
     public void shouldNotAddKeepAliveHeadersPost() throws Exception {
         Map<String, List<String>> headers = new HashMap<String, List<String>>();
@@ -454,19 +454,19 @@ public class ProxyServiceTest {
         String url = "http://somehost/someURL";
         String requestString = "POST " + url + " HTTP/1.1\r\nProxy-Connection: keep-alive\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
         String result = sendMethodAndHeaders(url, requestString, headers).toString("UTF-8");
-        
+
         assertThat(result, Matchers.not(Matchers.containsString("Connection")));
         assertThat(result, Matchers.not(Matchers.containsString("keep-alive")));
     }
-    
+
     private ByteArrayOutputStream sendMethodAndHeaders(String path, String requestString, Map<String, List<String>> headers) throws IOException {
-        if (headers == null )
+        if (headers == null)
             headers = Collections.emptyMap();
-        
+
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ByteArrayInputStream in =  new ByteArrayInputStream(requestString.getBytes(UTF8));
+        ByteArrayInputStream in = new ByteArrayInputStream(requestString.getBytes(UTF8));
         HttpRequest request = new HttpRequest(path, new ByteArrayInputStream(requestString.getBytes(UTF8)), out, 0, headers);
-        
+
         proxyService.sendMethodAndHeaders(request, in, out);
         return out;
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jscover.git



More information about the pkg-java-commits mailing list