INT-3831: Fix MessagingGatewaySupport MBean Export
JIRA: https://jira.spring.io/browse/INT-3831 - Add `@IntegrationManagedResource` - Suppress exporting as an endpoint Fix `outputChannel` issue for anonymous `MessagingGatewaySupport` INT-3831: Pure JavaConfig Test INT-3831: Polishing Check output channel name for anonymous message source metrics. Don't use getter on MGS to avoid early channel resolution. INT-3831: Fix Test - Avoid Second MBeanServer Reference the `MBSFB` in the context rather than create a new `MBeanServer`. Polishing
This commit is contained in:
committed by
Artem Bilan
parent
1012e588e4
commit
37aaa82272
@@ -15,20 +15,23 @@
|
||||
<jmx:mbean-export id="integrationMbeanExporter" server="mbs" default-domain="test.MBeanRegistration"/>
|
||||
|
||||
<context:mbean-server id="mbs" />
|
||||
|
||||
|
||||
<context:mbean-export server="mbs" default-domain="test.MBeanRegistration"/>
|
||||
|
||||
<int:channel id="testChannel" />
|
||||
|
||||
|
||||
<int:service-activator id="service" input-channel="testChannel" method="get">
|
||||
<bean class="org.springframework.integration.jmx.config.MBeanRegistrationTests$Source"/>
|
||||
</int:service-activator>
|
||||
|
||||
|
||||
<int:logging-channel-adapter id="logger" channel="testChannel"/>
|
||||
|
||||
|
||||
<int:chain id="chain" input-channel="chainin">
|
||||
<int:transformer id="t1" expression="'foo'"/>
|
||||
<int:filter id="f1" expression="true"/>
|
||||
</int:chain>
|
||||
|
||||
<bean id="org.springframework.integration.MyGateway"
|
||||
class="org.springframework.integration.jmx.config.MBeanRegistrationTests.MyMessagingGateway" />
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.gateway.MessagingGatewaySupport;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -62,6 +63,8 @@ public class MBeanRegistrationTests {
|
||||
// System.err.println(Arrays.asList(server.getMBeanInfo(server.queryNames(new ObjectName("*:type=*Handler,*"), null).iterator().next()).getAttributes()));
|
||||
Set<ObjectName> names = server.queryNames(new ObjectName("test.MBeanRegistration:type=IntegrationMBeanExporter,name=integrationMbeanExporter,*"), null);
|
||||
assertEquals(1, names.size());
|
||||
names = server.queryNames(new ObjectName("test.MBeanRegistration:*,name=org.springframework.integration.MyGateway"), null);
|
||||
assertEquals(server.toString(), 1, names.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,4 +86,8 @@ public class MBeanRegistrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyMessagingGateway extends MessagingGatewaySupport {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -133,7 +133,9 @@ public class EnableMBeanExportTests {
|
||||
|
||||
@Bean
|
||||
public MBeanServerFactoryBean mbeanServer() {
|
||||
return new MBeanServerFactoryBean();
|
||||
MBeanServerFactoryBean mBeanServerFactoryBean = new MBeanServerFactoryBean();
|
||||
mBeanServerFactoryBean.setLocateExistingServerIfPossible(true);
|
||||
return mBeanServerFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -28,7 +28,6 @@ import static org.junit.Assert.fail;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
@@ -76,6 +75,7 @@ import com.hazelcast.core.HazelcastInstance;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@@ -185,7 +185,9 @@ public class IdempotentReceiverIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public static MBeanServerFactoryBean mBeanServer() {
|
||||
return new MBeanServerFactoryBean();
|
||||
MBeanServerFactoryBean mBeanServerFactoryBean = new MBeanServerFactoryBean();
|
||||
mBeanServerFactoryBean.setLocateExistingServerIfPossible(true);
|
||||
return mBeanServerFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.gateway.MessagingGatewaySupport;
|
||||
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
|
||||
import org.springframework.jmx.support.MBeanServerFactoryBean;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 4.2.1
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class MessagingGatewaySupportRegistrationTests {
|
||||
|
||||
@Autowired
|
||||
private MBeanServer server;
|
||||
|
||||
@Test
|
||||
public void testHandlerMBeanRegistration() throws Exception {
|
||||
Set<ObjectName> names = this.server
|
||||
.queryNames(new ObjectName("org.springframework.integration:*,name=testGateway"), null);
|
||||
assertEquals(1, names.size());
|
||||
names = this.server.queryNames(new ObjectName("org.springframework.integration:*,type=MessageSource,name=foo"),
|
||||
null);
|
||||
assertEquals(1, names.size());
|
||||
names = this.server.queryNames(new ObjectName("org.springframework.integration:*,name=foo#2"), null);
|
||||
assertEquals(1, names.size());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableIntegration
|
||||
// TODO INT-3869
|
||||
@EnableIntegrationMBeanExport(server = "server")
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public MessagingGatewaySupport testGateway() {
|
||||
return new MessagingGatewaySupport() {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageChannel foo() {
|
||||
return new NullChannel();
|
||||
}
|
||||
|
||||
@Bean(name = "org.springframework.integration.foo1")
|
||||
public MessagingGatewaySupport anonymous1() {
|
||||
MessagingGatewaySupport messagingGatewaySupport = new MessagingGatewaySupport() {
|
||||
|
||||
};
|
||||
messagingGatewaySupport.setRequestChannel(foo());
|
||||
return messagingGatewaySupport;
|
||||
}
|
||||
|
||||
@Bean(name = "org.springframework.integration.foo2")
|
||||
public MessagingGatewaySupport anonymous2() {
|
||||
MessagingGatewaySupport messagingGatewaySupport = new MessagingGatewaySupport() {
|
||||
|
||||
};
|
||||
messagingGatewaySupport.setRequestChannelName("foo");
|
||||
return messagingGatewaySupport;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MBeanServerFactoryBean server() {
|
||||
MBeanServerFactoryBean fb = new MBeanServerFactoryBean();
|
||||
fb.setLocateExistingServerIfPossible(true);
|
||||
return fb;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,7 +128,9 @@ public class ScatterGatherHandlerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public static MBeanServerFactoryBean mBeanServer() {
|
||||
return new MBeanServerFactoryBean();
|
||||
MBeanServerFactoryBean mBeanServerFactoryBean = new MBeanServerFactoryBean();
|
||||
mBeanServerFactoryBean.setLocateExistingServerIfPossible(true);
|
||||
return mBeanServerFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user