Skip to content

Commit

Permalink
Merge pull request #82 from koculu/81-enhancement-type-validation-sho…
Browse files Browse the repository at this point in the history
…uld-not-fail-based-on-the-version-of-the-assembly-difference

81 enhancement type validation should not fail based on the version of the assembly difference
  • Loading branch information
koculu authored Aug 24, 2024
2 parents dbcd5fa + 20076c3 commit 76357cf
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 57 deletions.
8 changes: 4 additions & 4 deletions src/ZoneTree.UnitTests/AtomicUpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void IntIntAtomicIncrement(WriteAheadLogMode walMode)
data.Maintenance.StartMergeOperation().Join();
data.TryGet(counterKey, out var finalValue);
Assert.That(finalValue, Is.EqualTo(off));
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

[TestCase(WriteAheadLogMode.Sync)]
Expand Down Expand Up @@ -140,7 +140,7 @@ public void IntIntAtomicIncrementForBTree(WriteAheadLogMode walMode)

data.TryGet(3999, out var finalValue);
Assert.That(finalValue, Is.EqualTo(off));
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

[TestCase(WriteAheadLogMode.Sync)]
Expand Down Expand Up @@ -206,7 +206,7 @@ public void IntIntMutableSegmentOnlyAtomicIncrement(WriteAheadLogMode walMode)

data.TryGet(counterKey, out var finalValue);
Assert.That(finalValue, Is.EqualTo(off));
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

[TestCase(WriteAheadLogMode.Sync)]
Expand Down Expand Up @@ -255,6 +255,6 @@ public void IntIntMutableSegmentSeveralUpserts(WriteAheadLogMode walMode)
});
}

data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}
}
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/BottomSegmentMergeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void IntIntBottomMerge()

lens = m.BottomSegments.Select(x => x.Length).ToArray();
Assert.That(lens, Is.EqualTo(expected2));
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
zoneTree.Dispose();
}
}
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/CountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void CountRecordsDuringAMerge(
mergeThread?.Join();
isMergeFinished = true;
task.Wait();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();

Assert.That(failedCount, Is.EqualTo(0));
}
Expand Down
4 changes: 2 additions & 2 deletions src/ZoneTree.UnitTests/ExceptionlessTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void TransactionWithNoThrowAPI(int compactionThreshold)

Assert.Throws<TransactionAlreadyCommittedException>(() => zoneTree.CommitNoThrow(tx1));

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(0)]
Expand Down Expand Up @@ -106,6 +106,6 @@ await Parallel.ForEachAsync(Enumerable.Range(0, 1000), async (x, cancel) =>
Console.WriteLine("pending:" + transaction.TotalPendingTransactionsRetried);
});

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}
}
10 changes: 5 additions & 5 deletions src/ZoneTree.UnitTests/FixedSizeKeyAndValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void IntIntTreeTest()
Assert.That(v, Is.EqualTo(i + i));
Assert.That(data.ContainsKey(i), Is.True);
}
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -62,7 +62,7 @@ public void IntStringTreeTest()
Assert.That(data.ContainsKey(i), Is.True);
}
Assert.That(data.TryGet(n + 1, out var _), Is.False);
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -266,7 +266,7 @@ public void StringIntTreeTest(bool useSparseArray)
Assert.That(data.ContainsKey(i.ToString()), Is.True);
}
Assert.That(data.TryGet(n + 1.ToString(), out var _), Is.False);
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

[TestCase(true)]
Expand Down Expand Up @@ -301,7 +301,7 @@ public void StringStringTreeTest(bool useSparseArray)
Assert.That(data.ContainsKey(i.ToString()), Is.True);
}
Assert.That(data.TryGet(n + 1.ToString(), out var _), Is.False);
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}

static void ReloadIntIntTreeTestHelper(string dataPath, bool destroy)
Expand Down Expand Up @@ -342,7 +342,7 @@ static void ReloadIntIntTreeTestHelper(string dataPath, bool destroy)
}
Assert.That(data.Count(), Is.EqualTo(n - deleted.Count));
if (destroy)
data.Maintenance.DestroyTree();
data.Maintenance.Drop();
}
[Test]
public void ReloadIntIntTreeTest()
Expand Down
18 changes: 9 additions & 9 deletions src/ZoneTree.UnitTests/IteratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void IntIntIterator()
zoneTree.Maintenance.SaveMetaData();
iterator.Dispose();
reverseIterator.Dispose();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -166,7 +166,7 @@ public void IntIntIteratorSeek()
zoneTree.Maintenance.SaveMetaData();
iterator.Dispose();
reverseIterator.Dispose();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -230,7 +230,7 @@ public void IntIntIteratorReflectNewInserts()
Assert.That(zoneTree.Count(), Is.EqualTo(b / 2 - 2));
zoneTree.Maintenance.SaveMetaData();
iterator.Dispose();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -278,7 +278,7 @@ public void IntIntIteratorParallelInserts()
});

task.Wait();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(true)]
Expand Down Expand Up @@ -342,7 +342,7 @@ public void IntIntReverseIteratorParallelInserts(bool reverse)
});

task.Wait();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -389,7 +389,7 @@ public void IntIntSnapshotIteratorParallelInserts()
});

task.Wait();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -431,7 +431,7 @@ public void ReversePrefixSearch()

Assert.That(reverseIterator.Next(), Is.False);
Assert.That(zoneTree.Count(), Is.EqualTo(b - a + 1));
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down Expand Up @@ -473,7 +473,7 @@ public void PrefixSearch()

Assert.That(iterator.Next(), Is.False);
Assert.That(zoneTree.Count(), Is.EqualTo(b - a + 1));
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(true, DiskSegmentMode.SingleDiskSegment, 0, 0)]
Expand Down Expand Up @@ -516,7 +516,7 @@ public void SeekIteratorsAfterMerge(
DoPrefixSearch(zoneTree, list, random);
zoneTree.Maintenance.DiskSegment.InitSparseArray(100);
DoPrefixSearch(zoneTree, list, random);
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

static List<Tuple<string, int>> PrepareData1(IZoneTree<string, int> zoneTree, int n)
Expand Down
6 changes: 3 additions & 3 deletions src/ZoneTree.UnitTests/MergeEmptySegmentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void MergeEmptySegments(
}

zoneTree.Maintenance.SaveMetaData();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(DiskSegmentMode.SingleDiskSegment, 33, 77)]
Expand Down Expand Up @@ -108,7 +108,7 @@ public void MergeDeletedSegments(
}

zoneTree.Maintenance.SaveMetaData();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(DiskSegmentMode.SingleDiskSegment, 33, 77)]
Expand Down Expand Up @@ -173,6 +173,6 @@ public void MergeDeletedBottomSegments(
Assert.That(hasRecord, Is.False);
}
zoneTree.Maintenance.SaveMetaData();
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}
}
14 changes: 7 additions & 7 deletions src/ZoneTree.UnitTests/OptimisticTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void FirstTransaction(int compactionThreshold)

Assert.Throws<TransactionAlreadyCommittedException>(() => zoneTree.Commit(tx1));

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(WriteAheadLogMode.Sync)]
Expand Down Expand Up @@ -80,7 +80,7 @@ public void SeveralParallelTransactions(WriteAheadLogMode walMode)
zoneTree.Commit(tx);
});

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(WriteAheadLogMode.Sync)]
Expand All @@ -105,7 +105,7 @@ public void SeveralParallelUpserts(WriteAheadLogMode walMode)
zoneTree.Upsert(-x, -x - x);
});

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(0)]
Expand Down Expand Up @@ -158,7 +158,7 @@ public void ReadCommittedTest(int compactionThreshold)
Assert.That(zoneTree.ReadCommittedContainsKey(7), Is.False);
Assert.That(zoneTree.ReadCommittedTryGet(7, out var _), Is.False);

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(0)]
Expand Down Expand Up @@ -205,7 +205,7 @@ public void TransactionLogCompactionTest(int compactionThreshold)
Assert.That(v6, Is.EqualTo(14));

zoneTree.Rollback(tx3);
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(0)]
Expand Down Expand Up @@ -240,7 +240,7 @@ public void TransactionLogCompactionWithSkipWriteRule(int compactionThreshold)
Assert.That(zoneTree.ReadCommittedTryGet(5, out var v5), Is.True);
Assert.That(v5, Is.EqualTo(12));

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[TestCase(0)]
Expand Down Expand Up @@ -276,6 +276,6 @@ public void TransactionIsolationTest(int compactionThreshold)
// tx2 depends on tx1 bcs of read of key 9. tx1 aborted and so tx2.
Assert.That(zoneTree.PrepareAndCommitNoThrow(tx2).IsAborted, Is.True);

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}
}
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/StringTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void NullStringKeyTest()
Assert.That(iterator2.CurrentValue, Is.EqualTo(values[j]));
++j;
}
zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/TTLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public void TestTTL()
Assert.That(f1, Is.True);
Assert.That(f2, Is.False);

zoneTree.Maintenance.DestroyTree();
zoneTree.Maintenance.Drop();
}
}
37 changes: 37 additions & 0 deletions src/ZoneTree/Core/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Text;

namespace Tenray.ZoneTree.Core;

public static class TypeExtensions
{
public static string SimplifiedFullName(this Type type)
{
if (!type.IsGenericType)
return type.FullName;
var builder = new StringBuilder();
var typeName = type.Namespace + "." + type.Name;
int index = typeName.IndexOf('`');

Check warning on line 13 in src/ZoneTree/Core/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'string.IndexOf(char)' has a method overload that takes a 'StringComparison' parameter. Replace this call in 'Tenray.ZoneTree.Core.TypeExtensions.SimplifiedFullName(System.Type)' with a call to 'string.IndexOf(char, System.StringComparison)' for clarity of intent. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1307)
if (index > 0)
{
builder.Append(typeName.Substring(0, index));

Check warning on line 16 in src/ZoneTree/Core/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Prefer 'AsSpan' over 'Substring' when span-based overloads are available (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1846)
}
else
{
builder.Append(typeName);
}

builder.Append("<");

Check warning on line 23 in src/ZoneTree/Core/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Use 'StringBuilder.Append(char)' instead of 'StringBuilder.Append(string)' when the input is a constant unit string (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1834)
var genericArguments = type.GetGenericArguments();
var len = genericArguments.Length;
for (var i = 0; i < len; i++)
{
if (i > 0)
{
builder.Append(", ");
}
builder.Append(genericArguments[i].SimplifiedFullName());
}
builder.Append(">");

Check warning on line 34 in src/ZoneTree/Core/TypeExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Use 'StringBuilder.Append(char)' instead of 'StringBuilder.Append(string)' when the input is a constant unit string (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1834)
return builder.ToString();
}
}
12 changes: 6 additions & 6 deletions src/ZoneTree/Core/ZoneTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ void FillZoneTreeMeta()
{
if (MutableSegment != null)
ZoneTreeMeta.MutableSegment = MutableSegment.SegmentId;
ZoneTreeMeta.ComparerType = Options.Comparer.GetType().FullName;
ZoneTreeMeta.KeyType = typeof(TKey).FullName;
ZoneTreeMeta.ValueType = typeof(TValue).FullName;
ZoneTreeMeta.KeySerializerType = Options.KeySerializer.GetType().FullName;
ZoneTreeMeta.ValueSerializerType = Options.ValueSerializer.GetType().FullName;
ZoneTreeMeta.ComparerType = Options.Comparer.GetType().SimplifiedFullName();
ZoneTreeMeta.KeyType = typeof(TKey).SimplifiedFullName();
ZoneTreeMeta.ValueType = typeof(TValue).SimplifiedFullName();
ZoneTreeMeta.KeySerializerType = Options.KeySerializer.GetType().SimplifiedFullName();
ZoneTreeMeta.ValueSerializerType = Options.ValueSerializer.GetType().SimplifiedFullName();
ZoneTreeMeta.DiskSegment = DiskSegment.SegmentId;
ZoneTreeMeta.ReadOnlySegments = ReadOnlySegmentQueue.Select(x => x.SegmentId).ToArray();
ZoneTreeMeta.BottomSegments = BottomSegmentQueue.Select(x => x.SegmentId).ToArray();
Expand Down Expand Up @@ -264,7 +264,7 @@ public void Dispose()
bs.ReleaseResources();
}

public void DestroyTree()
public void Drop()
{
MetaWal.Dispose();
MutableSegment.Drop();
Expand Down
Loading

0 comments on commit 76357cf

Please sign in to comment.