Skip to content

Commit 99ad7c2

Browse files
authored
Merge pull request #93 from rabbitmq/lukebakken/port-ConsumerOutcomeTest-java
Port more tests from AMQP Java 1.0 client
2 parents 185b125 + f403308 commit 99ad7c2

File tree

7 files changed

+274
-78
lines changed

7 files changed

+274
-78
lines changed

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Auto detect text files and perform LF normalization
5+
*.cs text=auto
6+
*.txt text=auto
7+
8+
# Declare files that will always have CRLF line endings on checkout.
9+
*.sln text eol=crlf
10+
*.csproj text eol=crlf
11+
12+
# Custom for Visual Studio
13+
*.cs diff=csharp

Tests/ConnectionRecoveryTests.cs

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ public async Task RecoveryTopologyShouldRecoverTheTempQueues()
244244
Assert.Null(_connection);
245245
Assert.Null(_management);
246246

247-
string queueName = $"temp-queue-should-recover-{true}";
248247
IConnection connection = await AmqpConnection.CreateAsync(
249248
ConnectionSettingBuilder.Create()
250249
.RecoveryConfiguration(RecoveryConfiguration.Create()
@@ -263,18 +262,18 @@ public async Task RecoveryTopologyShouldRecoverTheTempQueues()
263262
};
264263
IManagement management = connection.Management();
265264
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
266-
await management.Queue().Name(queueName).AutoDelete(true).Exclusive(true).DeclareAsync();
265+
await management.Queue().Name(_queueName).AutoDelete(true).Exclusive(true).DeclareAsync();
267266
Assert.Equal(1, topologyListener.QueueCount());
268267

269268
await SystemUtils.WaitUntilConnectionIsKilled(_containerId);
270269
await twoRecoveryEventsSeenTcs.Task.WaitAsync(TimeSpan.FromSeconds(10));
271270
await SystemUtils.WaitUntilFuncAsync(() => recoveryEvents == 2);
272271

273-
await SystemUtils.WaitUntilQueueExistsAsync(queueName);
272+
await SystemUtils.WaitUntilQueueExistsAsync(_queueName);
274273

275274
await connection.CloseAsync();
276275

277-
await SystemUtils.WaitUntilQueueDeletedAsync(queueName);
276+
await SystemUtils.WaitUntilQueueDeletedAsync(_queueName);
278277

279278
Assert.Equal(0, topologyListener.QueueCount());
280279
}
@@ -292,7 +291,6 @@ public async Task RecoveryTopologyShouldNotRecoverTheTempQueues()
292291
Assert.Null(_connection);
293292
Assert.Null(_management);
294293

295-
string queueName = $"temp-queue-should-recover-{false}";
296294
IConnection connection = await AmqpConnection.CreateAsync(
297295
ConnectionSettingBuilder.Create()
298296
.RecoveryConfiguration(RecoveryConfiguration.Create()
@@ -311,13 +309,13 @@ public async Task RecoveryTopologyShouldNotRecoverTheTempQueues()
311309
};
312310
IManagement management = connection.Management();
313311
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
314-
await management.Queue().Name(queueName).AutoDelete(true).Exclusive(true).DeclareAsync();
312+
await management.Queue().Name(_queueName).AutoDelete(true).Exclusive(true).DeclareAsync();
315313
Assert.Equal(1, topologyListener.QueueCount());
316314

317315
await SystemUtils.WaitUntilConnectionIsKilled(_containerId);
318316
await oneRecoveryEventSeenTcs.Task.WaitAsync(TimeSpan.FromSeconds(10));
319317

320-
await SystemUtils.WaitUntilQueueDeletedAsync(queueName);
318+
await SystemUtils.WaitUntilQueueDeletedAsync(_queueName);
321319

322320
await connection.CloseAsync();
323321
Assert.Equal(0, topologyListener.QueueCount());
@@ -331,7 +329,6 @@ public async Task RecoveryTopologyShouldRecoverExchanges(bool topologyEnabled)
331329
Assert.Null(_connection);
332330
Assert.Null(_management);
333331

334-
const string exchangeName = "exchange-should-recover";
335332
IConnection connection = await AmqpConnection.CreateAsync(
336333
ConnectionSettingBuilder.Create()
337334
.RecoveryConfiguration(RecoveryConfiguration.Create()
@@ -350,26 +347,26 @@ public async Task RecoveryTopologyShouldRecoverExchanges(bool topologyEnabled)
350347
};
351348
IManagement management = connection.Management();
352349
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
353-
IExchangeSpecification exSpec = management.Exchange().Name(exchangeName).AutoDelete(true)
350+
IExchangeSpecification exSpec = management.Exchange().Name(_exchangeName).AutoDelete(true)
354351
.Type(ExchangeType.DIRECT);
355352
await exSpec.DeclareAsync();
356353
Assert.Equal(1, topologyListener.ExchangeCount());
357354

358355
// Since we cannot reboot the broker for this test we delete the exchange manually to simulate check if
359356
// the exchange is recovered.
360-
await SystemUtils.DeleteExchangeAsync("exchange-should-recover");
357+
await SystemUtils.DeleteExchangeAsync(_exchangeName);
361358

362359
await SystemUtils.WaitUntilConnectionIsKilled(_containerId);
363360

364361
await twoRecoveryEventsSeenTcs.Task.WaitAsync(TimeSpan.FromSeconds(10));
365362

366363
if (topologyEnabled)
367364
{
368-
await SystemUtils.WaitUntilExchangeExistsAsync(exchangeName);
365+
await SystemUtils.WaitUntilExchangeExistsAsync(_exchangeName);
369366
}
370367
else
371368
{
372-
await SystemUtils.WaitUntilExchangeDeletedAsync(exchangeName);
369+
await SystemUtils.WaitUntilExchangeDeletedAsync(_exchangeName);
373370
}
374371

375372
Assert.Equal(1, topologyListener.ExchangeCount());
@@ -408,12 +405,14 @@ public async Task RecoveryTopologyShouldRecoverBindings(bool topologyEnabled)
408405
};
409406
IManagement management = connection.Management();
410407
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
411-
IExchangeSpecification exSpec = management.Exchange().Name("exchange-should-recover-binding").AutoDelete(true)
408+
IExchangeSpecification exSpec = management.Exchange().Name(_exchangeName).AutoDelete(true)
412409
.Type(ExchangeType.DIRECT);
413410
await exSpec.DeclareAsync();
414411
Assert.Equal(1, topologyListener.ExchangeCount());
415-
IQueueSpecification queueSpec = management.Queue().Name("queue-should-recover-binding").AutoDelete(true).Exclusive(true);
412+
413+
IQueueSpecification queueSpec = management.Queue().Name(_queueName).AutoDelete(true).Exclusive(true);
416414
await queueSpec.DeclareAsync();
415+
417416
Assert.Equal(1, topologyListener.QueueCount());
418417
IBindingSpecification bindingSpec =
419418
management.Binding().SourceExchange(exSpec).DestinationQueue(queueSpec).Key("key");
@@ -422,25 +421,23 @@ public async Task RecoveryTopologyShouldRecoverBindings(bool topologyEnabled)
422421

423422
// Since we cannot reboot the broker for this test we delete the exchange manually to simulate check if
424423
// the exchange is recovered.
425-
await SystemUtils.DeleteExchangeAsync("exchange-should-recover-binding");
424+
await SystemUtils.DeleteExchangeAsync(_exchangeName);
426425

427426
// The queue will be deleted due of the auto-delete flag
428427
await SystemUtils.WaitUntilConnectionIsKilled(_containerId);
429428
await twoRecoveryEventsSeenTcs.Task.WaitAsync(TimeSpan.FromSeconds(10));
430429

431430
if (topologyEnabled)
432431
{
433-
await SystemUtils.WaitUntilExchangeExistsAsync("exchange-should-recover-binding");
434-
await SystemUtils.WaitUntilQueueExistsAsync("queue-should-recover-binding");
435-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync("exchange-should-recover-binding",
436-
"queue-should-recover-binding");
432+
await SystemUtils.WaitUntilExchangeExistsAsync(_exchangeName);
433+
await SystemUtils.WaitUntilQueueExistsAsync(_queueName);
434+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync(_exchangeName, _queueName);
437435
}
438436
else
439437
{
440-
await SystemUtils.WaitUntilExchangeDeletedAsync("exchange-should-recover-binding");
441-
await SystemUtils.WaitUntilQueueDeletedAsync("queue-should-recover-binding");
442-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync("exchange-should-recover-binding",
443-
"queue-should-recover-binding");
438+
await SystemUtils.WaitUntilExchangeDeletedAsync(_exchangeName);
439+
await SystemUtils.WaitUntilQueueDeletedAsync(_queueName);
440+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync(_exchangeName, _queueName);
444441
}
445442

446443
Assert.Equal(1, topologyListener.ExchangeCount());
@@ -471,6 +468,8 @@ public async Task RemoveAQueueShouldRemoveTheBindings()
471468
Assert.Null(_connection);
472469
Assert.Null(_management);
473470

471+
string wontDeleteQueueName = _queueName + "-wont-delete";
472+
474473
IConnection connection = await AmqpConnection.CreateAsync(
475474
ConnectionSettingBuilder.Create()
476475
.RecoveryConfiguration(RecoveryConfiguration.Create()
@@ -481,43 +480,39 @@ public async Task RemoveAQueueShouldRemoveTheBindings()
481480

482481
IManagement management = connection.Management();
483482
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
484-
IExchangeSpecification exSpec = management.Exchange().Name("e-remove-a-should-remove-binding")
483+
IExchangeSpecification exSpec = management.Exchange().Name(_exchangeName)
485484
.Type(ExchangeType.DIRECT);
486485

487486
await exSpec.DeclareAsync();
488487

489-
IQueueSpecification queueSpec = management.Queue().Name("q-remove-a-should-remove-binding")
488+
IQueueSpecification queueSpec = management.Queue().Name(_queueName)
490489
.AutoDelete(true).Exclusive(true);
491490
await queueSpec.DeclareAsync();
492491

493-
IQueueSpecification queueSpecWontDeleted = management.Queue().Name("q-remove-a-should-remove-binding-wont-delete")
492+
IQueueSpecification queueSpecWontDelete = management.Queue().Name(wontDeleteQueueName)
494493
.AutoDelete(true).Exclusive(true);
495-
496-
await queueSpecWontDeleted.DeclareAsync();
494+
await queueSpecWontDelete.DeclareAsync();
497495

498496
for (int i = 0; i < 10; i++)
499497
{
500498
await management.Binding().SourceExchange(exSpec)
501499
.DestinationQueue(queueSpec).Key($"key_{i}").BindAsync();
502500

503501
await management.Binding().SourceExchange(exSpec)
504-
.DestinationQueue(queueSpecWontDeleted).Key($"key_{i}").BindAsync();
502+
.DestinationQueue(queueSpecWontDelete).Key($"key_{i}").BindAsync();
505503
}
506504

507-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync("e-remove-a-should-remove-binding",
508-
"q-remove-a-should-remove-binding");
505+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync(_exchangeName, _queueName);
509506

510-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync("e-remove-a-should-remove-binding",
511-
"q-remove-a-should-remove-binding-wont-delete");
507+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync(_exchangeName, wontDeleteQueueName);
512508

513509
Assert.Equal(20, topologyListener.BindingCount());
514510
await queueSpec.DeleteAsync();
515511

516-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync("e-remove-a-should-remove-binding",
517-
"q-remove-a-should-remove-binding");
512+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync(_exchangeName, _queueName);
518513

519514
Assert.Equal(10, topologyListener.BindingCount());
520-
await queueSpecWontDeleted.DeleteAsync();
515+
await queueSpecWontDelete.DeleteAsync();
521516

522517
await exSpec.DeleteAsync();
523518

@@ -533,6 +528,8 @@ public async Task RemoveAnExchangeShouldRemoveTheBindings()
533528
Assert.Null(_connection);
534529
Assert.Null(_management);
535530

531+
string wontDeleteExchangeName = _exchangeName + "-wont-delete";
532+
536533
IConnection connection = await AmqpConnection.CreateAsync(
537534
ConnectionSettingBuilder.Create()
538535
.RecoveryConfiguration(RecoveryConfiguration.Create()
@@ -543,17 +540,17 @@ public async Task RemoveAnExchangeShouldRemoveTheBindings()
543540

544541
IManagement management = connection.Management();
545542
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
546-
IExchangeSpecification exSpec = management.Exchange().Name("e-remove-exchange-should-remove-binding")
543+
IExchangeSpecification exSpec = management.Exchange().Name(_exchangeName)
547544
.Type(ExchangeType.DIRECT);
548545

549546
await exSpec.DeclareAsync();
550547

551-
IExchangeSpecification exSpecWontDeleted = management.Exchange().Name("e-remove-exchange-should-remove-binding-wont-delete")
548+
IExchangeSpecification exSpecWontDeleted = management.Exchange().Name(wontDeleteExchangeName)
552549
.Type(ExchangeType.DIRECT);
553550

554551
await exSpecWontDeleted.DeclareAsync();
555552

556-
IQueueSpecification queueSpec = management.Queue().Name("q-remove-exchange-should-remove-binding")
553+
IQueueSpecification queueSpec = management.Queue().Name(_queueName)
557554
.AutoDelete(true).Exclusive(true);
558555
await queueSpec.DeclareAsync();
559556

@@ -566,19 +563,19 @@ await management.Binding().SourceExchange(exSpecWontDeleted)
566563
.DestinationQueue(queueSpec).Key($"key_{i}").BindAsync();
567564
}
568565

569-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync("e-remove-exchange-should-remove-binding",
570-
"q-remove-exchange-should-remove-binding");
566+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync(_exchangeName,
567+
_queueName);
571568

572569
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync(
573-
"e-remove-exchange-should-remove-binding-wont-delete",
574-
"q-remove-exchange-should-remove-binding");
570+
wontDeleteExchangeName,
571+
_queueName);
575572

576573
Assert.Equal(20, topologyListener.BindingCount());
577574
await exSpec.DeleteAsync();
578575

579576
await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync(
580-
"e-remove-exchange-should-remove-binding",
581-
"q-remove-exchange-should-remove-binding");
577+
_exchangeName,
578+
_queueName);
582579

583580
Assert.Equal(10, topologyListener.BindingCount());
584581
await exSpecWontDeleted.DeleteAsync();
@@ -600,6 +597,8 @@ public async Task RemoveAnExchangeBoundToAnotherExchangeShouldRemoveTheBindings(
600597
Assert.Null(_connection);
601598
Assert.Null(_management);
602599

600+
string destinationExchangeName = _exchangeName + "-destination";
601+
603602
IConnection connection = await AmqpConnection.CreateAsync(
604603
ConnectionSettingBuilder.Create()
605604
.RecoveryConfiguration(RecoveryConfiguration.Create()
@@ -611,13 +610,13 @@ public async Task RemoveAnExchangeBoundToAnotherExchangeShouldRemoveTheBindings(
611610
IManagement management = connection.Management();
612611
ITopologyListener topologyListener = ((IManagementTopology)management).TopologyListener();
613612

614-
IExchangeSpecification exSpec = management.Exchange().Name("e-remove-exchange-bound-to-another-exchange-should-remove-binding")
613+
IExchangeSpecification exSpec = management.Exchange().Name(_exchangeName)
615614
.Type(ExchangeType.DIRECT);
616615

617616
await exSpec.DeclareAsync();
618617

619618
IExchangeSpecification exSpecDestination = management.Exchange()
620-
.Name("e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination")
619+
.Name(destinationExchangeName)
621620
.Type(ExchangeType.DIRECT);
622621

623622
await exSpecDestination.DeclareAsync();
@@ -628,9 +627,7 @@ await management.Binding().SourceExchange(exSpec)
628627
.DestinationExchange(exSpecDestination).Key($"key_{i}").BindAsync();
629628
}
630629

631-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndExchangeExistAsync(
632-
"e-remove-exchange-bound-to-another-exchange-should-remove-binding",
633-
"e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination");
630+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndExchangeExistAsync(_exchangeName, destinationExchangeName);
634631

635632
Assert.Equal(10, topologyListener.BindingCount());
636633

@@ -639,9 +636,7 @@ await SystemUtils.WaitUntilBindingsBetweenExchangeAndExchangeExistAsync(
639636

640637
await exSpec.DeleteAsync();
641638

642-
await SystemUtils.WaitUntilBindingsBetweenExchangeAndExchangeDontExistAsync(
643-
"e-remove-exchange-bound-to-another-exchange-should-remove-binding",
644-
"e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination");
639+
await SystemUtils.WaitUntilBindingsBetweenExchangeAndExchangeDontExistAsync(_exchangeName, destinationExchangeName);
645640

646641
Assert.Equal(0, topologyListener.ExchangeCount());
647642

0 commit comments

Comments
 (0)