def test_open_open_close_query(tempdir):
    bds1 = BundleDependencyStore()
    bds2 = BundleDependencyStore()
    store_cache = StoreCache()
    store = plugin_get('FileStorageZODB', Store)()
    store.open(p(tempdir, 'db.fs'))
    trip = (URIRef('http://example.org/a'), URIRef('http://example.org/b'),
            URIRef('http://example.org/c'))
    store.add(trip, context=None)
    store.close()

    conf = dict(type='FileStorageZODB',
                conf={
                    'read_only': True,
                    'url': p(tempdir, 'db.fs')
                },
                cache=store_cache)

    print("OPEN BDS 1")
    bds1.open(conf)
    print("OPEN BDS 2")
    bds2.open(conf)

    print("CLOSE BDS 1")
    bds1.close()

    assert list(bds2.triples((None, None, None)))[0][0] == trip
def test_open_open_close_close_2(tempdir):
    '''
    A cached store, once opened, cannot be closed unilaterally by a BDS holdidng a
    reference to that store. Consequently, we must prevent closing of the store. However,
    calling 'close' on the store must remain an allowed operation (i.e., it must not raise
    an exception) so that the sharing of the store remains transparent to the BDS user.
    '''
    bds1 = BundleDependencyStore()
    bds2 = BundleDependencyStore()
    store_cache = StoreCache()
    store = plugin_get('FileStorageZODB', Store)()
    store.open(p(tempdir, 'db.fs'))
    store.close()

    conf = dict(type='FileStorageZODB',
                conf={
                    'read_only': True,
                    'url': p(tempdir, 'db.fs')
                },
                cache=store_cache)

    print("OPEN BDS 1")
    bds1.open(conf)
    print("OPEN BDS 2")
    bds2.open(conf)

    print("CLOSE BDS 2")
    bds2.close()
    print("CLOSE BDS 1")
    bds1.close()