Skip to content

Commit

Permalink
Feature: MergeManyChangeSets for Cache ChangeSets with List ChangeSets (
Browse files Browse the repository at this point in the history
#790)

* First drop of MergeManyChangeSets for List to Cache

* Fix test data

* Improved test

* Unit Testing a thread issue

* More progress on stress tests

* All Unit Tests Pass!

* Stress Tester refactor

* Finalization
- Code Cleanup
- Move Synchronization call
- Remove extra Cache / List that isn't needed
- Add EqualityComparer to List-to-List version

* API Fixes

* Fixed Unit Tests

* Fix Build, enable test

SourceErrorsImmediately_SubscriptionReceivesError is now re-enabled I ran on a loop test and passed every time

* So close!

* Switch to bools

* Code Cleanup

* Revert Change that may be the problem

* Revert debugging helper

* Update Stress Test

* Update List internal classes to be sealed

* Enable other Skipped tests, no issues seem to be present

* Convert to pure Observable no Sleep or Delay

* Improved Faker use of statics

* Simplify and add OnError notifications

* Revert "Update List internal classes to be sealed" because it has been moved to #796

This reverts commit 315f013.

* Add sealed to a few classes

* Finalize Test Code

---------

Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>
  • Loading branch information
dwcullop and ChrisPulman committed Dec 16, 2023
1 parent 71c0e68 commit 32ce42b
Show file tree
Hide file tree
Showing 22 changed files with 924 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ namespace DynamicData
public static System.IObservable<TDestination> MergeMany<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, TKey, System.IObservable<TDestination>> observableSelector)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TKey : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, TKey, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TKey : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>> MergeManyChangeSets<TObject, TKey, TDestination, TDestinationKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>>> observableSelector, System.Collections.Generic.IComparer<TDestination> comparer)
where TObject : notnull
where TKey : notnull
Expand Down Expand Up @@ -2128,7 +2136,7 @@ namespace DynamicData
where TKey : notnull { }
public static System.IObservable<TDestination> MergeMany<T, TDestination>(this System.IObservable<DynamicData.IChangeSet<T>> source, System.Func<T, System.IObservable<TDestination>> observableSelector)
where T : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector)
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>> MergeManyChangeSets<TObject, TDestination, TDestinationKey>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>>> observableSelector, System.Collections.Generic.IComparer<TDestination> comparer)
Expand Down Expand Up @@ -2708,9 +2716,9 @@ namespace DynamicData.Tests
where TKey : notnull
{
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source) { }
public bool Completed { get; }
public DynamicData.IObservableCache<TObject, TKey> Data { get; }
public System.Exception? Error { get; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject, TKey>> Messages { get; }
public DynamicData.Diagnostics.ChangeSummary Summary { get; }
public void Dispose() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ namespace DynamicData
public static System.IObservable<TDestination> MergeMany<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, TKey, System.IObservable<TDestination>> observableSelector)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TKey : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, TKey, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TKey : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>> MergeManyChangeSets<TObject, TKey, TDestination, TDestinationKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>>> observableSelector, System.Collections.Generic.IComparer<TDestination> comparer)
where TObject : notnull
where TKey : notnull
Expand Down Expand Up @@ -2128,7 +2136,7 @@ namespace DynamicData
where TKey : notnull { }
public static System.IObservable<TDestination> MergeMany<T, TDestination>(this System.IObservable<DynamicData.IChangeSet<T>> source, System.Func<T, System.IObservable<TDestination>> observableSelector)
where T : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector)
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>> MergeManyChangeSets<TObject, TDestination, TDestinationKey>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>>> observableSelector, System.Collections.Generic.IComparer<TDestination> comparer)
Expand Down Expand Up @@ -2708,9 +2716,9 @@ namespace DynamicData.Tests
where TKey : notnull
{
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source) { }
public bool Completed { get; }
public DynamicData.IObservableCache<TObject, TKey> Data { get; }
public System.Exception? Error { get; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject, TKey>> Messages { get; }
public DynamicData.Diagnostics.ChangeSummary Summary { get; }
public void Dispose() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ namespace DynamicData
public static System.IObservable<TDestination> MergeMany<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, TKey, System.IObservable<TDestination>> observableSelector)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TKey : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TKey, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, TKey, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TKey : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>> MergeManyChangeSets<TObject, TKey, TDestination, TDestinationKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>>> observableSelector, System.Collections.Generic.IComparer<TDestination> comparer)
where TObject : notnull
where TKey : notnull
Expand Down Expand Up @@ -2128,7 +2136,7 @@ namespace DynamicData
where TKey : notnull { }
public static System.IObservable<TDestination> MergeMany<T, TDestination>(this System.IObservable<DynamicData.IChangeSet<T>> source, System.Func<T, System.IObservable<TDestination>> observableSelector)
where T : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector)
public static System.IObservable<DynamicData.IChangeSet<TDestination>> MergeManyChangeSets<TObject, TDestination>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination>>> observableSelector, System.Collections.Generic.IEqualityComparer<TDestination>? equalityComparer = null)
where TObject : notnull
where TDestination : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>> MergeManyChangeSets<TObject, TDestination, TDestinationKey>(this System.IObservable<DynamicData.IChangeSet<TObject>> source, System.Func<TObject, System.IObservable<DynamicData.IChangeSet<TDestination, TDestinationKey>>> observableSelector, System.Collections.Generic.IComparer<TDestination> comparer)
Expand Down Expand Up @@ -2708,9 +2716,9 @@ namespace DynamicData.Tests
where TKey : notnull
{
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source) { }
public bool Completed { get; }
public DynamicData.IObservableCache<TObject, TKey> Data { get; }
public System.Exception? Error { get; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject, TKey>> Messages { get; }
public DynamicData.Diagnostics.ChangeSummary Summary { get; }
public void Dispose() { }
Expand Down
8 changes: 4 additions & 4 deletions src/DynamicData.Tests/Cache/MergeChangeSetsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public void EveryItemVisibleWhenSequenceCompletes()
using var results = fixedMarketList.Select(m => m.LatestPrices).MergeChangeSets(completable: true).AsAggregator();

// then
results.Completed.Should().Be(true);
results.IsCompleted.Should().Be(true);
results.Data.Count.Should().Be(PricesPerMarket * MarketCount);
results.Summary.Overall.Adds.Should().Be(PricesPerMarket * MarketCount);
results.Summary.Overall.Removes.Should().Be(0);
Expand All @@ -727,7 +727,7 @@ public void MergedObservableCompletesWhenAllSourcesComplete(bool completeSources
using var results = fixedMarketList.Select(m => m.LatestPrices).MergeChangeSets(completable: true).AsAggregator();

// then
results.Completed.Should().Be(completeSources);
results.IsCompleted.Should().Be(completeSources);
}

[Theory]
Expand All @@ -744,7 +744,7 @@ public void MergedObservableRespectsCompletableFlag(bool completeSource, bool co
using var results = fixedMarketList.Select(m => m.LatestPrices).MergeChangeSets(completable: completeSource).AsAggregator();

// then
results.Completed.Should().Be(completeSource && completeChildren);
results.IsCompleted.Should().Be(completeSource && completeChildren);
}

[Fact]
Expand Down Expand Up @@ -846,7 +846,7 @@ public void ObservableObservableCompletesIfAndOnlyIfSourceAndAllChildrenComplete
using var results = observableObservable.MergeChangeSets().AsAggregator();

// then
results.Completed.Should().Be(completeSource && completeChildren);
results.IsCompleted.Should().Be(completeSource && completeChildren);
}

public void Dispose() => _marketList.ForEach(m => (m as IDisposable)?.Dispose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace DynamicData.Tests.Cache;

public sealed class MergeManyCacheChangeSetsFixture : IDisposable
public sealed class MergeManyChangeSetsCacheFixture : IDisposable
{
#if DEBUG
const int MarketCount = 5;
Expand All @@ -37,7 +37,7 @@ public sealed class MergeManyCacheChangeSetsFixture : IDisposable

private readonly ChangeSetAggregator<IMarket, Guid> _marketCacheResults;

public MergeManyCacheChangeSetsFixture() => _marketCacheResults = _marketCache.Connect().AsAggregator();
public MergeManyChangeSetsCacheFixture() => _marketCacheResults = _marketCache.Connect().AsAggregator();

[Fact]
public void NullChecks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace DynamicData.Tests.Cache;

public sealed class MergeManyCacheChangeSetsSourceCompareFixture : IDisposable
public sealed class MergeManyChangeSetsCacheSourceCompareFixture : IDisposable
{
#if DEBUG
const int MarketCount = 5;
Expand All @@ -37,7 +37,7 @@ public sealed class MergeManyCacheChangeSetsSourceCompareFixture : IDisposable

private readonly ChangeSetAggregator<IMarket, Guid> _marketCacheResults;

public MergeManyCacheChangeSetsSourceCompareFixture() => _marketCacheResults = _marketCache.Connect().AsAggregator();
public MergeManyChangeSetsCacheSourceCompareFixture() => _marketCacheResults = _marketCache.Connect().AsAggregator();

[Fact]
public void NullChecks()
Expand Down

0 comments on commit 32ce42b

Please sign in to comment.