Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix on force return value flag. Fixes #47 #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Infinispan.Hotrod.Core.XUnitTest/DefaultCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ public async void PutTest()
await _cache.Put(key2, "chlorine");
Assert.Equal(initialSize + 2, await _cache.Size());
Assert.Equal("chlorine", await _cache.Get(key2));

_cache.ForceReturnValue=true;
String key3 = UniqueKey.NextKey();
String oldVal = await _cache.Put(key3, "oxygen");
Assert.Null(oldVal);
oldVal = await _cache.Put(key3, "sodium");
Assert.Equal("oxygen", oldVal);
}

[Fact]
Expand Down Expand Up @@ -417,6 +424,32 @@ public async void PutAllTest()
Assert.Equal("v3", await _cache.Get(key3));
}


[Fact]
public async void PutIfAbsentTest()
{
String key1 = UniqueKey.NextKey();
Int32 initialSize = await _cache.Size();

await _cache.PutIfAbsent(key1, "boron");
Assert.Equal(initialSize + 1, await _cache.Size());
Assert.Equal("boron", await _cache.Get(key1));

await _cache.PutIfAbsent(key1, "chlorine");
Assert.Equal(initialSize + 1, await _cache.Size());
Assert.Equal("boron", await _cache.Get(key1));

_cache.ForceReturnValue = true;
String key2 = UniqueKey.NextKey();
String oldVal = await _cache.PutIfAbsent(key2, "boron2");
Assert.Equal(initialSize + 2, await _cache.Size());
Assert.Null(oldVal);
Assert.Equal("boron2", await _cache.Get(key2));
oldVal = await _cache.PutIfAbsent(key2, "chlorine2");
Assert.Equal(initialSize + 2, await _cache.Size());
Assert.Equal(oldVal, await _cache.Get(key2));
}

// [Test]
// public void ContainsValueTest()
// {
Expand Down
2 changes: 1 addition & 1 deletion src/InfinispanCommands/PUTIFABSENT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal override void Execute(CommandContext ctx, InfinispanClient client, Pipe
}
public override Result OnReceive(InfinispanRequest request, ResponseStream stream)
{
if ((request.Command.Flags & 0x01) == 1)
if ((request.Command.Flags & 0x01) == 1 && request.ResponseStatus == 0x04)
{
PrevValue = ValueMarshaller.unmarshall(Codec.readArray(stream));
return new Result { Status = ResultStatus.Completed, ResultType = ResultType.Object };
Expand Down
4 changes: 2 additions & 2 deletions src/Marshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public StringMarshaller(Encoding enc = null)
}
public override byte[] marshall(string t)
{
return t == null ? null : Encoding.GetBytes(t);
return ((t == null) || (t.Length==0)) ? null : Encoding.GetBytes(t);
}
public override string unmarshall(byte[] buff)
{
return buff == null ? null : Encoding.GetString(buff);
return ((buff == null) || (buff.Length==0)) ? null : Encoding.GetString(buff);
}
}
}
Loading