Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / test / driver / JigsawHarnessPretex.java
diff --git a/JMCR-Stable/real-world application/jigsaw/test/driver/JigsawHarnessPretex.java b/JMCR-Stable/real-world application/jigsaw/test/driver/JigsawHarnessPretex.java
new file mode 100644 (file)
index 0000000..b4af582
--- /dev/null
@@ -0,0 +1,248 @@
+package driver;\r
+\r
+import java.io.*;\r
+import java.net.Socket;\r
+import java.net.URL;\r
+import java.net.URLConnection;\r
+\r
+/**\r
+ * Copyright (c) 2004\r
+ * <p/>\r
+ * Koushik Sen <ksen@cs.uiuc.edu>\r
+ * Pallavi Joshi <pallavi@cs.berkeley.edu>\r
+ * <p/>\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this\r
+ * software and associated documentation files (the "Software"), to deal in the Software\r
+ * without restriction, including without limitation the rights to use, copy, modify,\r
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\r
+ * permit persons to whom the Software is furnished to do so, subject to the following\r
+ * conditions:\r
+ * <p/>\r
+ * The above copyright notice and this permission notice shall be included in all copies\r
+ * or substantial portions of the Software.\r
+ * <p/>\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\r
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\r
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\r
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR\r
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+public class JigsawHarnessPretex \r
+{\r
+       \r
+    static final int iterations = 1;\r
+    static final String[] URLs = {\r
+            "http://localhost:8001/Doc/FAQ.html",\r
+            "http://localhost:8001/Doc/template.html",\r
+            "http://localhost:8001/Doc/background.gif",\r
+            "http://localhost:8001/Doc/Overview.html",\r
+            "http://localhost:8001/Doc/Programmer/design.html",\r
+            "http://localhost:8001/Doc/background.jpg",\r
+//            "http://localhost:8001/Overview.html",\r
+//            "http://localhost:8001/RelNotes.html",\r
+//            "http://localhost:8001/User/Administration/AdminTools.html",\r
+//            "http://localhost:8001/User/Administration/cmdline.html",\r
+//            "http://localhost:8001/User/Administration/fr-toc.html",\r
+//            "http://localhost:8001/User/Administration/JigAdm.html",\r
+//            "http://localhost:8001/User/Administration/Overview.html",\r
+//            "http://localhost:8001/User/Administration/pics.html",\r
+//            "http://localhost:8001/User/Administration/propeditor.html",\r
+//            "http://localhost:8001/User/Administration/resedit.html",\r
+//            "http://localhost:8001/User/Administration/tools/jhttpd.html",\r
+//            "http://localhost:8001/User/Administration/tools/jindex.html",\r
+//            "http://localhost:8001/User/Administration/tools/Overview.html",\r
+//            "http://localhost:8001/User/FAQ.html",\r
+//            "http://localhost:8001/User/fr-Overview.html",\r
+//            "http://localhost:8001/User/fr-toc.html",\r
+//            "http://localhost:8001/User/Introduction/architecture-new.html",\r
+//            "http://localhost:8001/User/Introduction/architecture.html",\r
+//            "http://localhost:8001/User/Introduction/fr-toc.html",\r
+//            "http://localhost:8001/User/Introduction/indexer.html",\r
+//            "http://localhost:8001/User/Introduction/installation.html",\r
+//            "http://localhost:8001/User/Introduction/mac.html",\r
+//            "http://localhost:8001/User/Introduction/Overview.html",\r
+//            "http://localhost:8001/User/Introduction/performance.html",\r
+//            "http://localhost:8001/User/Introduction/wp.html",\r
+//            "http://localhost:8001/User/Overview.html",\r
+//            "http://localhost:8001/User/Paper/Position.html",\r
+//            "http://localhost:8001/User/Reference/filters.html",\r
+//            "http://localhost:8001/User/Reference/fr-filters.html",\r
+//            "http://localhost:8001/User/Reference/fr-properties.html",\r
+//            "http://localhost:8001/User/Reference/fr-resources.html",\r
+//            "http://localhost:8001/User/Reference/fr-toc.html",\r
+//            "http://localhost:8001/User/Reference/Overview.html",\r
+//            "http://localhost:8001/User/Reference/resources.html",\r
+//            "http://localhost:8001/User/Reference/template.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.auth.AuthFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.auth.GenericAuthFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.contrib.CheckpointResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.contrib.LogFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.contrib.PasswordEditor.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.contrib.SalvagerResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.cvs.AutoLookupDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.cvs.CvsDirectoryResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.filters.AccessLimitFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.filters.CounterFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.filters.DebugFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.filters.ErrorFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.filters.ProcessFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.filters.PutSizeFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.forms.CgiResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.forms.PostableResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.http.GeneralProp.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.http.LoggingProp.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.http.socket.SocketConnectionProp.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.http.UnixProp.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.indexer.ExtensionsEditor.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.map.MapResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.pics.DataBaseBureauResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.pics.LabelBureauResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.pics.PICSFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.proxy.CacheProp.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.proxy.ForwardDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.proxy.MirrorDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.proxy.ProxyDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.proxy.ProxyProp.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.DirectoryResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.FileResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.FilteredResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.HTTPResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.NegotiatedResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.PassDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.ProcessFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.PutableDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.Resource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.ResourceFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.SSIResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.StoreContainer.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.resources.VirtualHostResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.servlet.RemoteServletWrapper.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.servlet.ServletDirectory.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.servlet.ServletWrapper.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.ssi.DefaultCommandRegistry.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.ssi.SSIResource.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.status.Statistics.html",\r
+//            "http://localhost:8001/User/Reference/w3c.jigsaw.status.ThreadStat.html",\r
+//            "http://localhost:8001/User/Reference/w3c.www.protocol.http.cache.CacheFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.www.protocol.http.cookies.CookieFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.www.protocol.http.HttpManager.html",\r
+//            "http://localhost:8001/User/Reference/w3c.www.protocol.http.icp.ICPFilter.html",\r
+//            "http://localhost:8001/User/Reference/w3c.www.protocol.http.proxy.ProxyDispatcher.html",\r
+//            "http://localhost:8001/User/Tutorials/configuration.html",\r
+//            "http://localhost:8001/User/Tutorials/filter.html",\r
+//            "http://localhost:8001/User/Tutorials/fr-toc.html",\r
+//            "http://localhost:8001/User/Tutorials/Overview.html",\r
+//            "http://localhost:8001/User/Tutorials/resource.html",\r
+//            "http://localhost:8001/User/Tutorials/SSIResource.html",\r
+//            "http://localhost:8001/User/Tutorials/usecvs.html"\r
+    };\r
+\r
+    private static String readFully(Reader r) throws IOException {\r
+        char[] buf = new char[10000];\r
+        StringBuffer str = new StringBuffer();\r
+        while (true) {\r
+            int len = r.read(buf);\r
+            if (len < 0) {\r
+                return str.toString();\r
+            } else {\r
+                str.append(buf, 0, len);\r
+            }\r
+        }\r
+    }\r
+\r
+    public static void readURL(String url) {\r
+        try {\r
+            //System.out.println("Opening url " + url + " at time " + System.currentTimeMillis());\r
+            URL u = new URL(url);\r
+            URLConnection c = u.openConnection();\r
+            c.connect();\r
+//            String encoding =null;// c.getContentEncoding();//\r
+//                     \r
+//            InputStream s = c.getInputStream();\r
+//            Reader r = new BufferedReader(encoding == null ? new InputStreamReader(s)\r
+//                    : new InputStreamReader(s, encoding));\r
+//            String result = readFully(r);\r
+//            r.close();\r
+            System.out.println("done with url");\r
+        } catch (FileNotFoundException ex) {\r
+               ex.printStackTrace();\r
+        } catch (IOException ex) {\r
+            ex.printStackTrace();\r
+            //System.exit(99);\r
+        }\r
+    }\r
+\r
+    static void waitForPort(int port) {\r
+        while (true) {\r
+            try {\r
+                Socket s = new Socket("localhost", port);\r
+                return;\r
+            } catch (IOException ex) {\r
+                try {\r
+                    Thread.sleep(100);\r
+                } catch (InterruptedException e) {\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    static void runLoader(String[] args) {\r
+        waitForPort(8001);\r
+        Thread[] threads = new Thread[URLs.length];\r
+        \r
+        int m=1,n=2;\r
+        if(args.length==2)\r
+        {\r
+               n=Integer.valueOf(args[0]);\r
+               m=Integer.valueOf(args[1]);\r
+        }\r
+        long t1 = System.currentTimeMillis();\r
+        for (int i = 0; i < m; i++) {\r
+            System.out.println("Iteration: " + i);\r
+            for (int j = 0; j < n; j++) {\r
+               //for (int j = 0; j < URLs.length; j++) {\r
+                threads[j] = (new MyThread(URLs[j]));\r
+                threads[j].start();\r
+                try {\r
+                    Thread.sleep(100);\r
+                }\r
+                catch (Exception e) {\r
+                    System.out.println("Exception while sleeping between spawning threads");\r
+                }\r
+                //readURL(URLs[j]);\r
+            }\r
+        }\r
+        for (int i = 0; i < 2; i++) {\r
+               //for (int i = 0; i < URLs.length; i++) {\r
+            try {\r
+                threads[i].join();\r
+            }\r
+            catch (InterruptedException e) {\r
+                System.out.println("Exception while waiting for thread " + i);\r
+            }\r
+        }\r
+        long t2 = System.currentTimeMillis();\r
+        System.out.println("Took " + (t2 - t1) + "ms");\r
+        //System.exit(0);\r
+    }\r
+\r
+    public static void main(String[] args){\r
+        runLoader(args);\r
+    }\r
+\r
+}\r
+\r
+class MyThread extends Thread {\r
+    private String url;\r
+\r
+    public MyThread(String name) {\r
+        super();\r
+        this.url = name;\r
+    }\r
+\r
+    public void run() {\r
+        JigsawHarnessPretex.readURL(url);\r
+    }\r
+}
\ No newline at end of file