func main() { flag.Parse() if *natsAddrs == "" { panic("need either nats addr") } client := yagnats.NewClient() clusterInfo := &yagnats.ConnectionCluster{} for _, addr := range strings.Split(*natsAddrs, ",") { clusterInfo.Members = append(clusterInfo.Members, &yagnats.ConnectionInfo{ Addr: addr, }) } err := client.Connect(clusterInfo) if err != nil { log.Fatalln("no nats:", err) } semaphore := make(chan bool, *maxConcurrent) repclient := repnatsclient.New(client, *timeout) client.SubscribeWithQueue("diego.auction", "auction-channel", func(msg *yagnats.Message) { semaphore <- true defer func() { <-semaphore }() var auctionRequest types.AuctionRequest err := json.Unmarshal(msg.Payload, &auctionRequest) if err != nil { client.Publish(msg.ReplyTo, errorResponse) return } auctionResult := auctioneer.Auction(repclient, auctionRequest) payload, _ := json.Marshal(auctionResult) client.Publish(msg.ReplyTo, payload) }) fmt.Println("auctioneering") select {} }
rules = auctioneer.DefaultRules natsClient = yagnats.NewClient() clusterInfo := &yagnats.ConnectionCluster{} for _, addr := range natsAddrs { clusterInfo.Members = append(clusterInfo.Members, &yagnats.ConnectionInfo{ Addr: addr, }) } err := natsClient.Connect(clusterInfo) Ω(err).ShouldNot(HaveOccurred()) client = repnatsclient.New(natsClient, timeout) if auctioneerMode == "inprocess" { communicator = func(auctionRequest types.AuctionRequest) types.AuctionResult { return auctioneer.Auction(client, auctionRequest) } } else if auctioneerMode == "remote" { communicator = func(auctionRequest types.AuctionRequest) types.AuctionResult { return auctioneer.RemoteAuction(natsClient, auctionRequest) } } else { panic("wat?") } }) var _ = BeforeEach(func() {
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!") }