Search in sources :

Example 1 with TestingHttpServer

use of io.airlift.http.server.testing.TestingHttpServer in project airlift by airlift.

the class TestMBeanServerResource method setup.

@BeforeMethod
public void setup() throws Exception {
    Bootstrap app = new Bootstrap(new TestingNodeModule(), new TestingHttpServerModule(), new JsonModule(), new JmxHttpRpcModule(TheServlet.class), binder -> {
        binder.bind(MBeanServer.class).toInstance(platformMBeanServer);
        binder.bind(TestMBean.class).in(Scopes.SINGLETON);
    });
    Injector injector = app.doNotInitializeLogging().initialize();
    lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    TestingHttpServer server = injector.getInstance(TestingHttpServer.class);
    testMBean = injector.getInstance(TestMBean.class);
    testMBeanName = new ObjectName(generatedNameOf(TestMBean.class));
    MBeanExporter exporter = new MBeanExporter(platformMBeanServer);
    exporter.export(testMBeanName.toString(), testMBean);
    JMXConnector connect = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:" + server.getBaseUrl()), ImmutableMap.of(JMXConnector.CREDENTIALS, new String[] { "foo", "bar" }));
    mbeanServerConnection = connect.getMBeanServerConnection();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) TestingHttpServerModule(io.airlift.http.server.testing.TestingHttpServerModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) MBeanExporter(org.weakref.jmx.MBeanExporter) JsonModule(io.airlift.json.JsonModule) TheServlet(io.airlift.http.server.TheServlet) ObjectName(javax.management.ObjectName) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) JMXConnector(javax.management.remote.JMXConnector) TestingHttpServer(io.airlift.http.server.testing.TestingHttpServer) Bootstrap(io.airlift.bootstrap.Bootstrap) MBeanServer(javax.management.MBeanServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Injector (com.google.inject.Injector)1 Bootstrap (io.airlift.bootstrap.Bootstrap)1 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)1 TheServlet (io.airlift.http.server.TheServlet)1 TestingHttpServer (io.airlift.http.server.testing.TestingHttpServer)1 TestingHttpServerModule (io.airlift.http.server.testing.TestingHttpServerModule)1 JsonModule (io.airlift.json.JsonModule)1 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 MBeanExporter (org.weakref.jmx.MBeanExporter)1