Commits

Anonymous committed 28081cf

created a few test cases, played with grinder a bit

Comments (0)

Files changed (8)

+.*~
+.*\.log
+from net.grinder.script.Grinder import grinder
+from net.grinder.script import Test
+from net.grinder.plugin.http import HTTPRequest
+
+test1 = Test(1, "HTML page")
+htmlRequest = test1.wrap(HTTPRequest())
+
+class TestRunner:
+    def __call__(self):
+        htmlResult = htmlRequest.GET("http://opsin.ch.cam.ac.uk/")
+
+
+
+
+

grinder.properties

+# grinder.script=metaprint.py
+#grinder.script=opsin.py
+grinder.script=proxy-sample.py
+grinder.processes=1
+grinder.runs=0
+#grinder.processIncrement=5
+#grinder.processIncrementInterval=5000
+
+export GRINDER_HOME=/Users/ojd20/usr/local/grinder-3.4/
+export CLASSPATH=$CLASSPATH:$GRINDER_HOME/lib/*
+
+java net.grinder.Grinder
+#!/bin/bash
+
+export GRINDER_HOME=/Users/ojd20/usr/local/grinder-3.4/
+export CLASSPATH=$CLASSPATH:$GRINDER_HOME/lib/*
+
+java net.grinder.Console &
+from net.grinder.script.Grinder import grinder
+from net.grinder.script import Test
+from net.grinder.plugin.http import HTTPRequest
+
+test1 = Test(1, "Metaprint page")
+htmlRequest = test1.wrap(HTTPRequest())
+
+class TestRunner:
+    def __call__(self):
+        htmlResult = htmlRequest.GET("http://www-metaprint2d.ch.cam.ac.uk/metaprint2d/metaprinter/c1ccccc1CCNC")
+
+
+
+
+
+from net.grinder.script.Grinder import grinder
+from net.grinder.script import Test
+from net.grinder.plugin.http import HTTPRequest
+
+test1 = Test(1, "CML + PNG")
+pngRequest = test1.wrap(HTTPRequest())
+cmlRequest = test1.wrap(HTTPRequest())
+
+class TestRunner:
+    def __call__(self):
+        base = "http://opsin.ch.cam.ac.uk/opsin/"
+        #base = "http://localhost:8989/opsin/"
+        pngResult = pngRequest.GET(base + "2,4,6-trinitrotoluene.png")
+        cmlResult = cmlRequest.GET(base + "2,4,6-trinitrotoluene.cml")
+
+
+
+
+# The Grinder 3.4
+# HTTP script recorded by TCPProxy at Apr 30, 2010 12:01:45 PM
+
+from net.grinder.script import Test
+from net.grinder.script.Grinder import grinder
+from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
+from HTTPClient import NVPair
+connectionDefaults = HTTPPluginControl.getConnectionDefaults()
+httpUtilities = HTTPPluginControl.getHTTPUtilities()
+
+# To use a proxy server, uncomment the next line and set the host and port.
+# connectionDefaults.setProxyServer("localhost", 8001)
+
+# These definitions at the top level of the file are evaluated once,
+# when the worker process is started.
+
+connectionDefaults.defaultHeaders = \
+  [ NVPair('Accept-Language', 'en-us,en;q=0.5'),
+    NVPair('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
+    NVPair('Referer', 'http://opsin.ch.cam.ac.uk/'),
+    NVPair('Accept-Encoding', 'gzip,deflate'),
+    NVPair('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'), ]
+
+headers0= \
+  [ NVPair('Accept', 'chemical/x-cml'), ]
+
+headers1= \
+  [ NVPair('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5'), ]
+
+headers2= \
+  [ NVPair('Accept', 'chemical/x-inchi'), ]
+
+headers3= \
+  [ NVPair('Accept', 'chemical/x-daylight-smiles'), ]
+
+url0 = 'http://opsin.ch.cam.ac.uk:80'
+
+# Create an HTTPRequest for each request, then replace the
+# reference to the HTTPRequest with an instrumented version.
+# You can access the unadorned instance using request101.__target__.
+# Quick test of opsin
+request101 = HTTPRequest(url=url0, headers=headers0)
+request101 = Test(101, 'GET 2,4,6-trinitrotoluene').wrap(request101)
+
+request102 = HTTPRequest(url=url0, headers=headers1)
+request102 = Test(102, 'GET 2,4,6-trinitrotoluene.png').wrap(request102)
+
+request201 = HTTPRequest(url=url0, headers=headers2)
+request201 = Test(201, 'GET 2,4,6-trinitrotoluene').wrap(request201)
+
+request301 = HTTPRequest(url=url0, headers=headers3)
+request301 = Test(301, 'GET 2,4,6-trinitrotoluene').wrap(request301)
+
+
+class TestRunner:
+  """A TestRunner instance is created for each worker thread."""
+
+  # A method for each recorded page.
+  def page1(self):
+    """GET 2,4,6-trinitrotoluene (requests 101-102)."""
+    result = request101.GET('/opsin/2,4,6-trinitrotoluene')
+
+    request102.GET('/opsin/2,4,6-trinitrotoluene.png')
+
+    return result
+
+  def page2(self):
+    """GET 2,4,6-trinitrotoluene (request 201)."""
+    result = request201.GET('/opsin/2,4,6-trinitrotoluene')
+
+    return result
+
+  def page3(self):
+    """GET 2,4,6-trinitrotoluene (request 301)."""
+    result = request301.GET('/opsin/2,4,6-trinitrotoluene')
+
+    return result
+
+  def __call__(self):
+    """This method is called for every run performed by the worker thread."""
+    self.page1()      # GET 2,4,6-trinitrotoluene (requests 101-102)
+
+    grinder.sleep(28)
+    self.page2()      # GET 2,4,6-trinitrotoluene (request 201)
+    self.page3()      # GET 2,4,6-trinitrotoluene (request 301)
+
+
+def instrumentMethod(test, method_name, c=TestRunner):
+  """Instrument a method with the given Test."""
+  unadorned = getattr(c, method_name)
+  import new
+  method = new.instancemethod(test.wrap(unadorned), None, c)
+  setattr(c, method_name, method)
+
+# Replace each method with an instrumented version.
+# You can call the unadorned method using self.page1.__target__().
+instrumentMethod(Test(100, 'Page 1'), 'page1')
+instrumentMethod(Test(200, 'Page 2'), 'page2')
+instrumentMethod(Test(300, 'Page 3'), 'page3')