Search in sources :

Example 1 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class PrestoVerifier method run.

public int run(String[] args) throws Exception {
    if (args.length > 0) {
        System.setProperty("config", args[0]);
    }
    ImmutableList.Builder<Module> builder = ImmutableList.<Module>builder().add(new PrestoVerifierModule()).addAll(getAdditionalModules());
    Bootstrap app = new Bootstrap(builder.build());
    Injector injector = app.strictConfig().initialize();
    try {
        VerifierConfig config = injector.getInstance(VerifierConfig.class);
        injector.injectMembers(this);
        Set<String> supportedEventClients = injector.getInstance(Key.get(new TypeLiteral<Set<String>>() {
        }, Names.named(SUPPORTED_EVENT_CLIENTS)));
        for (String clientType : config.getEventClients()) {
            checkArgument(supportedEventClients.contains(clientType), "Unsupported event client: %s", clientType);
        }
        Set<EventClient> eventClients = injector.getInstance(Key.get(new TypeLiteral<Set<EventClient>>() {
        }));
        VerifierDao dao = new DBI(config.getQueryDatabase()).onDemand(VerifierDao.class);
        ImmutableList.Builder<QueryPair> queriesBuilder = ImmutableList.builder();
        for (String suite : config.getSuites()) {
            queriesBuilder.addAll(dao.getQueriesBySuite(suite, config.getMaxQueries()));
        }
        List<QueryPair> queries = queriesBuilder.build();
        queries = applyOverrides(config, queries);
        queries = filterQueryTypes(new SqlParser(getParserOptions()), config, queries);
        queries = filterQueries(queries);
        if (config.getShadowWrites()) {
            Sets.SetView<QueryType> allowedTypes = Sets.union(config.getTestQueryTypes(), config.getControlQueryTypes());
            checkArgument(!Sets.intersection(allowedTypes, ImmutableSet.of(CREATE, MODIFY)).isEmpty(), "CREATE or MODIFY queries must be allowed in test or control to use write shadowing");
            queries = rewriteQueries(new SqlParser(getParserOptions()), config, queries);
        }
        // Load jdbc drivers if needed
        if (config.getAdditionalJdbcDriverPath() != null) {
            List<URL> urlList = getUrls(config.getAdditionalJdbcDriverPath());
            URL[] urls = new URL[urlList.size()];
            urlList.toArray(urls);
            if (config.getTestJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getTestJdbcDriverName());
            }
            if (config.getControlJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getControlJdbcDriverName());
            }
        }
        // TODO: construct this with Guice
        Verifier verifier = new Verifier(System.out, config, eventClients);
        return verifier.run(queries);
    } finally {
        injector.getInstance(LifeCycleManager.class).stop();
    }
}
Also used : ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) DBI(org.skife.jdbi.v2.DBI) URL(java.net.URL) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) Sets(com.google.common.collect.Sets) Bootstrap(io.airlift.bootstrap.Bootstrap) SqlParser(com.facebook.presto.sql.parser.SqlParser) EventClient(io.airlift.event.client.EventClient) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Module(com.google.inject.Module)

Example 2 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project carbondata by apache.

the class CarbondataConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new JsonModule(), new CarbondataModule(connectorId, context.getTypeManager()));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
        ConnectorMetadata metadata = injector.getInstance(CarbondataMetadata.class);
        ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
        ConnectorRecordSetProvider connectorRecordSet = injector.getInstance(ConnectorRecordSetProvider.class);
        ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
        return new CarbondataConnector(lifeCycleManager, new ClassLoaderSafeConnectorMetadata(metadata, classLoader), new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), connectorRecordSet, classLoader, new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : ClassLoaderSafeConnectorMetadata(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorMetadata) JsonModule(io.airlift.json.JsonModule) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) Injector(com.google.inject.Injector) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) Bootstrap(io.airlift.bootstrap.Bootstrap) ClassLoaderSafeConnectorMetadata(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorMetadata) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader)

Example 3 with Bootstrap

use of io.airlift.bootstrap.Bootstrap 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)

Example 4 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project airlift by airlift.

the class TestServer method setup.

@BeforeMethod
public void setup() throws Exception {
    Bootstrap app = new Bootstrap(new TestingNodeModule(), new TestingHttpServerModule(), new JsonModule(), new JaxrsModule(), new JmxHttpModule(), new JmxModule(), new MainModule());
    Injector injector = app.doNotInitializeLogging().initialize();
    lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    server = injector.getInstance(TestingHttpServer.class);
    client = new JettyHttpClient();
}
Also used : LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) TestingHttpServerModule(io.airlift.http.server.testing.TestingHttpServerModule) JmxModule(io.airlift.jmx.JmxModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) Injector(com.google.inject.Injector) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) JaxrsModule(io.airlift.jaxrs.JaxrsModule) TestingHttpServer(io.airlift.http.server.testing.TestingHttpServer) Bootstrap(io.airlift.bootstrap.Bootstrap) JsonModule(io.airlift.json.JsonModule) JmxHttpModule(io.airlift.jmx.JmxHttpModule) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project airlift by airlift.

the class TestHttpClientBinder method testWithoutFilters.

@Test
public void testWithoutFilters() {
    Injector injector = new Bootstrap(binder -> httpClientBinder(binder).bindHttpClient("foo", FooClient.class)).quiet().initialize();
    assertNotNull(injector.getInstance(Key.get(HttpClient.class, FooClient.class)));
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) Test(org.testng.annotations.Test)

Aggregations

Injector (com.google.inject.Injector)26 Bootstrap (io.airlift.bootstrap.Bootstrap)26 Test (org.testng.annotations.Test)17 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)15 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)13 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)12 JsonModule (io.airlift.json.JsonModule)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)7 InMemoryEventModule (io.airlift.event.client.InMemoryEventModule)5 JaxrsModule (io.airlift.jaxrs.JaxrsModule)5 Duration (io.airlift.units.Duration)5 HttpClient (io.airlift.http.client.HttpClient)4 TheServlet (io.airlift.http.server.TheServlet)4 File (java.io.File)4 ImmutableList (com.google.common.collect.ImmutableList)3 EventModule (io.airlift.event.client.EventModule)3 HttpClientConfig (io.airlift.http.client.HttpClientConfig)3 StatusResponse (io.airlift.http.client.StatusResponseHandler.StatusResponse)3 TestingHttpServer (io.airlift.http.server.testing.TestingHttpServer)3