You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2007/09/12 22:58:40 UTC
svn commit: r575073 - in /incubator/lucene.net/trunk/C#/src:
Lucene.Net/Store/FSDirectory.cs Lucene.Net/Store/NativeFSLockFactory.cs
Lucene.Net/Store/SimpleFSLockFactory.cs Lucene.Net/SupportClass.cs
Test/Store/TestLockFactory.cs
Author: aroush
Date: Wed Sep 12 13:58:40 2007
New Revision: 575073
URL: http://svn.apache.org/viewvc?rev=575073&view=rev
Log:
Fix: LUCENENET-96 "NUnit test for Lucene.Net.Store.TestLockFactory.TestLockClassProperty"
Modified:
incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs
incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/NativeFSLockFactory.cs
incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs
incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/FSDirectory.cs?rev=575073&r1=575072&r2=575073&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/FSDirectory.cs Wed Sep 12 13:58:40 2007
@@ -332,7 +332,7 @@
try
{
- lockFactory = (LockFactory) System.Activator.CreateInstance(c);
+ lockFactory = (LockFactory) System.Activator.CreateInstance(c, true);
}
catch (System.UnauthorizedAccessException e)
{
@@ -342,9 +342,18 @@
{
throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory");
}
- catch (System.Exception)
+ catch (System.Exception ex)
{
- throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName);
+ throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName + "\nDetails:" + ex.Message);
+ }
+
+ if (lockFactory is NativeFSLockFactory)
+ {
+ ((NativeFSLockFactory) lockFactory).SetLockDir(path);
+ }
+ else if (lockFactory is SimpleFSLockFactory)
+ {
+ ((SimpleFSLockFactory) lockFactory).SetLockDir(path);
}
}
else
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/NativeFSLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/NativeFSLockFactory.cs?rev=575073&r1=575072&r2=575073&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/NativeFSLockFactory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/NativeFSLockFactory.cs Wed Sep 12 13:58:40 2007
@@ -137,6 +137,38 @@
AcquireTestLock();
}
+ /// <summary>
+ /// </summary>
+ internal NativeFSLockFactory()
+ {
+ lockDir = null;
+ }
+
+ /// <summary>
+ /// Set the lock directory. This is package-private and is
+ /// only used externally by FSDirectory when creating this
+ /// LockFactory via the System property
+ /// org.apache.lucene.store.FSDirectoryLockFactoryClass.
+ /// </summary>
+ /// <param name="lockDir"></param>
+ internal void SetLockDir(System.IO.FileInfo lockDir)
+ {
+ this.lockDir = lockDir;
+ if (lockDir != null)
+ {
+ // Ensure that lockDir exists and is a directory.
+ if (!lockDir.Exists)
+ {
+ if (System.IO.Directory.CreateDirectory(lockDir.FullName) == null)
+ throw new System.IO.IOException("Cannot create directory: " + lockDir.FullName);
+ }
+ else if (!new System.IO.DirectoryInfo(lockDir.FullName).Exists)
+ {
+ throw new System.IO.IOException("Found regular file where directory expected: " + lockDir.FullName);
+ }
+ }
+ }
+
public override Lock MakeLock(System.String lockName)
{
lock (this)
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/SimpleFSLockFactory.cs?rev=575073&r1=575072&r2=575073&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs Wed Sep 12 13:58:40 2007
@@ -56,6 +56,38 @@
lockDir = new System.IO.FileInfo(lockDirName);
Init(lockDir);
}
+
+ /// <summary>
+ /// </summary>
+ internal SimpleFSLockFactory()
+ {
+ lockDir = null;
+ }
+
+ /// <summary>
+ /// Set the lock directory. This is package-private and is
+ /// only used externally by FSDirectory when creating this
+ /// LockFactory via the System property
+ /// org.apache.lucene.store.FSDirectoryLockFactoryClass.
+ /// </summary>
+ /// <param name="lockDir"></param>
+ internal void SetLockDir(System.IO.FileInfo lockDir)
+ {
+ this.lockDir = lockDir;
+ if (lockDir != null)
+ {
+ // Ensure that lockDir exists and is a directory.
+ if (!lockDir.Exists)
+ {
+ if (System.IO.Directory.CreateDirectory(lockDir.FullName) == null)
+ throw new System.IO.IOException("Cannot create directory: " + lockDir.FullName);
+ }
+ else if (!new System.IO.DirectoryInfo(lockDir.FullName).Exists)
+ {
+ throw new System.IO.IOException("Found regular file where directory expected: " + lockDir.FullName);
+ }
+ }
+ }
protected internal virtual void Init(System.IO.FileInfo lockDir)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/SupportClass.cs?rev=575073&r1=575072&r2=575073&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Wed Sep 12 13:58:40 2007
@@ -686,6 +686,38 @@
/// </summary>
public class AppSettings
{
+ static System.Collections.Specialized.ListDictionary settings = new System.Collections.Specialized.ListDictionary();
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="key"></param>
+ /// <param name="defValue"></param>
+ public static void Set(System.String key, int defValue)
+ {
+ settings[key] = defValue;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="key"></param>
+ /// <param name="defValue"></param>
+ public static void Set(System.String key, long defValue)
+ {
+ settings[key] = defValue;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="Key"></param>
+ /// <param name="Value"></param>
+ public static void Set(System.String key, System.String defValue)
+ {
+ settings[key] = defValue;
+ }
+
/// <summary>
///
/// </summary>
@@ -694,6 +726,11 @@
/// <returns></returns>
public static int Get(System.String key, int defValue)
{
+ if (settings[key] != null)
+ {
+ return (int) settings[key];
+ }
+
System.String theValue = System.Configuration.ConfigurationSettings.AppSettings.Get(key);
if (theValue == null)
{
@@ -710,6 +747,11 @@
/// <returns></returns>
public static long Get(System.String key, long defValue)
{
+ if (settings[key] != null)
+ {
+ return (long) settings[key];
+ }
+
System.String theValue = System.Configuration.ConfigurationSettings.AppSettings.Get(key);
if (theValue == null)
{
@@ -726,6 +768,11 @@
/// <returns></returns>
public static System.String Get(System.String key, System.String defValue)
{
+ if (settings[key] != null)
+ {
+ return (System.String) settings[key];
+ }
+
System.String theValue = System.Configuration.ConfigurationSettings.AppSettings.Get(key);
if (theValue == null)
{
@@ -811,7 +858,11 @@
byte[] Uncompress(byte[] input);
}
+#if SHARP_ZIP_LIB
+ private static ICompressionAdapter compressionAdapter = new Lucene.Net.Index.Compression.SharpZipLibAdapter();
+#else
private static ICompressionAdapter compressionAdapter;
+#endif
public static byte[] Uncompress(byte[] input)
{
Modified: incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Store/TestLockFactory.cs?rev=575073&r1=575072&r2=575073&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Store/TestLockFactory.cs Wed Sep 12 13:58:40 2007
@@ -218,21 +218,46 @@
[Test]
public virtual void TestLockClassProperty()
{
- Assert.Fail("TestLockClassProperty() needs conversion to C#");
-
System.String indexDirName = "index.TestLockFactory3";
+ String prpName = "Lucene.Net.Store.FSDirectoryLockFactoryClass";
- //System.Configuration.ConfigurationSettings.AppSettings.Set("Lucene.Net.Store.FSDirectoryLockFactoryClass", "Lucene.Net.Store.NoLockFactory");
-
- IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
-
- Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
-
- // Put back to the correct default for subsequent tests:
- // System.clearProperty("Lucene.Net.Store.FSDirectoryLockFactoryClass");
- //System.Configuration.ConfigurationSettings.AppSettings.Set("Lucene.Net.Store.FSDirectoryLockFactoryClass", "");
-
- writer.Close();
+ try
+ {
+ // NoLockFactory:
+ SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.NoLockFactory");
+ IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()),
+ "FSDirectory did not use correct LockFactory.\nExpected: " + SupportClass.AppSettings.Get(prpName, "") + "\nGot: " + writer.GetDirectory().GetLockFactory().GetType().ToString());
+ writer.Close();
+
+ // SingleInstanceLockFactory:
+ SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.SingleInstanceLockFactory");
+ writer = writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ Assert.IsTrue(typeof(SingleInstanceLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()),
+ "FSDirectory did not use correct LockFactory.\nExpected: " + prpName + "\nGot: " + writer.GetDirectory().GetLockFactory().GetType().ToString());
+ writer.Close();
+
+ // NativeFSLockFactory:
+ SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.NativeFSLockFactory");
+ writer = writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ Assert.IsTrue(typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()),
+ "FSDirectory did not use correct LockFactory.\nExpected: " + prpName + "\nGot: " + writer.GetDirectory().GetLockFactory().GetType().ToString());
+ writer.Close();
+
+ // SimpleFSLockFactory:
+ SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.SimpleFSLockFactory");
+ writer = writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
+ Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()),
+ "FSDirectory did not use correct LockFactory.\nExpected: " + prpName + "\nGot: " + writer.GetDirectory().GetLockFactory().GetType().ToString());
+ writer.Close();
+ }
+ finally
+ {
+ // Put back to the correct default for subsequent tests:
+ // System.clearProperty("Lucene.Net.Store.FSDirectoryLockFactoryClass");
+ SupportClass.AppSettings.Set(prpName, "");
+ }
+
// Cleanup
RmDir(indexDirName);
}