/*
 * 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.testing;

import com.facebook.presto.client.NodeVersion;
import com.facebook.presto.metadata.PrestoNode;
import com.facebook.presto.spi.Node;
import com.facebook.presto.spi.NodeManager;
import com.google.common.collect.ImmutableSet;

import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import static java.util.Objects.requireNonNull;

public class TestingNodeManager
        implements NodeManager
{
    private final Node localNode;
    private final Set<Node> nodes = new CopyOnWriteArraySet<>();

    public TestingNodeManager()
    {
        this(new PrestoNode("local", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
    }

    public TestingNodeManager(Node localNode)
    {
        this(localNode, ImmutableSet.of());
    }

    public TestingNodeManager(List<Node> allNodes)
    {
        this(allNodes.iterator().next(), allNodes);
    }

    public TestingNodeManager(Node localNode, Collection<Node> otherNodes)
    {
        this.localNode = requireNonNull(localNode, "localNode is null");
        nodes.add(localNode);
        nodes.addAll(otherNodes);
    }

    public void addNode(Node node)
    {
        nodes.add(node);
    }

    @Override
    public Set<Node> getAllNodes()
    {
        return nodes;
    }

    @Override
    public Set<Node> getWorkerNodes()
    {
        return nodes;
    }

    @Override
    public Node getCurrentNode()
    {
        return localNode;
    }

    @Override
    public String getEnvironment()
    {
        return "testenv";
    }
}

@@ -1076,16 +1076,117 @@
 nager%0A%7B%0A
+    private static final String TEST_ENVIRONMENT = %22testenv%22;%0A%0A    private final String environment;%0A
     priv
@@ -1328,16 +1328,124 @@
    this(
+TEST_ENVIRONMENT);%0A    %7D%0A%0A    public TestingNodeManager(String environment)%0A    %7B%0A        this(environment, 
 new Pres
@@ -1519,16 +1519,35 @@
 N, true)
+, ImmutableSet.of()
 );%0A    %7D
@@ -1840,32 +1840,235 @@
 herNodes)%0A    %7B%0A
+        this(TEST_ENVIRONMENT, localNode, otherNodes);%0A    %7D%0A%0A    public TestingNodeManager(String environment, Node localNode, Collection%3CNode%3E otherNodes)%0A    %7B%0A        this.environment = environment;%0A
         this.loc
@@ -2595,25 +2595,27 @@
  return 
-%22testenv%22
+environment
 ;%0A    %7D%0A

Allow configuration of environment in TestingNodeManager