Example #1
0
def controller(request):
    impl, use_cache = request.param
    storage = lru_memory_cache.LRUMemoryCache(1024 * 1024)

    write_session = storage.begin_write(command_digest)
    write_session.write(command.SerializeToString())
    storage.commit_write(command_digest, write_session)

    write_session = storage.begin_write(action_digest)
    write_session.write(action.SerializeToString())
    storage.commit_write(action_digest, write_session)

    if impl == "sql":
        _, db = tempfile.mkstemp()
        data_store = SQLDataStore(storage,
                                  connection_string="sqlite:///%s" % db,
                                  automigrate=True)
    elif impl == "mem":
        data_store = MemoryDataStore(storage)
    try:
        if use_cache == "action-cache":
            cache = ActionCache(storage, 50)
            yield ExecutionController(data_store,
                                      storage=storage,
                                      action_cache=cache)
        else:
            yield ExecutionController(data_store, storage=storage)
    finally:
        if impl == "sql":
            if os.path.exists(db):
                os.remove(db)
Example #2
0
def test_file_based_sqlite_db(conn_str):
    # Those should be OK and not raise anything during instantiation
    with mock.patch('buildgrid.server.persistence.sql.impl.create_engine'
                    ) as create_engine:
        database = SQLDataStore(None, connection_string=conn_str)
        assert create_engine.call_count == 1
        call_args, call_kwargs = create_engine.call_args
Example #3
0
def database():
    storage = lru_memory_cache.LRUMemoryCache(1024 * 1024)
    _, db = tempfile.mkstemp()
    data_store = SQLDataStore(storage,
                              connection_string="sqlite:///%s" % db,
                              automigrate=True)
    try:
        yield data_store
    finally:
        if os.path.exists(db):
            os.remove(db)
Example #4
0
 def __new__(cls,
             storage,
             connection_string=None,
             automigrate=False,
             **kwargs):
     try:
         return SQLDataStore(storage,
                             connection_string=connection_string,
                             automigrate=automigrate,
                             **kwargs)
     except TypeError as type_error:
         click.echo(type_error, err=True)
         sys.exit(-1)
Example #5
0
def controller(request):
    storage = lru_memory_cache.LRUMemoryCache(1024 * 1024)
    impl, timeout = request.param
    if impl == "sql":
        _, db = tempfile.mkstemp()
        data_store = SQLDataStore(storage,
                                  connection_string="sqlite:///%s" % db,
                                  automigrate=True)
    elif impl == "mem":
        data_store = MemoryDataStore(storage)
    try:
        yield ExecutionController(data_store,
                                  bot_session_keepalive_timeout=timeout)
    finally:
        if impl == "sql":
            if os.path.exists(db):
                os.remove(db)
Example #6
0
def test_is_sqlite_inmemory_connection_string(conn_str):
    with pytest.raises(ValueError):
        # Should raise ValueError when trying to instantiate
        database = SQLDataStore(None, connection_string=conn_str)