Esempio n. 1
0
func registerAddr(reg *registry.RouteRegistry, path string, routeServiceUrl string, addr net.Addr, instanceId string) {
	host, portStr, err := net.SplitHostPort(addr.String())
	Expect(err).NotTo(HaveOccurred())

	port, err := strconv.Atoi(portStr)
	Expect(err).NotTo(HaveOccurred())

	reg.Register(route.Uri(path), route.NewEndpoint("", host, uint16(port), instanceId, nil, -1, routeServiceUrl))
}
Esempio n. 2
0
func registerAddr(r *registry.RouteRegistry, u string, a net.Addr, instanceId string) {
	h, p, err := net.SplitHostPort(a.String())
	Ω(err).NotTo(HaveOccurred())

	x, err := strconv.Atoi(p)
	Ω(err).NotTo(HaveOccurred())

	r.Register(route.Uri(u), route.NewEndpoint("", h, uint16(x), instanceId, nil))
}
func waitMsgReceived(registry *registry.RouteRegistry, app *test.TestApp, expectedToBeFound bool, timeout time.Duration) bool {
	interval := time.Millisecond * 50
	repetitions := int(timeout / interval)

	for j := 0; j < repetitions; j++ {
		if j > 0 {
			time.Sleep(interval)
		}

		received := true
		for _, url := range app.Urls() {
			pool := registry.Lookup(url)
			if expectedToBeFound && pool == nil {
				received = false
				break
			} else if !expectedToBeFound && pool != nil {
				received = false
				break
			}
		}
		if received {
			return true
		}
	}

	return false
}
Esempio n. 4
0
func appUnregistered(registry *registry.RouteRegistry, app *common.TestApp) bool {
	for _, url := range app.Urls() {
		pool := registry.Lookup(url)
		if pool != nil {
			return false
		}
	}

	return true
}
Esempio n. 5
0
	fakelogger "github.com/cloudfoundry/gorouter/access_log/fakes"
	"github.com/cloudfoundry/gorouter/metrics/fakes"
	"github.com/cloudfoundry/gorouter/proxy"
	"github.com/cloudfoundry/gorouter/registry"
	"github.com/cloudfoundry/gorouter/route"
	"github.com/cloudfoundry/gorouter/test_util"
	"github.com/cloudfoundry/yagnats/fakeyagnats"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Proxy Unit tests", func() {
	var (
		proxyObj         proxy.Proxy
		fakeAccessLogger *fakelogger.FakeAccessLogger

		r *registry.RouteRegistry
	)

	Context("ServeHTTP", func() {
		BeforeEach(func() {
			tlsConfig := &tls.Config{
				CipherSuites:       conf.CipherSuites,
				InsecureSkipVerify: conf.SSLSkipValidation,
			}

			fakeAccessLogger = &fakelogger.FakeAccessLogger{}

			mbus := fakeyagnats.Connect()
			r = registry.NewRouteRegistry(conf, mbus, new(fakes.FakeRouteReporter))
Esempio n. 6
0
	. "github.com/cloudfoundry/gorouter/varz"
	"github.com/cloudfoundry/yagnats/fakeyagnats"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/lager"
	"github.com/pivotal-golang/lager/lagertest"

	"encoding/json"
	"fmt"
	"net/http"
	"time"
)

var _ = Describe("Varz", func() {
	var Varz Varz
	var Registry *registry.RouteRegistry
	var logger lager.Logger

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
		Registry = registry.NewRouteRegistry(logger, config.DefaultConfig(), fakeyagnats.Connect(), new(fakes.FakeRouteRegistryReporter))
		Varz = NewVarz(Registry)
	})

	It("contains the following items", func() {
		v := Varz

		members := []string{
			"responses_2xx",
			"responses_3xx",
			"responses_4xx",
Esempio n. 7
0
	testcommon "github.com/cloudfoundry/gorouter/test/common"
	"github.com/pivotal-golang/lager"
	"github.com/pivotal-golang/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
		signals      chan os.Signal
		closeChannel chan struct{}
		readyChan    chan struct{}
		logger       lager.Logger
	)

	BeforeEach(func() {
		natsPort = test_util.NextAvailPort()
		natsRunner = test_util.NewNATSRunner(int(natsPort))
		natsRunner.Start()

		fakeEmitter := fake.NewFakeEventEmitter("fake")
		dropsonde.InitializeWithEmitter(fakeEmitter)