Exemple #1
0
def test_initAlias1():
    """ calls initAlias with bogus arguments.  Should succeed."""
    alias = 'pomposity'
    D.initAlias(alias, 'anything', 'anything', True, True)
    try:
        assert D._aliases.has_key(alias)
    finally:
        D.delAlias(alias)
        assert not D._aliases.has_key(alias)
def test_initAlias1():
    """ calls initAlias with bogus arguments.  Should succeed."""    
    alias='pomposity'
    D.initAlias(alias, 'anything', 'anything', True, True)
    try:
        assert D._aliases.has_key(alias)
    finally:
        D.delAlias(alias)
        assert not D._aliases.has_key(alias)
Exemple #3
0
def test_initAlias2():
    """ calls initAlias twice with the same arguments.  Should succeed. """
    alias = 'fruitcake'
    driver = 'pong'
    connectArgs = 'blimp'

    D.initAlias(alias, driver, connectArgs)
    try:
        try:
            D.initAlias(alias, driver, connectArgs)
        except ValueError:
            raise ValueError, \
                  "ValueError should not be raised when an alias is reinitialized"\
                  " with identical data!"

    finally:
        D.delAlias(alias)
def test_initAlias2():
    """ calls initAlias twice with the same arguments.  Should succeed. """
    alias='fruitcake'
    driver='pong'
    connectArgs='blimp'
    
    D.initAlias(alias, driver, connectArgs)
    try:
        try:
            D.initAlias(alias, driver, connectArgs)
        except ValueError:
            raise ValueError, \
                  "ValueError should not be raised when an alias is reinitialized"\
                  " with identical data!"
        
    finally:
        D.delAlias(alias)
Exemple #5
0
def test_initAlias3():
    """ calls initAlias twice with different arguments.  Should fail. """
    alias = 'fruitcake'
    driver = 'pong'
    connectArgs = 'blimp'
    D.initAlias(alias, driver, connectArgs)
    connectArgs = 'potato'
    try:
        try:
            D.initAlias(alias, driver, connectArgs)
        except ValueError:
            error_raised = True
        else:
            error_raised = False
        assert error_raised, \
               "ValueError should be raised when a change is made to alias config"
    finally:
        D.delAlias(alias)
def test_initAlias3():
    """ calls initAlias twice with different arguments.  Should fail. """
    alias='fruitcake'
    driver='pong'
    connectArgs='blimp'
    D.initAlias(alias, driver, connectArgs)
    connectArgs='potato'
    try:
        try:
            D.initAlias(alias, driver, connectArgs)
        except ValueError:
            error_raised=True
        else:
            error_raised=False
        assert error_raised, \
               "ValueError should be raised when a change is made to alias config"
    finally:
        D.delAlias(alias)
Exemple #7
0
def test_pool2():
    stuff = D._aliases['pydotest'].copy()
    D.initAlias(
        'pydotestpool',
        stuff['driver'],
        stuff['connectArgs'],
        # keep_poolsize actually doesn't matter here
        D.ConnectionPool(max_poolsize=0, keep_poolsize=4),
        stuff['verbose'])
    hold = True
    threads = []

    class mythread(threading.Thread):
        def run(self):
            mydb = D.getConnection('pydotestpool')
            self.connid = id(mydb.conn)
            while hold:
                time.sleep(0.1)

    for i in range(10):
        t = mythread()
        threads.append(t)
        t.start()
    # we don't want any threads to terminate until
    # all threads have been initialized; otherwise,
    # some connections might get reused.
    ready = lambda t: hasattr(t, 'connid')
    while 1:
        if every(True, (ready(t) for t in threads)):
            break
        time.sleep(0.1)

    # let the threads die
    hold = False
    for t in threads:
        t.join()
    connids = [t.connid for t in threads]
    # assertion means: no connection has been handed out
    # to a plural number of simultaneously active threads
    assert len(connids) == len(set(connids))
Exemple #8
0
def test_pool1():
    stuff = D._aliases['pydotest'].copy()
    D.initAlias('pydotestpool', stuff['driver'], stuff['connectArgs'],
                D.ConnectionPool(max_poolsize=4, keep_poolsize=4),
                stuff['verbose'])
    db = D.getConnection('pydotestpool')
    try:
        assert len(db.pool._busy) == 0
        assert len(db.pool._free) == 0
        conn = db.conn
        assert len(db.pool._busy) == 1
        assert len(db.pool._free) == 0
        c = conn.cursor()
        c.execute('SELECT 1+1')
        res = c.fetchone()
        assert res[0] == 2
        c.close()
        conn.close()
        assert len(db.pool._busy) == 0
        assert len(db.pool._free) == 1
    finally:
        D.delAlias('pydotestpool')
def test_pool2():
    stuff=D._aliases['pydotest'].copy()
    D.initAlias('pydotestpool',
                stuff['driver'],
                stuff['connectArgs'],
                # keep_poolsize actually doesn't matter here
                D.ConnectionPool(max_poolsize=0, keep_poolsize=4),
                stuff['verbose'])
    hold=True
    threads=[]    
    class mythread(threading.Thread):
        def run(self):
            mydb=D.getConnection('pydotestpool')
            self.connid=id(mydb.conn)
            while hold:
                time.sleep(0.1)

    for i in range(10):
        t=mythread()
        threads.append(t)
        t.start()
    # we don't want any threads to terminate until
    # all threads have been initialized; otherwise,
    # some connections might get reused.
    ready=lambda t: hasattr(t, 'connid')
    while 1:
        if every(True, (ready(t) for t in threads)):
            break
        time.sleep(0.1)

    # let the threads die
    hold=False
    for t in threads:
        t.join()
    connids=[t.connid for t in threads]
    # assertion means: no connection has been handed out
    # to a plural number of simultaneously active threads
    assert len(connids)== len(set(connids))
def test_pool1():
    stuff=D._aliases['pydotest'].copy()
    D.initAlias('pydotestpool',
                stuff['driver'],
                stuff['connectArgs'],
                D.ConnectionPool(max_poolsize=4, keep_poolsize=4),
                stuff['verbose'])
    db=D.getConnection('pydotestpool')
    try:
        assert len(db.pool._busy)==0
        assert len(db.pool._free)==0
        conn=db.conn
        assert len(db.pool._busy)==1
        assert len(db.pool._free)==0
        c=conn.cursor()
        c.execute('SELECT 1+1')
        res=c.fetchone()
        assert res[0]==2
        c.close()
        conn.close()
        assert len(db.pool._busy)==0
        assert len(db.pool._free)==1
    finally:
        D.delAlias('pydotestpool')