Skip to content

Conversation

@Havret
Copy link
Owner

@Havret Havret commented Dec 30, 2025

No description provided.

@Havret Havret marked this pull request as ready for review December 30, 2025 21:50
@Havret Havret requested a review from Copilot December 30, 2025 21:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for ISet<T> collections to the RocksDb.Extensions library, mirroring the existing IList<T> functionality. The implementation refactors the existing list serializers by introducing base classes that can be shared between list and set serializers.

Key Changes:

  • Introduced abstract base classes FixedSizeCollectionSerializer and VariableSizeCollectionSerializer for code reuse
  • Created FixedSizeSetSerializer and VariableSizeSetSerializer for set-specific implementations
  • Refactored existing list serializers to inherit from the new base classes
  • Updated RocksDbBuilder to automatically create appropriate serializers for ISet<T> types
  • Added comprehensive test coverage for set support across all serializer types

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/RocksDb.Extensions/FixedSizeCollectionSerializer.cs New abstract base class for serializing collections with fixed-size elements (primitives)
src/RocksDb.Extensions/VariableSizeCollectionSerializer.cs New abstract base class for serializing collections with variable-size elements (strings, complex objects)
src/RocksDb.Extensions/FixedSizeSetSerializer.cs Concrete implementation for serializing ISet with fixed-size elements
src/RocksDb.Extensions/VariableSizeSetSerializer.cs Concrete implementation for serializing ISet with variable-size elements
src/RocksDb.Extensions/FixedSizeListSerializer.cs Refactored to extend FixedSizeCollectionSerializer base class
src/RocksDb.Extensions/VariableSizeListSerializer.cs Refactored to extend VariableSizeCollectionSerializer base class
src/RocksDb.Extensions/RocksDbBuilder.cs Added logic to detect ISet types and create appropriate serializers (fixed vs variable size)
test/RocksDb.Extensions.Tests/RocksDbStoreWithProtobufSerializerTests.cs Added test for set support with Protobuf serializer
test/RocksDb.Extensions.Tests/RocksDbStoreWithProtoBufNetSerializerTests.cs Added test for set support with ProtoBufNet serializer
test/RocksDb.Extensions.Tests/RocksDbStoreWithPrimitiveSerializerTests.cs Added tests for set support with primitive types (int and string)
test/RocksDb.Extensions.Tests/RocksDbStoreWithJsonSerializerTests.cs Added test for set support with JSON serializer
README.md Updated documentation to reflect ISet support alongside IList

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Write the elements of the collection
int offset = sizeof(int);
var elementSize = (span.Length - offset) / value.Count;
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero will occur when value.Count is 0. While TryCalculateSize handles empty collections correctly, WriteTo does not check if the collection is empty before dividing. This will cause a DivideByZeroException when serializing an empty collection. Add a check to return early when value.Count is 0.

Copilot uses AI. Check for mistakes.

// Read the elements of the collection
int offset = sizeof(int);
var elementSize = (buffer.Length - offset) / size;
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero will occur when size is 0. The Deserialize method does not check if the deserialized size is 0 before dividing. This will cause a DivideByZeroException when deserializing an empty collection. Add a check to return an empty collection when size is 0.

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +201
[Test]
public void should_put_and_retrieve_data_with_sets_from_store()
{
// Arrange
using var testFixture = CreateTestFixture<ISet<CacheKey>, ISet<CacheValue>>();
var store = testFixture.GetStore<RocksDbGenericStore<ISet<CacheKey>, ISet<CacheValue>>>();

// Act
var cacheKey = Enumerable.Range(0, 100)
.Select(x => new CacheKey
{
Id = x,
})
.ToHashSet();

var cacheValue = Enumerable.Range(0, 100)
.Select(x => new CacheValue
{
Id = x,
Value = $"value-{x}",
})
.ToHashSet();

store.Put(cacheKey, cacheValue);

store.HasKey(cacheKey).ShouldBeTrue();
store.TryGet(cacheKey, out var value).ShouldBeTrue();
value.ShouldBeEquivalentTo(cacheValue);
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and non-primitive element types) to ensure the serializer handles edge cases correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +171
[Test]
public void should_put_and_retrieve_data_with_sets_from_store()
{
// Arrange
using var testFixture = CreateTestFixture<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>();
var store = testFixture.GetStore<RocksDbGenericStore<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>>();

// Act
var cacheKey = Enumerable.Range(0, 100)
.Select(x => new ProtoNetCacheKey
{
Id = x,
})
.ToHashSet();

var cacheValue = Enumerable.Range(0, 100)
.Select(x => new ProtoNetCacheValue
{
Id = x,
Value = $"value-{x}",
})
.ToHashSet();

store.Put(cacheKey, cacheValue);

store.HasKey(cacheKey).ShouldBeTrue();
store.TryGet(cacheKey, out var value).ShouldBeTrue();
value.ShouldBeEquivalentTo(cacheValue);
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and non-primitive element types) to ensure the serializer handles edge cases correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +302 to +336
[Test]
public void should_put_and_retrieve_data_from_store_using_set_of_ints()
{
// Arrange
using var testFixture = CreateTestFixture<ISet<int>, ISet<long>>();
var store = testFixture.GetStore<RocksDbGenericStore<ISet<int>, ISet<long>>>();

// Act
var key = new HashSet<int> { 1, 2, 3 };
var value = new HashSet<long> { 4, 5, 6 };
store.Put(key, value);

// Assert
store.HasKey(key).ShouldBeTrue();
store.TryGet(key, out var cacheValue).ShouldBeTrue();
cacheValue.ShouldBeEquivalentTo(value);
}

[Test]
public void should_put_and_retrieve_data_from_store_using_set_of_strings()
{
// Arrange
using var testFixture = CreateTestFixture<ISet<string>, ISet<string>>();
var store = testFixture.GetStore<RocksDbGenericStore<ISet<string>, ISet<string>>>();
var key = new HashSet<string> { "key1", "key2", string.Empty, "key3" };
var value = new HashSet<string> { "value1", string.Empty, "value2", "value3" };

// Act
store.Put(key, value);

// Assert
store.HasKey(key).ShouldBeTrue();
store.TryGet(key, out var retrievedValue).ShouldBeTrue();
retrievedValue.ShouldBeEquivalentTo(value);
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and string element types) to ensure the serializer handles edge cases correctly, particularly for the FixedSizeSetSerializer used with primitive types.

Copilot uses AI. Check for mistakes.
Comment on lines +142 to +170
[Test]
public void should_put_and_retrieve_data_with_sets_from_store()
{
// Arrange
using var testFixture = CreateTestFixture<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>();
var store = testFixture.GetStore<RocksDbGenericStore<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>>();

// Act
var cacheKey = Enumerable.Range(0, 100)
.Select(x => new ProtoNetCacheKey
{
Id = x,
})
.ToHashSet();

var cacheValue = Enumerable.Range(0, 100)
.Select(x => new ProtoNetCacheValue
{
Id = x,
Value = $"value-{x}",
})
.ToHashSet();

store.Put(cacheKey, cacheValue);

store.HasKey(cacheKey).ShouldBeTrue();
store.TryGet(cacheKey, out var value).ShouldBeTrue();
value.ShouldBeEquivalentTo(cacheValue);
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and non-primitive element types) to ensure the serializer handles edge cases correctly.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants