Пример #1
0
class ShelveStateStoreTestCase(TestCase):
    @setup
    def setup_store(self):
        self.filename = os.path.join(tempfile.gettempdir(), 'state')
        self.store = ShelveStateStore(self.filename)

    @teardown
    def teardown_store(self):
        os.unlink(self.filename)

    def test__init__(self):
        assert_equal(self.filename, self.store.filename)

    def test_save(self):
        key_value_pairs = [(ShelveKey("one", "two"), {
            'this': 'data'
        }), (ShelveKey("three", "four"), {
            'this': 'data2'
        })]
        self.store.save(key_value_pairs)
        self.store.cleanup()

        stored_data = shelve.open(self.filename)
        for key, value in key_value_pairs:
            assert_equal(stored_data[key.key], value)

    def test_restore(self):
        keys = [ShelveKey("thing", i) for i in xrange(5)]
        value = {'this': 'data'}
        store = shelve.open(self.filename)
        for key in keys:
            store[key.key] = value
        store.close()

        retrieved_data = self.store.restore(keys)
        for key in keys:
            assert_equal(retrieved_data[key], value)
Пример #2
0
class ShelveStateStoreTestCase(TestCase):

    @setup
    def setup_store(self):
        self.filename = os.path.join(tempfile.gettempdir(), 'state')
        self.store = ShelveStateStore(self.filename)

    @teardown
    def teardown_store(self):
        os.unlink(self.filename)

    def test__init__(self):
        assert_equal(self.filename, self.store.filename)

    def test_save(self):
        key_value_pairs = [
            (ShelveKey("one", "two"), {'this': 'data'}),
            (ShelveKey("three", "four"), {'this': 'data2'})
        ]
        self.store.save(key_value_pairs)
        self.store.cleanup()

        stored_data = shelve.open(self.filename)
        for key, value in key_value_pairs:
            assert_equal(stored_data[key.key], value)

    def test_restore(self):
        keys = [ShelveKey("thing", i) for i in xrange(5)]
        value = {'this': 'data'}
        store = shelve.open(self.filename)
        for key in keys:
            store[key.key] = value
        store.close()

        retrieved_data = self.store.restore(keys)
        for key in keys:
            assert_equal(retrieved_data[key], value)
Пример #3
0
class TestShelveStateStore(TestCase):
    @setup
    def setup_store(self):
        self.tmpdir = tempfile.mkdtemp()
        self.filename = os.path.join(self.tmpdir, 'state')
        self.store = ShelveStateStore(self.filename)

    @teardown
    def teardown_store(self):
        shutil.rmtree(self.tmpdir)

    def test__init__(self):
        assert_equal(self.filename, self.store.filename)

    def test_save(self):
        key_value_pairs = [
            (
                ShelveKey("one", "two"),
                {
                    'this': 'data',
                },
            ),
            (
                ShelveKey("three", "four"),
                {
                    'this': 'data2',
                },
            ),
        ]
        self.store.save(key_value_pairs)
        self.store.cleanup()

        stored_data = Py2Shelf(self.filename)
        for key, value in key_value_pairs:
            assert_equal(stored_data[str(key.key)], value)
        stored_data.close()

    def test_restore(self):
        self.store.cleanup()
        keys = [ShelveKey("thing", i) for i in range(5)]
        value = {'this': 'data'}
        store = Py2Shelf(self.filename)
        for key in keys:
            store[str(key.key)] = value
        store.close()

        self.store.shelve = Py2Shelf(self.filename)
        retrieved_data = self.store.restore(keys)
        for key in keys:
            assert_equal(retrieved_data[key], value)
Пример #4
0
    def from_config(cls, persistence_config):
        store_type = schema.StatePersistenceTypes(persistence_config.store_type)
        name = persistence_config.name
        buffer_size = persistence_config.buffer_size
        store = None

        if store_type == schema.StatePersistenceTypes.shelve:
            store = ShelveStateStore(name)

        if store_type == schema.StatePersistenceTypes.yaml:
            store = YamlStateStore(name)

        if store_type == schema.StatePersistenceTypes.dynamodb:
            table_name = persistence_config.table_name
            dynamodb_region = persistence_config.dynamodb_region
            store = DynamoDBStateStore(table_name, dynamodb_region)

        buffer = StateSaveBuffer(buffer_size)
        return PersistentStateManager(store, buffer)
Пример #5
0
    def from_config(cls, persistence_config):
        store_type = persistence_config.store_type
        name = persistence_config.name
        connection_details = persistence_config.connection_details
        buffer_size = persistence_config.buffer_size
        store = None

        if store_type not in schema.StatePersistenceTypes:
            raise PersistenceStoreError("Unknown store type: %s" % store_type)

        if store_type == schema.StatePersistenceTypes.shelve:
            store = ShelveStateStore(name)

        if store_type == schema.StatePersistenceTypes.sql:
            store = SQLAlchemyStateStore(name, connection_details)

        if store_type == schema.StatePersistenceTypes.yaml:
            store = YamlStateStore(name)

        buffer = StateSaveBuffer(buffer_size)
        return PersistentStateManager(store, buffer)
Пример #6
0
 def setup_store(self):
     self.filename = os.path.join(tempfile.gettempdir(), 'state')
     self.store = ShelveStateStore(self.filename)
Пример #7
0
 def setup_store(self):
     self.tmpdir = tempfile.mkdtemp()
     self.filename = os.path.join(self.tmpdir, 'state')
     self.store = ShelveStateStore(self.filename)
Пример #8
0
 def setup_store(self):
     self.filename = os.path.join(tempfile.gettempdir(), 'state')
     self.store = ShelveStateStore(self.filename)