@@ -38,16 +38,27 @@ public KafkaIntegrationTests(string actorSystemName, ITestOutputHelper output, K
38
38
39
39
protected string CreateTopic ( int number ) => $ "topic-{ number } -{ Uuid } ";
40
40
protected string CreateGroup ( int number ) => $ "group-{ number } -{ Uuid } ";
41
+
42
+ protected ProducerSettings < Null , string > ProducerSettings => BuildProducerSettings < Null , string > ( ) ;
41
43
42
- protected ProducerSettings < Null , string > ProducerSettings
44
+ protected ProducerSettings < TKey , TValue > BuildProducerSettings < TKey , TValue > ( )
43
45
{
44
- get => ProducerSettings < Null , string > . Create ( Sys , null , null ) . WithBootstrapServers ( _fixture . KafkaServer ) ;
46
+ return ProducerSettings < TKey , TValue > . Create ( Sys , null , null ) . WithBootstrapServers ( _fixture . KafkaServer ) ;
45
47
}
46
48
47
49
protected CommitterSettings CommitterSettings
48
50
{
49
51
get => CommitterSettings . Create ( Sys ) ;
50
52
}
53
+
54
+ protected ConsumerSettings < TKey , TValue > CreateConsumerSettings < TKey , TValue > ( string group )
55
+ {
56
+ return ConsumerSettings < TKey , TValue > . Create ( Sys , null , null )
57
+ . WithBootstrapServers ( _fixture . KafkaServer )
58
+ . WithStopTimeout ( TimeSpan . FromSeconds ( 1 ) )
59
+ . WithProperty ( "auto.offset.reset" , "earliest" )
60
+ . WithGroupId ( group ) ;
61
+ }
51
62
52
63
protected ConsumerSettings < Null , TValue > CreateConsumerSettings < TValue > ( string group )
53
64
{
@@ -58,41 +69,54 @@ protected ConsumerSettings<Null, TValue> CreateConsumerSettings<TValue>(string g
58
69
. WithGroupId ( group ) ;
59
70
}
60
71
61
- protected async Task ProduceStrings ( string topic , IEnumerable < int > range , ProducerSettings < Null , string > producerSettings )
72
+ protected async Task ProduceStrings < TKey > ( string topic , IEnumerable < int > range , ProducerSettings < TKey , string > producerSettings )
62
73
{
63
74
await Source
64
75
. From ( range )
65
- . Select ( elem => new MessageAndMeta < Null , string > { Topic = topic , Message = new Message < Null , string > { Value = elem . ToString ( ) } } )
76
+ . Select ( elem => new ProducerRecord < TKey , string > ( topic , elem . ToString ( ) ) )
66
77
. RunWith ( KafkaProducer . PlainSink ( producerSettings ) , Materializer ) ;
67
78
}
68
79
69
- protected async Task ProduceStrings ( Func < int , TopicPartition > partitionSelector , IEnumerable < int > range , ProducerSettings < Null , string > producerSettings )
80
+ protected async Task ProduceStrings < TKey > ( Func < int , TopicPartition > partitionSelector , IEnumerable < int > range , ProducerSettings < TKey , string > producerSettings )
70
81
{
71
82
await Source
72
83
. From ( range )
73
- . Select ( elem => new MessageAndMeta < Null , string > { TopicPartition = partitionSelector ( elem ) , Message = new Message < Null , string > { Value = elem . ToString ( ) } } )
84
+ . Select ( elem => new ProducerRecord < TKey , string > ( partitionSelector ( elem ) , elem . ToString ( ) ) )
74
85
. RunWith ( KafkaProducer . PlainSink ( producerSettings ) , Materializer ) ;
75
86
}
76
87
77
- protected async Task ProduceStrings ( TopicPartition topicPartition , IEnumerable < int > range , ProducerSettings < Null , string > producerSettings )
88
+ protected async Task ProduceStrings < TKey > ( TopicPartition topicPartition , IEnumerable < int > range , ProducerSettings < TKey , string > producerSettings )
78
89
{
79
90
await Source
80
91
. From ( range )
81
- . Select ( elem => new MessageAndMeta < Null , string > { TopicPartition = topicPartition , Message = new Message < Null , string > { Value = elem . ToString ( ) } } )
92
+ . Select ( elem => new ProducerRecord < TKey , string > ( topicPartition , elem . ToString ( ) ) )
82
93
. RunWith ( KafkaProducer . PlainSink ( producerSettings ) , Materializer ) ;
83
94
}
84
95
85
96
/// <summary>
86
97
/// Asserts that task will finish successfully until specified timeout.
87
98
/// Throws task exception if task failes
88
99
/// </summary>
89
- protected async Task AssertCompletesSuccessfullyWithin ( TimeSpan timeout , Task task )
100
+ protected void AssertTaskCompletesWithin ( TimeSpan timeout , Task task , bool assertIsSuccessful = true )
90
101
{
91
- var timeoutTask = Task . Delay ( timeout ) ;
92
-
93
- await Task . WhenAny ( timeoutTask , task ) ;
102
+ AwaitCondition ( ( ) => task . IsCompleted , timeout , $ "task should complete within { timeout } timeout") ;
103
+
104
+ if ( assertIsSuccessful )
105
+ task . IsCompletedSuccessfully . Should ( ) . Be ( true , "task should compete successfully" ) ;
106
+ }
107
+
108
+ /// <summary>
109
+ /// Asserts that task will finish successfully until specified timeout.
110
+ /// Throws task exception if task failes
111
+ /// </summary>
112
+ protected TResult AssertTaskCompletesWithin < TResult > ( TimeSpan timeout , Task < TResult > task , bool assertIsSuccessful = true )
113
+ {
114
+ AwaitCondition ( ( ) => task . IsCompleted , timeout , $ "task should complete within { timeout } timeout") ;
115
+
116
+ if ( assertIsSuccessful )
117
+ task . IsCompletedSuccessfully . Should ( ) . Be ( true , "task should compete successfully" ) ;
94
118
95
- task . IsCompletedSuccessfully . Should ( ) . Be ( true , $ "Timeout { timeout } while waitilng task finish successfully" ) ;
119
+ return task . Result ;
96
120
}
97
121
98
122
protected async Task GivenInitializedTopic ( string topic )
0 commit comments