MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:rburnett Date:May 26 2006 6:14pm
Subject:Connector/NET commit: r245 - in branches/1.0: . TestSuite mysqlclient
View as plain text  
Added:
   branches/1.0/TestSuite/Threading.cs
Modified:
   branches/1.0/CHANGES
   branches/1.0/TestSuite/BaseTest.cs
   branches/1.0/TestSuite/MySql.Data.Tests.csproj
   branches/1.0/mysqlclient/CharSetMap.cs
   branches/1.0/mysqlclient/Logger.cs
Log:
Bug #17106 MySql.Data.MySqlClient.CharSetMap.GetEncoding thread synchronization issue

Fixed this bug by using a static constructor on charsetmap.  (thanks to Frank Vera for the suggestion).
Also added LogInformation to Logger class.
The CharSetMap class now logs the fact that it is initializing the mapping array
Added the Threading test class for all test cases related to threading

Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES	2006-05-22 20:55:47 UTC (rev 244)
+++ branches/1.0/CHANGES	2006-05-26 18:14:17 UTC (rev 245)
@@ -12,6 +12,10 @@
     Bug #17814 Stored procedure fails unless DbType set explicitly [fixed]
     Bug #19294 IDataRecord.GetString method should return null for null values [fixed]
     Bug #13590 ExecuteScalar returns only Int64 regardless of actual SQL type [added test case]
+    Bug #19017 GetBytes Error [fixed]
+    Bug #19936 DataReader already open exception [fixed]
+    Bug #17106 MySql.Data.MySqlClient.CharSetMap.GetEncoding thread synchronization issue [fixed]
+    
 x-xx-05 - Version 1.0.7
 
     Bugs fixed or addressed

Modified: branches/1.0/TestSuite/BaseTest.cs
===================================================================
--- branches/1.0/TestSuite/BaseTest.cs	2006-05-22 20:55:47 UTC (rev 244)
+++ branches/1.0/TestSuite/BaseTest.cs	2006-05-26 18:14:17 UTC (rev 245)
@@ -37,17 +37,20 @@
 		protected string			host;
 		protected string			user;
 		protected string			password;
-		//protected string			nopassuser;
 		protected string			otherkeys;
 
 		public BaseTest() 
 		{
 			csAdditions = ";pooling=false";
-		}
+            user = "root";
+            password = "";
+            otherkeys = ConfigurationSettings.AppSettings["otherkeys"];
+        }
 
 		protected string GetConnectionString(bool includedb)
 		{
-			if (includedb)
+            host = ConfigurationSettings.AppSettings["host"];
+            if (includedb)
 				return String.Format("server={0};user id={1};password={2};database=test;" +
 					"persist security info=true;{3}{4}", host, user, password, otherkeys, csAdditions );
 			return String.Format("server={0};user id={1};password={2};" +
@@ -58,10 +61,6 @@
 		{
 			try 
 			{
-				host = ConfigurationSettings.AppSettings["host"];
-				user = "root";
-				password = "";
-				otherkeys = ConfigurationSettings.AppSettings["otherkeys"];
 				string connString = GetConnectionString(true);
 				conn = new MySqlConnection( connString );
 				conn.Open();
@@ -127,7 +126,7 @@
 		}
 
 		[TearDown]
-		protected void Teardown()
+		protected virtual void Teardown()
 		{
 		}
 

Modified: branches/1.0/TestSuite/MySql.Data.Tests.csproj
===================================================================
--- branches/1.0/TestSuite/MySql.Data.Tests.csproj	2006-05-22 20:55:47 UTC (rev 244)
+++ branches/1.0/TestSuite/MySql.Data.Tests.csproj	2006-05-26 18:14:17 UTC (rev 245)
@@ -160,6 +160,7 @@
     <Compile Include="Syntax.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Threading.cs" />
     <Compile Include="Transactions.cs">
       <SubType>Code</SubType>
     </Compile>

Added: branches/1.0/TestSuite/Threading.cs
===================================================================
--- branches/1.0/TestSuite/Threading.cs	2006-05-22 20:55:47 UTC (rev 244)
+++ branches/1.0/TestSuite/Threading.cs	2006-05-26 18:14:17 UTC (rev 245)
@@ -0,0 +1,133 @@
+// Copyright (C) 2004-2006 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL 
+// as it is applied to this software. View the full text of the 
+// exception in file EXCEPTIONS in the directory of this software 
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+
+using System;
+using MySql.Data.MySqlClient;
+using System.Data;
+using NUnit.Framework;
+using System.Threading;
+using System.Collections;
+using System.Diagnostics;
+
+namespace MySql.Data.MySqlClient.Tests
+{
+    class MyListener : TraceListener
+    {
+        private int numInits;
+
+        public MyListener()
+        {
+            numInits = 0;
+        }
+
+        public int NumInits
+        {
+            get { return numInits; }
+        }
+
+        public override void Write(string message)
+        {
+            if (message == "Initializing character set mapping array")
+                numInits++;
+        }
+
+        public override void WriteLine(string message)
+        {
+            if (message == "Initializing character set mapping array")
+                numInits++;
+        }
+    }
+
+	/// <summary>
+	/// Summary description for ConnectionTests.
+	/// </summary>
+	[TestFixture] 
+	public class ThreadingTests : BaseTest
+	{
+		[TestFixtureSetUp]
+		public void FixtureSetup()
+		{
+        }
+
+		[TestFixtureTearDown]
+		public void FixtureTearDown()
+		{
+        }
+
+        [SetUp]
+        protected override void Setup()
+        {
+        }
+
+        [TearDown]
+        protected override void Teardown()
+        {
+        }
+
+        private void MultipleThreadsWorker(object ev)
+        {
+            (ev as ManualResetEvent).WaitOne();
+
+            try
+            {
+                MySqlConnection c = new MySqlConnection(GetConnectionString(true));
+                c.Open();
+                c.Close();
+            }
+            catch (Exception ex)
+            {
+                Assert.Fail(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// Bug #17106 MySql.Data.MySqlClient.CharSetMap.GetEncoding thread synchronization issue
+        /// </summary>
+        [Test]
+        public void MultipleThreads()
+        {
+            MyListener myListener = new MyListener();
+            ManualResetEvent ev = new ManualResetEvent(false);
+            ArrayList threads = new ArrayList();
+            System.Diagnostics.Trace.Listeners.Add(myListener);
+
+            for (int i=0; i < 20; i++)
+            {
+                ParameterizedThreadStart ts = new ParameterizedThreadStart(MultipleThreadsWorker);
+                Thread t = new Thread(ts);
+                threads.Add(t);
+                t.Start(ev);
+            }
+            // now let the threads go
+            ev.Set();
+
+            // wait for the threads to end
+            int x = 0;
+            while (x < threads.Count)
+            {
+                while ((threads[x] as Thread).IsAlive)
+                    Thread.Sleep(50);
+                x++;
+            }
+            Assert.AreEqual(1, myListener.NumInits);
+        }
+    }
+
+}

Modified: branches/1.0/mysqlclient/CharSetMap.cs
===================================================================
--- branches/1.0/mysqlclient/CharSetMap.cs	2006-05-22 20:55:47 UTC (rev 244)
+++ branches/1.0/mysqlclient/CharSetMap.cs	2006-05-26 18:14:17 UTC (rev 245)
@@ -32,10 +32,12 @@
 	{
 		private static Hashtable	mapping;
 
-		// Declare a private ctor so a default one won't be made by the compiler
-		private CharSetMap() 
+        // we use a static constructor here since we only want to init
+        // the mapping once
+		static CharSetMap() 
 		{
-		}
+            InitializeMapping();
+        }
 
 		/// <summary>
 		/// Returns the text encoding for a given MySQL character set name
@@ -45,8 +47,6 @@
 		/// <returns>Encoding object for the given character set name</returns>
 		public static Encoding GetEncoding( DBVersion version, string CharSetName ) 
 		{
-			if (mapping == null )
-				InitializeMapping();
 			try 
 			{
 				if (! mapping.Contains( CharSetName ))
@@ -74,6 +74,7 @@
 		/// </summary>
 		private static void InitializeMapping()
 		{
+            Logger.LogInformation("Initializing character set mapping array");
 			LoadCharsetMap();
 		}
 

Modified: branches/1.0/mysqlclient/Logger.cs
===================================================================
--- branches/1.0/mysqlclient/Logger.cs	2006-05-22 20:55:47 UTC (rev 244)
+++ branches/1.0/mysqlclient/Logger.cs	2006-05-26 18:14:17 UTC (rev 245)
@@ -42,6 +42,11 @@
 			Trace.WriteLine( msg );
 		}
 
+        static public void LogInformation(string msg)
+        {
+            Trace.WriteLine(msg);
+        }
+
 		static public void LogException( Exception ex )
 		{
 			string msg = String.Format("EXCEPTION: " + ex.Message);

Thread
Connector/NET commit: r245 - in branches/1.0: . TestSuite mysqlclientrburnett26 May