Add JMX MBean for Tomcat DataSource
If the DataSource is a Tomcat one we force it to register an MBean if spring.jmx.enabled=true Fixes gh-1590
This commit is contained in:
@@ -1,29 +1,38 @@
|
||||
package sample.data.jpa;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Integration test to run the application.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleDataJpaApplication.class)
|
||||
@WebAppConfiguration
|
||||
// Enable JMX so we can test the MBeans (you can't do this in a properties file)
|
||||
@TestPropertySource(properties="spring.jmx.enabled:true")
|
||||
@ActiveProfiles("scratch")
|
||||
// Separate profile for web tests to avoid clashing databases
|
||||
public class SampleDataJpaApplicationTests {
|
||||
@@ -44,4 +53,11 @@ public class SampleDataJpaApplicationTests {
|
||||
this.mvc.perform(get("/")).andExpect(status().isOk())
|
||||
.andExpect(content().string("Bath"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmx() throws Exception {
|
||||
assertEquals(1, ManagementFactory.getPlatformMBeanServer().queryMBeans(
|
||||
new ObjectName("jpa.sample:type=ConnectionPool,*"), null).size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user