Skip to content

Commit

Permalink
spring-projectsGH-885: Work in process
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Jan 22, 2019
1 parent b9d5e11 commit aef9bc7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ public void initialize() {

this.logger.debug("Initializing declarations");
Collection<Exchange> contextExchanges = new LinkedList<Exchange>(
this.applicationContext.getBeansOfType(Exchange.class).values());
this.applicationContext.getBeansOfType(Exchange.class, false, false).values());
Collection<Queue> contextQueues = new LinkedList<Queue>(
this.applicationContext.getBeansOfType(Queue.class).values());
this.applicationContext.getBeansOfType(Queue.class, false, false).values());
Collection<Binding> contextBindings = new LinkedList<Binding>(
this.applicationContext.getBeansOfType(Binding.class).values());
this.applicationContext.getBeansOfType(Binding.class, false, false).values());

processLegacyCollections(contextExchanges, contextQueues, contextBindings);
processDeclarables(contextExchanges, contextQueues, contextBindings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
Expand Down Expand Up @@ -75,6 +76,8 @@
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
Expand All @@ -83,6 +86,7 @@
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.GenericApplicationContext;

Expand Down Expand Up @@ -203,12 +207,12 @@ public void testTemporaryLogs() throws Exception {
queues.put("adQ", new Queue("testq.ad", true, false, true));
queues.put("exclQ", new Queue("testq.excl", true, true, false));
queues.put("allQ", new Queue("testq.all", false, true, true));
when(ctx.getBeansOfType(Queue.class)).thenReturn(queues);
when(ctx.getBeansOfType(Queue.class, false, false)).thenReturn(queues);
Map<String, Exchange> exchanges = new HashMap<String, Exchange>();
exchanges.put("nonDurEx", new DirectExchange("testex.nonDur", false, false));
exchanges.put("adEx", new DirectExchange("testex.ad", true, true));
exchanges.put("allEx", new DirectExchange("testex.all", false, true));
when(ctx.getBeansOfType(Exchange.class)).thenReturn(exchanges);
when(ctx.getBeansOfType(Exchange.class, false, false)).thenReturn(exchanges);
rabbitAdmin.setApplicationContext(ctx);
rabbitAdmin.afterPropertiesSet();
Log logger = spy(TestUtils.getPropertyValue(rabbitAdmin, "logger", Log.class));
Expand Down Expand Up @@ -265,7 +269,9 @@ public void testMultiEntities() {
admin.deleteExchange("e2");
admin.deleteExchange("e3");
admin.deleteExchange("e4");
assertNull(admin.getQueueProperties(ctx.getBean(Config.class).prototypeQueueName));
Config config = ctx.getBean(Config.class);
assertNull(admin.getQueueProperties(config.prototypeQueueName));
assertFalse("lazy FB instantiated", config.lazyFactoryBeanInstantiated);
ctx.close();
}

Expand Down Expand Up @@ -409,19 +415,21 @@ public static class Config {

public String prototypeQueueName = UUID.randomUUID().toString();

public volatile boolean lazyFactoryBeanInstantiated;

@Bean
public ConnectionFactory cf() {
return new CachingConnectionFactory("localhost");
}

@Bean
public RabbitAdmin admin(ConnectionFactory cf) {
return new RabbitAdmin(cf);
public RabbitAdmin admin() {
return new RabbitAdmin(cf());
}

@Bean
public RabbitTemplate template(ConnectionFactory cf) {
return new RabbitTemplate(cf);
public RabbitTemplate template() {
return new RabbitTemplate(cf());
}

@Bean
Expand Down Expand Up @@ -474,6 +482,25 @@ public Declarables ds() {
new Binding("q4", DestinationType.QUEUE, "e4", "k4", null));
}

@Bean
@Lazy
public FactoryBean<Object> lazyFB() {
this.lazyFactoryBeanInstantiated = true;
return new AbstractFactoryBean<Object>() {

@Override
public Class<?> getObjectType() {
return Object.class;
}

@Override
protected Object createInstance() throws Exception {
return new Object();
}

};
}

}

private static final class EventPublisher implements ApplicationEventPublisher {
Expand Down

0 comments on commit aef9bc7

Please sign in to comment.