-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/Streamiz.Kafka.Net.Tests/Helpers/MockProcessorContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using Confluent.Kafka; | ||
using Streamiz.Kafka.Net.Metrics; | ||
using Streamiz.Kafka.Net.Mock; | ||
using Streamiz.Kafka.Net.Processors; | ||
using Streamiz.Kafka.Net.Processors.Internal; | ||
|
||
namespace Streamiz.Kafka.Net.Tests.Helpers; | ||
|
||
public class MockProcessorContext : ProcessorContext | ||
{ | ||
public MockProcessorContext(TaskId id, StreamConfig config) | ||
: base(UnassignedStreamTask.Create(), config, new ProcessorStateManager( | ||
id, | ||
new List<TopicPartition>(), | ||
new Dictionary<string, string>(), | ||
new MockChangelogRegister(), | ||
new MockOffsetCheckpointManager()), new StreamMetricsRegistry()) | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using NUnit.Framework; | ||
using Streamiz.Kafka.Net.Processors.Internal; | ||
using Streamiz.Kafka.Net.State.Cache; | ||
using Streamiz.Kafka.Net.State.InMemory; | ||
using Streamiz.Kafka.Net.Table; | ||
using Streamiz.Kafka.Net.Tests.Helpers; | ||
|
||
namespace Streamiz.Kafka.Net.Tests.Public; | ||
|
||
public class CacheSizeTests | ||
{ | ||
[Test] | ||
public void CacheSizeKVStoreEnabledWithDefaultConf() | ||
{ | ||
var config = new StreamConfig(); | ||
config.DefaultStateStoreCacheMaxBytes = CacheSize.OfMb(1).CacheSizeBytes; | ||
var context = new MockProcessorContext(new TaskId { Id = 0, Partition = 0 }, config); | ||
var inMemoryKeyValue = new InMemoryKeyValueStore("store"); | ||
var cache = new CachingKeyValueStore(inMemoryKeyValue, null); | ||
cache.Init(context, cache); | ||
Assert.IsTrue(cache.IsCachedStore); | ||
Assert.AreEqual(CacheSize.OfMb(1).CacheSizeBytes, cache.Cache.Capacity); | ||
} | ||
|
||
[Test] | ||
public void CacheSizeKVStoreEnabledWithSpecificConf() | ||
{ | ||
var config = new StreamConfig(); | ||
config.DefaultStateStoreCacheMaxBytes = CacheSize.OfMb(1).CacheSizeBytes; | ||
var context = new MockProcessorContext(new TaskId { Id = 0, Partition = 0 }, config); | ||
var inMemoryKeyValue = new InMemoryKeyValueStore("store"); | ||
var cache = new CachingKeyValueStore(inMemoryKeyValue, CacheSize.OfMb(10)); | ||
cache.Init(context, cache); | ||
Assert.IsTrue(cache.IsCachedStore); | ||
Assert.AreEqual(CacheSize.OfMb(10).CacheSizeBytes, cache.Cache.Capacity); | ||
} | ||
|
||
[Test] | ||
public void CacheSizeKVStoreDisabled() | ||
{ | ||
var config = new StreamConfig(); | ||
config.DefaultStateStoreCacheMaxBytes = 0L; | ||
var context = new MockProcessorContext(new TaskId { Id = 0, Partition = 0 }, config); | ||
var inMemoryKeyValue = new InMemoryKeyValueStore("store"); | ||
var cache = new CachingKeyValueStore(inMemoryKeyValue, null); | ||
cache.Init(context, cache); | ||
Assert.IsFalse(cache.IsCachedStore); | ||
} | ||
|
||
[Test] | ||
public void CacheSizeKVStoreDisabledExplicitConf() | ||
{ | ||
var config = new StreamConfig(); | ||
config.DefaultStateStoreCacheMaxBytes = 0L; | ||
var context = new MockProcessorContext(new TaskId { Id = 0, Partition = 0 }, config); | ||
var inMemoryKeyValue = new InMemoryKeyValueStore("store"); | ||
var cache = new CachingKeyValueStore(inMemoryKeyValue, CacheSize.OfB(0)); | ||
cache.Init(context, cache); | ||
Assert.IsFalse(cache.IsCachedStore); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters