func natsOptions(logger lager.Logger, c *config.Config, natsHost *atomic.Value, startMsg chan<- struct{}) nats.Options { natsServers := c.NatsServers() options := nats.DefaultOptions options.Servers = natsServers options.PingInterval = c.NatsClientPingInterval options.ClosedCB = func(conn *nats.Conn) { logger.Fatal("nats-connection-closed", errors.New("unexpected close"), lager.Data{"last_error": conn.LastError()}) } options.DisconnectedCB = func(conn *nats.Conn) { hostStr := natsHost.Load().(string) logger.Info("nats-connection-disconnected", lager.Data{"nats-host": hostStr}) } options.ReconnectedCB = func(conn *nats.Conn) { natsURL, err := url.Parse(conn.ConnectedUrl()) natsHostStr := "" if err != nil { logger.Error("nats-url-parse-error", err) } else { natsHostStr = natsURL.Host } natsHost.Store(natsHostStr) data := lager.Data{"nats-host": natsHostStr} logger.Info("nats-connection-reconnected", data) startMsg <- struct{}{} } // in the case of suspending pruning, we need to ensure we retry reconnects indefinitely if c.SuspendPruningIfNatsUnavailable { options.MaxReconnect = -1 } return options }
func init() { sender = metrics_fakes.NewFakeMetricSender() metrics.Initialize(sender, nil) } var _ = Describe("RouteFetcher", func() { var ( cfg *config.Config uaaClient *testUaaClient.FakeClient registry *testRegistry.FakeRegistryInterface fetcher *RouteFetcher logger lager.Logger client *fake_routing_api.FakeClient eventSource *fake_routing_api.FakeEventSource token *schema.Token response []models.Route process ifrit.Process eventChannel chan routing_api.Event errorChannel chan error clock *fakeclock.FakeClock ) BeforeEach(func() { logger = lagertest.NewTestLogger("test") cfg = config.DefaultConfig() cfg.PruneStaleDropletsInterval = 2 * time.Millisecond retryInterval := 0
"code.cloudfoundry.org/lager" "code.cloudfoundry.org/lager/lagertest" "github.com/nats-io/nats" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/tedsuo/ifrit" ) var _ = Describe("Router", func() { var ( logger lager.Logger natsRunner *test_util.NATSRunner config *cfg.Config p proxy.Proxy mbusClient *nats.Conn registry *rregistry.RouteRegistry varz vvarz.Varz rtr *router.Router subscriber ifrit.Process natsPort uint16 healthCheck int32 ) testAndVerifyRouterStopsNoDrain := func(signals chan os.Signal, closeChannel chan struct{}, sigs ...os.Signal) { app := common.NewTestApp([]route.Uri{"drain.vcap.me"}, config.Port, mbusClient, nil, "") blocker := make(chan bool) resultCh := make(chan bool, 2) app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { blocker <- true _, err := ioutil.ReadAll(r.Body)
"github.com/onsi/gomega/gbytes" "code.cloudfoundry.org/gorouter/config" "code.cloudfoundry.org/gorouter/metrics/reporter/fakes" "code.cloudfoundry.org/gorouter/route" "encoding/json" "time" ) var _ = Describe("RouteRegistry", func() { var r *RouteRegistry var reporter *fakes.FakeRouteRegistryReporter var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint var configObj *config.Config var logger lager.Logger var modTag models.ModificationTag BeforeEach(func() { logger = lagertest.NewTestLogger("test") configObj = config.DefaultConfig() configObj.PruneStaleDropletsInterval = 50 * time.Millisecond configObj.DropletStaleThreshold = 24 * time.Millisecond reporter = new(fakes.FakeRouteRegistryReporter) r = NewRouteRegistry(logger, configObj, reporter) modTag = models.ModificationTag{} fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234,
"code.cloudfoundry.org/gorouter/metrics/reporter/fakes" testcommon "code.cloudfoundry.org/gorouter/test/common" "code.cloudfoundry.org/lager" "code.cloudfoundry.org/lager/lagertest" ) var _ = Describe("Router", func() { const uuid_regex = `^[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}$` var ( natsRunner *test_util.NATSRunner natsPort uint16 config *cfg.Config mbusClient *nats.Conn registry *rregistry.RouteRegistry varz vvarz.Varz router *Router logger lager.Logger statusPort uint16 ) BeforeEach(func() { natsPort = test_util.NextAvailPort() proxyPort := test_util.NextAvailPort() statusPort = test_util.NextAvailPort() cert, err := tls.LoadX509KeyPair("../test/assets/certs/server.pem", "../test/assets/certs/server.key") Expect(err).ToNot(HaveOccurred()) config = test_util.SpecConfig(statusPort, proxyPort, natsPort) config.EnableSSL = true
"testing" "time" "code.cloudfoundry.org/gorouter/metrics/reporter/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var ( r *registry.RouteRegistry p proxy.Proxy fakeReporter *fakes.FakeProxyReporter conf *config.Config proxyServer net.Listener accessLog access_log.AccessLogger accessLogFile *test_util.FakeFile crypto secure.Crypto logger lager.Logger cryptoPrev secure.Crypto caCertPool *x509.CertPool recommendHttps bool heartbeatOK int32 ) func TestProxy(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Proxy Suite") } var _ = BeforeEach(func() { logger = lagertest.NewTestLogger("test")