Beispiel #1
0
 def open_handler(err, file):
     tu.check_context()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     self.written = 0
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         def write_handler(err, res):
             tu.check_context()
             self.written += 1
             if self.written == num_chunks:
               # all written
               tot_read = Buffer.create()
               self.read = 0
               for j in range(0, num_chunks):
                 pos = j * chunk_size
                 def read_handler(err, buff):
                     tu.check_context
                     tu.azzert(err == None)
                     self.read += 1
                     if self.read == num_chunks:
                         # all read
                         tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                         def close_handler(err, res):
                             tu.check_context()
                             tu.test_complete()
                         file.close(close_handler)
                 file.read(tot_read, pos, pos, chunk_size, read_handler)
         file.write(buff, i * chunk_size, write_handler)
Beispiel #2
0
        def client_connect_handler(socket):
            tu.check_context()
            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_context()
                received.append_buffer(data)
                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()
            @socket.drain_handler
            def drain_handler(stream):
                tu.check_context()
                #print "drained\n"

            @socket.end_handler
            def end_handler(stream):
                tu.check_context()
                #print "end\n"

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write_buffer(data)
Beispiel #3
0
        def client_connect_handler(socket):
            tu.check_context()
            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_context()
                received.append_buffer(data)
                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()

            @socket.drain_handler
            def drain_handler(stream):
                tu.check_context()
                #print "drained\n"

            @socket.end_handler
            def end_handler(stream):
                tu.check_context()
                #print "end\n"

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write_buffer(data)
Beispiel #4
0
    def echo(self, binary):
        @server.websocket_handler
        def websocket_handler(ws):
            tu.check_context()
            @ws.data_handler
            def data_handler(buff):
                tu.check_context()
                ws.write_buffer(buff)
            
        server.listen(8080)

        if binary:
            self.buff = TestUtils.gen_buffer(1000)
        else:
            self.str_ = TestUtils.random_unicode_string(1000)

        def connect_handler(ws):
            tu.check_context()
            received = Buffer.create()

            @ws.data_handler
            def data_handler(buff):
                tu.check_context()
                received.append_buffer(buff)
                if received.length == buff.length:
                    tu.azzert(TestUtils.buffers_equal(buff, received))
                    tu.test_complete()
        
            if binary:
                ws.write_binary_frame(self.buff)
            else:
                ws.write_text_frame(self.str_)
        client.connect_web_socket("/someurl", connect_handler)
Beispiel #5
0
 def open_handler(err, file):
     tu.check_context()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     write_stream = file.write_stream
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         write_stream.write_buffer(buff)
     def close_handler(err, file):
         def open_handler2(err, file):
             tu.check_context()
             tu.azzert(err == None)
             read_stream = file.read_stream
             tot_read = Buffer.create()
             def data_handler(data):
                 tot_read.append_buffer(data)  
             read_stream.data_handler(data_handler)
             def end_handler(stream):
                 tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                 tu.check_context
                 def close_handler2(err, result):
                     tu.check_context()
                     tu.test_complete()
                 file.close(close_handler2)
             read_stream.end_handler(end_handler)
         FileSystem.open(filename, handler=open_handler2)
     
     file.close(close_handler)
 def open_handler(err, file):
     tu.check_thread()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     self.written = 0
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         def write_handler(err, res):
             tu.check_thread()
             self.written += 1
             if self.written == num_chunks:
               # all written
               tot_read = Buffer.create()
               self.read = 0
               for j in range(0, num_chunks):
                 pos = j * chunk_size
                 def read_handler(err, buff):
                     tu.check_thread
                     tu.azzert(err == None)
                     self.read += 1
                     if self.read == num_chunks:
                         # all read
                         tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                         def close_handler(err, res):
                             tu.check_thread()
                             tu.test_complete()
                         file.close(close_handler)
                 file.read_at_pos(tot_read, pos, pos, chunk_size, read_handler)
         file.write_at_pos(buff, i * chunk_size, write_handler)
 def open_handler(err, file):
     tu.check_thread()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         file.write(buff)
     def close_handler(err, file):
         def open_handler2(err, file):
             tu.check_thread()
             tu.azzert(err == None)
             read_stream = file
             tot_read = Buffer.create()
             def data_handler(data):
                 tot_read.append_buffer(data)  
             read_stream.data_handler(data_handler)
             def end_handler():
                 tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                 tu.check_thread
                 def close_handler2(err, result):
                     tu.check_thread()
                     tu.test_complete()
                 file.close(close_handler2)
             read_stream.end_handler(end_handler)
         fs.open(filename, handler=open_handler2)
     
     file.close(close_handler)
    def test_hash(self):
        hash1 = SharedData.get_hash("map1")
        tu.azzert(hash1 != None)
        hash2 = SharedData.get_hash("map1")
        tu.azzert(hash2 != None)

        tu.azzert(hash1 == hash2)

        hash3 = SharedData.get_hash("map3")
        tu.azzert(hash3 != None)
        tu.azzert(hash1 != hash3)

        key = 'wibble'

        hash1[key] = 'hello'

        tu.azzert(hash1[key] == 'hello')
        tu.azzert(hash2[key] == 'hello')
        tu.azzert(isinstance(hash1[key],
                             unicode))  # Make sure it's not a Java String

        hash1[key] = 12
        tu.azzert(hash1[key] == 12)
        tu.azzert(hash2[key] == 12)

        hash1[key] = 1.2344
        tu.azzert(hash1[key] == 1.2344)
        tu.azzert(hash2[key] == 1.2344)

        hash1[key] = True
        tu.azzert(hash1[key] == True)
        tu.azzert(hash2[key] == True)

        hash1[key] = False
        tu.azzert(hash1[key] == False)
        tu.azzert(hash2[key] == False)

        succeeded = False
        try:
            hash1[key] = SomeOtherClass()
            succeeded = True
        except:
            pass  # OK

        tu.azzert(not succeeded, 'Should throw exception')

        # Make sure it deals with Ruby buffers ok, and copies them
        buff1 = TestUtils.gen_buffer(100)
        hash1[key] = buff1
        buff2 = hash1[key]
        tu.azzert(isinstance(buff2, Buffer))
        tu.azzert(buff1 != buff2)
        tu.azzert(TestUtils.buffers_equal(buff1, buff2))

        tu.azzert(SharedData.remove_hash("map1"))
        tu.azzert(not SharedData.remove_hash("map1"))
        tu.azzert(SharedData.remove_hash("map3"))
        tu.test_complete()
Beispiel #9
0
    def test_hash(self):
        hash1 = SharedData.get_hash("map1")
        tu.azzert(hash1 != None)
        hash2 = SharedData.get_hash("map1")
        tu.azzert(hash2 != None)

        tu.azzert(hash1 == hash2)

        hash3 = SharedData.get_hash("map3")
        tu.azzert(hash3 != None)
        tu.azzert(hash1 != hash3)

        key = 'wibble'

        hash1[key] = 'hello'

        tu.azzert(hash1[key] == 'hello')
        tu.azzert(hash2[key] == 'hello')
        tu.azzert(isinstance(hash1[key], unicode)) # Make sure it's not a Java String

        hash1[key] = 12
        tu.azzert(hash1[key] == 12)
        tu.azzert(hash2[key] == 12)

        hash1[key] = 1.2344
        tu.azzert(hash1[key] == 1.2344)
        tu.azzert(hash2[key] == 1.2344)

        hash1[key] = True
        tu.azzert(hash1[key] == True)
        tu.azzert(hash2[key] == True)

        hash1[key] = False
        tu.azzert(hash1[key] == False)
        tu.azzert(hash2[key] == False)

        succeeded = False
        try:
            hash1[key] = SomeOtherClass()
            succeeded = True
        except:
            pass # OK
          
        tu.azzert(not succeeded, 'Should throw exception')

        # Make sure it deals with Ruby buffers ok, and copies them
        buff1 = TestUtils.gen_buffer(100)
        hash1[key] = buff1
        buff2 = hash1[key]
        tu.azzert(isinstance(buff2, Buffer))
        tu.azzert(buff1 != buff2)
        tu.azzert(TestUtils.buffers_equal(buff1, buff2))

        tu.azzert(SharedData.remove_hash("map1"))
        tu.azzert(not SharedData.remove_hash("map1"))
        tu.azzert(SharedData.remove_hash("map3"))
        tu.test_complete()
Beispiel #10
0
        def listen_handler(err, sock):
            tu.azzert(err is None)
            tu.azzert(sock == peer2)
            buffer = TestUtils.gen_buffer(128)

            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                tu.test_complete()

            def send_handler(err, sock):
                tu.check_thread()
                tu.azzert(err is None)
                tu.azzert(sock == peer1)

            peer1.send('255.255.255.255', 1234, buffer, send_handler)
Beispiel #11
0
        def listen_handler(err, sock):
            tu.azzert(err is None)
            tu.azzert(sock == peer2)
            buffer = TestUtils.gen_buffer(128)

            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                tu.test_complete()

            def send_handler(err, sock):
                tu.check_thread()
                tu.azzert(err is None)
                tu.azzert(sock == peer1)

            peer1.send('255.255.255.255', 1234, buffer, send_handler)
Beispiel #12
0
        def client_connect_handler(err, socket):
            tu.azzert(err == None)
            tu.check_thread()
            tu.azzert(socket.local_address[0] is not None)
            tu.azzert(socket.local_address[1] > -1)
            tu.azzert(socket.remote_address[0] is not None)
            tu.azzert(socket.remote_address[1] > -1)

            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_thread()
                received.append_buffer(data)

                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()

            #Just call the methods. Real testing is done in java tests
            @socket.drain_handler
            def drain_handler():
                tu.check_thread()

            @socket.end_handler
            def end_handler():
                tu.check_thread()

            @socket.close_handler
            def close_handler():
                tu.check_thread()

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write(data)
Beispiel #13
0
        def client_connect_handler(err, socket):
            tu.azzert(err == None)
            tu.check_thread()
            tu.azzert(socket.local_address[0] is not None)
            tu.azzert(socket.local_address[1] > -1)
            tu.azzert(socket.remote_address[0] is not None)
            tu.azzert(socket.remote_address[1] > -1)

            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_thread()
                received.append_buffer(data)

                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()

            #Just call the methods. Real testing is done in java tests
            @socket.drain_handler
            def drain_handler():
                tu.check_thread()

            @socket.end_handler
            def end_handler():
                tu.check_thread()

            @socket.close_handler
            def close_handler():
                tu.check_thread()

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write(data)
Beispiel #14
0
        def peer2_listen_handler(err, serv):
            tu.check_thread()
            tu.azzert(err is None)
            tu.azzert(serv == peer2)
            buffer = TestUtils.gen_buffer(128)

            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                tu.test_complete()

            def send_handler(err, result):
                tu.check_thread()
                tu.azzert(err is None)
                tu.azzert(result == peer1)

            peer1.send('127.0.0.1', 1234, buffer, send_handler)
Beispiel #15
0
        def peer2_listen_handler(err, serv):
            tu.check_thread()
            tu.azzert(err is None)
            tu.azzert(serv == peer2)
            buffer = TestUtils.gen_buffer(128)

            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                tu.test_complete()


            def send_handler(err, result):
                tu.check_thread()
                tu.azzert(err is None)
                tu.azzert(result == peer1)

            peer1.send('127.0.0.1', 1234, buffer, send_handler)
Beispiel #16
0
    def test_echo(self):
        @peer1.exception_handler
        def exception_handler(err):
            tu.azzert(False)

        @peer2.exception_handler
        def exception_handler(err):
            tu.azzert(False)

        buffer = TestUtils.gen_buffer(128)

        def peer2_listen_handler(err, sock):
            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))

                def send_handler(err, sock):
                    tu.check_thread()
                    tu.azzert(err is None)
                    tu.azzert(sock == peer2)

                peer2.send('127.0.0.1', 1235, data.data, send_handler)

            def peer1_listen_handler(err, sock):
                @peer1.data_handler
                def data_handler(data):
                    tu.check_thread()
                    tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                    tu.test_complete()

                def send_handler(err, sock):
                    tu.check_thread()
                    tu.azzert(err is None)
                    tu.azzert(sock == peer1)

                peer1.send('127.0.0.1', 1234, buffer, send_handler)

            peer1.listen(1235, '127.0.0.1', peer1_listen_handler)

        peer2.listen(1234, '127.0.0.1', peer2_listen_handler)
Beispiel #17
0
    def test_echo(self):
        @peer1.exception_handler
        def exception_handler(err):
            tu.azzert(False)

        @peer2.exception_handler
        def exception_handler(err):
            tu.azzert(False)

        buffer = TestUtils.gen_buffer(128)

        def peer2_listen_handler(err, sock):
            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))

                def send_handler(err, sock):
                    tu.check_thread()
                    tu.azzert(err is None)
                    tu.azzert(sock == peer2)

                peer2.send('127.0.0.1', 1235, data.data, send_handler)


            def peer1_listen_handler(err, sock):
                @peer1.data_handler
                def data_handler(data):
                    tu.check_thread()
                    tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                    tu.test_complete()

                def send_handler(err, sock):
                    tu.check_thread()
                    tu.azzert(err is None)
                    tu.azzert(sock ==  peer1)

                peer1.send('127.0.0.1', 1234, buffer, send_handler)
            peer1.listen(1235, '127.0.0.1', peer1_listen_handler)

        peer2.listen(1234, '127.0.0.1', peer2_listen_handler)
    def echo(self, binary):
        @server.websocket_handler
        def websocket_handler(ws):
            tu.check_thread()

            @ws.data_handler
            def data_handler(buff):
                tu.check_thread()
                ws.write(buff)

        if binary:
            self.buff = TestUtils.gen_buffer(1000)
        else:
            self.str_ = TestUtils.random_unicode_string(1000)

        def connect_handler(ws):
            tu.check_thread()
            received = Buffer.create()

            @ws.data_handler
            def data_handler(buff):
                tu.check_thread()
                received.append_buffer(buff)
                if received.length == buff.length:
                    tu.azzert(TestUtils.buffers_equal(buff, received))
                    tu.test_complete()

            if binary:
                ws.write_binary_frame(self.buff)
            else:
                ws.write_text_frame(self.str_)

        def listen_handler(err, serv):
            tu.azzert(err == None)
            tu.azzert(serv == server)
            client.connect_web_socket("/someurl", connect_handler)

        server.listen(8080, "0.0.0.0", listen_handler)
Beispiel #19
0
def http_method(ssl, method, chunked):

    logger.info("in http method %s" % method)

    if ssl:
        server.ssl = True
        server.key_store_path = "./src/test/keystores/server-keystore.jks"
        server.key_store_password = "******"
        server.trust_store_path = "./src/test/keystores/server-truststore.jks"
        server.trust_store_password = "******"
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query

    @server.request_handler
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers["header1"] == "vheader1")
        tu.azzert(req.headers["header2"] == "vheader2")
        tu.azzert(req.params["param1"] == "vparam1")
        tu.azzert(req.params["param2"] == "vparam2")
        req.response.put_header("rheader1", "vrheader1")
        req.response.put_header("rheader2", "vrheader2")
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if method != "HEAD" and method != "CONNECT":
                if not chunked:
                    req.response.put_header("Content-Length", body.length)
                req.response.write_buffer(body)
                if chunked:
                    req.response.put_trailer("trailer1", "vtrailer1")
                    req.response.put_trailer("trailer2", "vtrailer2")
            req.response.end()

    server.listen(8080)

    if ssl:
        client.ssl = True
        client.key_store_path = "./src/test/keystores/client-keystore.jks"
        client.key_store_password = "******"
        client.trust_store_path = "./src/test/keystores/client-truststore.jks"
        client.trust_store_password = "******"

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert("vrheader1" == resp.headers["rheader1"])
        tu.azzert("vrheader2" == resp.headers["rheader2"])
        body = Buffer.create()

        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            if method != "HEAD" and method != "CONNECT":
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert("vtrailer1" == resp.trailers["trailer1"])
                    tu.azzert("vtrailer2" == resp.trailers["trailer2"])
            tu.test_complete()

    request = client.request(method, uri, response_handler)

    request.chunked = chunked
    request.put_header("header1", "vheader1")
    request.put_header("header2", "vheader2")
    if not chunked:
        request.put_header("Content-Length", sent_buff.length)

    request.write_buffer(sent_buff)
    request.end()
Beispiel #20
0
    def test_set(self):
        set1 = SharedData.get_set("set1")
        tu.azzert(set1 != None)

        set2 = SharedData.get_set("set1")
        tu.azzert(set2 != None)

        tu.azzert(set1 == set2)

        set3 = SharedData.get_set("set3")
        tu.azzert(set3 != None)

        tu.azzert(set1 != set3)

        set1.add("foo")
        set1.add("bar")
        set1.add("quux")

        tu.azzert(3 == len(set1))

        tu.azzert("foo" in set1)
        tu.azzert("bar" in set1)
        tu.azzert("quux" in set1)
        tu.azzert(not ("wibble" in set1))
        tu.azzert(not set1.empty())

        set1.delete("foo")
        tu.azzert(2 == len(set1))
        tu.azzert(2 == set1.size())
        tu.azzert(not ("foo" in set1))
        tu.azzert("bar" in set1)
        tu.azzert("quux" in set1)
        tu.azzert(not set1.empty())

        set1.clear()
        tu.azzert(set1.empty())

        set1.add("foo")
        set1.add("bar")
        set1.add("quux")

        set2 = set()

        @set1.each
        def each(o):
            set2.add(o)
    
        tu.azzert("foo" in set2)
        tu.azzert("bar" in set2)
        tu.azzert("quux" in set2)

        set1.clear()
        set1.add(12)
        @set1.each
        def each2(elem):
            tu.azzert(elem == 12)

        set1.clear()
        set1.add(1.234)
        @set1.each
        def each3(elem):
            tu.azzert(elem == 1.234)

        set1.clear()
        set1.add("foo")
        @set1.each
        def each4(elem):
            tu.azzert(elem == "foo")
            tu.azzert(isinstance(elem, unicode))
        
        set1.clear()
        set1.add(True)
        @set1.each
        def each5(elem):
            tu.azzert(elem == True)

        set1.clear()
        set1.add(False)
        @set1.each
        def each6(elem):
            tu.azzert(elem == False)

        buff = TestUtils.gen_buffer(100)
        set1.clear()
        set1.add(buff)
        @set1.each
        def each7(elem):
            tu.azzert(TestUtils.buffers_equal(buff, elem))
            tu.azzert(buff != elem)
            tu.azzert(isinstance(elem, Buffer))

        set1.clear()
        succeeded = False
        try:
            set1.add(SomeOtherClass())
            succeeded = True
        except: 
            pass # OK
    
        tu.azzert(not succeeded, 'Should throw exception')

        tu.azzert(SharedData.remove_set("set1"))
        tu.azzert(not SharedData.remove_set("set1"))
        tu.azzert(SharedData.remove_set("set3"))

        tu.test_complete()
Beispiel #21
0
def http_method(ssl, method, chunked):

    logger.info("in http method %s" % method)

    if ssl:
        server.ssl = True
        server.key_store_path = './src/test/keystores/server-keystore.jks'
        server.key_store_password = '******'
        server.trust_store_path = './src/test/keystores/server-truststore.jks'
        server.trust_store_password = '******'
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query

    @server.request_handler
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')
        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if not chunked:
                req.response.put_header('Content-Length', body.length)
            req.response.write_buffer(body)
            if chunked:
                req.response.put_trailer('trailer1', 'vtrailer1')
                req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()

    server.listen(8080)

    if ssl:
        client.ssl = True
        client.key_store_path = './src/test/keystores/client-keystore.jks'
        client.key_store_password = '******'
        client.trust_store_path = './src/test/keystores/client-truststore.jks'
        client.trust_store_password = '******'

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()

        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            tu.azzert(TestUtils.buffers_equal(sent_buff, body))
            if chunked:
                tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                tu.azzert('vtrailer2' == resp.trailers['trailer2'])
            tu.test_complete()

    request = client.request(method, uri, response_handler)

    request.chunked = chunked
    request.put_header('header1', 'vheader1')
    request.put_header('header2', 'vheader2')
    if not chunked:
        request.put_header('Content-Length', sent_buff.length)

    request.write_buffer(sent_buff)
    request.end()
Beispiel #22
0
 def create_buffer(self, len):
     return TestUtils.gen_buffer(len)
Beispiel #23
0
def http_method(ssl, method, chunked):

    logger.info("in http method %s"% method)

    server.compression_supported = True
    tu.azzert(server.compression_supported)

    if ssl:
        server.ssl = True
        server.key_store_path = './src/test/keystores/server-keystore.jks'
        server.key_store_password = '******'
        server.trust_store_path = './src/test/keystores/server-truststore.jks'
        server.trust_store_password = '******'
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query;

    @server.request_handler
    def request_handler(req):
        tu.check_thread()
        tu.azzert(req.version == 'HTTP_1_1')
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')


        headers = req.headers
        tu.azzert(headers.contains('header1'))
        tu.azzert(headers.contains('header2'))
        tu.azzert(headers.contains('header3'))
        tu.azzert(not headers.is_empty)

        headers.remove('header3')
        tu.azzert(not headers.contains('header3'))

        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        if method != 'HEAD' and method != 'CONNECT':
            req.response.chunked = chunked

        @req.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                if not chunked:
                    req.response.put_header('Content-Length', str(body.length))
                req.response.write(body)
                if chunked:
                    req.response.put_trailer('trailer1', 'vtrailer1')
                    req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()

    client.try_use_compression = False
    tu.azzert(client.try_use_compression == False)

    if ssl:
        client.ssl = True
        client.key_store_path = './src/test/keystores/client-keystore.jks'
        client.key_store_password = '******'
        client.trust_store_path = './src/test/keystores/client-truststore.jks'
        client.trust_store_password = '******'

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_thread()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()
        
        @resp.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                    tu.azzert('vtrailer2' == resp.trailers['trailer2'])

            resp.headers.clear()
            tu.azzert(resp.headers.is_empty)
            tu.test_complete()

    def listen_handler(err, serv):
        tu.azzert(err == None)
        tu.azzert(serv == server)
        request = client.request(method, uri, response_handler)

        request.chunked = chunked
        request.put_header('header1', 'vheader1')
        request.put_header('header2', 'vheader2')
        if not chunked:
            request.put_header('Content-Length', str(sent_buff.length))

        request.headers.add('header3', 'vheader3_1').add('header3', 'vheader3')


        size = request.headers.size
        names = request.headers.names()
        tu.azzert(size == len(names))

        for k in names:
            tu.azzert(request.headers.get_all(k) is not None)

        request.write(sent_buff)
        request.end()

    server.listen(8080, "0.0.0.0", listen_handler)
Beispiel #24
0
 def create_buffer(self, len):
     return TestUtils.gen_buffer(len)
Beispiel #25
0
def http_method(ssl, method, chunked):

    logger.info("in http method %s" % method)

    if ssl:
        server.ssl = True
        server.key_store_path = './src/test/keystores/server-keystore.jks'
        server.key_store_password = '******'
        server.trust_store_path = './src/test/keystores/server-truststore.jks'
        server.trust_store_password = '******'
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query

    @server.request_handler
    def request_handler(req):
        tu.check_thread()
        tu.azzert(req.version == 'HTTP_1_1')
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')

        headers = req.headers
        tu.azzert(headers.contains('header1'))
        tu.azzert(headers.contains('header2'))
        tu.azzert(headers.contains('header3'))
        tu.azzert(not headers.is_empty)

        headers.remove('header3')
        tu.azzert(not headers.contains('header3'))

        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        if method != 'HEAD' and method != 'CONNECT':
            req.response.chunked = chunked

        @req.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                if not chunked:
                    req.response.put_header('Content-Length', str(body.length))
                req.response.write(body)
                if chunked:
                    req.response.put_trailer('trailer1', 'vtrailer1')
                    req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()

    if ssl:
        client.ssl = True
        client.key_store_path = './src/test/keystores/client-keystore.jks'
        client.key_store_password = '******'
        client.trust_store_path = './src/test/keystores/client-truststore.jks'
        client.trust_store_password = '******'

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_thread()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()

        @resp.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                    tu.azzert('vtrailer2' == resp.trailers['trailer2'])

            resp.headers.clear()
            tu.azzert(resp.headers.is_empty)
            tu.test_complete()

    def listen_handler(err, serv):
        tu.azzert(err == None)
        tu.azzert(serv == server)
        request = client.request(method, uri, response_handler)

        request.chunked = chunked
        request.put_header('header1', 'vheader1')
        request.put_header('header2', 'vheader2')
        if not chunked:
            request.put_header('Content-Length', str(sent_buff.length))

        request.headers.add('header3', 'vheader3_1').add('header3', 'vheader3')

        size = request.headers.size
        names = request.headers.names()
        tu.azzert(size == len(names))

        for k in names:
            tu.azzert(request.headers.get_all(k) is not None)

        request.write(sent_buff)
        request.end()

    server.listen(8080, "0.0.0.0", listen_handler)
    def test_set(self):
        set1 = SharedData.get_set("set1")
        tu.azzert(set1 != None)

        set2 = SharedData.get_set("set1")
        tu.azzert(set2 != None)

        tu.azzert(set1 == set2)

        set3 = SharedData.get_set("set3")
        tu.azzert(set3 != None)

        tu.azzert(set1 != set3)

        set1.add("foo")
        set1.add("bar")
        set1.add("quux")

        tu.azzert(3 == len(set1))

        tu.azzert("foo" in set1)
        tu.azzert("bar" in set1)
        tu.azzert("quux" in set1)
        tu.azzert(not ("wibble" in set1))
        tu.azzert(not set1.empty())

        set1.delete("foo")
        tu.azzert(2 == len(set1))
        tu.azzert(2 == set1.size())
        tu.azzert(not ("foo" in set1))
        tu.azzert("bar" in set1)
        tu.azzert("quux" in set1)
        tu.azzert(not set1.empty())

        set1.clear()
        tu.azzert(set1.empty())

        set1.add("foo")
        set1.add("bar")
        set1.add("quux")

        set2 = set()

        @set1.each
        def each(o):
            set2.add(o)

        tu.azzert("foo" in set2)
        tu.azzert("bar" in set2)
        tu.azzert("quux" in set2)

        set1.clear()
        set1.add(12)

        @set1.each
        def each2(elem):
            tu.azzert(elem == 12)

        set1.clear()
        set1.add(1.234)

        @set1.each
        def each3(elem):
            tu.azzert(elem == 1.234)

        set1.clear()
        set1.add("foo")

        @set1.each
        def each4(elem):
            tu.azzert(elem == "foo")
            tu.azzert(isinstance(elem, unicode))

        set1.clear()
        set1.add(True)

        @set1.each
        def each5(elem):
            tu.azzert(elem == True)

        set1.clear()
        set1.add(False)

        @set1.each
        def each6(elem):
            tu.azzert(elem == False)

        buff = TestUtils.gen_buffer(100)
        set1.clear()
        set1.add(buff)

        @set1.each
        def each7(elem):
            tu.azzert(TestUtils.buffers_equal(buff, elem))
            tu.azzert(buff != elem)
            tu.azzert(isinstance(elem, Buffer))

        set1.clear()
        succeeded = False
        try:
            set1.add(SomeOtherClass())
            succeeded = True
        except:
            pass  # OK

        tu.azzert(not succeeded, 'Should throw exception')

        tu.azzert(SharedData.remove_set("set1"))
        tu.azzert(not SharedData.remove_set("set1"))
        tu.azzert(SharedData.remove_set("set3"))

        tu.test_complete()
Beispiel #27
0
def http_method(ssl, method, chunked):

    logger.info("in http method %s"% method)

    if ssl:
        server.ssl = True
        server.key_store_path = './src/test/keystores/server-keystore.jks'
        server.key_store_password = '******'
        server.trust_store_path = './src/test/keystores/server-truststore.jks'
        server.trust_store_password = '******'
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query;

    @server.request_handler
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')
        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)
        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if not chunked:
                req.response.put_header('Content-Length', body.length)
            req.response.write_buffer(body)
            if chunked:
                req.response.put_trailer('trailer1', 'vtrailer1')
                req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()

    server.listen(8080)

    if ssl:
        client.ssl = True
        client.key_store_path = './src/test/keystores/client-keystore.jks'
        client.key_store_password = '******'
        client.trust_store_path = './src/test/keystores/client-truststore.jks'
        client.trust_store_password = '******'

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()
        
        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            tu.azzert(TestUtils.buffers_equal(sent_buff, body))
            if chunked:
                tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                tu.azzert('vtrailer2' == resp.trailers['trailer2'])
            tu.test_complete()

    request = client.request(method, uri, response_handler)
    
    request.chunked = chunked
    request.put_header('header1', 'vheader1')
    request.put_header('header2', 'vheader2')
    if not chunked:
        request.put_header('Content-Length', sent_buff.length) 

    request.write_buffer(sent_buff)
    request.end()