Exemplo n.º 1
0
class DataStoreTestCase(unittest.TestCase):

    def setUp(self):
        self.datastore = DataStore(**config.datastore_params)
        self.datastore.global_execute(entities_table)

    def tearDown(self):
        self.datastore.global_execute('DROP TABLE entities')
Exemplo n.º 2
0
    def setUp(self):
        self.datastore = DataStore(**config.sharded_datastore_params)
        self.datastore.global_execute(entities_table)

        self.datastore.global_execute("""
        CREATE TABLE index_user (
            username VARCHAR(255) NOT NULL UNIQUE,
            entity_id CHAR(32) NOT NULL UNIQUE,
            PRIMARY KEY (username, entity_id)
        ) ENGINE=InnoDB;
        """)

        self.datastore.global_execute("""
        CREATE TABLE index_user_entries (
            user_id CHAR(32) NOT NULL,
            entity_id CHAR(32) NOT NULL UNIQUE,
            PRIMARY KEY (user_id, entity_id)
        ) ENGINE=InnoDB;
        """)

        self.datastore.add_index(Index('index_user',
                                       properties=['username'],
                                       shard_on='username'))

        # distribute entries across shards based on user_id
        self.datastore.add_index(Index('index_user_entries',
                                       properties=['user_id'],
                                       shard_on='user_id'))
Exemplo n.º 3
0
 def setUp(self):
     self.datastore = DataStore(**config.datastore_params)
     self.datastore.global_execute(entities_table)
Exemplo n.º 4
0
class ShardTestCase(unittest.TestCase):

    def setUp(self):
        self.datastore = DataStore(**config.sharded_datastore_params)
        self.datastore.global_execute(entities_table)

        self.datastore.global_execute("""
        CREATE TABLE index_user (
            username VARCHAR(255) NOT NULL UNIQUE,
            entity_id CHAR(32) NOT NULL UNIQUE,
            PRIMARY KEY (username, entity_id)
        ) ENGINE=InnoDB;
        """)

        self.datastore.global_execute("""
        CREATE TABLE index_user_entries (
            user_id CHAR(32) NOT NULL,
            entity_id CHAR(32) NOT NULL UNIQUE,
            PRIMARY KEY (user_id, entity_id)
        ) ENGINE=InnoDB;
        """)

        self.datastore.add_index(Index('index_user',
                                       properties=['username'],
                                       shard_on='username'))

        # distribute entries across shards based on user_id
        self.datastore.add_index(Index('index_user_entries',
                                       properties=['user_id'],
                                       shard_on='user_id'))

    def tearDown(self):
        self.datastore.global_execute('DROP TABLE entities')
        self.datastore.global_execute('DROP TABLE index_user')
        self.datastore.global_execute('DROP TABLE index_user_entries')

    def test_put_get(self):
        user = User(id=gen_uuid(), firstname='David', lastname='Reynolds')
        user.username = '******'
        self.datastore.put(user)

        index = self.datastore.indexes['index_user']
        user = index.get(self.datastore, username='******')

        entries = []
        for i in xrange(10):
            entry = Entry(id=gen_uuid(),
                          user_id=user['id'],
                          title='%s' % i,
                          content='Hello, world')
            entries.append(entry)
        self.datastore.put_list(entries)

        # the entries and their indexes are distributed across the two test shards
        entry_index = self.datastore.indexes['index_user_entries']
        user_entries = entry_index.get_all(self.datastore, user_id=user['id'])

        assert len(user_entries) == 10