Permalink
Browse files

Performance monitor factory bugfix.

  • Loading branch information...
1 parent fa13a23 commit f6dd44f6a8e4b427f590c4dfb764909e853f82b2 @enyim committed Dec 29, 2010
@@ -52,7 +52,7 @@ public TFactory CreateInstance()
var type = this.Factory;
if (type == null)
{
- if (this.IsOptional)
+ if (this.IsOptional || !this.ElementInformation.IsPresent)
return null;
throw new ConfigurationErrorsException("factory must be defined");
@@ -113,7 +113,15 @@ ITranscoder IMembaseClientConfiguration.CreateTranscoder()
IPerformanceMonitor IMembaseClientConfiguration.CreatePerformanceMonitor()
{
- return this.PerformanceMonitorFactory.CreateInstance().Create(this.Servers.Bucket);
+ var pmf = this.PerformanceMonitorFactory;
+ if (pmf.ElementInformation.IsPresent)
+ {
+ var f = pmf.CreateInstance();
+ if (f != null)
+ return f.Create(this.Servers.Bucket);
+ }
+
+ return null;
}
NetworkCredential IMembaseClientConfiguration.Credentials
@@ -34,7 +34,6 @@
<add address="192.168.2.160" port="11211" />
<add address="192.168.2.162" port="11211" />
</servers>
- <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" />
</memcached>
</enyim.com>
@@ -119,23 +118,21 @@
<add address="192.168.2.160" port="11211" />
<add address="192.168.2.162" port="11211" />
</servers>
- <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" />
</binaryConfig>
<textConfig protocol="Text">
<servers>
- <add address="192.168.2.160" port="11211" />
- <add address="192.168.2.162" port="11211" />
+ <add address="192.168.2.2" port="11211" />
+ <!--<add address="192.168.2.162" port="11211" />-->
</servers>
- <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" />
</textConfig>
<validConfig>
<servers>
<add address="192.168.2.160" port="20002" />
<add address="192.168.2.162" port="20004" />
</servers>
- <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" />
+ <socketPool />
</validConfig>
<!--<invalidConfig>
@@ -133,6 +133,16 @@ public void ProgrammaticConfigurationTestWithDefaults()
}
[TestCase]
+ public void TestPerfMonNull()
+ {
+ Assert.IsNull(((IMemcachedClientConfiguration)ConfigurationManager.GetSection("test/validConfig")).CreatePerformanceMonitor());
+ Assert.IsNull(((IMembaseClientConfiguration)ConfigurationManager.GetSection("test/membase")).CreatePerformanceMonitor());
+
+ Assert.IsNull(((IMemcachedClientConfiguration)new Enyim.Caching.Configuration.MemcachedClientConfiguration()).CreatePerformanceMonitor());
+ Assert.IsNull(((IMembaseClientConfiguration)new Membase.Configuration.MembaseClientConfiguration()).CreatePerformanceMonitor());
+ }
+
+ [TestCase]
public void TestPerfMonByMembaseFactory()
{
var config = ConfigurationManager.GetSection("test/membasePerfMon") as IMembaseClientConfiguration;
@@ -73,6 +73,8 @@ public void GetObjectTest()
Assert.AreEqual(td2.FieldB, "World", "Object was corrupted.");
Assert.AreEqual(td2.FieldC, 19810619, "Object was corrupted.");
Assert.AreEqual(td2.FieldD, true, "Object was corrupted.");
+ Assert.Catch(() => client.Get((string)null));
+ Assert.Catch(() => client.Get(String.Empty));
}
}

0 comments on commit f6dd44f

Please sign in to comment.