Пример #1
0

def vertx_stop():
    tu.unregister_all()
    if peer1 is not None:

        def close_handler():
            if peer2 is not None:

                def close_handler():
                    tu.app_stopped()

                peer2.close(close_handler)
            else:
                tu.app_stopped()

        peer1.close(close_handler)

    elif peer2 is not None:

        def close_handler():
            tu.app_stopped()

        peer2.close(close_handler)
    else:
        tu.app_stopped()


tu.register_all(DatagramTest())
tu.app_ready()
Пример #2
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.

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()
Пример #3
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()


tu.register_all(IsolationTest())
tu.app_ready()
Пример #4
0
    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_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 create_buffer(self, len):
        return TestUtils.gen_buffer(len)


def vertx_stop():
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(BufferTest())
tu.app_ready()
Пример #5
0
            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 vertx_stop():
    tu.check_context()
    tu.unregister_all()
    client.close()

    def close_handler():
        tu.app_stopped()

    server.close(close_handler)


tu.register_all(HttpTest())
tu.app_ready()
Пример #6
0
# 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()
Пример #7
0
        client.ssl = True
        client.key_store_path = "foo.jks"
        client.key_store_password = "******"
        client.trust_store_path = "bar.jks"
        client.trust_store_password = "******"
        client.trust_all = True
        client.send_buffer_size = 123123
        client.receive_buffer_size = 218123
        client.tcp_keep_alive = True
        client.reuse_address = True
        client.so_linger = True
        client.traffic_class = 123

        client.close()

        tu.test_complete()


def vertx_stop():
    tu.unregister_all()
    client.close()

    def close_handler():
        tu.app_stopped()

    server.close(close_handler)


tu.register_all(NetTest())
tu.app_ready()
Пример #8
0
        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()

class SomeOtherClass: 
    pass

def vertx_stop():
  tu.unregister_all()
  tu.app_stopped()

tu.register_all(SharedDataTest())
tu.app_ready()
Пример #9
0
        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 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 create_buffer(self, len):
        return TestUtils.gen_buffer(len)

def vertx_stop():
    tu.unregister_all()
    tu.app_stopped()

tu.register_all(BufferTest())
tu.app_ready()
Пример #10
0
                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)
        fs.open(filename, handler=open_handler)

def vertx_stop():
    tu.check_thread()
    fs.delete_recursive_sync(FILEDIR)
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(FileSystemTest())
setup(tu.app_ready)
Пример #11
0
        req.response.end()

    def listen_handler(err, serv):
        tu.azzert(err == None)
        tu.azzert(serv == server)
        if regex:
            getattr(rm, method + '_re')(pattern, handler)
        else:
            getattr(rm, method)(pattern, handler)

        def response_handler(resp):
            tu.azzert(200 == resp.status_code)
            tu.test_complete()

        getattr(client, m)(uri, response_handler).end()

    server.listen(8080, '0.0.0.0', listen_handler)


def vertx_stop():
    tu.unregister_all()
    client.close()

    def close_handler(err, ok):
        tu.app_stopped()

    server.close(close_handler)


tu.register_all(RouteMatcherTest())
tu.app_ready()
Пример #12
0
# 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
import vertx

tu = TestUtils()    

class ContextTest(object):

  def test_run_on_context(self):
    def handler():
        tu.check_thread()
        tu.test_complete()
    vertx.run_on_context(handler)

  def test_get_context(self):
      def handler():
          tu.check_thread()
          tu.test_complete()
      ctx = vertx.current_context()
      ctx.run_on_context(handler)

def vertx_stop():
  tu.unregister_all()
  tu.app_stopped()

tu.register_all(ContextTest())
tu.app_ready()
Пример #13
0
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)
        parser = RecordParser.new_delimited("\n", each_line)
        
        parser.input(Buffer.create_from_str(str))

        count = 0
        for line in self.lines:    
            tu.azzert("line %i"% count == line.to_string())
            count += 1
        tu.test_complete()


def vertx_stop():
    tu.unregister_all()
    tu.app_stopped()

tu.register_all(ParseToolsTest())
tu.app_ready()
Пример #14
0
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
        def handler(timer_id):
            tu.check_thread()
            self.count += 1
            if self.count == fires:
                vertx.cancel_timer(timer_id)
                # End test in another timer in case the first timer fires again - we want to catch that
                def complete(timer_id):
                    tu.test_complete()            
                vertx.set_timer(100, complete)
            elif self.count > fires:
                tu.azzert(False, 'Fired too many times')
        vertx.set_periodic(10, handler)
    
def vertx_stop():
    tu.check_thread()
    tu.unregister_all()
    tu.app_stopped()

tu.register_all(TimerTest())
tu.app_ready()
Пример #15
0
handler_id = None

class DeployTest(object):
    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 test_undeploy(self):
        global handler_id
        def handler(message):
            if message.body == "stopped":
                tu.test_complete()        
        handler_id = EventBus.register_handler("test-handler", False, handler)
        conf = {'foo' : 'bar'}
        def deploy_handler(id):
            vertx.undeploy_verticle(id)
        vertx.deploy_verticle("core/deploy/child.py", conf, handler=deploy_handler)

def vertx_stop():
    EventBus.unregister_handler(handler_id)
    tu.unregister_all()
    tu.app_stopped()

tu.register_all(DeployTest())
tu.app_ready()
Пример #16
0
            ws.close()

        def connect_handler(ws):
            tu.check_thread()

            @ws.close_handler
            def close_handler():
                tu.test_complete()

        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 vertx_stop():
    tu.check_thread()
    tu.unregister_all()
    client.close()

    def close_handler(err, ok):
        tu.app_stopped()

    server.close(close_handler)


tu.register_all(WebsocketTest())
tu.app_ready()
Пример #17
0
        tu.azzert(peer1.multicast_time_to_live != 2)
        peer1.multicast_time_to_live = 2
        tu.azzert(peer1.multicast_time_to_live == 2)

        tu.test_complete()

def vertx_stop():
    tu.unregister_all()
    if peer1 is not None:
        def close_handler():
            if peer2 is not None:
                def close_handler():
                    tu.app_stopped()
                peer2.close(close_handler)
            else:
                tu.app_stopped()

        peer1.close(close_handler)

    elif peer2 is not None:
        def close_handler():
            tu.app_stopped()
        peer2.close(close_handler)
    else:
        tu.app_stopped()

    

tu.register_all(DatagramTest())
tu.app_ready()
Пример #18
0
            def reply_handler1(reply):
                tu.azzert("reply-of-reply" == reply.body)
                reply.reply("reply-of-reply-of-reply")

            msg.reply("reply", reply_handler1)

        id = EventBus.register_handler(address, handler=handler)

        def reply_handler2(reply):
            tu.azzert("reply" == reply.body)

            def reply_handler3(reply2):
                tu.azzert("reply-of-reply-of-reply" == reply2.body)
                EventBus.unregister_handler(id)
                tu.test_complete()

            reply.reply("reply-of-reply", reply_handler3)

        EventBus.send(address, "message", reply_handler2)


def vertx_stop():
    tu.check_context()
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(EventBusTest())
tu.app_ready()
Пример #19
0
        client = vertx.create_net_client()

        client.ssl=True
        client.key_store_path="foo.jks"
        client.key_store_password="******"
        client.trust_store_path="bar.jks"
        client.trust_store_password="******"
        client.trust_all=True
        client.send_buffer_size=123123
        client.receive_buffer_size=218123
        client.tcp_keep_alive=True
        client.reuse_address=True
        client.so_linger = True
        client.traffic_class=123

        client.close()

        tu.test_complete()

def vertx_stop():
    tu.unregister_all()
    client.close()
    def close_handler():
        tu.app_stopped()
    server.close(close_handler)
    

tu.register_all(NetTest())
tu.app_ready()
Пример #20
0
            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()


class SomeOtherClass:
    pass


def vertx_stop():
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(SharedDataTest())
tu.app_ready()
Пример #21
0
            def closed_handler():
                tu.test_complete()
            ws.write_text_frame("foo")
        
        client.connect_web_socket("/someurl",connect_handler)
    
    def test_close_from_connect(self):
        @server.websocket_handler
        def websocket_handler(ws):
            tu.check_context()
            ws.close()

        server.listen(8080)
        def connect_handler(ws):
            tu.check_context()
            @ws.closed_handler
            def closed_handler():
                tu.test_complete()
        client.connect_web_socket("/someurl", connect_handler)

def vertx_stop():
    tu.check_context()
    tu.unregister_all()
    client.close()
    @server.close
    def close():
        tu.app_stopped()
  
tu.register_all(WebsocketTest())
tu.app_ready()
Пример #22
0
        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)

        parser = RecordParser.new_delimited("\n", each_line)

        parser.input(Buffer.create_from_str(str))

        count = 0
        for line in self.lines:
            tu.azzert("line %i" % count == line.to_string())
            count += 1
        tu.test_complete()


def vertx_stop():
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(ParseToolsTest())
tu.app_ready()
Пример #23
0
        @bridge.unregister_handler
        def handler(socket, address):
            tu.azzert(isinstance(socket, SockJSSocket))
            tu.azzert(address == 'some-address')
            tu.test_complete()

        bridge.hook.handleUnregister(None, 'some-address')

    def test_authorise_hook(self):
        server = vertx.create_sockjs_server(vertx.create_http_server())
        bridge = server.bridge({'prefix': '/eventbus'}, [], [])

        @bridge.authorise_handler
        def handler(message, session_id, handler):
            tu.azzert(message['foo'] == 'bar')
            tu.azzert(session_id == 'some-id')
            handler(True)

        def done_handler(error, result):
            tu.azzert(error is None)
            tu.azzert(result)
            tu.test_complete()
        bridge.hook.handleAuthorise({'foo': 'bar'}, 'some-id', AsyncHandler(done_handler))

def vertx_stop():
  tu.unregister_all()
  tu.app_stopped()

tu.register_all(SockJSTest())
tu.app_ready()
Пример #24
0
                    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)

        fs.open(filename, handler=open_handler)


def vertx_stop():
    tu.check_thread()
    fs.delete_recursive_sync(FILEDIR)
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(FileSystemTest())
setup(tu.app_ready)
Пример #25
0
        EventBus.send(address, msg, reply_handler)

    def test_reply_of_reply_of_reply(self):
        address = "some-address"
        def handler(msg):
            tu.azzert("message" == msg.body)
            def reply_handler1(reply):
                tu.azzert("reply-of-reply" == reply.body)
                reply.reply("reply-of-reply-of-reply")  
            msg.reply("reply", reply_handler1)
          
        id = EventBus.register_handler(address, handler=handler)

        def reply_handler2(reply):
            tu.azzert("reply" == reply.body)
            def reply_handler3(reply2):
                tu.azzert("reply-of-reply-of-reply" == reply2.body)
                EventBus.unregister_handler(id)
                tu.test_complete()
            reply.reply("reply-of-reply", reply_handler3)
          
        EventBus.send(address, "message", reply_handler2)

def vertx_stop():
    tu.check_thread()
    tu.unregister_all()
    tu.app_stopped()

tu.register_all(EventBusTest())
tu.app_ready()
Пример #26
0
# 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()

tu.register_all(IsolationTest())
tu.app_ready()
Пример #27
0
    def test_periodic(self):
        fires = 10
        self.count = 0

        def handler(timer_id):
            tu.check_thread()
            self.count += 1
            if self.count == fires:
                vertx.cancel_timer(timer_id)

                # End test in another timer in case the first timer fires again - we want to catch that
                def complete(timer_id):
                    tu.test_complete()

                vertx.set_timer(100, complete)
            elif self.count > fires:
                tu.azzert(False, 'Fired too many times')

        vertx.set_periodic(10, handler)


def vertx_stop():
    tu.check_thread()
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(TimerTest())
tu.app_ready()
Пример #28
0
        def handler(err, result):
            tu.check_thread()
            tu.azzert(err is None)
            tu.azzert(ptr == result)
            tu.test_complete()

        client = self.prepare_dns(org.vertx.testtools.TestDnsServer.testReverseLookup(ptr))
        client.reverse_lookup('10.0.0.1', handler)

    def test_reverse_lookup_ipv6(self):
        ptr = 'ptr.vertx.io'
        def handler(err, result):
            tu.check_thread()
            tu.azzert(err is None)
            tu.azzert(ptr == result)
            tu.test_complete()

        client = self.prepare_dns(org.vertx.testtools.TestDnsServer.testReverseLookup(ptr))
        client.reverse_lookup('::1', handler)

def vertx_stop():
    if server is not None:
        server.stop()
    tu.check_thread()
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(DnsClientTest())
tu.app_ready()
Пример #29
0
        tu.azzert(len(req.params) == len(params))
        for k,v in params.iteritems():
            tu.azzert(v == req.params[k])
        req.response.end()

    if regex:
        #print "calling rm.%s_re with pattern %s"%(method, pattern)
        getattr(rm, method + '_re')(pattern, handler)
    else:
        #print "calling rm.%s with pattern %s"%(method, pattern)
        getattr(rm, method)(pattern, handler)

    if method == 'all':
        method = 'get' 

    def response_handler(resp):
        tu.azzert(200 == resp.status_code)
        tu.test_complete()

    getattr(client, method)(uri, response_handler).end()

def vertx_stop(): 
    tu.unregister_all()
    client.close()

    @server.close
    def close():
        tu.app_stopped()

tu.register_all(RouteMatcherTest())
tu.app_ready()
Пример #30
0
        @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 vertx_stop():
    tu.check_context()
    tu.unregister_all()
    client.close()
    def close_handler():
        tu.app_stopped()
    server.close(close_handler)

tu.register_all(HttpTest())
tu.app_ready()
Пример #31
0
    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 test_undeploy(self):
        global handler_id
        def handler(message):
            if message.body == "stopped":
                tu.test_complete()
        handler_id = EventBus.register_handler("test-handler", False, handler)
        conf = {'foo' : 'bar'}
        def deploy_handler(id):
            vertx.undeploy_verticle(id)
        vertx.deploy_verticle("core/deploy/child.py", conf, handler=deploy_handler)

def vertx_stop():
    EventBus.unregister_handler(handler_id)
    tu.unregister_all()
    tu.app_stopped()

tu.register_all(DeployTest())
tu.app_ready()
Пример #32
0
            tu.test_complete()

        client = self.prepare_dns(
            org.vertx.testtools.TestDnsServer.testReverseLookup(ptr))
        client.reverse_lookup('10.0.0.1', handler)

    def test_reverse_lookup_ipv6(self):
        ptr = 'ptr.vertx.io'

        def handler(err, result):
            tu.check_thread()
            tu.azzert(err is None)
            tu.azzert(ptr == result)
            tu.test_complete()

        client = self.prepare_dns(
            org.vertx.testtools.TestDnsServer.testReverseLookup(ptr))
        client.reverse_lookup('::1', handler)


def vertx_stop():
    if server is not None:
        server.stop()
    tu.check_thread()
    tu.unregister_all()
    tu.app_stopped()


tu.register_all(DnsClientTest())
tu.app_ready()