Skip to content

Commit dc55654

Browse files
committed
test: skipping recovery manual declaration when no application context
1 parent b81a4af commit dc55654

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminTests.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,52 @@ void manualDeclarations() {
445445
cf.destroy();
446446
}
447447

448+
@Test
449+
void manualDeclarationsWithoutApplicationContext() {
450+
CachingConnectionFactory cf = new CachingConnectionFactory(
451+
RabbitAvailableCondition.getBrokerRunning().getConnectionFactory());
452+
RabbitAdmin admin = new RabbitAdmin(cf);
453+
admin.setRedeclareManualDeclarations(true);
454+
Map<?, ?> declarables = TestUtils.getPropertyValue(admin, "manualDeclarables", Map.class);
455+
assertThat(declarables).hasSize(0);
456+
RabbitTemplate template = new RabbitTemplate(cf);
457+
// manual declarations
458+
admin.declareQueue(new Queue("test1", false, true, true));
459+
admin.declareQueue(new Queue("test2", false, true, true));
460+
admin.declareExchange(new DirectExchange("ex1", false, true));
461+
admin.declareBinding(new Binding("test1", DestinationType.QUEUE, "ex1", "test", null));
462+
admin.deleteQueue("test2");
463+
template.execute(chan -> chan.queueDelete("test1"));
464+
cf.resetConnection();
465+
admin.initialize();
466+
assertThat(admin.getQueueProperties("test1")).isNotNull();
467+
assertThat(admin.getQueueProperties("test2")).isNull();
468+
assertThat(declarables).hasSize(3);
469+
// verify the exchange and binding were recovered too
470+
template.convertAndSend("ex1", "test", "foo");
471+
Object received = template.receiveAndConvert("test1", 5000);
472+
assertThat(received).isEqualTo("foo");
473+
admin.resetAllManualDeclarations();
474+
assertThat(declarables).hasSize(0);
475+
cf.resetConnection();
476+
admin.initialize();
477+
assertThat(admin.getQueueProperties("test1")).isNull();
478+
admin.declareQueue(new Queue("test1", false, true, true));
479+
admin.declareExchange(new DirectExchange("ex1", false, true));
480+
admin.declareBinding(new Binding("test1", DestinationType.QUEUE, "ex1", "test", null));
481+
admin.declareExchange(new DirectExchange("ex2", false, true));
482+
admin.declareBinding(new Binding("test1", DestinationType.QUEUE, "ex2", "test", null));
483+
admin.declareBinding(new Binding("ex1", DestinationType.EXCHANGE, "ex2", "ex1", null));
484+
assertThat(declarables).hasSize(6);
485+
admin.deleteExchange("ex2");
486+
assertThat(declarables).hasSize(3);
487+
admin.deleteQueue("test1");
488+
assertThat(declarables).hasSize(1);
489+
admin.deleteExchange("ex1");
490+
assertThat(declarables).hasSize(0);
491+
cf.destroy();
492+
}
493+
448494
@Configuration
449495
public static class Config {
450496

0 commit comments

Comments
 (0)