def test_chained_read_through_write(): foo = artifact_record(id='foo') read_repo = r.MemoryRepo([foo], read=True, write=False) repo_ahead = r.MemoryRepo(read=True, write=True, read_through_write=True) read_through_write_repo = r.MemoryRepo(read=True, write=True, read_through_write=True) no_read_through_write_repo = r.MemoryRepo(read=True, write=True, read_through_write=False) repos = [ no_read_through_write_repo, read_through_write_repo, read_repo, repo_ahead ] chained_repo = r.ChainedRepo(repos) assert 'foo' not in read_through_write_repo assert 'foo' not in no_read_through_write_repo assert 'foo' not in repo_ahead # verify we read from the read-only store assert chained_repo['foo'].id == foo.id assert 'foo' in read_through_write_repo assert 'foo' not in repo_ahead assert 'foo' not in no_read_through_write_repo
def repo(request, db_session): # clean old config settings r.Config.set_current(r.Config({}, {}, None)) disk_store_gen = None disk_store_gen2 = None repo2 = None prevdir = os.getcwd() if request.param == 'memoryrepo': repo = r.MemoryRepo(read=True, write=True, delete=True) elif request.param == 'dbrepo-diskstore': disk_store_gen = disk_store() repo = r.DbRepo(db_session, next(disk_store_gen), read=True, write=True, delete=True) elif request.param == 'chained-memmem': repo = r.ChainedRepo([ r.MemoryRepo(read=True, write=True, delete=True), r.MemoryRepo(read=True, write=True, delete=True), ]) elif request.param == 'chained-repo': disk_store_gen = disk_store() disk_store_gen2 = disk_store() repo1 = r.DbRepo(db_session, next(disk_store_gen), read=True, write=True, delete=True) os.chdir(prevdir) repo2 = r.DbRepo( 'postgresql://localhost/test_provenance', next(disk_store_gen2), read=True, write=True, delete=True, schema='second_repo', ) repo = r.ChainedRepo([repo1, repo2]) else: repo = r.DbRepo(db_session, memory_store(), read=True, write=True, delete=True) p.set_default_repo(repo) yield repo p.set_default_repo(None) if repo2 is not None: repo2._db_engine.execute('drop schema second_repo cascade;') if disk_store_gen: next(disk_store_gen, 'ignore') if disk_store_gen2: next(disk_store_gen2, 'ignore')
def test_chained_writes_may_be_allowed_on_read_throughs_only(): foo = artifact_record(id='foo') read_repo = r.MemoryRepo([foo], read=True, write=False) read_through_write_only_repo = r.MemoryRepo(read=True, write=False, read_through_write=True) write_repo = r.MemoryRepo(read=True, write=True, read_through_write=False) repos = [write_repo, read_through_write_only_repo, read_repo] chained_repo = r.ChainedRepo(repos) # verify we read from the read-only repo assert chained_repo['foo'].id == foo.id assert 'foo' in read_through_write_only_repo assert 'foo' not in write_repo bar = artifact_record(id='bar') chained_repo.put(bar) assert 'bar' in chained_repo assert 'bar' not in read_through_write_only_repo assert 'bar' in write_repo
def test_chained_with_readonly(): read_repo = r.MemoryRepo([artifact_record(id='foo')], read=True, write=False, delete=False) write_repo = r.MemoryRepo(read=True, write=True, delete=False) repos = [read_repo, write_repo] chained = r.ChainedRepo(repos) # verify we read from the read-only store assert 'foo' in chained # but that it is not written to record = artifact_record(id='bar', value_id='baz') chained.put(record) assert 'bar' in chained assert 'bar' in write_repo assert 'bar' not in read_repo assert chained.get_by_value_id(record.value_id).id == record.id assert chained.get_by_id(record.id).id == record.id assert chained.get_value(record) == record.value
def memory_repo(): repo = r.MemoryRepo(read=True, write=True, delete=True) p.set_default_repo(repo) yield repo p.set_default_repo(None)