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)
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()
def test_run(self): settings_list = [1, 1, 1, 1, 1, 1] S_DIR = os.path.dirname(os.path.abspath(__file__)) + "/region_files" test_num = "t2" t_u = TestUtils() t_u.copy(S_DIR, test_num, settings_list) self.assertTrue(os.path.exists(S_DIR + "_copy/" + test_num)) self.assertTrue(t_u.are_files_equal(S_DIR, test_num))
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)
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 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)
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 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()
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 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 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 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 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 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)
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 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)
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)
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)
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 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)
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 data_handler(data): tu.check_thread() tu.azzert(TestUtils.buffers_equal(buffer, data.data)) tu.test_complete()
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from test_utils import TestUtils from core.parsetools import RecordParser from core.buffer import Buffer tu = TestUtils() class ParseToolsTest(object): def test_delimited(self): str = "" iters = 100 for i in range(0, iters): str += "line %s" % i if i != iters - 1: str += "\n" self.lines = [] def each_line(line): self.lines.append(line)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.http import RouteMatcher tu = TestUtils() server = vertx.create_http_server() rm = RouteMatcher() server.request_handler(rm) server.listen(8080) client = vertx.create_http_client() client.port = 8080; class RouteMatcherTest(object): def __init__(self): self.params = { "name" : "foo", "version" : "v0.1"} self.re_params = { "param0" : "foo", "param1" : "v0.1"} self.regex = "\\/([^\\/]+)\\/([^\\/]+)"
from test_utils import TestUtils tu = TestUtils() import hello2 print "in hello" def vertx_stop(): tu.unregister_all() tu.app_stopped()
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils tu = TestUtils() execfile("src/test/python_scripts/core/scriptloading/script1.py") class ScriptingLoadingTest(object): def test_scriptloading(self): tu.azzert(Foo.func1(tu) == "foo") tu.test_complete() def vertx_stop(): tu.unregister_all() tu.app_stopped() tu.register_all(ScriptingLoadingTest()) tu.app_ready()
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.buffer import Buffer tu = TestUtils() tu.check_thread() server = vertx.create_http_server() client = vertx.create_http_client() client.port = 8080 class WebsocketTest(object): def test_echo_binary(self): self.echo(True) def test_echo_text(self): self.echo(False) def echo(self, binary): @server.websocket_handler
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.buffer import Buffer tu = TestUtils() tu.check_context() server = vertx.create_http_server() client = vertx.create_http_client() client.port = 8080 class WebsocketTest(object): def test_echo_binary(self): self.echo(True) def test_echo_text(self): self.echo(False) def echo(self, binary): @server.websocket_handler
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.buffer import Buffer tu = TestUtils() tu.check_context() server = vertx.create_http_server() client = vertx.create_http_client() client.port = 8080 logger = vertx.get_logger() # This is just a basic test. Most testing occurs in the Java tests class HttpTest(object): def test_get(self): http_method(False, "GET", False) def test_get_ssl(self): http_method(True, "GET", False) def test_put(self):
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¶m2=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()
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import java.net.NetworkInterface import java.net.InetAddress import vertx from test_utils import TestUtils tu = TestUtils() tu.check_thread() peer1 = vertx.create_datagram_socket() peer2 = vertx.create_datagram_socket() class DatagramTest(object): def test_send_receive(self): @peer2.exception_handler def exception_handler(err): tu.azzert(False) def peer2_listen_handler(err, serv): tu.check_thread()
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.buffer import Buffer tu = TestUtils() tu.check_context() server = vertx.create_http_server() client = vertx.create_http_client() client.port = 8080 logger = vertx.get_logger() # This is just a basic test. Most testing occurs in the Java tests class HttpTest(object): def test_get(self): http_method(False, "GET", False) def test_get_ssl(self): http_method(True, "GET", False)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx import org.vertx.testtools.TestDnsServer from test_utils import TestUtils tu = TestUtils() tu.check_thread() logger = vertx.logger() server = None # This is just a basic test. Most testing occurs in the Java tests class DnsClientTest(object): def prepare_dns(self, server): server.start() server = server return vertx.create_dns_client(('127.0.0.1', server.getTransports()[0].getAcceptor().getLocalAddress().getPort())) def test_resolve_a(self): ip = '10.0.0.1' def handler(err, result):
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¶m2=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()
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()
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.event_bus import EventBus tu = TestUtils() tu.check_thread() class EventBusTest(object): def test_simple_send(self): json = {'message' : 'hello world!'} address = "some-address" def handler(msg): tu.azzert(msg.body['message'] == json['message']) EventBus.unregister_handler(id) tu.test_complete() id = EventBus.register_handler(address, handler=handler) tu.azzert(id != None) EventBus.send(address, json)
# Copyright 2011-2012 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.event_bus import EventBus tu = TestUtils() config = vertx.config() tu.azzert(config['foo'] == 'bar') EventBus.send("test-handler", "started") def vertx_stop(): EventBus.send("test-handler", "stopped")
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils tu = TestUtils() tu.check_thread() class TimerTest(object): def test_one_off(self): def handler(timer_id): tu.check_thread() tu.test_complete() vertx.set_timer(10, handler) def test_periodic(self): fires = 10 self.count = 0
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from test_utils import TestUtils from core.buffer import Buffer tu = TestUtils() class BufferTest(object): 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 test_append_buff_with_offset(self): buff_len = 100 buff1 = self.create_buffer(buff_len) buff2 = Buffer.create()
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from test_utils import TestUtils tu = TestUtils() test_global = None class IsolationTest(object): def test_isolation(self): global test_global # Make sure global variables aren't visible between applications tu.azzert(test_global == None) test_global = 123 tu.test_complete() def vertx_stop(): tu.unregister_all()
def create_buffer(self, len): return TestUtils.gen_buffer(len)
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from test_utils import TestUtils tu = TestUtils() test_global = None class IsolationTest(object): def test_isolation(self): global test_global # Make sure global variables aren't visible between applications tu.azzert(test_global == None) test_global = 123 tu.test_complete() def vertx_stop(): tu.unregister_all() tu.app_stopped()
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from core.sock_js import SockJSSocket from core.handlers import AsyncHandler from test_utils import TestUtils tu = TestUtils() class SockJSTest(object): def test_socket_created_hook(self): server = vertx.create_sockjs_server(vertx.create_http_server()) bridge = server.bridge({'prefix': '/eventbus'}, [], []) @bridge.socket_created_handler def handler(socket): tu.azzert(isinstance(socket, SockJSSocket)) tu.test_complete() bridge.hook.handleSocketCreated(None) def test_socket_closed_hook(self):
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from test_utils import TestUtils from foo_class import FooClass tu = TestUtils() class ScriptingLoadingTest(object): def test_scriptloading(self): tu.azzert(FooClass().foo() == "foo") tu.test_complete() def vertx_stop(): tu.unregister_all() tu.app_stopped() tu.register_all(ScriptingLoadingTest()) tu.app_ready()
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import vertx from test_utils import TestUtils from core.event_bus import EventBus tu = TestUtils() class DeployTest(object): handler_id = None def test_deploy(self): global handler_id def handler(message): if message.body == "started": tu.test_complete() handler_id = EventBus.register_handler("test-handler", False, handler) conf = {'foo' : 'bar'} vertx.deploy_verticle("core/deploy/child.py", conf)
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¶m2=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)