示例#1
0
def test_chained_read_through_write():
    read_store = bs.MemoryStore({'foo': 42}, read=True, write=False)
    store_ahead = bs.MemoryStore(read=True,
                                 write=True,
                                 read_through_write=True)
    read_through_write_store = bs.MemoryStore(read=True,
                                              write=True,
                                              read_through_write=True)
    no_read_through_write_store = bs.MemoryStore(read=True,
                                                 write=True,
                                                 read_through_write=False)
    stores = [
        no_read_through_write_store, read_through_write_store, read_store,
        store_ahead
    ]
    chained_store = bs.ChainedStore(stores)

    assert 'foo' not in read_through_write_store
    assert 'foo' not in no_read_through_write_store
    assert 'foo' not in store_ahead
    # verify we read from the read-only store
    assert chained_store['foo'] == 42

    assert 'foo' in read_through_write_store
    assert 'foo' not in store_ahead
    assert 'foo' not in no_read_through_write_store
示例#2
0
def test_chained_with_readonly():
    read_store = bs.MemoryStore({'foo': 42},
                                read=True,
                                write=False,
                                delete=False)
    write_store = bs.MemoryStore(read=True, write=True, delete=False)
    stores = [read_store, write_store]
    chained_store = bs.ChainedStore(stores)

    # verify we read from the read-only store
    assert chained_store['foo'] == 42

    # but that it is not written to
    chained_store.put('bar', 55)
    assert 'bar' in chained_store
    assert 'bar' in write_store
    assert 'bar' not in read_store
示例#3
0
def test_chained_storage_with_disk_and_s3_sharing_cachedir(s3fs):
    tmp_dir = '/tmp/prov_shared_store'
    shutil.rmtree(tmp_dir, ignore_errors=True)
    mem_store = bs.MemoryStore(read=True, write=True, delete=True)
    disk_store = bs.DiskStore(tmp_dir, read=True, write=True, delete=True)
    s3_store = bs.S3Store(
        tmp_dir,
        s3fs=s3fs,
        basepath='bucket/prov_test',
        read=True,
        write=True,
        delete=True,
        always_check_remote=True,
    )
    stores = [mem_store, disk_store, s3_store]

    chained_store = bs.ChainedStore(stores)

    key = 'foobar'
    data = {'a': 1, 'b': 2}

    for store in stores:
        assert key not in store
    assert key not in store

    chained_store.put(key, data)
    assert key in store
    for store in stores:
        assert key in store

    assert store.get(key) == data
    assert store[key] == data

    store.delete(key)
    assert key not in store

    with pytest.raises(KeyError):
        store.delete(key)

    with pytest.raises(KeyError):
        store.get(key)
示例#4
0
def test_chained_writes_may_be_allowed_on_read_throughs_only():
    read_store = bs.MemoryStore({'foo': 42}, read=True, write=False)
    read_through_write_only_store = bs.MemoryStore(read=True,
                                                   write=False,
                                                   read_through_write=True)
    write_store = bs.MemoryStore(read=True,
                                 write=True,
                                 read_through_write=False)
    stores = [write_store, read_through_write_only_store, read_store]
    chained_store = bs.ChainedStore(stores)

    # verify we read from the read-only store
    assert chained_store['foo'] == 42

    assert 'foo' in read_through_write_only_store
    assert 'foo' not in write_store

    chained_store.put('bar', 55)
    assert 'bar' in chained_store
    assert 'bar' not in read_through_write_only_store
    assert 'bar' in write_store