<commit_before>package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"os/exec"
	"strings"
	"time"

	"github.com/smallfish/simpleyaml"
)

type version struct {
	Kafka string
	Scala string
}

func main() {
	var healthCheckCommand string
	var baseDir string
	flag.StringVar(&healthCheckCommand, "health-check", "", "kafka health check executable to test")
	flag.StringVar(&baseDir, "base-dir", "", "directory containing the Java and Kafka docker build contexts")
	flag.Parse()

	specs := parseSpecs(baseDir)

	buildDocker("java:8", baseDir+"/docker/java")

	successTotal := true
	for _, spec := range specs {
		fmt.Print("=== RUN checking compatibility with Kafka ", spec.Kafka, " and Scala ", spec.Scala, "...\n")
		tag := fmt.Sprintf("kafka:%s-%s", spec.Scala, spec.Kafka)
		buildDocker(tag, baseDir+"/docker/kafka", "scala_version="+spec.Scala, "kafka_version="+spec.Kafka)

		success := runTest(tag, spec, healthCheckCommand)
		successTotal = successTotal && success
	}

	if successTotal {
		fmt.Println("PASS")
	} else {
		fmt.Println("FAIL")
	}
}

func runTest(tag string, spec version, healthCheckCommand string) bool {
	zkID, kafkaID, hcCmd := startAll(tag, healthCheckCommand)

	success := waitForResponse("http://localhost:8000/", "sync")
	if success {
		fmt.Println("--- PASS: Kafka", spec.Kafka, "and Scala", spec.Scala, "broker status reported as in sync.")
	} else {
		fmt.Println("--- FAIL: Kafka", spec.Kafka, "and Scala", spec.Scala, "broker status wasn't reported as in sync within timeout.")

		stopAll(zkID, kafkaID, hcCmd)
		return false
	}

	success = waitForResponse("http://localhost:8000/cluster", "green")
	if success {
		fmt.Println("--- PASS: Kafka", spec.Kafka, "and Scala", spec.Scala, "cluster status reported as green.")
	} else {
		fmt.Println("--- FAIL: Kafka", spec.Kafka, "and Scala", spec.Scala, "cluster status wasn't reported as green within timeout.")
	}

	stopAll(zkID, kafkaID, hcCmd)
	return success<commit_msg>doing the exit code on failure.<commit_after>package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"os/exec"
	"strings"
	"time"

	"github.com/smallfish/simpleyaml"
	"os"
)

type version struct {
	Kafka string
	Scala string
}

func main() {
	var healthCheckCommand string
	var baseDir string
	flag.StringVar(&healthCheckCommand, "health-check", "", "kafka health check executable to test")
	flag.StringVar(&baseDir, "base-dir", "", "directory containing the Java and Kafka docker build contexts")
	flag.Parse()

	specs := parseSpecs(baseDir)

	buildDocker("java:8", baseDir+"/docker/java")

	successTotal := true
	for _, spec := range specs {
		fmt.Print("=== RUN checking compatibility with Kafka ", spec.Kafka, " and Scala ", spec.Scala, "...\n")
		tag := fmt.Sprintf("kafka:%s-%s", spec.Scala, spec.Kafka)
		buildDocker(tag, baseDir+"/docker/kafka", "scala_version="+spec.Scala, "kafka_version="+spec.Kafka)

		success := runTest(tag, spec, healthCheckCommand)
		successTotal = successTotal && success
	}

	if successTotal {
		fmt.Println("PASS")
	} else {
		fmt.Println("FAIL")
		os.Exit(1)
	}
}

func runTest(tag string, spec version, healthCheckCommand string) bool {
	zkID, kafkaID, hcCmd := startAll(tag, healthCheckCommand)

	success := waitForResponse("http://localhost:8000/", "sync")
	if success {
		fmt.Println("--- PASS: Kafka", spec.Kafka, "and Scala", spec.Scala, "broker status reported as in sync.")
	} else {
		fmt.Println("--- FAIL: Kafka", spec.Kafka, "and Scala", spec.Scala, "broker status wasn't reported as in sync within timeout.")

		stopAll(zkID, kafkaID, hcCmd)
		return false
	}

	success = waitForResponse("http://localhost:8000/cluster", "green")
	if success {
		fmt.Println("--- PASS: Kafka", spec.Kafka, "and Scala", spec.Scala, "cluster status reported as green.")
	} else {
		fmt.Println("--- FAIL: Kafka", spec.Kafka, "and Scala", spec.Scala, "cluster status wasn't reported as green within timeout.")
	}

	stopAll(zkID, kafkaID, hcCmd)
	return success
{'fraction_non_alphanumeric': 0.15633557381130198, 'fraction_numerical': 0.004729897933781429, 'mean_word_length': 4.4815825375170535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3702844', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1402, 'n_words': 370}