Skip to content

Commit

Permalink
Fix some Tsavorite.tests to use SpanByteAndMemory.AsReadOnlySpan()
Browse files Browse the repository at this point in the history
Fix some 'format' whitespace issues
Minor other Tsavorite.test cleanup, mostly related to removal of RUMDAsync
  • Loading branch information
TedHartMS committed Jun 4, 2024
1 parent 87375f9 commit 8837a1b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 82 deletions.
5 changes: 3 additions & 2 deletions libs/storage/Tsavorite/cs/test/ConcurrentCounterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Licensed under the MIT license.

using NUnit.Framework;
using Tsavorite.core;

namespace Tsavorite.core.Tests
namespace Tsavorite.test
{
[TestFixture]
public class ConcurrentCounterTests
Expand Down Expand Up @@ -75,7 +76,7 @@ public void Increment_WithMinValue_IncreasesCounterValue()
}

[Test]
public void IncrementndTotal_WithMultipleThreads_ReturnsCorrectValue()
public void IncrementedTotal_WithMultipleThreads_ReturnsCorrectValue()
{
// Arrange
var numThreads = 10;
Expand Down
4 changes: 2 additions & 2 deletions libs/storage/Tsavorite/cs/test/LargeObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public async ValueTask LargeObjectTest([Values] CheckpointType checkpointType)
new LogSettings { LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, PageSizeBits = 21, MemorySizeBits = 26 },
new CheckpointSettings { CheckpointDir = MethodTestDir },
new SerializerSettings<MyKey, MyLargeValue> { keySerializer = () => new MyKeySerializer(), valueSerializer = () => new MyLargeValueSerializer() }))
{
{
store.Recover(token);

using (var session = store.NewSession<MyInput, MyLargeOutput, Empty, MyLargeFunctions>(new MyLargeFunctions()))
{
{
var bContext = session.BasicContext;

for (int keycnt = 0; keycnt < numOps; keycnt++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// Licensed under the MIT license.

using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using Tsavorite.core;

namespace Tsavorite.test.LowMem
namespace Tsavorite.test.LowMemory
{
[TestFixture]
public class LowMemTests
public class LowMemoryTests
{
IDevice log;
TsavoriteKV<long, long> store1;
Expand Down Expand Up @@ -97,7 +96,7 @@ public void LowMemConcurrentUpsertRMWReadTest([Values] bool completeSync)
{
var status = bContext1.RMW(ref key, ref key);
if (status.IsPending && (++numPending % 256) == 0)
{
{
bContext1.CompletePending(wait: true);
numPending = 0;
}
Expand All @@ -111,7 +110,7 @@ public void LowMemConcurrentUpsertRMWReadTest([Values] bool completeSync)
{
var (status, output) = bContext1.Read(key);
if (!status.IsPending)
{
{
++numCompleted;
Assert.IsTrue(status.Found, $"{status}");
Assert.AreEqual(key + key, output);
Expand Down
2 changes: 1 addition & 1 deletion libs/storage/Tsavorite/cs/test/ObjectRecoveryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using NUnit.Framework;
using Tsavorite.core;

namespace Tsavorite.test.recovery.objectstore
namespace Tsavorite.test.recovery.objects
{
internal struct StructTuple<T1, T2>
{
Expand Down
2 changes: 1 addition & 1 deletion libs/storage/Tsavorite/cs/test/ObjectRecoveryTestTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading;
using Tsavorite.core;

namespace Tsavorite.test.recovery.objectstore
namespace Tsavorite.test.recovery.objects
{
public class AdId : ITsavoriteEqualityComparer<AdId>
{
Expand Down
10 changes: 5 additions & 5 deletions libs/storage/Tsavorite/cs/test/ReadCacheChainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ unsafe void runReadThread(int tid)

Assert.IsTrue(status.Found, $"tid {tid}, key {ii}, {status}, wasPending {false}, pt 1");
Assert.IsNotNull(output.Memory, $"tid {tid}, key {ii}, wasPending {false}, pt 2");
long value = BitConverter.ToInt64(output.Memory.Memory.Span);
long value = BitConverter.ToInt64(output.AsReadOnlySpan());
Assert.AreEqual(ii, value % valueAdd, $"tid {tid}, key {ii}, wasPending {false}, pt 3");
output.Memory.Dispose();
}
Expand All @@ -1084,10 +1084,10 @@ unsafe void runReadThread(int tid)
long keyLong = BitConverter.ToInt64(completedOutputs.Current.Key.AsReadOnlySpan());

Assert.AreEqual(completedOutputs.Current.RecordMetadata.Address == Constants.kInvalidAddress, status.Record.CopiedToReadCache, $"key {keyLong}: {status}");

Assert.IsTrue(status.Found, $"tid {tid}, key {keyLong}, {status}, wasPending {true}, pt 1");
Assert.IsNotNull(output.Memory, $"tid {tid}, key {keyLong}, wasPending {true}, pt 2");
long value = BitConverter.ToInt64(output.Memory.Memory.Span);
long value = BitConverter.ToInt64(output.AsReadOnlySpan());
Assert.AreEqual(keyLong, value % valueAdd, $"tid {tid}, key {keyLong}, wasPending {true}, pt 3");
output.Memory.Dispose();
}
Expand Down Expand Up @@ -1133,7 +1133,7 @@ unsafe void runUpdateThread(int tid)
if (updateOp == UpdateOp.RMW) // Upsert will not try to find records below HeadAddress, but it may find them in-memory
Assert.IsTrue(status.Found, $"tid {tid}, key {ii}, {status}");

long value = BitConverter.ToInt64(output.Memory.Memory.Span);
long value = BitConverter.ToInt64(output.AsReadOnlySpan());
Assert.AreEqual(ii + valueAdd, value, $"tid {tid}, key {ii}, wasPending {false}");

output.Memory?.Dispose();
Expand All @@ -1156,7 +1156,7 @@ unsafe void runUpdateThread(int tid)
if (updateOp == UpdateOp.RMW) // Upsert will not try to find records below HeadAddress, but it may find them in-memory
Assert.IsTrue(status.Found, $"tid {tid}, key {keyLong}, {status}");

long value = BitConverter.ToInt64(output.Memory.Memory.Span);
long value = BitConverter.ToInt64(output.AsReadOnlySpan());
Assert.AreEqual(keyLong + valueAdd, value, $"tid {tid}, key {keyLong}, wasPending {true}");

output.Memory?.Dispose();
Expand Down
44 changes: 23 additions & 21 deletions libs/storage/Tsavorite/cs/test/ReproReadCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public override bool SingleReader(ref SpanByte key, ref SpanByte input, ref Span
var keyString = new string(MemoryMarshal.Cast<byte, char>(key.AsReadOnlySpan()));
var inputString = new string(MemoryMarshal.Cast<byte, char>(input.AsReadOnlySpan()));
var valueString = new string(MemoryMarshal.Cast<byte, char>(value.AsReadOnlySpan()));
Assert.AreEqual(long.Parse(keyString) * 2, long.Parse(valueString));
Assert.AreEqual(long.Parse(inputString), long.Parse(valueString));
var actualValue = long.Parse(valueString);
Assert.AreEqual(long.Parse(keyString) * 2, actualValue);
Assert.AreEqual(long.Parse(inputString), actualValue);

value.CopyTo(ref dst, MemoryPool<byte>.Shared);
return true;
Expand All @@ -40,9 +41,10 @@ public override void ReadCompletionCallback(ref SpanByte key, ref SpanByte input
var keyString = new string(MemoryMarshal.Cast<byte, char>(key.AsReadOnlySpan()));
var inputString = new string(MemoryMarshal.Cast<byte, char>(input.AsReadOnlySpan()));
var outputString = new string(MemoryMarshal.Cast<byte, char>(output.AsReadOnlySpan()));
Assert.AreEqual(long.Parse(keyString) * 2, long.Parse(outputString));
Assert.AreEqual(long.Parse(inputString), long.Parse(outputString));
Assert.IsNotNull(output.Memory, $"key {keyString}, wasPending {true}, pt 2");
var actualValue = long.Parse(outputString);
Assert.AreEqual(long.Parse(keyString) * 2, actualValue);
Assert.AreEqual(long.Parse(inputString), actualValue);
Assert.IsNotNull(output.Memory, $"key {keyString}, in ReadCC");
}
}

Expand Down Expand Up @@ -148,25 +150,25 @@ void LocalRead(BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, Emp
Assert.IsTrue(status.IsPending, $"was not Pending: {keyString}; status {status}");
++numPending;
}
}

if (numPending > 0 && ((numPending % PendingMod) == 0 || isLast))
if (numPending > 0 && ((numPending % PendingMod) == 0 || isLast))
{
sessionContext.CompletePendingWithOutputs(out var completedOutputs, wait: true);
using (completedOutputs)
{
sessionContext.CompletePendingWithOutputs(out var completedOutputs, wait: true);
using (completedOutputs)
while (completedOutputs.Next())
{
while (completedOutputs.Next())
{
status = completedOutputs.Current.Status;
output = completedOutputs.Current.Output;
// Note: do NOT overwrite 'key' here
long keyLong = long.Parse(new string(MemoryMarshal.Cast<byte, char>(completedOutputs.Current.Key.AsReadOnlySpan())));

Assert.IsTrue(status.Found, $"key {keyLong}, {status}, wasPending {true}, pt 1");
Assert.IsNotNull(output.Memory, $"key {keyLong}, wasPending {true}, pt 2");
var outputString = new string(MemoryMarshal.Cast<byte, char>(output.AsReadOnlySpan()));
Assert.AreEqual(keyLong * 2, long.Parse(outputString), $"key {keyLong}, wasPending {true}, pt 3");
output.Memory.Dispose();
}
var status = completedOutputs.Current.Status;
var output = completedOutputs.Current.Output;
// Note: do NOT overwrite 'key' here
long keyLong = long.Parse(new string(MemoryMarshal.Cast<byte, char>(completedOutputs.Current.Key.AsReadOnlySpan())));

Assert.IsTrue(status.Found, $"key {keyLong}, {status}, wasPending {true}, pt 1");
Assert.IsNotNull(output.Memory, $"key {keyLong}, wasPending {true}, pt 2");
var outputString = new string(MemoryMarshal.Cast<byte, char>(output.AsReadOnlySpan()));
Assert.AreEqual(keyLong * 2, long.Parse(outputString), $"key {keyLong}, wasPending {true}, pt 3");
output.Memory.Dispose();
}
}
}
Expand Down
Loading

0 comments on commit 8837a1b

Please sign in to comment.