lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccurr...@apache.org
Subject git commit: LUCENENET-518 - Changed exceptions to be serializable and added unit tests to verify Contributor: Simon Fenton <simon.fenton@justgiving.com>
Date Wed, 27 Mar 2013 19:50:21 GMT
Updated Branches:
  refs/heads/master 02b2430ad -> c7f9cab71


LUCENENET-518 - Changed exceptions to be serializable and added unit tests to verify
Contributor: Simon Fenton <simon.fenton@justgiving.com>


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/c7f9cab7
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/c7f9cab7
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/c7f9cab7

Branch: refs/heads/master
Commit: c7f9cab71f2ec241fcaa07e3d6fc8eb0a4807992
Parents: 02b2430
Author: ccurrens <currens.chris@gmail.com>
Authored: Wed Mar 27 12:49:58 2013 -0700
Committer: ccurrens <currens.chris@gmail.com>
Committed: Wed Mar 27 12:49:58 2013 -0700

----------------------------------------------------------------------
 src/core/Index/CorruptIndexException.cs         |   46 ++-
 src/core/Index/FieldReaderException.cs          |  130 +++---
 src/core/Index/MergePolicy.cs                   |   53 ++-
 src/core/Index/StaleReaderException.cs          |   44 ++-
 src/core/QueryParser/ParseException.cs          |    9 +-
 src/core/QueryParser/QueryParser.cs             |   20 +-
 src/core/QueryParser/TokenMgrError.cs           |    6 +
 src/core/Search/BooleanQuery.cs                 |   22 +
 src/core/Search/FieldCacheImpl.cs               |   31 ++-
 src/core/Search/TimeLimitingCollector.cs        |  392 +++++++++---------
 src/core/Store/LockObtainFailedException.cs     |   39 ++-
 src/core/Store/LockReleaseFailedException.cs    |   42 ++-
 src/core/Store/NoSuchDirectoryException.cs      |   39 ++-
 test/core/Lucene.Net.Test.csproj                |    1 +
 test/core/Support/TestExceptionSerialization.cs |  102 +++++
 test/core/Util/LocalizedTestCase.cs             |   10 +-
 16 files changed, 651 insertions(+), 335 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Index/CorruptIndexException.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/CorruptIndexException.cs b/src/core/Index/CorruptIndexException.cs
index d846cb3..7ff9cef 100644
--- a/src/core/Index/CorruptIndexException.cs
+++ b/src/core/Index/CorruptIndexException.cs
@@ -16,21 +16,39 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.Index
 {
-	
-	/// <summary> This exception is thrown when Lucene detects
-	/// an inconsistency in the index.
-	/// </summary>
-	[Serializable]
-	public class CorruptIndexException:System.IO.IOException
-	{
-		public CorruptIndexException(String message):base(message)
-		{
-		}
-		public CorruptIndexException(String message, Exception exp):base(message, exp)
-		{
-		}
-	}
+    /// <summary> This exception is thrown when Lucene detects
+    /// an inconsistency in the index.
+    /// </summary>
+    [Serializable]
+    public class CorruptIndexException : System.IO.IOException
+    {
+        //
+        // For guidelines regarding the creation of new exception types, see
+        //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
+        // and
+        //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
+        //
+
+        public CorruptIndexException()
+        {
+        }
+
+        public CorruptIndexException(string message) : base(message)
+        {
+        }
+
+        public CorruptIndexException(string message, Exception inner) : base(message, inner)
+        {
+        }
+
+        protected CorruptIndexException(
+                SerializationInfo info,
+                StreamingContext context) : base(info, context)
+        {
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Index/FieldReaderException.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/FieldReaderException.cs b/src/core/Index/FieldReaderException.cs
index 7654fb4..816d67b 100644
--- a/src/core/Index/FieldReaderException.cs
+++ b/src/core/Index/FieldReaderException.cs
@@ -16,75 +16,81 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.Index
 {
-	
-	/// <summary> 
-	/// 
-	/// 
-	/// </summary>
-	[Serializable]
-	public class FieldReaderException:System.SystemException
-	{
-		/// <summary> Constructs a new runtime exception with <c>null</c> as
its
-		/// detail message.  The cause is not initialized, and may subsequently be
+    /// <summary> 
+    /// 
+    /// 
+    /// </summary>
+    [Serializable]
+    public class FieldReaderException:System.SystemException
+    {
+        /// <summary> Constructs a new runtime exception with <c>null</c>
as its
+        /// detail message.  The cause is not initialized, and may subsequently be
         /// initialized by a call to <see cref="Exception.InnerException" />.
-		/// </summary>
-		public FieldReaderException()
-		{
-		}
-		
-		/// <summary> Constructs a new runtime exception with the specified cause and a
-		/// detail message of <tt>(cause==null &#63; null : cause.toString())</tt>
-		/// (which typically contains the class and detail message of
-		/// <tt>cause</tt>).  
-		/// <p/>
-		/// This constructor is useful for runtime exceptions
-		/// that are little more than wrappers for other throwables.
-		/// 
-		/// </summary>
-		/// <param name="cause">the cause (which is saved for later retrieval by the
+        /// </summary>
+        public FieldReaderException()
+        {
+        }
+        
+        /// <summary> Constructs a new runtime exception with the specified cause and
a
+        /// detail message of <tt>(cause==null &#63; null : cause.toString())</tt>
+        /// (which typically contains the class and detail message of
+        /// <tt>cause</tt>).  
+        /// <p/>
+        /// This constructor is useful for runtime exceptions
+        /// that are little more than wrappers for other throwables.
+        /// 
+        /// </summary>
+        /// <param name="cause">the cause (which is saved for later retrieval by the
         /// <see cref="Exception.InnerException" />).  (A <tt>null</tt>
value is
-		/// permitted, and indicates that the cause is nonexistent or
-		/// unknown.)
-		/// </param>
-		/// <since> 1.4
-		/// </since>
-		public FieldReaderException(System.Exception cause):base((cause == null)?null:cause.Message,
cause)
-		{
-		}
-		
-		/// <summary> Constructs a new runtime exception with the specified detail message.
-		/// The cause is not initialized, and may subsequently be initialized by a
+        /// permitted, and indicates that the cause is nonexistent or
+        /// unknown.)
+        /// </param>
+        /// <since> 1.4
+        /// </since>
+        public FieldReaderException(System.Exception cause):base((cause == null)?null:cause.Message,
cause)
+        {
+        }
+        
+        /// <summary> Constructs a new runtime exception with the specified detail
message.
+        /// The cause is not initialized, and may subsequently be initialized by a
         /// call to <see cref="Exception.InnerException" />.
-		/// 
-		/// </summary>
-		/// <param name="message">the detail message. The detail message is saved for
+        /// 
+        /// </summary>
+        /// <param name="message">the detail message. The detail message is saved for
         /// later retrieval by the <see cref="Exception.Message" /> method.
-		/// </param>
-		public FieldReaderException(System.String message):base(message)
-		{
-		}
-		
-		/// <summary> Constructs a new runtime exception with the specified detail message
and
-		/// cause.  <p/>Note that the detail message associated with
-		/// <c>cause</c> is <i>not</i> automatically incorporated in
-		/// this runtime exception's detail message.
-		/// 
-		/// </summary>
-		/// <param name="message">the detail message (which is saved for later retrieval
+        /// </param>
+        public FieldReaderException(System.String message):base(message)
+        {
+        }
+        
+        /// <summary> Constructs a new runtime exception with the specified detail
message and
+        /// cause.  <p/>Note that the detail message associated with
+        /// <c>cause</c> is <i>not</i> automatically incorporated
in
+        /// this runtime exception's detail message.
+        /// 
+        /// </summary>
+        /// <param name="message">the detail message (which is saved for later retrieval
         /// by the <see cref="Exception.Message" /> method).
-		/// </param>
-		/// <param name="cause">  the cause (which is saved for later retrieval by the
+        /// </param>
+        /// <param name="cause">  the cause (which is saved for later retrieval by
the
         /// <see cref="Exception.InnerException" /> method).  (A <tt>null</tt>
value is
-		/// permitted, and indicates that the cause is nonexistent or
-		/// unknown.)
-		/// </param>
-		/// <since> 1.4
-		/// </since>
-		public FieldReaderException(System.String message, System.Exception cause):base(message,
cause)
-		{
-		}
-	}
+        /// permitted, and indicates that the cause is nonexistent or
+        /// unknown.)
+        /// </param>
+        /// <since> 1.4
+        /// </since>
+        public FieldReaderException(System.String message, System.Exception cause):base(message,
cause)
+        {
+        }
+
+        protected FieldReaderException(
+                SerializationInfo info,
+                StreamingContext context) : base(info, context)
+        {
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Index/MergePolicy.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/MergePolicy.cs b/src/core/Index/MergePolicy.cs
index 59b4817..cdc2060 100644
--- a/src/core/Index/MergePolicy.cs
+++ b/src/core/Index/MergePolicy.cs
@@ -17,6 +17,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Runtime.Serialization;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Index
@@ -218,6 +219,24 @@ namespace Lucene.Net.Index
 				this.dir = dir;
 			}
 
+		    public MergeException()
+		    {
+            }
+
+		    public MergeException(string message) : base(message)
+		    {
+            }
+
+		    public MergeException(string message, Exception ex) : base(message, ex)
+		    {
+            }
+
+            protected MergeException(
+	                SerializationInfo info,
+	                StreamingContext context) : base(info, context)
+	        {
+	        }
+
 		    /// <summary>Returns the <see cref="Directory" /> of the index that hit
 		    /// the exception. 
 		    /// </summary>
@@ -226,17 +245,29 @@ namespace Lucene.Net.Index
 		        get { return dir; }
 		    }
 		}
-		
-		[Serializable]
-		public class MergeAbortedException:System.IO.IOException
-		{
-			public MergeAbortedException():base("merge is aborted")
-			{
-			}
-			public MergeAbortedException(System.String message):base(message)
-			{
-			}
-		}
+
+	    [Serializable]
+        public class MergeAbortedException : System.IO.IOException
+	    {
+            public MergeAbortedException()
+                : base("merge is aborted")
+	        {
+	        }
+
+	        public MergeAbortedException(string message) : base(message)
+	        {
+	        }
+
+	        public MergeAbortedException(string message, Exception inner) : base(message, inner)
+	        {
+	        }
+
+	        protected MergeAbortedException(
+	                SerializationInfo info,
+	                StreamingContext context) : base(info, context)
+	        {
+	        }
+	    }
 		
 		protected internal IndexWriter writer;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Index/StaleReaderException.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/StaleReaderException.cs b/src/core/Index/StaleReaderException.cs
index 271070f..f2e5760 100644
--- a/src/core/Index/StaleReaderException.cs
+++ b/src/core/Index/StaleReaderException.cs
@@ -16,24 +16,34 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.Index
 {
-	
-	/// <summary> This exception is thrown when an <see cref="IndexReader" />
-	/// tries to make changes to the index (via <see cref="IndexReader.DeleteDocument" />
-	///, <see cref="IndexReader.UndeleteAll" />
-	/// or <see cref="IndexReader.SetNorm(int,string,float)" />)
-	/// but changes have already been committed to the index
-	/// since this reader was instantiated.  When this happens
-	/// you must open a new reader on the current index to make
-	/// the changes.
-	/// </summary>
-	[Serializable]
-	public class StaleReaderException:System.IO.IOException
-	{
-		public StaleReaderException(System.String message):base(message)
-		{
-		}
-	}
+    /// <summary> This exception is thrown when an <see cref="IndexReader" />
+    /// tries to make changes to the index (via <see cref="IndexReader.DeleteDocument"
/>
+    ///, <see cref="IndexReader.UndeleteAll" />
+    /// or <see cref="IndexReader.SetNorm(int,string,float)" />)
+    /// but changes have already been committed to the index
+    /// since this reader was instantiated.  When this happens
+    /// you must open a new reader on the current index to make
+    /// the changes.
+    /// </summary>
+    [Serializable]
+    public class StaleReaderException : System.IO.IOException
+    {
+        public StaleReaderException(string message) : base(message)
+        {
+        }
+
+        public StaleReaderException(string message, Exception inner) : base(message, inner)
+        {
+        }
+
+        protected StaleReaderException(
+                SerializationInfo info,
+                StreamingContext context) : base(info, context)
+        {
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/QueryParser/ParseException.cs
----------------------------------------------------------------------
diff --git a/src/core/QueryParser/ParseException.cs b/src/core/QueryParser/ParseException.cs
index ab0fbca..39a18fd 100644
--- a/src/core/QueryParser/ParseException.cs
+++ b/src/core/QueryParser/ParseException.cs
@@ -19,11 +19,11 @@
 /* JavaCCOptions:KEEP_LINE_COL=null */
 
 using System;
+using System.Runtime.Serialization;
 using Lucene.Net.Support;
 
 namespace Lucene.Net.QueryParsers
 {
-	
 	/// <summary> This exception is thrown when parse errors are encountered.
 	/// You can explicitly create objects of this exception type by
 	/// calling the method generateParseException in the generated
@@ -147,6 +147,13 @@ namespace Lucene.Net.QueryParsers
         {
 	        specialConstructor = false;
         }
+
+        protected ParseException(
+                SerializationInfo info,
+                StreamingContext context)
+            : base(info, context)
+        {
+        }
 		
 		/// <summary> This variable determines which constructor was used to create
 		/// this object and thereby affects the semantics of the

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/QueryParser/QueryParser.cs
----------------------------------------------------------------------
diff --git a/src/core/QueryParser/QueryParser.cs b/src/core/QueryParser/QueryParser.cs
index e58ecea..1e04228 100644
--- a/src/core/QueryParser/QueryParser.cs
+++ b/src/core/QueryParser/QueryParser.cs
@@ -24,6 +24,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
 using System.IO;
+using System.Runtime.Serialization;
 using System.Text;
 using Lucene.Net.Analysis;
 using Lucene.Net.Analysis.Tokenattributes;
@@ -1862,8 +1863,25 @@ namespace Lucene.Net.QueryParsers
         }
 
         [Serializable]
-        private sealed class LookaheadSuccess : System.Exception
+        public class LookaheadSuccess : Exception
         {
+            public LookaheadSuccess()
+            {
+            }
+
+            public LookaheadSuccess(string message) : base(message)
+            {
+            }
+
+            public LookaheadSuccess(string message, Exception inner) : base(message, inner)
+            {
+            }
+
+            protected LookaheadSuccess(
+                    SerializationInfo info,
+                    StreamingContext context) : base(info, context)
+            {
+            }
         }
 
         private LookaheadSuccess jj_ls = new LookaheadSuccess();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/QueryParser/TokenMgrError.cs
----------------------------------------------------------------------
diff --git a/src/core/QueryParser/TokenMgrError.cs b/src/core/QueryParser/TokenMgrError.cs
index d69f88c..1f95636 100644
--- a/src/core/QueryParser/TokenMgrError.cs
+++ b/src/core/QueryParser/TokenMgrError.cs
@@ -19,6 +19,7 @@
 /* JavaCCOptions: */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.QueryParsers
 {
@@ -164,6 +165,11 @@ namespace Lucene.Net.QueryParsers
 		public TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, System.String
errorAfter, char curChar, int reason):this(LexicalError(EOFSeen, lexState, errorLine, errorColumn,
errorAfter, curChar), reason)
 		{
 		}
+
+	    public TokenMgrError(SerializationInfo info, StreamingContext context)
+	            : base(info, context)
+	    {
+	    }
 	}
     /* JavaCC - OriginalChecksum=1c94e13236c7e0121e49427992341ee3 (do not edit this line)
*/
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Search/BooleanQuery.cs
----------------------------------------------------------------------
diff --git a/src/core/Search/BooleanQuery.cs b/src/core/Search/BooleanQuery.cs
index 22b6371..dee4def 100644
--- a/src/core/Search/BooleanQuery.cs
+++ b/src/core/Search/BooleanQuery.cs
@@ -17,6 +17,7 @@
 
 using System;
 using System.Collections;
+using System.Runtime.Serialization;
 using Lucene.Net.Index;
 using Lucene.Net.Support;
 using IndexReader = Lucene.Net.Index.IndexReader;
@@ -77,6 +78,27 @@ namespace Lucene.Net.Search
 				}
 				
 			}
+
+
+		    public TooManyClauses()
+		    {
+		        
+		    }
+
+		    public TooManyClauses(string message) : base(message)
+		    {
+		        
+		    }
+
+		    public TooManyClauses(string message, Exception inner) : base(message, inner)
+		    {
+		        
+		    }
+
+            public TooManyClauses(SerializationInfo info, StreamingContext context)
+		            : base(info, context)
+		    {
+		    }
 		}
 
 	    /// <summary>Gets or sets the maximum number of clauses permitted, 1024 by default.

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Search/FieldCacheImpl.cs
----------------------------------------------------------------------
diff --git a/src/core/Search/FieldCacheImpl.cs b/src/core/Search/FieldCacheImpl.cs
index 6c24dcc..87195ae 100644
--- a/src/core/Search/FieldCacheImpl.cs
+++ b/src/core/Search/FieldCacheImpl.cs
@@ -19,6 +19,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Runtime.Serialization;
 using Lucene.Net.Support;
 using NumericField = Lucene.Net.Documents.NumericField;
 using IndexReader = Lucene.Net.Index.IndexReader;
@@ -165,14 +166,38 @@ namespace Lucene.Net.Search
                 get { return value; }
             }
         }
-        
+
         /// <summary> Hack: When thrown from a Parser (NUMERIC_UTILS_* ones), this
stops
         /// processing terms and returns the current FieldCache
         /// array.
         /// </summary>
         [Serializable]
-        internal sealed class StopFillCacheException:System.SystemException
-        {
+        internal sealed class StopFillCacheException : SystemException
+        {
+            //
+            // For guidelines regarding the creation of new exception types, see
+            //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
+            // and
+            //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
+            //
+
+            public StopFillCacheException()
+            {
+            }
+
+            public StopFillCacheException(string message) : base(message)
+            {
+            }
+
+            public StopFillCacheException(string message, Exception inner) : base(message,
inner)
+            {
+            }
+
+            protected StopFillCacheException(
+                    SerializationInfo info,
+                    StreamingContext context) : base(info, context)
+            {
+            }
         }
         
         /// <summary>Expert: Internal cache. </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Search/TimeLimitingCollector.cs
----------------------------------------------------------------------
diff --git a/src/core/Search/TimeLimitingCollector.cs b/src/core/Search/TimeLimitingCollector.cs
index 2917df3..11ce614 100644
--- a/src/core/Search/TimeLimitingCollector.cs
+++ b/src/core/Search/TimeLimitingCollector.cs
@@ -16,137 +16,157 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 using Lucene.Net.Support;
 using IndexReader = Lucene.Net.Index.IndexReader;
 
 namespace Lucene.Net.Search
 {
-	
-	/// <summary> The <see cref="TimeLimitingCollector" /> is used to timeout search
requests that
-	/// take longer than the maximum allowed search time limit. After this time is
-	/// exceeded, the search thread is stopped by throwing a
-	/// <see cref="TimeExceededException" />.
-	/// </summary>
-	public class TimeLimitingCollector:Collector
-	{
-		private void  InitBlock()
-		{
-			greedy = DEFAULT_GREEDY;
-		}
-		
-		/// <summary> Default timer resolution.</summary>
-		/// <seealso cref="Resolution">
-		/// </seealso>
-		public const int DEFAULT_RESOLUTION = 20;
-		
-		/// <summary> Default for <see cref="IsGreedy()" />.</summary>
-		/// <seealso cref="IsGreedy()">
-		/// </seealso>
-		public bool DEFAULT_GREEDY = false;
-		
-		private static uint resolution = DEFAULT_RESOLUTION;
-		
-		private bool greedy;
-		
-		private sealed class TimerThread:ThreadClass
-		{
-			
-			// NOTE: we can avoid explicit synchronization here for several reasons:
-			// * updates to volatile long variables are atomic
-			// * only single thread modifies this value
-			// * use of volatile keyword ensures that it does not reside in
-			//   a register, but in main memory (so that changes are visible to
-			//   other threads).
-			// * visibility of changes does not need to be instantanous, we can
-			//   afford losing a tick or two.
-			//
-			// See section 17 of the Java Language Specification for details.
-			private volatile uint time = 0;
-			
-			/// <summary> TimerThread provides a pseudo-clock service to all searching
-			/// threads, so that they can count elapsed time with less overhead
-			/// than repeatedly calling System.currentTimeMillis.  A single
-			/// thread should be created to be used for all searches.
-			/// </summary>
-			internal TimerThread():base("TimeLimitedCollector timer thread")
-			{
-				this.IsBackground = true;
-			}
-			
-			override public void  Run()
-			{
-				while (true)
-				{
-					// TODO: Use System.nanoTime() when Lucene moves to Java SE 5.
-					time += Lucene.Net.Search.TimeLimitingCollector.resolution;
-					System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * Lucene.Net.Search.TimeLimitingCollector.resolution));
-					
-				}
-			}
-
-		    /// <summary> Get the timer value in milliseconds.</summary>
-		    public long Milliseconds
-		    {
-		        get { return time; }
-		    }
-		}
-		
-		/// <summary>Thrown when elapsed search time exceeds allowed search time. </summary>
-		[Serializable]
-		public class TimeExceededException:System.SystemException
-		{
-			private long timeAllowed;
-			private long timeElapsed;
-			private int lastDocCollected;
-			internal TimeExceededException(long timeAllowed, long timeElapsed, int lastDocCollected):base("Elapsed
time: " + timeElapsed + "Exceeded allowed search time: " + timeAllowed + " ms.")
-			{
-				this.timeAllowed = timeAllowed;
-				this.timeElapsed = timeElapsed;
-				this.lastDocCollected = lastDocCollected;
-			}
-
-		    /// <summary>Returns allowed time (milliseconds). </summary>
-		    public virtual long TimeAllowed
-		    {
-		        get { return timeAllowed; }
-		    }
-
-		    /// <summary>Returns elapsed time (milliseconds). </summary>
-		    public virtual long TimeElapsed
-		    {
-		        get { return timeElapsed; }
-		    }
-
-		    /// <summary>Returns last doc(absolute doc id) that was collected when the search
time exceeded. </summary>
-		    public virtual int LastDocCollected
-		    {
-		        get { return lastDocCollected; }
-		    }
-		}
-		
-		// Declare and initialize a single static timer thread to be used by
-		// all TimeLimitedCollector instances.  The JVM assures that
-		// this only happens once.
-		private static readonly TimerThread TIMER_THREAD = new TimerThread();
-		
-		private long t0;
-		private long timeout;
-		private Collector collector;
+    
+    /// <summary> The <see cref="TimeLimitingCollector" /> is used to timeout
search requests that
+    /// take longer than the maximum allowed search time limit. After this time is
+    /// exceeded, the search thread is stopped by throwing a
+    /// <see cref="TimeExceededException" />.
+    /// </summary>
+    public class TimeLimitingCollector:Collector
+    {
+        private void  InitBlock()
+        {
+            greedy = DEFAULT_GREEDY;
+        }
+        
+        /// <summary> Default timer resolution.</summary>
+        /// <seealso cref="Resolution">
+        /// </seealso>
+        public const int DEFAULT_RESOLUTION = 20;
+        
+        /// <summary> Default for <see cref="IsGreedy()" />.</summary>
+        /// <seealso cref="IsGreedy()">
+        /// </seealso>
+        public bool DEFAULT_GREEDY = false;
+        
+        private static uint resolution = DEFAULT_RESOLUTION;
+        
+        private bool greedy;
+        
+        private sealed class TimerThread:ThreadClass
+        {
+            
+            // NOTE: we can avoid explicit synchronization here for several reasons:
+            // * updates to volatile long variables are atomic
+            // * only single thread modifies this value
+            // * use of volatile keyword ensures that it does not reside in
+            //   a register, but in main memory (so that changes are visible to
+            //   other threads).
+            // * visibility of changes does not need to be instantanous, we can
+            //   afford losing a tick or two.
+            //
+            // See section 17 of the Java Language Specification for details.
+            private volatile uint time = 0;
+            
+            /// <summary> TimerThread provides a pseudo-clock service to all searching
+            /// threads, so that they can count elapsed time with less overhead
+            /// than repeatedly calling System.currentTimeMillis.  A single
+            /// thread should be created to be used for all searches.
+            /// </summary>
+            internal TimerThread():base("TimeLimitedCollector timer thread")
+            {
+                this.IsBackground = true;
+            }
+            
+            override public void  Run()
+            {
+                while (true)
+                {
+                    // TODO: Use System.nanoTime() when Lucene moves to Java SE 5.
+                    time += Lucene.Net.Search.TimeLimitingCollector.resolution;
+                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000
* Lucene.Net.Search.TimeLimitingCollector.resolution));
+                    
+                }
+            }
+
+            /// <summary> Get the timer value in milliseconds.</summary>
+            public long Milliseconds
+            {
+                get { return time; }
+            }
+        }
+
+        /// <summary>Thrown when elapsed search time exceeds allowed search time. </summary>
+        [Serializable]
+        public class TimeExceededException:System.SystemException
+        {
+            private long timeAllowed;
+            private long timeElapsed;
+            private int lastDocCollected;
+            internal TimeExceededException(long timeAllowed, long timeElapsed, int lastDocCollected):base("Elapsed
time: " + timeElapsed + "Exceeded allowed search time: " + timeAllowed + " ms.")
+            {
+                this.timeAllowed = timeAllowed;
+                this.timeElapsed = timeElapsed;
+                this.lastDocCollected = lastDocCollected;
+            }
+
+            internal TimeExceededException()
+            {
+            }
+
+            public TimeExceededException(string message) : base(message)
+            {
+            }
+
+            public TimeExceededException(string message, Exception inner)
+                : base(message, inner)
+            {
+            }
+
+            protected TimeExceededException(
+                    SerializationInfo info,
+                    StreamingContext context) : base(info, context)
+            {
+            }
+
+            /// <summary>Returns allowed time (milliseconds). </summary>
+            public virtual long TimeAllowed
+            {
+                get { return timeAllowed; }
+            }
+
+            /// <summary>Returns elapsed time (milliseconds). </summary>
+            public virtual long TimeElapsed
+            {
+                get { return timeElapsed; }
+            }
+
+            /// <summary>Returns last doc(absolute doc id) that was collected when
the search time exceeded. </summary>
+            public virtual int LastDocCollected
+            {
+                get { return lastDocCollected; }
+            }
+        }
+        
+        // Declare and initialize a single static timer thread to be used by
+        // all TimeLimitedCollector instances.  The JVM assures that
+        // this only happens once.
+        private static readonly TimerThread TIMER_THREAD = new TimerThread();
+        
+        private long t0;
+        private long timeout;
+        private Collector collector;
 
         private int docBase;
-		
-		/// <summary> Create a TimeLimitedCollector wrapper over another <see cref="Collector"
/> with a specified timeout.</summary>
-		/// <param name="collector">the wrapped <see cref="Collector" />
-		/// </param>
-		/// <param name="timeAllowed">max time allowed for collecting hits after which <see
cref="TimeExceededException" /> is thrown
-		/// </param>
-		public TimeLimitingCollector(Collector collector, long timeAllowed)
-		{
-			InitBlock();
-			this.collector = collector;
-			t0 = TIMER_THREAD.Milliseconds;
-			this.timeout = t0 + timeAllowed;
-		}
+        
+        /// <summary> Create a TimeLimitedCollector wrapper over another <see cref="Collector"
/> with a specified timeout.</summary>
+        /// <param name="collector">the wrapped <see cref="Collector" />
+        /// </param>
+        /// <param name="timeAllowed">max time allowed for collecting hits after which
<see cref="TimeExceededException" /> is thrown
+        /// </param>
+        public TimeLimitingCollector(Collector collector, long timeAllowed)
+        {
+            InitBlock();
+            this.collector = collector;
+            t0 = TIMER_THREAD.Milliseconds;
+            this.timeout = t0 + timeAllowed;
+        }
 
         /// <summary>
         /// Gets or sets the timer resolution.
@@ -162,73 +182,73 @@ namespace Lucene.Net.Search
         /// then it can take up to 20 milliseconds for the change to have effect.</item>
         /// </list> 
         /// </summary>
-	    public static long Resolution
-	    {
-	        get { return resolution; }
+        public static long Resolution
+        {
+            get { return resolution; }
             set
             {
                 // 5 milliseconds is about the minimum reasonable time for a Object.wait(long)
call.
                 resolution = (uint)System.Math.Max(value, 5);
             }
-	    }
-
-	    /// <summary> Checks if this time limited collector is greedy in collecting the
last hit.
-	    /// A non greedy collector, upon a timeout, would throw a <see cref="TimeExceededException"
/> 
-	    /// without allowing the wrapped collector to collect current doc. A greedy one would

-	    /// first allow the wrapped hit collector to collect current doc and only then 
-	    /// throw a <see cref="TimeExceededException" />.
-	    /// </summary>
-	    public virtual bool IsGreedy
-	    {
-	        get { return greedy; }
-	        set { this.greedy = value; }
-	    }
-
-	    /// <summary> Calls <see cref="Collector.Collect(int)" /> on the decorated
<see cref="Collector" />
-		/// unless the allowed time has passed, in which case it throws an exception.
-		/// 
-		/// </summary>
-		/// <throws>  TimeExceededException </throws>
-		/// <summary>           if the time allowed has exceeded.
-		/// </summary>
-		public override void  Collect(int doc)
-		{
-			long time = TIMER_THREAD.Milliseconds;
-			if (timeout < time)
-			{
-				if (greedy)
-				{
-					//System.out.println(this+"  greedy: before failing, collecting doc: "+doc+"  "+(time-t0));
-					collector.Collect(doc);
-				}
-				//System.out.println(this+"  failing on:  "+doc+"  "+(time-t0));
+        }
+
+        /// <summary> Checks if this time limited collector is greedy in collecting
the last hit.
+        /// A non greedy collector, upon a timeout, would throw a <see cref="TimeExceededException"
/> 
+        /// without allowing the wrapped collector to collect current doc. A greedy one would

+        /// first allow the wrapped hit collector to collect current doc and only then 
+        /// throw a <see cref="TimeExceededException" />.
+        /// </summary>
+        public virtual bool IsGreedy
+        {
+            get { return greedy; }
+            set { this.greedy = value; }
+        }
+
+        /// <summary> Calls <see cref="Collector.Collect(int)" /> on the decorated
<see cref="Collector" />
+        /// unless the allowed time has passed, in which case it throws an exception.
+        /// 
+        /// </summary>
+        /// <throws>  TimeExceededException </throws>
+        /// <summary>           if the time allowed has exceeded.
+        /// </summary>
+        public override void  Collect(int doc)
+        {
+            long time = TIMER_THREAD.Milliseconds;
+            if (timeout < time)
+            {
+                if (greedy)
+                {
+                    //System.out.println(this+"  greedy: before failing, collecting doc:
"+doc+"  "+(time-t0));
+                    collector.Collect(doc);
+                }
+                //System.out.println(this+"  failing on:  "+doc+"  "+(time-t0));
                 throw new TimeExceededException(timeout - t0, time - t0, docBase + doc);
-			}
-			//System.out.println(this+"  collecting: "+doc+"  "+(time-t0));
-			collector.Collect(doc);
-		}
-		
-		public override void  SetNextReader(IndexReader reader, int base_Renamed)
-		{
-			collector.SetNextReader(reader, base_Renamed);
+            }
+            //System.out.println(this+"  collecting: "+doc+"  "+(time-t0));
+            collector.Collect(doc);
+        }
+        
+        public override void  SetNextReader(IndexReader reader, int base_Renamed)
+        {
+            collector.SetNextReader(reader, base_Renamed);
             this.docBase = base_Renamed;
-		}
-		
-		public override void  SetScorer(Scorer scorer)
-		{
-			collector.SetScorer(scorer);
-		}
-
-	    public override bool AcceptsDocsOutOfOrder
-	    {
-	        get { return collector.AcceptsDocsOutOfOrder; }
-	    }
-
-	    static TimeLimitingCollector()
-		{
-			{
-				TIMER_THREAD.Start();
-			}
-		}
-	}
+        }
+        
+        public override void  SetScorer(Scorer scorer)
+        {
+            collector.SetScorer(scorer);
+        }
+
+        public override bool AcceptsDocsOutOfOrder
+        {
+            get { return collector.AcceptsDocsOutOfOrder; }
+        }
+
+        static TimeLimitingCollector()
+        {
+            {
+                TIMER_THREAD.Start();
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Store/LockObtainFailedException.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/LockObtainFailedException.cs b/src/core/Store/LockObtainFailedException.cs
index 065b362..2cfd733 100644
--- a/src/core/Store/LockObtainFailedException.cs
+++ b/src/core/Store/LockObtainFailedException.cs
@@ -16,26 +16,37 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.Store
 {
-	
-	/// <summary> This exception is thrown when the <c>write.lock</c>
-	/// could not be acquired.  This
-	/// happens when a writer tries to open an index
-	/// that another writer already has open.
-	/// </summary>
-	/// <seealso cref="Lock.Obtain(long)">
-	/// </seealso>
-	[Serializable]
-	public class LockObtainFailedException:System.IO.IOException
-	{
-		public LockObtainFailedException(System.String message):base(message)
-		{
-		}
+    
+    /// <summary> This exception is thrown when the <c>write.lock</c>
+    /// could not be acquired.  This
+    /// happens when a writer tries to open an index
+    /// that another writer already has open.
+    /// </summary>
+    /// <seealso cref="Lock.Obtain(long)">
+    /// </seealso>
+    [Serializable]
+    public class LockObtainFailedException:System.IO.IOException
+    {
+        public LockObtainFailedException(System.String message):base(message)
+        {
+        }
 
         public LockObtainFailedException(System.String message, System.Exception ex) : base(message,
ex)
         {
         }
+
+        internal LockObtainFailedException()
+        {
+        }
+
+        protected LockObtainFailedException(
+                SerializationInfo info,
+                StreamingContext context) : base(info, context)
+        {
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Store/LockReleaseFailedException.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/LockReleaseFailedException.cs b/src/core/Store/LockReleaseFailedException.cs
index 121283e..58d311e 100644
--- a/src/core/Store/LockReleaseFailedException.cs
+++ b/src/core/Store/LockReleaseFailedException.cs
@@ -16,20 +16,36 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.Store
 {
-	
-	/// <summary> This exception is thrown when the <c>write.lock</c>
-	/// could not be released.
-	/// </summary>
-	/// <seealso cref="Lock.Release()">
-	/// </seealso>
-	[Serializable]
-	public class LockReleaseFailedException:System.IO.IOException
-	{
-		public LockReleaseFailedException(System.String message):base(message)
-		{
-		}
-	}
+    
+    /// <summary> This exception is thrown when the <c>write.lock</c>
+    /// could not be released.
+    /// </summary>
+    /// <seealso cref="Lock.Release()">
+    /// </seealso>
+    [Serializable]
+    public class LockReleaseFailedException:System.IO.IOException
+    {
+        public LockReleaseFailedException(System.String message):base(message)
+        {
+        }
+        
+        internal LockReleaseFailedException()
+        {
+        }
+
+        internal LockReleaseFailedException(string message, Exception inner)
+            : base(message, inner)
+        {
+        }
+
+        protected LockReleaseFailedException(
+                SerializationInfo info,
+                StreamingContext context) : base(info, context)
+        {
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/src/core/Store/NoSuchDirectoryException.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/NoSuchDirectoryException.cs b/src/core/Store/NoSuchDirectoryException.cs
index c3b01ae..b3ff9f4 100644
--- a/src/core/Store/NoSuchDirectoryException.cs
+++ b/src/core/Store/NoSuchDirectoryException.cs
@@ -16,19 +16,34 @@
  */
 
 using System;
+using System.Runtime.Serialization;
 
 namespace Lucene.Net.Store
 {
-	
-	/// <summary> This exception is thrown when you try to list a
-	/// non-existent directory.
-	/// </summary>
-	
-	[Serializable]
-	public class NoSuchDirectoryException:System.IO.FileNotFoundException
-	{
-		public NoSuchDirectoryException(System.String message):base(message)
-		{
-		}
-	}
+    
+    /// <summary> This exception is thrown when you try to list a
+    /// non-existent directory.
+    /// </summary>
+
+    [Serializable]
+    public class NoSuchDirectoryException : System.IO.FileNotFoundException
+    {
+        public NoSuchDirectoryException()
+        {
+        }
+
+        public NoSuchDirectoryException(string message) : base(message)
+        {
+        }
+
+        public NoSuchDirectoryException(string message, Exception inner) : base(message,
inner)
+        {
+        }
+
+        protected NoSuchDirectoryException(
+                SerializationInfo info,
+                StreamingContext context) : base(info, context)
+        {
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/test/core/Lucene.Net.Test.csproj
----------------------------------------------------------------------
diff --git a/test/core/Lucene.Net.Test.csproj b/test/core/Lucene.Net.Test.csproj
index 39eeacd..6f64384 100644
--- a/test/core/Lucene.Net.Test.csproj
+++ b/test/core/Lucene.Net.Test.csproj
@@ -506,6 +506,7 @@
     <Compile Include="SupportClassException.cs" />
     <Compile Include="Support\BigObject.cs" />
     <Compile Include="Support\CollisionTester.cs" />
+    <Compile Include="Support\TestExceptionSerialization.cs" />
     <Compile Include="Support\TestWeakDictionaryBehavior.cs" />
     <Compile Include="Support\TestWeakDictionary.cs" />
     <Compile Include="Support\SmallObject.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/test/core/Support/TestExceptionSerialization.cs
----------------------------------------------------------------------
diff --git a/test/core/Support/TestExceptionSerialization.cs b/test/core/Support/TestExceptionSerialization.cs
new file mode 100644
index 0000000..8691d9d
--- /dev/null
+++ b/test/core/Support/TestExceptionSerialization.cs
@@ -0,0 +1,102 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+using Lucene.Net.Store;
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+    [TestFixture]
+    public class TestExceptionSerialization
+    {
+        public IEnumerable<object> ExceptionTestData 
+        {
+            get
+            {
+                return typeof(NoSuchDirectoryException).Assembly.GetTypes().Where(t =>
typeof(Exception).IsAssignableFrom(t)).Cast<object>();
+            }
+        }
+
+        [Test]
+        public void NoSuchDirectoryExceptionCanBeDeserialized()
+        {
+            var exception = new NoSuchDirectoryException("Message text");
+            Assert.That(TypeCanSerialize(exception));
+        }
+
+        [Test]
+        public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type
luceneException)
+        {
+            var instance = TryInstantiate(luceneException);
+            Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}",
luceneException.FullName));
+        }
+
+        private static bool TypeCanSerialize<T>(T exception)
+        {
+            T clone;
+
+            try
+            {
+                var binaryFormatter = new BinaryFormatter();
+                using (var serializationStream = new MemoryStream())
+                {
+                    binaryFormatter.Serialize(serializationStream, exception);
+                    serializationStream.Seek(0, SeekOrigin.Begin);
+                    clone = (T)binaryFormatter.Deserialize(serializationStream);
+                }
+            }
+            catch (SerializationException)
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+        private static object TryInstantiate(Type type)
+        {
+            object instance = null;
+            try
+            {
+                instance = Activator.CreateInstance(type, new object[] { "A message" });
+            }
+            catch (MissingMethodException)
+            {
+                try
+                {
+                    instance = Activator.CreateInstance(type);
+                }
+                catch (MissingMethodException)
+                {
+                    Assert.Fail("Can't instantiate type {0}, it's missing the necessary constructors.",
type.FullName);
+                }
+            }
+            return instance;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7f9cab7/test/core/Util/LocalizedTestCase.cs
----------------------------------------------------------------------
diff --git a/test/core/Util/LocalizedTestCase.cs b/test/core/Util/LocalizedTestCase.cs
index b815686..998bde6 100644
--- a/test/core/Util/LocalizedTestCase.cs
+++ b/test/core/Util/LocalizedTestCase.cs
@@ -113,9 +113,17 @@ namespace Lucene.Net.Util
                         {
                             test.Invoke(this, null);
                         }
-                        catch (Exception)
+                        catch (Exception e)
                         {
+                            // Culture hsb fails on Windows 8.   see http://stackoverflow.com/questions/12482772/net-4-5-datetime-format-convert-bug-with-upper-sorbian-culture
+                            if(t.Name.StartsWith("hsb", StringComparison.InvariantCulture)
&& Environment.OSVersion.Version == new System.Version(6, 2, 9200, 0))
+                            {
+                                continue;
+                            }
+
                             Console.Out.WriteLine("Test failure of '" + test.Name + "' occurred
under a different Locale " + t.Name);
+
+                            Console.Out.WriteLine(e);
                             throw;
                         }
                     }


Mime
View raw message