Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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 com.facebook.presto.server.testing;
 
 
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
 import static com.facebook.presto.server.testing.FileUtils.deleteRecursively;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public class TestingPrestoServer
         implements Closeable
 {
     private final Path baseDataDir;
     private final LifeCycleManager lifeCycleManager;
     private final PluginManager pluginManager;
     private final ConnectorManager connectorManager;
     private final TestingHttpServer server;
     private final Metadata metadata;
     private final InternalNodeManager nodeManager;
 
     public TestingPrestoServer()
             throws Exception
     {
         this(ImmutableList.<Module>of());
     }
 
     public TestingPrestoServer(List<ModuleadditionalModules)
             throws Exception
     {
         this(true, ImmutableMap.<StringString>of(), nullnulladditionalModules);
     }
 
     public TestingPrestoServer(boolean coordinatorMap<StringStringpropertiesString environmentURI discoveryUriList<ModuleadditionalModules)
             throws Exception
     {
          = Files.createTempDirectory("PrestoTest");
 
         ImmutableMap.Builder<StringStringserverProperties = ImmutableMap.<StringString>builder()
                 .putAll(properties)
                 .put("coordinator", String.valueOf(coordinator))
                 .put("storage-manager.data-directory".toString())
                 .put("presto-metastore.db.type""h2")
                 .put("presto-metastore.db.filename".resolve("db/MetaStore").toString())
                 .put("presto.version""testversion")
                 .put("analyzer.experimental-syntax-enabled""true");
 
         if (coordinator) {
             // TODO: enable failure detector
             serverProperties.put("failure-detector.enabled""false");
         }
 
         ImmutableList.Builder<Modulemodules = ImmutableList.<Module>builder()
                .add(new TestingNodeModule(Optional.fromNullable(environment)))
                .add(new TestingHttpServerModule())
                .add(new JsonModule())
                .add(new JaxrsModule())
                .add(new MBeanModule())
                .add(new TestingJmxModule())
                .add(new InMemoryEventModule())
                .add(new TraceTokenModule())
                .add(new ServerMainModule());
        if (discoveryUri != null) {
            checkNotNull(environment"environment required when discoveryUri is present");
            serverProperties.put("discovery.uri"discoveryUri.toString());
            modules.add(new DiscoveryModule());
        }
        else {
            modules.add(new TestingDiscoveryModule());
        }
        modules.addAll(additionalModules);
        Bootstrap app = new Bootstrap(modules.build());
        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(serverProperties.build())
                .initialize();
        injector.getInstance(Announcer.class).start();
         = injector.getInstance(LifeCycleManager.class);
         = injector.getInstance(PluginManager.class);
         = injector.getInstance(ConnectorManager.class);
        .createConnection("default""native", ImmutableMap.<StringString>of());
         = injector.getInstance(TestingHttpServer.class);
         = injector.getInstance(Metadata.class);
         = injector.getInstance(InternalNodeManager.class);
         = injector.getInstance(ServiceSelectorManager.class);
        refreshNodes();
    }
    @Override
    public void close()
    {
        try {
            if ( != null) {
                .stop();
            }
        }
        catch (Exception e) {
            throw Throwables.propagate(e);
        }
        finally {
            deleteRecursively();
        }
    }
    public void installPlugin(Plugin pluginString catalogNameString connectorName)
    {
        .installPlugin(plugin);
        .createConnection(catalogNameconnectorName, ImmutableMap.<StringString>of());
    }
    public URI getBaseUrl()
    {
        return .getBaseUrl();
    }
    public URI resolve(String path)
    {
        return .getBaseUrl().resolve(path);
    }
    public HostAndPort getAddress()
    {
        return HostAndPort.fromParts(getBaseUrl().getHost(), getBaseUrl().getPort());
    }
    public Metadata getMetadata()
    {
        return ;
    }
    public final AllNodes refreshNodes()
    {
        .refreshNodes();
        return .getAllNodes();
    }
New to GrepCode? Check out our FAQ X