def test_remote_build_iterkeys_split(self): 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) pd = StorageDict(tablename, [('position', 'int')], [('value', 'text')]) count = 0 res = set() for partition in pd.split(): id = partition.storage_id from storage.api import getByID rebuild = getByID(id) for val in rebuild.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.tab_b0')[0] self.assertEqual(count, num_inserts) pd.delete_persistent()
def test_flush_items_10K(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 = 10000 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 LIMIT " + str(num_inserts + 1))[0] self.assertEqual(count, num_inserts) pd = StorageDict('ksp.tb1', [('pk1', 'int')], [('val1', 'text')]) pd.delete_persistent()
def test_write_and_then_read(self): 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 import gc gc.collect() 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)) pd.delete_persistent()
def test_write_and_then_read_named_tuple(self): 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 import gc gc.collect() 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) pd.delete_persistent()
def test_composed_iteritems(self): 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) count = 0 res = {} for partition in pd.split(): for key, val in partition.items(): res[key] = val count += 1 self.assertEqual(count, num_inserts) count, = config.session.execute( 'SELECT count(*) FROM my_app.tab_b1')[0] 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) pd.delete_persistent()