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)
def test_create(self): buff1 = Buffer.create() tu.azzert(0 == buff1.length) buff2 = Buffer.create(100) tu.azzert(0 == buff1.length) str = "oqkdioqjwdijqwed" buff3 = Buffer.create_from_str(str) tu.azzert(str == buff3.to_string()) tu.test_complete()
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_set_buff_with_offset(self): buff_len = 100 buff1 = self.create_buffer(buff_len) buff2 = Buffer.create() buff2.set_buffer(0, buff1, 50, 50) tu.azzert(50 == buff2.length, 'Invalid length') tu.test_complete()
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()
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)
def test_append_buff(self): buff_len = 100 buff1 = self.create_buffer(buff_len) buff2 = Buffer.create() buff2.append_buffer(buff1) tu.azzert(buff_len == buff2.length, 'Invalid length') tu.test_complete()
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)
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)
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 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()
def test_set_buff(self): buff_len = 100 buff1 = self.create_buffer(buff_len) buff2 = Buffer.create() buff2.set_buffer(0, buff1) tu.azzert(buff_len == buff2.length, 'Invalid length') tu.test_complete()
def test_append_int(self): buff1 = Buffer.create() for i in range(100): buff1.append_int(i) for i in range(100): val = buff1.get_int(i) tu.azzert(val == i)
def set_fixnum(self, num_bytes): buff1 = Buffer.create() for i in range(-128,128): buff1.set_fixnum((i + 128) * num_bytes, i << ((num_bytes -1) * 8), num_bytes) for i in range(-128,128): val = buff1.get_fixnum((i + 128) * num_bytes, num_bytes) tu.azzert(val == i << ((num_bytes -1)* 8)) tu.test_complete()
def test_set_int(self): buff1 = Buffer.create() for i in range(100): buff1.set_int(i, i) for i in range(100): val = buff1.get_int(i) tu.azzert(val == i)
def test_copy(self): str = "iajdoiqwjdiqwdioqwdjiqwd" buff1 = Buffer.create(str) buff2 = buff1.copy() tu.azzert(buff1.length == buff2.length) for i in range(0,buff1.length): tu.azzert(buff1.get_byte(i) == buff2.get_byte(i)) tu.test_complete()
def test_length(self): buff1 = Buffer.create() tu.azzert(buff1.length == 0) num = 50 for i in range(0,num): buff1.append_fixnum(i, 1) tu.azzert(buff1.length == num, "Received %d expected %d"% (buff1.length, num)) tu.test_complete()
def test_copy(self): str = "iajdoiqwjdiqwdioqwdjiqwd" buff1 = Buffer.create(str) buff2 = buff1.copy() tu.azzert(buff1.length == buff2.length) for i in range(0, buff1.length): tu.azzert(buff1.get_byte(i) == buff2.get_byte(i)) tu.test_complete()
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)
def test_length(self): buff1 = Buffer.create() tu.azzert(buff1.length == 0) num = 50 for i in range(0, num): buff1.append_str("1") tu.azzert(buff1.length == num, "Received %d expected %d" % (buff1.length, num)) tu.test_complete()
def set_fixnum(self, num_bytes): buff1 = Buffer.create() for i in range(-128, 128): buff1.set_fixnum((i + 128) * num_bytes, i << ((num_bytes - 1) * 8), num_bytes) for i in range(-128, 128): val = buff1.get_fixnum((i + 128) * num_bytes, num_bytes) tu.azzert(val == i << ((num_bytes - 1) * 8)) tu.test_complete()
def append_float(self, num_bytes): buff1 = Buffer.create() for i in range(0,100): buff1.append_float(i, num_bytes) for i in range(0,100): val = buff1.get_float(i * num_bytes, num_bytes) tu.azzert(val == i) tu.test_complete()
def append_float(self, num_bytes): buff1 = Buffer.create() for i in range(0, 100): buff1.append_float(i, num_bytes) for i in range(0, 100): val = buff1.get_float(i * num_bytes, num_bytes) tu.azzert(val == i) tu.test_complete()
def client_connect_handler(socket): tu.check_context() sent = 'some-string' received = Buffer.create() @socket.data_handler def data_handler(data): tu.check_context() received.append_buffer(data) if received.length == len(sent): tu.azzert(sent == received.to_string()) tu.test_complete() socket.write_str(sent)
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)
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_)
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)
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 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()
def listen_handler (err, serv): tu.azzert(err is None) client.port = 8080 def post_handler(resp): # assert the response tu.azzert(200 == resp.status_code) @resp.body_handler def body_handler(body): tu.azzert(0 == body.length) tu.test_complete() req = client.post("/form", post_handler) buffer = Buffer.create() buffer.append_str('framework=vertx&runson=jvm') req.put_header('content-length', str(buffer.length)) req.put_header('content-type', 'application/x-www-form-urlencoded') req.write(buffer).end()
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()
def listen_handler(err, serv): tu.azzert(err is None) client.port = 8080 def post_handler(resp): # assert the response tu.azzert(200 == resp.status_code) @resp.body_handler def body_handler(body): tu.azzert(0 == body.length) tu.test_complete() req = client.post("/form", post_handler) buffer = Buffer.create() buffer.append_str('framework=vertx&runson=jvm') req.put_header('content-length', str(buffer.length)) req.put_header('content-type', 'application/x-www-form-urlencoded') req.write(buffer).end()
def listen_handler (err, serv): tu.azzert(err is None) client.port = 8080 def post_handler(resp): # assert the response tu.azzert(200 == resp.status_code) @resp.body_handler def body_handler(body): tu.azzert(0 == body.length) tu.test_complete() req = client.post("/form", post_handler) boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO" buffer = Buffer.create() b = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" + "Content-Type: image/gif\r\n" + "\r\n" + content + "\r\n" + "--" + boundary + "--\r\n" buffer.append_str(b) req.put_header('content-length', str(buffer.length)) req.put_header('content-type', 'multipart/form-data; boundary=' + boundary) req.write(buffer).end()
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) sent = 'some-string' received = Buffer.create() @socket.data_handler def data_handler(data): tu.check_thread() received.append_buffer(data) if received.length == len(sent): tu.azzert(sent == received.to_string()) tu.test_complete() socket.write_str(sent)
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()
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 is None) client.port = 8080 def post_handler(resp): # assert the response tu.azzert(200 == resp.status_code) @resp.body_handler def body_handler(body): tu.azzert(0 == body.length) tu.test_complete() req = client.post("/form", post_handler) boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO" buffer = Buffer.create() b = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" + "Content-Type: image/gif\r\n" + "\r\n" + content + "\r\n" + "--" + boundary + "--\r\n" buffer.append_str(b) req.put_header('content-length', str(buffer.length)) req.put_header('content-type', 'multipart/form-data; boundary=' + boundary) req.write(buffer).end()
def test_append_string_2(self): buff1 = Buffer.create() str = "piajdioasdioasdoiasdjiqjiqdjiqwjidqwid" buff1.append_str(str, 'UTF-8') tu.azzert(str == buff1.to_string('UTF-8')) tu.test_complete()