def test_streaming_zero_results(self): try: master_conn = get_connection() master_conn.begin() master_conn._execute( "delete from vt_insert_test", {}, KEYSPACE_NAME, 'master', keyranges=[keyrange.KeyRange(shard_names[self.shard_index])]) master_conn.commit() # After deletion, should result zero. stream_cursor = vtgate_cursor.StreamVTGateCursor( master_conn, KEYSPACE_NAME, 'master', keyranges=[keyrange.KeyRange(shard_names[self.shard_index])]) stream_cursor.execute("select * from vt_insert_test", {}) rows = stream_cursor.fetchall() rowcount = 0 for r in rows: rowcount += 1 self.assertEqual(rowcount, 0) except Exception, e: self.fail("Failed with error %s %s" % (str(e), traceback.print_exc()))
def test_streaming_fetchone(self): try: count = 100 do_write(count, self.shard_index) # Fetch one. vtgate_conn = get_connection() stream_cursor = vtgate_cursor.StreamVTGateCursor( vtgate_conn, KEYSPACE_NAME, 'master', keyranges=[get_keyrange(shard_names[self.shard_index])]) stream_cursor.execute("select * from vt_insert_test", {}) rows = stream_cursor.fetchone() self.assertTrue(type(rows) == tuple, "Received a valid row") stream_cursor.close() except Exception, e: self.fail("Failed with error %s %s" % (str(e), traceback.print_exc()))
def test_streaming_fetchall(self): try: count = 100 do_write(count, self.shard_index) # Fetch all. vtgate_conn = get_connection() stream_cursor = vtgate_cursor.StreamVTGateCursor( vtgate_conn, KEYSPACE_NAME, 'master', keyranges=[get_keyrange(shard_names[self.shard_index])]) stream_cursor.execute("select * from vt_insert_test", {}) rows = stream_cursor.fetchall() rowcount = 0 for r in rows: rowcount +=1 self.assertEqual(rowcount, count) stream_cursor.close() except Exception, e: self.fail("Failed with error %s %s" % (str(e), traceback.print_exc()))
def create_stream_cursor_from_cursor(original_cursor): """Creates streaming cursor from a regular cursor. Args: original_cursor: Cursor of VTGateCursor type Returns: Returns StreamVTGateCursor that is not writable. """ if not isinstance(original_cursor, vtgate_cursor.VTGateCursor): raise dbexceptions.ProgrammingError( 'Original cursor should be of VTGateCursor type.') stream_cursor = vtgate_cursor.StreamVTGateCursor( original_cursor._conn, original_cursor.keyspace, original_cursor.tablet_type, keyspace_ids=original_cursor.keyspace_ids, keyranges=original_cursor.keyranges, writable=False) return stream_cursor
def test_streaming_fetchsubset(self): try: count = 100 do_write(count, self.shard_index) # Fetch a subset of the total size. master_conn = get_connection() stream_cursor = vtgate_cursor.StreamVTGateCursor( master_conn, KEYSPACE_NAME, 'master', keyranges=[keyrange.KeyRange(shard_names[self.shard_index])]) stream_cursor.execute("select * from vt_insert_test", {}) fetch_size = 10 rows = stream_cursor.fetchmany(size=fetch_size) rowcount = 0 for r in rows: rowcount +=1 self.assertEqual(rowcount, fetch_size) stream_cursor.close() except Exception, e: self.fail("Failed with error %s %s" % (str(e), traceback.print_exc()))
KEYSPACE_NAME, 'replica', keyranges=[keyrange.KeyRange(shard_names[self.shard_index])]) except Exception, e: self.fail( "Communication with shard %s replica failed with error %s" % (shard_names[self.shard_index], str(e))) def test_tablet_restart_stream_execute(self): try: replica_conn = get_connection() except Exception, e: self.fail("Connection to vtgate failed with error %s" % (str(e))) stream_cursor = vtgate_cursor.StreamVTGateCursor( replica_conn, KEYSPACE_NAME, 'replica', keyranges=[keyrange.KeyRange(shard_names[self.shard_index])]) self.replica_tablet.kill_vttablet() with self.assertRaises(dbexceptions.DatabaseError): stream_cursor.execute("select * from vt_insert_test", {}) proc = self.replica_tablet.start_vttablet() self.replica_tablet.wait_for_vttablet_state('SERVING') try: stream_cursor.execute("select * from vt_insert_test", {}) except Exception, e: self.fail( "Communication with shard0 replica failed with error %s" % str(e)) def test_vtgate_restart_stream_execute(self):
try: results = vtgate_conn._execute("select 1 from vt_insert_test", {}, KEYSPACE_NAME, 'replica', keyranges=[self.keyrange]) except Exception, e: self.fail( "Communication with shard %s replica failed with error %s" % (shard_names[self.shard_index], str(e))) def test_tablet_restart_stream_execute(self): try: vtgate_conn = get_connection() except Exception, e: self.fail("Connection to vtgate failed with error %s" % (str(e))) stream_cursor = vtgate_cursor.StreamVTGateCursor( vtgate_conn, KEYSPACE_NAME, 'replica', keyranges=[self.keyrange]) self.replica_tablet.kill_vttablet() with self.assertRaises(dbexceptions.DatabaseError): stream_cursor.execute("select * from vt_insert_test", {}) proc = self.replica_tablet.start_vttablet() self.replica_tablet.wait_for_vttablet_state('SERVING') try: stream_cursor.execute("select * from vt_insert_test", {}) except Exception, e: self.fail( "Communication with shard0 replica failed with error %s" % str(e)) def test_vtgate_restart_stream_execute(self): global vtgate_server, vtgate_port try: