Ejemplo n.º 1
0
def test_file_memory_write_transaction_error():
    mem = FileMemory(filename, tree_conf)
    mem._lock = mock.Mock()
    mem._cache[424242] = node

    with pytest.raises(ValueError):
        with mem.write_transaction:
            mem.set_node(node)
            assert mem._wal._not_committed_pages == {3: 9}
            assert mem._wal._committed_pages == {}
            assert mem._lock.writer_lock.acquire.call_count == 1
            raise ValueError('Foo')

    assert mem._wal._not_committed_pages == {}
    assert mem._wal._committed_pages == {}
    assert mem._lock.writer_lock.release.call_count == 1
    assert mem._cache.get(424242) is None
Ejemplo n.º 2
0
def test_file_memory_write_transaction():
    mem = FileMemory(filename, tree_conf)
    mem._lock = mock.Mock()

    assert mem._wal._not_committed_pages == {}
    assert mem._wal._committed_pages == {}

    with mem.write_transaction:
        mem.set_node(node)
        assert mem._wal._not_committed_pages == {3: 9}
        assert mem._wal._committed_pages == {}
        assert mem._lock.writer_lock.acquire.call_count == 1

    assert mem._wal._not_committed_pages == {}
    assert mem._wal._committed_pages == {3: 9}
    assert mem._lock.writer_lock.release.call_count == 1
    assert mem._lock.reader_lock.acquire.call_count == 0

    with mem.read_transaction:
        assert mem._lock.reader_lock.acquire.call_count == 1
        assert node == mem.get_node(3)

    assert mem._lock.reader_lock.release.call_count == 1
    mem.close()