Exemplo n.º 1
0
def test_broker(broker, backend, config, servicename):
    """Test the router."""
    from Cauldron import DFW
    svc = DFW.Service(servicename, config=config)
    
    from Cauldron import ktl
    client = ktl.Service(servicename)
    
    svc.shutdown()
    svc = DFW.Service(servicename, config=config)
    svc.shutdown()
Exemplo n.º 2
0
def test_Service_with_strict_xml(backend, servicename, config,
                                 dispatcher_name):
    """Test the backend with strict xml enabled, so it should raise an exception."""
    from Cauldron.api import use_strict_xml
    use_strict_xml()
    from Cauldron import DFW

    os.environ.pop('RELDIR', None)
    with pytest.raises(KeyError):
        svc = DFW.Service(servicename, config, dispatcher=dispatcher_name)
    os.environ['RELDIR'] = "directory/does/not/exist"
    with pytest.raises(IOError):
        svc = DFW.Service(servicename, config, dispatcher=dispatcher_name)
Exemplo n.º 3
0
def test_Service_with_dispatcher(xmlvar, backend, servicename, config,
                                 keyword_name_ENUMERATED, dispatcher_name):
    """XML service with dispatcher explicitly set."""
    from Cauldron import DFW
    svc = DFW.Service(servicename, config, dispatcher=dispatcher_name)
    keyword = svc[keyword_name_ENUMERATED]
    svc.shutdown()
Exemplo n.º 4
0
def test_Service_with_wrong_dispatcher(strictxml, backend, servicename, config,
                                       keyword_name_ENUMERATED,
                                       dispatcher_name2):
    """XML service with dispatcher explicitly set."""
    from Cauldron import DFW
    from Cauldron.exc import WrongDispatcher
    svc = DFW.Service(servicename, config, dispatcher=dispatcher_name2)
    with pytest.raises(WrongDispatcher):
        keyword = svc[keyword_name_ENUMERATED]
Exemplo n.º 5
0
def test_setup(broker, backend, config, servicename):
    """Test setup and broadcast functions"""
    from Cauldron import DFW
    
    def setup(service):
        """Setup function."""
        DFW.Keyword.Keyword("KEYWORD", service, initial="SOMEVALUE")
    
    svc = DFW.Service(servicename, config=config, setup=setup)
    svc["KEYWORD"]
Exemplo n.º 6
0
def test_multiple_binds_other_serivce(backend, dispatcher, config, cls):
    """Test for binds against multiple services"""
    from Cauldron import DFW
    svc = DFW.Service("OTHERSERVCE", config)
    try:
        instance = cls()
        instance.bind(dispatcher)
        with pytest.raises(ServiceAlreadyBound):
            instance.bind(svc)
    finally:
        svc.shutdown()
Exemplo n.º 7
0
def test_Service_with_xml(xmlvar, backend, servicename, config,
                          missing_keyword_name, keyword_name_ENUMERATED):
    """Test a service with XML."""
    from Cauldron import DFW
    svc = DFW.Service(servicename, config, dispatcher='+service+_dispatch_1')
    assert svc.xml is not None
    assert keyword_name_ENUMERATED in svc
    assert missing_keyword_name not in svc
    kwd = svc[missing_keyword_name]
    assert missing_keyword_name in svc
    kwd = svc[keyword_name_ENUMERATED]
    assert kwd.KTL_TYPE == 'enumerated'
Exemplo n.º 8
0
def test_write_before_begin(backend, servicename, config, keyword_name):
    """Test a dispatcher setup function."""
    from Cauldron import DFW

    def setup(service):
        """Set up a service"""
        DFW.Keyword.Integer(keyword_name, service, initial=5)
        service[keyword_name].modify(str(10))

    service = DFW.Service(servicename, config, setup=setup)
    assert keyword_name in service
    assert service[keyword_name]['value'] == str(10)
Exemplo n.º 9
0
def test_bad_initial_value(backend, servicename, config, keyword_name,
                           keyword_name1):
    """Test a dispatcher setup function."""
    from Cauldron import DFW

    def setup(service):
        """Set up a service"""
        DFW.Keyword.Boolean(keyword_name1, service, initial=100)
        DFW.Keyword.Integer(keyword_name, service, initial=100)

    service = DFW.Service(servicename, config, setup=setup)
    assert keyword_name1 in service
    assert service[keyword_name1]['value'] == None
    assert int(service[keyword_name]['value']) == 100
Exemplo n.º 10
0
def test_setup_function(backend, servicename, config, keyword_name):
    """Test a dispatcher setup function."""
    from Cauldron import DFW

    def setup(service):
        """Set up a service"""
        kwd = DFW.Keyword.Keyword(keyword_name, service)
        print("Service setup")

    service = DFW.Service(servicename, config, setup=setup)
    print("Service __init__")
    assert keyword_name in service
    print("Service check")
    del service
    print("Service done.")
Exemplo n.º 11
0
log = getLogger("example.zmq")

# Get ready!
from Cauldron.api import use
use("zmq")

from Cauldron import DFW


def setup(service):
    """Setup the service."""
    kwd = DFW.Keyword.Keyword("TEST", service)
    print("Service setup")


disp = DFW.Service("testsvc", setup=setup, config=None)
dtest = disp["TEST"]
log.info("Dispatcher Keyword {0!r}".format(dtest))

VALUE = "SOMEVALUE"
time.sleep(1.0)
log.info("Starting KTL client...")
from Cauldron import ktl
svc = ktl.Service("testsvc")
log.info("Getting KTL keyword object...")
test = svc["TEST"]
log.info("Writing '{0}'".format(VALUE))
test.write(VALUE)
log.info("'{0}' =? '{1}'".format(VALUE, test.read()))
log.info("Done!")
svc
Exemplo n.º 12
0
"""
Demonstrate REDIS read-write ability.
"""
import time
from lumberjack import setup_logging
setup_logging(mode='stream')
from logging import getLogger
from Cauldron.conftest import clear_registry
log = getLogger("example.redis")
# Start up!
from Cauldron.redis.common import configure_pool, REDIS_SERVICES_REGISTRY
configure_pool(host='localhost', port=6379, db=0)
clear_registry()

# Get ready!
from Cauldron.api import use
use("redis")

from Cauldron import DFW
disp = DFW.Service("testsvc", config=None)
dtest = disp["TEST"]
log.info(dtest)

from Cauldron import ktl
svc = ktl.Service("testsvc")
test = svc["TEST"]
log.info("Writing")
test.write("SOMEVALUE")
log.info(test.read())
log.info("Done!")
disp.shutdown()
Exemplo n.º 13
0
def dispatcher(request, backend, servicename, config, dispatcher_name):
    """Establish the dispatcher for a particular kind of service."""
    from Cauldron import DFW
    svc = DFW.Service(servicename, config, dispatcher=dispatcher_name)
    request.addfinalizer(lambda: svc.shutdown())
    return svc