Beispiel #1
0
func main() {
	flag.Parse()

	if *guid == "" {
		panic("need guid")
	}

	if *natsAddrs == "" && *httpAddr == "" {
		panic("need either nats or http addr (or both)")
	}

	rep := representative.New(*guid, *resources)

	if *natsAddrs != "" {
		go repnatsserver.Start(strings.Split(*natsAddrs, ","), rep)
	}

	if *httpAddr != "" {
		go rephttpserver.Start(*httpAddr, rep)
	}

	select {}
}
Beispiel #2
0
func buildClient(numReps int, repResources int) (types.TestRepPoolClient, []string) {
	repNodeBinary, err := gexec.Build("github.com/onsi/auction/repnode")
	Ω(err).ShouldNot(HaveOccurred())

	if communicationMode == InProcess {
		lossyrep.LatencyMin = 2 * time.Millisecond
		lossyrep.LatencyMax = 12 * time.Millisecond
		lossyrep.Timeout = 50 * time.Millisecond
		lossyrep.Flakiness = 0.95

		guids := []string{}
		repMap := map[string]*representative.Representative{}

		for i := 0; i < numReps; i++ {
			guid := util.NewGuid("REP")
			guids = append(guids, guid)
			repMap[guid] = representative.New(guid, repResources)
		}

		client := lossyrep.New(repMap, map[string]bool{})
		return client, guids
	} else if communicationMode == NATS {
		guids := []string{}

		for i := 0; i < numReps; i++ {
			guid := util.NewGuid("REP")

			serverCmd := exec.Command(
				repNodeBinary,
				"-guid", guid,
				"-natsAddr", fmt.Sprintf("127.0.0.1:%d", natsPort),
				"-resources", fmt.Sprintf("%d", repResources),
			)

			sess, err := gexec.Start(serverCmd, GinkgoWriter, GinkgoWriter)
			Ω(err).ShouldNot(HaveOccurred())
			Eventually(sess).Should(gbytes.Say("listening"))
			sessionsToTerminate = append(sessionsToTerminate, sess)

			guids = append(guids, guid)
		}

		client := repnatsclient.New(natsRunner.MessageBus, timeout)

		return client, guids
	} else if communicationMode == HTTP {
		startPort := 18000 + (numReps * GinkgoParallelNode())
		guids := []string{}

		repMap := map[string]string{}

		for i := 0; i < numReps; i++ {
			guid := util.NewGuid("REP")
			port := startPort + i

			serverCmd := exec.Command(
				repNodeBinary,
				"-guid", guid,
				"-httpAddr", fmt.Sprintf("0.0.0.0:%d", port),
				"-resources", fmt.Sprintf("%d", repResources),
			)

			repMap[guid] = fmt.Sprintf("http://127.0.0.1:%d", port)

			sess, err := gexec.Start(serverCmd, GinkgoWriter, GinkgoWriter)
			Ω(err).ShouldNot(HaveOccurred())
			Eventually(sess).Should(gbytes.Say("serving"))
			sessionsToTerminate = append(sessionsToTerminate, sess)

			guids = append(guids, guid)
		}

		client := rephttpclient.New(repMap, timeout)

		return client, guids
	}

	panic("wat!")
}