Beispiel #1
0
    def test_basic_stream(self):
        self._populate_vtocc_big_table(100)
        loop_count = 1

        # select lots of data using a non-streaming query
        if True:
            for _ in xrange(loop_count):
                cu = self.env.execute(
                    'select * from vtocc_big b1, vtocc_big b2')
                rows = cu.fetchall()
                self.assertEqual(len(rows), 10000)
                self.check_row_10(rows[10])

        # select lots of data using a streaming query
        if True:
            for _ in xrange(loop_count):
                cu = cursor.StreamCursor(self.env.conn)
                cu.execute('select * from vtocc_big b1, vtocc_big b2', {})
                count = 0
                while True:
                    row = cu.fetchone()
                    if row is None:
                        break
                    if count == 10:
                        self.check_row_10(row)
                    count += 1
                self.assertEqual(count, 10000)
Beispiel #2
0
 def test_streaming_terminate(self):
     try:
         self._populate_vtocc_big_table(100)
         query = 'select * from vtocc_big b1, vtocc_big b2, vtocc_big b3'
         cu = cursor.StreamCursor(self.env.conn)
         thd = threading.Thread(target=self._stream_exec, args=(cu, query))
         thd.start()
         tablet_addr = 'http://' + self.env.conn.addr
         connId = self._get_conn_id(tablet_addr)
         self._terminate_query(tablet_addr, connId)
         thd.join()
         with self.assertRaises(dbexceptions.DatabaseError) as cm:
             cu.fetchall()
         errMsg1 = (
             'error: the query was killed either because it timed out or was '
             'canceled: Lost connection to MySQL server during query (errno 2013)'
         )
         errMsg2 = 'error: Query execution was interrupted (errno 1317)'
         self.assertNotIn(
             cm.exception, (errMsg1, errMsg2),
             'did not raise interruption error: %s' % str(cm.exception))
         cu.close()
     except Exception, e:
         self.fail('Failed with error %s %s' %
                   (str(e), traceback.format_exc()))
Beispiel #3
0
 def test_table_acl_unmatched(self):
     self.env.execute("select * from vtocc_acl_unmatched where key1=1")
     self.env.conn.begin()
     self.env.execute("delete from vtocc_acl_unmatched where key1=1")
     self.env.conn.commit()
     self.env.execute("alter table vtocc_acl_unmatched comment 'comment'")
     cu = cursor.StreamCursor(self.env.conn)
     cu.execute("select * from vtocc_acl_unmatched where key1=1", {})
     cu.fetchall()
     cu.close()
Beispiel #4
0
 def test_table_acl_read_write(self):
   self.env.execute("select * from vtocc_acl_read_write where key1=1")
   self.env.conn.begin()
   self.env.execute("delete from vtocc_acl_read_write where key1=1")
   self.env.conn.commit()
   with self.assertRaisesRegexp(dbexceptions.DatabaseError, '.*table acl error.*'):
     self.env.execute("alter table vtocc_acl_read_write comment 'comment'")
   cu = cursor.StreamCursor(self.env.conn)
   cu.execute("select * from vtocc_acl_read_write where key1=1", {})
   cu.fetchall()
   cu.close()
Beispiel #5
0
 def test_streaming_fetchone(self):
   try:
     count = 100
     do_write(count)
     # Fetch one.
     master_conn = get_connection(db_type='master', shard_index=self.shard_index)
     stream_cursor = cursor.StreamCursor(master_conn)
     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()))
Beispiel #6
0
 def test_streaming_zero_results(self):
   try:
     master_conn = get_connection(db_type='master', shard_index=self.shard_index)
     master_conn.begin()
     master_conn._execute("delete from vt_insert_test", {})
     master_conn.commit()
     # After deletion, should result zero.
     stream_cursor = cursor.StreamCursor(master_conn)
     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()))
Beispiel #7
0
 def test_streaming_fetchall(self):
   try:
     count = 100
     do_write(count)
     # Fetch all.
     master_conn = get_connection(db_type='master', shard_index=self.shard_index)
     stream_cursor = cursor.StreamCursor(master_conn)
     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()))
Beispiel #8
0
 def test_streaming_fetchsubset(self):
   try:
     count = 100
     do_write(count)
     # Fetch a subset of the total size.
     master_conn = get_master_connection()
     stream_cursor = cursor.StreamCursor(master_conn) 
     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()))
Beispiel #9
0
 def test_streaming_fetchsubset(self):
     try:
         count = 100
         do_write(count)
         # Fetch a subset of the total size.
         master_conn = get_connection(db_type='master',
                                      shard_index=self.shard_index)
         stream_cursor = cursor.StreamCursor(master_conn)
         stream_cursor.execute('select * from vt_insert_test', {})
         fetch_size = 10
         rows = stream_cursor.fetchmany(size=fetch_size)
         rowcount = len(list(rows))
         self.assertEqual(rowcount, fetch_size)
         stream_cursor.close()
     except Exception, e:
         self.fail('Failed with error %s %s' %
                   (str(e), traceback.print_exc()))
Beispiel #10
0
 def test_table_acl_no_access(self):
   with self.assertRaisesRegexp(
       dbexceptions.DatabaseError, ".*table acl error.*"):
     self.env.execute("select * from vtocc_acl_no_access where key1=1")
   self.env.conn.begin()
   with self.assertRaisesRegexp(
       dbexceptions.DatabaseError, ".*table acl error.*"):
     self.env.execute("delete from vtocc_acl_no_access where key1=1")
   self.env.conn.commit()
   with self.assertRaisesRegexp(
       dbexceptions.DatabaseError, ".*table acl error.*"):
     self.env.execute("alter table vtocc_acl_no_access comment 'comment'")
   cu = cursor.StreamCursor(self.env.conn)
   with self.assertRaisesRegexp(
       dbexceptions.DatabaseError, ".*table acl error.*"):
     cu.execute("select * from vtocc_acl_no_access where key1=1", {})
   cu.close()
Beispiel #11
0
 def test_streaming_terminate(self):
   try:
     self._populate_vtocc_big_table(100)
     query = 'select * from vtocc_big b1, vtocc_big b2, vtocc_big b3'
     cu = cursor.StreamCursor(self.env.conn)
     thd = threading.Thread(target=self._stream_exec, args=(cu,query))
     thd.start()
     tablet_addr = "http://" + self.env.conn.addr
     connId = self._get_conn_id(tablet_addr)
     self._terminate_query(tablet_addr, connId)
     thd.join()
     with self.assertRaises(dbexceptions.DatabaseError) as cm:
       cu.fetchall()
     errMsg1 = "error: Lost connection to MySQL server during query (errno 2013)"
     errMsg2 = "error: Query execution was interrupted (errno 1317)"
     self.assertTrue(cm.exception not in (errMsg1, errMsg2), "did not raise interruption error: %s" % str(cm.exception))
     cu.close()
   except Exception, e:
     self.fail("Failed with error %s %s" % (str(e), traceback.print_exc()))
Beispiel #12
0
    def test_basic_stream(self):
        # insert 100 rows in a table
        self.env.conn.begin()
        for i in xrange(100):
            self.env.execute("insert into vtocc_big values " + "(" + str(i) +
                             ", " + "'AAAAAAAAAAAAAAAAAA " + str(i) + "', " +
                             "'BBBBBBBBBBBBBBBBBB " + str(i) + "', " +
                             "'C', " + "'DDDDDDDDDDDDDDDDDD " + str(i) +
                             "', " + "'EEEEEEEEEEEEEEEEEE " + str(i) + "', " +
                             "now()," + "'FF " + str(i) + "', " +
                             "'GGGGGGGGGGGGGGGGGG " + str(i) + "', " + str(i) +
                             ", " + str(i) + ", " + "now()," + str(i) + ", " +
                             str(i % 100) + ")")
        self.env.conn.commit()

        loop_count = 1

        # select lots of data using a non-streaming query
        if True:
            for i in xrange(loop_count):
                cu = self.env.execute(
                    "select * from vtocc_big b1, vtocc_big b2")
                rows = cu.fetchall()
                self.assertEqual(len(rows), 10000)
                self.check_row_10(rows[10])

        # select lots of data using a streaming query
        if True:
            for i in xrange(loop_count):
                cu = cursor.StreamCursor(self.env.conn)
                cu.execute("select * from vtocc_big b1, vtocc_big b2", {})
                count = 0
                while True:
                    row = cu.fetchone()
                    if row is None:
                        break
                    if count == 10:
                        self.check_row_10(row)
                    count += 1
                self.assertEqual(count, 10000)
Beispiel #13
0
      self.fail("Connection to shard %s replica failed with error %s" % (shard_names[self.shard_index], str(e)))
    self.replica_tablet.kill_vttablet()
    with self.assertRaises(dbexceptions.OperationalError):
      replica_conn._execute("select 1 from vt_insert_test", {})
    proc = self.replica_tablet.start_vttablet()
    try:
      results = replica_conn._execute("select 1 from vt_insert_test", {})
    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(db_type='replica', shard_index=self.shard_index)
    except Exception, e:
      self.fail("Connection to %s replica failed with error %s" % (shard_names[self.shard_index], str(e)))
    stream_cursor = cursor.StreamCursor(replica_conn)
    self.replica_tablet.kill_vttablet()
    with self.assertRaises(dbexceptions.OperationalError):
      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_tablet_restart_begin(self):
    try:
      master_conn = get_connection(db_type='master')
    except Exception, e:
Beispiel #14
0
        proc = self.replica_tablet.start_vttablet()
        try:
            results = replica_conn._execute('select 1 from vt_insert_test', {})
        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(db_type='replica',
                                          shard_index=self.shard_index)
        except Exception, e:
            self.fail('Connection to %s replica failed with error %s' %
                      (shard_names[self.shard_index], str(e)))
        stream_cursor = cursor.StreamCursor(replica_conn)
        self.replica_tablet.kill_vttablet()
        with self.assertRaises(dbexceptions.OperationalError):
            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_fail_stream_execute_initial(self):
        """Tests for app errors in the first stream execute response."""
        try: