Beispiel #1
0
 def make_keyfs():
     keyfs = KeyFS(tmpdir, storage)
     key1 = keyfs.add_key("NAME1", "hello", int)
     keyfs.notifier.on_key_change(key1, queue.put)
     pool = ThreadPool()
     pool.register(keyfs.notifier)
     pool.start()
     try:
         yield key1
     finally:
         pool.shutdown()
Beispiel #2
0
 def test_import_changes_subscriber_error(self, keyfs, storage, tmpdir):
     pkey = keyfs.add_key("NAME", "hello/{name}", dict)
     D = pkey(name="world")
     with keyfs.transaction(write=True):
         D.set({1:1})
     new_keyfs = KeyFS(tmpdir.join("newkeyfs"), storage)
     pkey = new_keyfs.add_key("NAME", "hello/{name}", dict)
     new_keyfs.subscribe_on_import(pkey, lambda *args: 0/0)
     serial = new_keyfs.get_current_serial()
     with keyfs.transaction() as tx:
         changes = tx.conn.get_changes(0)
     with pytest.raises(ZeroDivisionError):
         new_keyfs.import_changes(0, changes)
     assert new_keyfs.get_current_serial() == serial
Beispiel #3
0
 def test_import_changes_subscriber(self, keyfs, storage, tmpdir):
     pkey = keyfs.add_key("NAME", "hello/{name}", dict)
     D = pkey(name="world")
     with keyfs.transaction(write=True):
         D.set({1:1})
     assert keyfs.get_current_serial() == 0
     # load entries into new keyfs instance
     new_keyfs = KeyFS(tmpdir.join("newkeyfs"), storage)
     pkey = new_keyfs.add_key("NAME", "hello/{name}", dict)
     l = []
     new_keyfs.subscribe_on_import(pkey, lambda *args: l.append(args))
     with keyfs.transaction() as tx:
         changes = tx.conn.get_changes(0)
     new_keyfs.import_changes(0, changes)
     assert l[0][1:] == (new_keyfs.NAME(name="world"), {1:1}, -1)
Beispiel #4
0
    def test_import_changes(self, keyfs, storage, tmpdir):
        D = keyfs.add_key("NAME", "hello", dict)
        with keyfs.transaction(write=True):
            D.set({1:1})
        with keyfs.transaction(write=True):
            D.delete()
        with keyfs.transaction(write=True):
            D.set({2:2})
        with keyfs._storage.get_connection() as conn:
            serial = conn.last_changelog_serial

        assert serial == 2
        # load entries into new keyfs instance
        new_keyfs = KeyFS(tmpdir.join("newkeyfs"), storage)
        D2 = new_keyfs.add_key("NAME", "hello", dict)
        for serial in range(3):
            with keyfs.transaction() as tx:
                changes = tx.conn.get_changes(serial)
            new_keyfs.import_changes(serial, changes)
        with new_keyfs.transaction() as tx:
            assert tx.get_value_at(D2, 0) == {1:1}
            with pytest.raises(KeyError):
                assert tx.get_value_at(D2, 1)
            assert tx.get_value_at(D2, 2) == {2:2}