[libagilejedi commit] r17 - in trunk: AjileJedi.MemcachedForMonorail AjileJedi.MemcachedForMonorail.Tests AjileJedi.Mem...

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 17, 2008, 1:41:03 PM4/17/08
to libagileje...@googlegroups.com
Author: Daniel.Pupek
Date: Thu Apr 17 10:40:17 2008
New Revision: 17

Added:
trunk/AjileJedi.MemcachedForMonorail/ARSessionItem.cs
Modified:
trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs
trunk/AjileJedi.MemcachedForMonorail/AjileJedi.MemcachedForMonorail.csproj
trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs

Log:
Started Adding the ActiveRecord portions.


Modified: trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs
==============================================================================
---
trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs (original)
+++
trunk/AjileJedi.MemcachedForMonorail.Tests/MemcachedSessionDictionaryTests.cs
Thu Apr 17 10:40:17 2008
@@ -17,13 +17,15 @@
public class MemcachedSessionDictionaryTests
{
private IDictionary<string,object> session;
+ private MemcachedClient client;


[SetUp]
public void Setup()
{
-
- session = new MemCachedSessionDictionary(Guid.NewGuid().ToString());
+ client = new MemcachedClient(MemCachedSessionDictionary.STR_Sessionstate);
+ session = new MemCachedSessionDictionary(Guid.NewGuid().ToString(),client);
+

}

@@ -33,6 +35,11 @@
session.Clear();
}

+
+
+ #region Standard Smoke Tests
+
+
[Test]
public void SetValueAndReadItTest()
{
@@ -41,7 +48,7 @@
session.Add(testKey, testValue);

Assert.AreEqual(testValue, (string)session[testKey]);
-
+

}

@@ -53,7 +60,7 @@
session.Add(testKey, testValue);

Assert.AreEqual(testValue, session[testKey], "RemoveValueTest
cannot continue. Setting Failed.");
-
+
session.Remove(testKey);

Assert.IsNull(session[testKey]);
@@ -65,7 +72,7 @@
{
TestingObject obj = new TestingObject();
obj.SomeString = "This is a test";
- session.Add("testobject",obj);
+ session.Add("testobject", obj);
obj = (TestingObject)session["testobject"];

Assert.AreEqual("This is a test", obj.SomeString);
@@ -78,7 +85,7 @@
{
Assert.Fail("Test Not Implemented");
}
-
+
[Test]
public void EnumerateAllKeys()
{
@@ -94,12 +101,12 @@
public void ClearTheSessionTest()
{
for (int i = 0; i < 100; i++)
- {
+ {
session.Add("testKey" + i.ToString(), "testValue");
Assert.AreEqual("testValue", session["testKey" + i.ToString()]);
- }
+ }
//Assert.AreEqual(100, session.Count, "the session value count is wrong.");
-
+
session.Clear();
//Assert.AreEqual(0, session.Count, "the session value count is wrong.");
for (int i = 0; i < 100; i++)
@@ -108,25 +115,44 @@
}


-
+

}
[Test]
public void UnsetItemReturnsNullTest()
{
-
+
Assert.IsNull(session["nonexistentkey"]);

}
+ #endregion
+
+ #region DB Persistence Tests

[Test]
+ public void SaveObjectAndClearMemcached()
+ {
+
+ TestingObject obj = new TestingObject();
+ session["testobject"] = obj;
+ client.FlushAll();
+ Assert.AreEqual(obj.SomeGuid, ((TestingObject)session["testobject"]).SomeGuid);
+
+
+ }
+ #endregion
+
+ #region Performance Tests
+
+
+ [Test(), Ignore()]
public void WhichTranscoderIsBest()
{
StoreThisType(typeof(TestingObject));

StoreThisType(typeof(string));

-
+

}
private static void StoreThisType(Type testtype)
@@ -144,13 +170,13 @@
MemcachedClient client;
client = new MemcachedClient(config);
long start = DateTime.Now.Ticks;
-
+

for (int i = 0; i < repeatFor; i++)
{
object obj;

- switch (Type.GetTypeCode( testtype))
+ switch (Type.GetTypeCode(testtype))
{
case TypeCode.String:
obj = Guid.NewGuid().ToString();
@@ -159,7 +185,7 @@
obj = FastActivator.CreateInstance(testtype);
break;
}
-
+
client.Store(StoreMode.Add, "test" + i.ToString(), obj);

}
@@ -194,6 +220,7 @@
Console.WriteLine();
client.FlushAll();
}
+#endregion

}
[Serializable]

Added: trunk/AjileJedi.MemcachedForMonorail/ARSessionItem.cs
==============================================================================
--- (empty file)
+++ trunk/AjileJedi.MemcachedForMonorail/ARSessionItem.cs Thu Apr 17
10:40:17 2008
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AgileJedi.MemcachedForMonorail
+{
+ /// <summary>
+ /// Used to persist session items to a database
+ /// </summary>
+ class ARSessionItem : Castle.ActiveRecord.ActiveRecordBase
+ {
+
+ private byte[] _ItemData;
+ [Castle.ActiveRecord.Property()]
+ public byte[] ItemData
+ {
+ get { return _ItemData; }
+ set { _ItemData = value; }
+ }
+
+ private object _Item;
+ public object Item
+ {
+ get { return _Item; }
+ set { _Item = value; }
+ }
+ }
+}

Modified: trunk/AjileJedi.MemcachedForMonorail/AjileJedi.MemcachedForMonorail.csproj
==============================================================================
---
trunk/AjileJedi.MemcachedForMonorail/AjileJedi.MemcachedForMonorail.csproj (original)
+++
trunk/AjileJedi.MemcachedForMonorail/AjileJedi.MemcachedForMonorail.csproj
Thu Apr 17 10:40:17 2008
@@ -7,7 +7,7 @@
<ProjectGuid>{3A85FAF5-AF28-490F-8C55-E100ED7370A4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>AjileJedi.MemcachedForMonorail</RootNamespace>
+ <RootNamespace>AgileJedi.MemcachedForMonorail</RootNamespace>
<AssemblyName>AgileJedi.MemcachedForMonorail</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -28,6 +28,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Castle.ActiveRecord, Version=1.0.3.0,
Culture=neutral, PublicKeyToken=407dd0808d44fbdc,
processorArchitecture=MSIL" />
<Reference Include="Castle.MonoRail.Framework, Version=1.0.3.0,
Culture=neutral, PublicKeyToken=407dd0808d44fbdc,
processorArchitecture=MSIL" />
<Reference Include="Enyim.Caching, Version=1.0.6.0,
Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -43,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="ARSessionItem.cs" />
<Compile Include="CustomSessionState\MemCacheSessionFactory.cs" />
<Compile Include="CustomSessionState\MemCachedSession.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

Modified: trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs
==============================================================================
---
trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs (original)
+++
trunk/AjileJedi.MemcachedForMonorail/CustomSessionState/MemCachedSession.cs
Thu Apr 17 10:40:17 2008
@@ -46,13 +46,19 @@
}

public MemCachedSessionDictionary(string sessionId, string configSection)
+ : this(sessionId, new Enyim.Caching.MemcachedClient(configSection))
+ {
+
+ }
+
+ public MemCachedSessionDictionary(string sessionId, MemcachedClient client)
+
{
_sessionId = sessionId;
- _mcClient = new Enyim.Caching.MemcachedClient(configSection);
+ _mcClient = client;
this._SessionTimeToLiveMinutes = 20;

}
-

#endregion

Reply all
Reply to author
Forward
0 new messages