Skip to content

Commit 1573214

Browse files
authored
Fix ToString function in case partitions is null. (#410)
* Fix to string in case partitions is null. The bug was introduced on #406 --------- Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 3f18a21 commit 1573214

File tree

6 files changed

+71
-22
lines changed

6 files changed

+71
-22
lines changed

RabbitMQ.Stream.Client/IConsumer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public ConsumerInfo(string stream, string reference, string identifier, List<str
8989

9090
public override string ToString()
9191
{
92-
return $"ConsumerInfo(Stream={Stream}, Reference={Reference}, Identifier={Identifier}, Partitions={string.Join(",", Partitions)})";
92+
var partitions = Partitions ?? [];
93+
return $"ConsumerInfo(Stream={Stream}, Reference={Reference}, Identifier={Identifier}, Partitions={string.Join(",", partitions)})";
9394
}
9495
}

RabbitMQ.Stream.Client/IProducer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public ProducerInfo(string stream, string reference, string identifier, List<str
121121

122122
public override string ToString()
123123
{
124-
return $"ProducerInfo(Stream={Stream}, Reference={Reference}, Identifier={Identifier}, Partitions={string.Join(",", Partitions)})";
124+
var partitions = Partitions ?? [];
125+
126+
return $"ProducerInfo(Stream={Stream}, Reference={Reference}, Identifier={Identifier}, Partitions={string.Join(",", partitions)})";
125127
}
126128
}

Tests/RawConsumerSystemTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public async Task ConsumerStoreOffset()
122122
}
123123
});
124124

125+
Assert.Equal(
126+
$"ConsumerInfo(Stream={stream}, Reference=consumer_offset, Identifier=, Partitions=)",
127+
consumer.Info.ToString());
128+
125129
new Utils<int>(testOutputHelper).WaitUntilTaskCompletes(testPassed);
126130
await SystemUtils.WaitAsync();
127131
// // Here we use the standard client to check the offest

Tests/RawProducerSystemTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ await SystemUtils.PublishMessages(system, stream, NumberOfMessages,
278278
// sequence start from zero
279279
Assert.True(resAfter == (NumberOfMessages - 1));
280280

281-
var rawProducer = await system.CreateRawProducer(new RawProducerConfig(stream) { Reference = ProducerName });
281+
var rawProducer =
282+
await system.CreateRawProducer(new RawProducerConfig(stream) { Reference = ProducerName });
282283
Assert.True(await rawProducer.GetLastPublishingId() == (NumberOfMessages - 1));
283284
await system.DeleteStream(stream);
284285
await system.Close();
@@ -339,6 +340,9 @@ public async Task ProducerBatchConfirmNumberOfMessages()
339340
}
340341
}
341342
);
343+
Assert.Equal(
344+
$"ProducerInfo(Stream={stream}, Reference=producer, Identifier=, Partitions=)",
345+
rawProducer.Info.ToString());
342346
var messages = new List<(ulong, Message)>();
343347
for (var i = 1; i <= NumberOfMessages; i++)
344348
{

Tests/SuperStreamConsumerTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ public async Task ReliableConsumerSuperStreamInfoShouldBeTheSame()
661661
Assert.Contains(SystemUtils.InvoicesStream0, consumer.Info.Partitions);
662662
Assert.Contains(SystemUtils.InvoicesStream1, consumer.Info.Partitions);
663663
Assert.Contains(SystemUtils.InvoicesStream2, consumer.Info.Partitions);
664+
Assert.Equal(
665+
$"ConsumerInfo(Stream={SystemUtils.InvoicesExchange}, Reference=, Identifier=, Partitions={SystemUtils.InvoicesStream0},{SystemUtils.InvoicesStream1},{SystemUtils.InvoicesStream2})",
666+
consumer.Info.ToString());
664667
await consumer.Close();
665668
}
666669
}

Tests/SuperStreamProducerTests.cs

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,50 @@ private class MessageIdToStreamTestCases : IEnumerable<object[]>
6565
{
6666
public IEnumerator<object[]> GetEnumerator()
6767
{
68-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello1" } };
69-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello2" } };
70-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello3" } };
71-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-03", MessageId = "hello4" } };
72-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello5" } };
73-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-03", MessageId = "hello6" } };
74-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello7" } };
75-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello8" } };
76-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello9" } };
77-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-03", MessageId = "hello10" } };
78-
yield return new object[] { new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello88" } };
68+
yield return new object[]
69+
{
70+
new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello1" }
71+
};
72+
yield return new object[]
73+
{
74+
new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello2" }
75+
};
76+
yield return new object[]
77+
{
78+
new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello3" }
79+
};
80+
yield return new object[]
81+
{
82+
new MessageIdToStream { StreamExpected = "invoices-03", MessageId = "hello4" }
83+
};
84+
yield return new object[]
85+
{
86+
new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello5" }
87+
};
88+
yield return new object[]
89+
{
90+
new MessageIdToStream { StreamExpected = "invoices-03", MessageId = "hello6" }
91+
};
92+
yield return new object[]
93+
{
94+
new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello7" }
95+
};
96+
yield return new object[]
97+
{
98+
new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello8" }
99+
};
100+
yield return new object[]
101+
{
102+
new MessageIdToStream { StreamExpected = "invoices-01", MessageId = "hello9" }
103+
};
104+
yield return new object[]
105+
{
106+
new MessageIdToStream { StreamExpected = "invoices-03", MessageId = "hello10" }
107+
};
108+
yield return new object[]
109+
{
110+
new MessageIdToStream { StreamExpected = "invoices-02", MessageId = "hello88" }
111+
};
79112
}
80113

81114
IEnumerator IEnumerable.GetEnumerator()
@@ -360,13 +393,13 @@ await Producer.Create(new ProducerConfig(system, SuperStream)
360393
});
361394
var messages = new List<Message>()
362395
{
363-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "italy"}},
364-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "italy"}},
365-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "france"}},
366-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "spain"}},
367-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "germany"}},
368-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "germany"}},
369-
new(Encoding.Default.GetBytes("hello")) {Properties = new Properties() {MessageId = "uk"}},
396+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "italy" } },
397+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "italy" } },
398+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "france" } },
399+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "spain" } },
400+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "germany" } },
401+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "germany" } },
402+
new(Encoding.Default.GetBytes("hello")) { Properties = new Properties() { MessageId = "uk" } },
370403
};
371404

372405
foreach (var message in messages)
@@ -952,7 +985,9 @@ public async Task ReliableProducerSuperStreamInfoShouldBeTheSame()
952985
Assert.Contains(SystemUtils.InvoicesStream0, producer.Info.Partitions);
953986
Assert.Contains(SystemUtils.InvoicesStream1, producer.Info.Partitions);
954987
Assert.Contains(SystemUtils.InvoicesStream2, producer.Info.Partitions);
988+
Assert.Equal(
989+
$"ProducerInfo(Stream={SystemUtils.InvoicesExchange}, Reference=, Identifier=, Partitions={SystemUtils.InvoicesStream0},{SystemUtils.InvoicesStream1},{SystemUtils.InvoicesStream2})",
990+
producer.Info.ToString());
955991
await producer.Close();
956-
957992
}
958993
}

0 commit comments

Comments
 (0)