Esempio n. 1
0
    def test_remote_build_iterkeys_split_test(self):
        config.session.execute("DROP TABLE IF EXISTS my_app.tab_b0")
        config.session.execute(
            "CREATE TABLE IF NOT EXISTS my_app.tab_b0(position int, value text, PRIMARY KEY(position))"
        )
        tablename = "tab_b0"
        pd = StorageDict(tablename, [('position', 'int')], [('value', 'text')])
        num_inserts = 10000
        what_should_be = set()
        for i in range(num_inserts):
            pd[i] = 'ciao' + str(i)
            what_should_be.add(i)
        del pd
        count, = config.session.execute(
            'SELECT count(*) FROM my_app.tab_b0')[0]
        self.assertEqual(count, num_inserts)

        pd = StorageDict(tablename, [('position', 'int')], [('value', 'text')])

        count = 0
        res = set()
        for partition in pd.split():
            id = partition.getID()
            from storage.api import getByID
            rebuild = getByID(id)
            for val in rebuild.iterkeys():
                res.add(val)
                count += 1
        self.assertEqual(count, num_inserts)
        self.assertEqual(what_should_be, res)
Esempio n. 2
0
    def inmemory_composed_keys_test(self):
        pd = StorageDict(None, [('pk1', 'int'), ('pk2', 'int')],
                         [('val1', 'text')])

        pd[0, 1] = '1'
        pd[1, 1] = '2'
        pd[2, 0] = '3'
        pd[3, 1] = '4'
        self.assertEqual({(0, 1), (1, 1), (2, 0), (3, 1)}, set(pd.keys()))
Esempio n. 3
0
    def inmemory_keys_test(self):
        pd = StorageDict(None, [('pk1', 'int'), ('pk2', 'int')],
                         [('val1', 'text')])

        pd[0] = '1'
        pd[1] = '2'
        pd[2] = '3'
        pd[3] = '4'
        self.assertEqual({0, 1, 2, 3}, set(pd.keys()))
Esempio n. 4
0
    def test_write_and_then_read(self):
        config.session.execute("DROP TABLE IF EXISTS ksp.tb1")
        config.session.execute("CREATE TABLE ksp.tb1(pk1 int, val1 text,PRIMARY KEY(pk1))")
        pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('val1', 'text')])
        for i in range(100):
            pd[i] = 'ciao' + str(i)
        del pd  # To force hfetch to flush data
        count, = config.session.execute("SELECT count(*) FROM ksp.tb1")[0]

        self.assertEqual(count, 100)
        pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('val1', 'text')])
        for i in range(100):
            self.assertEqual(pd[i], u'ciao' + str(i))
Esempio n. 5
0
    def test_write_and_then_read_named_tuple(self):
        config.session.execute("DROP TABLE IF EXISTS ksp.tb1")
        config.session.execute("CREATE TABLE ksp.tb1(pk1 int, name text,age int,PRIMARY KEY(pk1))")
        pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('name', 'text'), ('age', 'int')])
        for i in range(100):
            pd[i] = ('ciao' + str(i), i)
        del pd  # To force hfetch to flush data
        count, = config.session.execute("SELECT count(*) FROM ksp.tb1")[0]

        self.assertEqual(count, 100)
        pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('name', 'text'), ('age', 'int')])
        for i in range(100):
            name, age = pd[i]
            self.assertEqual(name, u'ciao' + str(i))
            self.assertEqual(age, i)

            self.assertEqual(pd[i].name, u'ciao' + str(i))
            self.assertEqual(pd[i].age, i)
Esempio n. 6
0
 def test_flush_items_10K(self):
     config.session.execute("DROP TABLE IF EXISTS ksp.tb1")
     config.session.execute("CREATE TABLE ksp.tb1(pk1 int, val1 text,PRIMARY KEY(pk1))")
     pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('val1', 'text')])
     num_inserts = 10000
     for i in range(num_inserts):
         pd[i] = 'ciao' + str(i)
     del pd  # To force hfetch to flush data
     count, = config.session.execute("SELECT count(*) FROM ksp.tb1 LIMIT " + str(num_inserts + 1))[0]
     self.assertEqual(count, num_inserts)
Esempio n. 7
0
    def test_composed_iteritems_test(self):
        config.session.execute("DROP TABLE IF EXISTS my_app.tab_b1")
        config.session.execute(
            "CREATE TABLE IF NOT EXISTS my_app.tab_b1(pid int,time int, value text,x float,y float,z float, PRIMARY KEY(pid,time))"
        )
        tablename = "tab_b1"
        pd = StorageDict(tablename, [('pid', 'int'), ('time', 'int')],
                         [('value', 'text'), ('x', 'double'), ('y', 'double'),
                          ('z', 'double')])
        num_inserts = 10000
        what_should_be = {}
        for i in range(num_inserts):
            pd[i, i + 100] = ('ciao' + str(i), i * 0.1, i * 0.2, i * 0.3)
            what_should_be[i, i + 100] = ('ciao' + str(i), i * 0.1, i * 0.2,
                                          i * 0.3)

        del pd

        count, = config.session.execute(
            'SELECT count(*) FROM my_app.tab_b1')[0]
        self.assertEqual(count, num_inserts)
        pd = StorageDict(tablename, [('pid', 'int'), ('time', 'int')],
                         [('value', 'text'), ('x', 'float'), ('y', 'float'),
                          ('z', 'float')])
        count = 0
        res = {}
        for partition in pd.split():
            for key, val in partition.iteritems():
                res[key] = val
                count += 1
        self.assertEqual(count, num_inserts)
        delta = 0.0001
        for i in range(num_inserts):
            a = what_should_be[i, i + 100]
            b = res[i, i + 100]
            self.assertEqual(a[0], b.value)
            self.assertAlmostEquals(a[1], b.x, delta=delta)
            self.assertAlmostEquals(a[2], b.y, delta=delta)
            self.assertAlmostEquals(a[3], b.z, delta=delta)
Esempio n. 8
0
    def test_simple_iterkeys_split(self):
        config.session.execute(
            "CREATE TABLE IF NOT EXISTS my_app.tab30(position int, value text, PRIMARY KEY(position))"
        )
        tablename = "tab30"
        pd = StorageDict(tablename, [('position', 'int')], [('value', 'text')])
        num_inserts = 10000
        what_should_be = set()
        for i in range(num_inserts):
            pd[i] = 'ciao' + str(i)
            what_should_be.add(i)

        count = 0
        res = set()
        for partition in pd.split():
            for val in partition.keys():
                res.add(val)
                count += 1
        self.assertEqual(count, num_inserts)
        self.assertEqual(what_should_be, res)

        count, = config.session.execute('SELECT count(*) FROM my_app.tab30')[0]
        self.assertEqual(count, num_inserts)
        pd.delete_persistent()
Esempio n. 9
0
    def inmemory_getitem_setitem_test(self):
        pd = StorageDict(None, [('pk1', 'int'), ('pk2', 'int')],
                         [('val1', 'text')])

        import random
        types = [
            random.randint(0, 100),
            random.random(),
            float(random.random()), 'string_rand_' + str(random.random())
        ]
        typeskeys = types[:]
        typeskeys.append([i for i in range(random.randint(0, 100))])
        typeskeys.append(False)

        for key in types:
            for value in typeskeys:
                pd[key] = value
                self.assertEqual(pd[key], value)
Esempio n. 10
0
    def test_flush_items_100(self):
        config.session.execute(
            "CREATE TABLE ksp.tb1(pk1 int, val1 text,PRIMARY KEY(pk1))")
        pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('val1', 'text')])
        num_inserts = 100
        for i in range(num_inserts):
            pd[i] = 'ciao' + str(i)
        del pd  # To force hfetch to flush data
        import gc
        gc.collect()
        count, = config.session.execute("SELECT count(*) FROM ksp.tb1")[0]

        self.assertEqual(count, num_inserts)
        pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('val1', 'text')])
        pd.delete_persistent()
Esempio n. 11
0
 def inmemory_contains_test(self):
     pd = StorageDict(None, [('pk1', 'int')], [('val1', 'text')])
     pd[3] = '4'
     self.assertEqual(True, 3 in pd)
     self.assertEqual('4', pd[3])
Esempio n. 12
0
 def test_initializestoragedict_test(self):
     tablename = 'examplestorageobjclass1'
     my_persistent_storageDict = StorageDict(tablename,
                                             [('position', 'int')],
                                             [('value', 'text')])
Esempio n. 13
0
 def test_init_storagedictwithinitmultivalnames_test(self):
     tablename = 'examplestoragedictclass1'
     my_example_class = ExampleStoragedictClassInitMultiValNames()
     StorageDict.__init__(my_example_class)
     my_example_class.make_persistent(tablename)
Esempio n. 14
0
 def init_storagedictwithinitmultival_test(self):
     tablename = 'examplestoragedictclass1'
     config.session.execute("DROP TABLE IF EXISTS my_app." + tablename)
     my_example_class = ExampleStoragedictClassInitMultiVal()
     StorageDict.__init__(my_example_class)
     my_example_class.make_persistent(tablename)
Esempio n. 15
0
 def initializestoragedict_test(self):
     tablename = 'examplestorageobjclass1'
     config.session.execute("DROP TABLE IF EXISTS my_app." + tablename)
     config.session.execute("DROP TABLE IF EXISTS my_app." + tablename + '_my_dict')
     my_persistent_storageDict = StorageDict(tablename, [('position', 'int')], [('value', 'text')])