Skip to content

Commit

Permalink
Merge pull request #115 from SyndARn/TestingSimpleActor
Browse files Browse the repository at this point in the history
Clearing a dictionary
  • Loading branch information
SyndARn committed Apr 28, 2020
2 parents 1e97aa0 + b5ae77b commit cacbaa8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
21 changes: 21 additions & 0 deletions ARnActorSolution/TestActor/Collection/DictionaryActorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,26 @@ public void AsEnumerableTest()
Assert.AreEqual("[1, 1]", first.ToString());
});
}

[TestMethod()]
public void ClearTest()
{
TestLauncherActor.Test(() =>
{
var act = new DictionaryActor<string, int>();
Assert.IsNotNull(act);
act.AddKeyValue("1", 1);
act.AddKeyValue("2", 2);
act.AddKeyValue("3", 3);
act.AddKeyValue("4", 4);
var future = act.GetKeyValue("1");
var result = future.Result();
Assert.IsTrue(result.Item1);
Assert.AreEqual(1, result.Item3);
act.Clear();
var nofuture = act.GetKeyValue("1");
Assert.IsFalse(nofuture.Result().Item1);
});
}
}
}
4 changes: 2 additions & 2 deletions ARnActorSolution/TestActor/Util/TestLauncherActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public static void Test(TestContext testContext, Action action, int timeOutMS)
catch (Exception e)
{
launcher.fLauncherException = e;
launcher.Fail();
if (testContext != null)
{
testContext.WriteLine(e.Message);
testContext.WriteLine(e.StackTrace);
}
throw;
launcher.Fail();
// throw;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Actor.Util
public class DictionaryBehavior<TKey, TValue> : Behaviors, IDictionaryActor<TKey, TValue>
{
private readonly Dictionary<TKey, TValue> _dico = new Dictionary<TKey, TValue>();
public enum DictionaryBehaviorOrder {clear };

public DictionaryBehavior()
{
Expand All @@ -24,10 +25,17 @@ public DictionaryBehavior()
{
a.SendMessage(_dico.AsEnumerable<KeyValuePair<TKey, TValue>>());
});
Behavior<DictionaryBehaviorOrder> bhv5 = new Behavior<DictionaryBehaviorOrder>
(
o => o == DictionaryBehaviorOrder.clear,
o => _dico.Clear()
) ;

AddBehavior(bhv1);
AddBehavior(bhv2);
AddBehavior(bhv3);
AddBehavior(bhv4);
AddBehavior(bhv5);
}

public void AddKeyValue(TKey key, TValue value)
Expand All @@ -53,6 +61,11 @@ public void RemoveKey(TKey key)
{
LinkedActor.SendMessage(key);
}

public void Clear()
{
LinkedActor.SendMessage(DictionaryBehaviorOrder.clear);
}
}

public class DictionaryActor<TKey, TValue> : BaseActor, IDictionaryActor<TKey, TValue>
Expand Down Expand Up @@ -85,5 +98,10 @@ public void RemoveKey(TKey key)
{
return _serviceDictionary.AsEnumerable();
}

public void Clear()
{
_serviceDictionary.Clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void RemoveKey(TKey key)
return future;
}

public void Clear()
{
throw new NotImplementedException();
}
}

public class DistributedDictionaryBehaviors<TKey, TValue> : Behaviors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IDictionaryActor<TKey, TValue>
IFuture<bool, TKey, TValue> GetKeyValue(TKey key);
void RemoveKey(TKey key);
IFuture<IEnumerable<KeyValuePair<TKey, TValue>>> AsEnumerable();
void Clear();
}
}

0 comments on commit cacbaa8

Please sign in to comment.