Skip to content

Commit

Permalink
stashing reference equality
Browse files Browse the repository at this point in the history
added test
  • Loading branch information
rogeralsing committed Sep 19, 2015
1 parent f4bb06a commit 884330d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/core/Akka.TestKit/Internal/BlockingQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ IEnumerator IEnumerable.GetEnumerator()
public object SyncRoot { get { throw new NotImplementedException(); } }

public bool IsSynchronized { get { return false; } }



}
}
}
Expand Down
79 changes: 78 additions & 1 deletion src/core/Akka.Tests/Actor/Stash/ActorWithStashSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,85 @@ public StateObj(TestKitBase testKit)
public TestBarrier Finished;
public TestLatch ExpectedException;
}
}

[Fact]
public void An_actor_should_not_throw_an_exception_if_sent_two_messages_with_same_value_different_reference()
{
_state.ExpectedException = new TestLatch();
var stasher = ActorOf<StashEverythingActor>("stashing-actor");
stasher.Tell(new CustomMessageOverrideEquals("A"));
stasher.Tell(new CustomMessageOverrideEquals("A"));

// NOTE:
// here we should test for no exception thrown..
// but I don't know how....
}

public class CustomMessageOverrideEquals
{

public CustomMessageOverrideEquals(string cargo)
{
Cargo = cargo;
}
public override int GetHashCode()
{
return base.GetHashCode() ^ 314;
}
public override bool Equals(System.Object obj)
{
// If parameter is null return false.
if (obj == null)
{
return false;
}

// If parameter cannot be cast to Point return false.
CustomMessageOverrideEquals p = obj as CustomMessageOverrideEquals;
if ((System.Object)p == null)
{
return false;
}

// Return true if the fields match:
return (Cargo == p.Cargo);
}

public bool Equals(CustomMessageOverrideEquals p)
{
// If parameter is null return false:
if ((object)p == null)
{
return false;
}

// Return true if the fields match:
return (Cargo == p.Cargo);
}
public static bool operator ==(CustomMessageOverrideEquals a, CustomMessageOverrideEquals b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}

// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null))
{
return false;
}

// Return true if the fields match:
return (a.Cargo == b.Cargo);
}

public static bool operator !=(CustomMessageOverrideEquals a, CustomMessageOverrideEquals b)
{
return !(a == b);
}
public string Cargo { get; private set; }
}
}
}

2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Stash/Internal/AbstractStash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Stash()
if(_theStash.Count > 0)
{
var lastEnvelope = _theStash.Last.Value;
if(lastEnvelope.Message.Equals(currMsg) && lastEnvelope.Sender == sender)
if(ReferenceEquals(lastEnvelope.Message,currMsg) && lastEnvelope.Sender == sender)
throw new IllegalActorStateException(string.Format("Can't stash the same message {0} more than once", currMsg));
}
if(_capacity <= 0 || _theStash.Count < _capacity)
Expand Down

0 comments on commit 884330d

Please sign in to comment.