List:Commits« Previous MessageNext Message »
From:Julio Casal Date:May 10 2011 11:01pm
Subject:bzr commit into connector-net-6.0 branch (julio.casal:872) Bug#58004
View as plain text  
#At file:///D:/Users/jcasalt/Dev/connector-net/6.0/ based on revid:julio.casal@stripped

  872 Julio Casal	2011-05-10
      Introduced a new unit test to ensure a commit will not timeout after a heavly load of inserts (MySQL bug #58004).

    modified:
      CHANGES
      MySql.Data/Tests/Source/Transactions.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2011-05-10 22:59:34 +0000
+++ b/CHANGES	2011-05-10 23:01:09 +0000
@@ -34,6 +34,7 @@
 - Introduced more detailed exceptions for invalid connection strings errors (MySQL bug#44654, MySQL bug#53076).
 - Introduced the real NUnit framework to the CF test suite and fixed issues on BaseTest to properly run with CF libraries. 
 - Modified MySql.Data.Entity.ProviderServices to use the correct schema definition file when server is 5.5 or greater (Oracle bug #12407444).
+- Introduced a new unit test to ensure a commit will not timeout after a heavly load of inserts (MySQL bug #58004).
 
 Version 6.0.7
 - Fix authorization popup after modifying stored procedure in VS (Bug #44715)

=== modified file 'MySql.Data/Tests/Source/Transactions.cs'
--- a/MySql.Data/Tests/Source/Transactions.cs	2009-09-01 01:00:37 +0000
+++ b/MySql.Data/Tests/Source/Transactions.cs	2011-05-10 23:01:09 +0000
@@ -24,6 +24,8 @@
 using NUnit.Framework;
 using System.Transactions;
 using System.Data.Common;
+using System.Diagnostics;
+using System.Text;
 
 namespace MySql.Data.MySqlClient.Tests
 {
@@ -420,5 +422,157 @@
             ReusingSameConnection(false, false);
       //      Assert.AreEqual(processes + 1, CountProcesses());
         }
+
+        /// <summary>
+        /// Ensures that a commit after heavy ammount of inserts does not timeout.
+        /// </summary>
+        [Test]
+        public void CommitDoesNotTimeout()
+        {
+            const int requiredNumberOfRuns = 1;
+            const int binarySize = 5000000;
+            const int requiredNumberOfRowsPerRun = 100;
+
+            Debug.WriteLine("Required Number Of Runs :" + requiredNumberOfRuns);
+            Debug.WriteLine("Required Number Of Rows Per Run :" + requiredNumberOfRowsPerRun);
+
+            suExecSQL("SET GLOBAL max_allowed_packet=64000000");
+
+            MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
+
+            using (MySqlConnection connection = new MySqlConnection(GetConnectionString(true)))
+            {
+                connection.Open();
+
+                using (MySqlCommand command = new MySqlCommand())
+                {
+                    command.Connection = connection;
+                    command.CommandType = CommandType.Text;
+                    command.CommandText = "DROP TABLE IF EXISTS test_timeout;";
+                    command.ExecuteNonQuery();
+
+                    StringBuilder sqlCommand = new StringBuilder(512);
+
+                    sqlCommand.Append("CREATE TABLE test_timeout (");
+                    sqlCommand.Append("identity INT NOT NULL auto_increment, ");
+                    sqlCommand.Append("a INT NOT NULL, ");
+                    sqlCommand.Append("b INT NOT NULL, ");
+                    sqlCommand.Append("c INT NOT NULL, ");
+                    sqlCommand.Append("binary_data LONGBLOB NOT NULL, ");
+                    sqlCommand.Append("PRIMARY KEY(identity), ");
+                    sqlCommand.Append("KEY `abc` (`a`,`b`, `c`) ");
+                    sqlCommand.Append(") TYPE = INNODB");
+
+                    command.CommandText = sqlCommand.ToString();
+                    command.ExecuteNonQuery();
+                }
+
+                for (int numberOfRuns = 0; numberOfRuns < requiredNumberOfRuns; ++numberOfRuns)
+                {
+                    using (MySqlTransaction transaction = connection.BeginTransaction())
+                    {
+                        Stopwatch stopwatch = Stopwatch.StartNew();
+
+                        using (MySqlCommand command = new MySqlCommand())
+                        {
+                            command.Connection = connection;
+                            command.CommandText = "INSERT INTO test_timeout VALUES (?f1, ?f2, ?f3, ?f4, ?f5)";
+                            command.Parameters.Add("?f1", MySqlDbType.Int32);
+                            command.Parameters.Add("?f2", MySqlDbType.Int32);
+                            command.Parameters.Add("?f3", MySqlDbType.Int32);
+                            command.Parameters.Add("?f4", MySqlDbType.Int32);
+                            command.Parameters.Add("?f5", MySqlDbType.LongBlob);
+                            command.CommandTimeout = 0;
+                            command.Prepare();
+
+
+                            byte[] buffer;
+
+                            using (MemoryStream stream = new MemoryStream())
+                            {
+                                using (BinaryWriter binary = new BinaryWriter(stream))
+                                {
+                                    int count = 0;
+
+                                    while (stream.Position < binarySize)
+                                    {
+                                        binary.Write(++count);
+                                    }
+                                }
+
+                                buffer = stream.ToArray();
+                            }
+
+                            for (int i = 0; i < requiredNumberOfRowsPerRun; ++i)
+                            {
+                                command.Parameters[1].Value = i;
+                                command.Parameters[2].Value = i;
+                                command.Parameters[3].Value = i;
+                                command.Parameters[4].Value = buffer;
+                                command.ExecuteNonQuery();
+                            }
+                        }
+
+                        transaction.Commit();
+
+                        Assert.IsNotNull(transaction);
+
+                        stopwatch.Stop();
+
+                        double seconds = stopwatch.Elapsed.TotalSeconds;
+                        double recordsPerSecond = requiredNumberOfRowsPerRun / seconds;
+
+                        StringBuilder sb = new StringBuilder();
+                        sb.AppendFormat("Truncate Result : Insert {0} Took {1:F4}; Per Second {2:F1} ",
+                        requiredNumberOfRowsPerRun, seconds, recordsPerSecond);
+
+                        Debug.WriteLine(sb.ToString());
+                    }
+
+                    using (MySqlCommand command = new MySqlCommand())
+                    {
+                        command.Connection = connection;
+                        command.CommandText = "SELECT * FROM test_timeout";
+
+                        Stopwatch stopwatch = Stopwatch.StartNew();
+                        int count = 0;
+
+                        using (MySqlDataReader reader = command.ExecuteReader())
+                        {
+                            int previous = -1;
+
+                            while (reader.Read())
+                            {
+                                int current = reader.GetInt32(0);
+                                Assert.Greater(current, previous);
+                                previous = current;
+
+                                ++count;
+                            }
+                        }
+
+                        stopwatch.Stop();
+
+                        double seconds = stopwatch.Elapsed.TotalSeconds;
+                        double recordsPerSecond = count / seconds;
+
+                        StringBuilder sb = new StringBuilder();
+                        sb.AppendFormat("Test Result : Select {0} Took {1:F4}; Per Second {2:F1} ",
+                        count, seconds, recordsPerSecond);
+
+                        Debug.WriteLine(sb.ToString());
+                    }
+
+                    using (MySqlCommand command = new MySqlCommand())
+                    {
+                        command.Connection = connection;
+                        command.CommandText = "TRUNCATE TABLE test_timeout";
+                        command.ExecuteNonQuery();
+                    }
+                }
+
+                MySqlConnection.ClearPool(connection);
+            }
+        }
     }
 }


Attachment: [text/bzr-bundle] bzr/julio.casal@oracle.com-20110510230109-vx214yqpmb21qk1e.bundle
Thread
bzr commit into connector-net-6.0 branch (julio.casal:872) Bug#58004Julio Casal11 May