예제 #1
0
 def testMany(self):
     cnn = None
     try:
         cnn = HTTPConnection()
         cnn.connect(('localhost', 9090))
         response = cnn.perform(cnn.get('/many'))
         self.assertEquals('blaat' * 10, response.body)
     finally:
         if cnn: cnn.close()
예제 #2
0
 def testMany(self):
     cnn = None
     try:           
         cnn = HTTPConnection()
         cnn.connect(('localhost', 9090))
         response = cnn.perform(cnn.get('/many'))
         self.assertEquals('blaat' * 10, response.body)
     finally:
         if cnn: cnn.close()
예제 #3
0
    def testWebJSON(self):

        cnn = None
        try:           
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))
            response = cnn.perform(cnn.get('/json'))
            status = response.status
            self.assertEquals('HTTP/1.1 200 OK', status)    
            self.assertEquals('application/json; charset=UTF-8', response.get_header('Content-Type'))
            self.assertEquals('9', response.get_header('Content-Length'))
            self.assertEquals("[1,2,3,4]",  response.body)
        finally:
            if cnn: cnn.close()
예제 #4
0
    def testWeb(self):

        cnn = None
        try:           
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))
            response = cnn.perform(cnn.get('/hello'))
            status = response.status
            self.assertEquals('HTTP/1.1 200 OK', status)    
            self.assertEquals('text/html; charset=UTF-8', response.get_header('Content-Type'))
            self.assertEquals('13', response.get_header('Content-Length'))
            self.assertEquals(u"Héllo World!",  ''.join(response).decode('UTF-8'))
        finally:
            if cnn: cnn.close()
예제 #5
0
    def testWebJSON(self):

        cnn = None
        try:
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))
            response = cnn.perform(cnn.get('/json'))
            status = response.status
            self.assertEquals('HTTP/1.1 200 OK', status)
            self.assertEquals('application/json; charset=UTF-8',
                              response.get_header('Content-Type'))
            self.assertEquals('9', response.get_header('Content-Length'))
            self.assertEquals("[1,2,3,4]", response.body)
        finally:
            if cnn: cnn.close()
예제 #6
0
    def testWeb(self):

        cnn = None
        try:
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))
            response = cnn.perform(cnn.get('/hello'))
            status = response.status
            self.assertEquals('HTTP/1.1 200 OK', status)
            self.assertEquals('text/html; charset=UTF-8',
                              response.get_header('Content-Type'))
            self.assertEquals('13', response.get_header('Content-Length'))
            self.assertEquals(u"Héllo World!",
                              ''.join(response).decode('UTF-8'))
        finally:
            if cnn: cnn.close()
예제 #7
0
    def testWebTimeout(self):

        cnn = None
        try:           
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))

            request = cnn.get('/timeout')
            request.add_header('Timeout', 1.0)
            response = cnn.perform(request)
            status = response.status            
            self.assertEquals('HTTP/1.1 500 Internal Server Error', status)    
            self.assertEquals('text/plain', response.get_header('Content-Type'))
            
        finally:
            if cnn: cnn.close()
예제 #8
0
    def testWebTimeout(self):

        cnn = None
        try:
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))

            request = cnn.get('/timeout')
            request.add_header('Timeout', 1.0)
            response = cnn.perform(request)
            status = response.status
            self.assertEquals('HTTP/1.1 500 Internal Server Error', status)
            self.assertEquals('text/plain',
                              response.get_header('Content-Type'))

        finally:
            if cnn: cnn.close()
예제 #9
0
    def session(self, host, port, path):
        cnn = None

        pipeline_tokens = Deque()

        for _ in range(self.options.pipeline): # can append take iterator?, or list?
            pipeline_tokens.append(True)

        try:
            cnn = HTTPConnection()
            cnn.connect((host, port))

            Tasklet.new(self.session_response_reader)(cnn, pipeline_tokens)
            
            requests = 0 #no requests in this session
            while True:

                if self.options.requests != -1 and requests >= self.options.requests:
                    break #we are done with this session
                       
                if self.dispenser.receive() is None:
                    return False #we are done globally

                pipeline_tokens.popleft(True)

                #do the request
                cnn.send(cnn.get(path))
                #print response
                  
                requests += 1
                
                self.count('request')
                
        finally:    
            #if response_reader_task is not None:   
            #    response_reader_task.kill()
            if cnn is not None:
                cnn.close() 

        return True