func initializeAuctionRunner(logger lager.Logger, cellStateTimeout time.Duration, bbsClient bbs.Client, serviceClient bbs.ServiceClient) auctiontypes.AuctionRunner { httpClient := cf_http.NewClient() stateClient := cf_http.NewCustomTimeoutClient(cellStateTimeout) repClientFactory := rep.NewClientFactory(httpClient, stateClient) delegate := auctionrunnerdelegate.New(repClientFactory, bbsClient, serviceClient, logger) metricEmitter := auctionmetricemitterdelegate.New() workPool, err := workpool.NewWorkPool(*auctionRunnerWorkers) if err != nil { logger.Fatal("failed-to-construct-auction-runner-workpool", err, lager.Data{"num-workers": *auctionRunnerWorkers}) // should never happen } return auctionrunner.New( delegate, metricEmitter, clock.NewClock(), workPool, logger, ) }
func FetchStateAndBuildZones(logger lager.Logger, workPool *workpool.WorkPool, clients map[string]rep.Client, metricEmitter auctiontypes.AuctionMetricEmitterDelegate) map[string]Zone { var zones map[string]Zone var oldTimeout time.Duration for i := 0; ; i++ { zones = fetchStateAndBuildZones(logger, workPool, clients, metricEmitter) if len(zones) > 0 { break } if i == 3 { logger.Info("failed-to-communicate-to-cells-abort", lager.Data{"state-client-timeout-seconds": oldTimeout * 2 / time.Second}) break } for _, client := range clients { oldTimeout = client.StateClientTimeout() stateClient := cf_http.NewCustomTimeoutClient(client.StateClientTimeout() * 2) client.SetStateClient(stateClient) } logger.Info("failed-to-communicate-to-cells-retry", lager.Data{"state-client-timeout-seconds": oldTimeout / time.Second}) } return zones }
Expect(cells[cellID]).To(Equal(cellPresence)) Expect(runner.Session).NotTo(Exit()) }) }) }) Context("acting as an auction representative", func() { var client rep.Client JustBeforeEach(func() { Eventually(fetchCells(logger, serviceClient)).Should(HaveLen(1)) cells, err := serviceClient.Cells(logger) Expect(err).NotTo(HaveOccurred()) client = rep.NewClient(http.DefaultClient, cf_http.NewCustomTimeoutClient(100*time.Millisecond), cells[cellID].RepAddress) }) Context("Capacity with a container", func() { BeforeEach(func() { fakeGarden.RouteToHandler("GET", "/containers", ghttp.RespondWithJSONEncoded(http.StatusOK, map[string][]string{"handles": []string{"handle-guid"}}), ) fakeGarden.RouteToHandler("GET", "/containers/bulk_info", ghttp.RespondWithJSONEncoded(http.StatusOK, map[string]garden.ContainerInfoEntry{ "handle-guid": garden.ContainerInfoEntry{Info: garden.ContainerInfo{ Properties: map[string]string{ gardenstore.ContainerStateProperty: string(executor.StateRunning), gardenstore.ContainerMemoryMBProperty: "512", gardenstore.ContainerDiskMBProperty: "1024"}, }},
cf_http.Initialize(timeout) }) Describe("NewClient", func() { It("returns an http client", func() { client := cf_http.NewClient() Expect(client.Timeout).To(Equal(timeout)) transport := client.Transport.(*http.Transport) Expect(transport.Dial).NotTo(BeNil()) Expect(transport.DisableKeepAlives).To(BeFalse()) }) }) Describe("NewCustomTimeoutClient", func() { It("returns an http client with specified timeout", func() { client := cf_http.NewCustomTimeoutClient(5 * time.Second) Expect(client.Timeout).To(Equal(5 * time.Second)) transport := client.Transport.(*http.Transport) Expect(transport.Dial).NotTo(BeNil()) Expect(transport.DisableKeepAlives).To(BeFalse()) }) }) Describe("NewStreamingClient", func() { It("returns an http client", func() { client := cf_http.NewStreamingClient() Expect(client.Timeout).To(BeZero()) transport := client.Transport.(*http.Transport) Expect(transport.Dial).NotTo(BeNil()) Expect(transport.DisableKeepAlives).To(BeFalse()) })