<commit_before>package consulrunner

import (
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path"
	"strings"
	"sync"
	"time"

	"code.cloudfoundry.org/cfhttp"
	"code.cloudfoundry.org/consuladapter"
	"github.com/hashicorp/consul/api"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

type ClusterRunner struct {
	startingPort    int
	numNodes        int
	consulProcesses []ifrit.Process
	running         bool
	dataDir         string
	configDir       string
	scheme          string
	sessionTTL      time.Duration

	mutex *sync.RWMutex
}

const defaultDataDirPrefix = "consul_data"
const defaultConfigDirPrefix = "consul_config"

func NewClusterRunner(startingPort int, numNodes int, scheme string) *ClusterRunner {
	Expect(startingPort).To(BeNumerically(">", 0))
	Expect(startingPort).To(BeNumerically("<", 1<<16))
	Expect(numNodes).To(BeNumerically(">", 0))

	return &ClusterRunner{
		startingPort: startingPort,
		numNodes:     numNodes,
		scheme:       scheme,
		sessionTTL:   5 * time.Second,

		mutex: &sync.RWMutex{},
	}
}

func (cr *ClusterRunner) SessionTTL() time.Duration {
	return cr.sessionTTL
}

func (cr *ClusterRunner) ConsulVersion() string {
	cmd := exec.Command("consul", "-v")
	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	Eventually(session).Should(gexec.Exit(0))
	Expect(session.Out).To(gbytes.Say("Consul v"))
	lines := strings.Split(string(session.Out.Contents()), "\n")
	versionLine := lines[0]
	return strings.TrimPrefix(versionLine, "Consul v")
}

func (cr *ClusterRunner) HasPerformanceFlag() bool {
	return !strings.HasPrefix(cr.ConsulVersion(), "0.6")
}<commit_msg>Hack for 'consuladapter'<commit_after>package consulrunner

import (
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path"
	"strings"
	"sync"
	"time"

	"code.cloudfoundry.org/cfhttp"
	"code.cloudfoundry.org/consuladapter"
	"github.com/hashicorp/consul/api"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

type ClusterRunner struct {
	startingPort    int
	numNodes        int
	consulProcesses []ifrit.Process
	running         bool
	dataDir         string
	configDir       string
	scheme          string
	sessionTTL      time.Duration

	mutex *sync.RWMutex
}

const defaultDataDirPrefix = "consul_data"
const defaultConfigDirPrefix = "consul_config"

func NewClusterRunner(startingPort int, numNodes int, scheme string) *ClusterRunner {
	Expect(startingPort).To(BeNumerically(">", 0))
	Expect(startingPort).To(BeNumerically("<", 1<<16))
	Expect(numNodes).To(BeNumerically(">", 0))

	return &ClusterRunner{
		startingPort: startingPort,
		numNodes:     numNodes,
		scheme:       scheme,
		sessionTTL:   5 * time.Second,

		mutex: &sync.RWMutex{},
	}
}

func (cr *ClusterRunner) SessionTTL() time.Duration {
	return cr.sessionTTL
}

func (cr *ClusterRunner) ConsulVersion() string {
	cmd := exec.Command("consul", "-v")
	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
	Eventually(session).Should(gexec.Exit(0))
	Expect(session.Out).To(gbytes.Say("Consul "))
	lines := strings.Split(string(session.Out.Contents()), "\n")
	versionLine := lines[0]
	return strings.TrimPrefix(versionLine, "Consul ")
}

func (cr *ClusterRunner) HasPerformanceFlag() bool {
	return !strings.HasPrefix(cr.ConsulVersion(), "0.6")
}
{'fraction_non_alphanumeric': 0.14305671975412126, 'fraction_numerical': 0.005588153115395362, 'mean_word_length': 4.550387596899225, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4046530', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1309, 'n_words': 232}