本文整理汇总了Golang中github.com/polyverse-security/vulcand/Godeps/_workspace/src/github.com/mailgun/oxy/testutils.NewResponder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResponder函数的具体用法?Golang NewResponder怎么用?Golang NewResponder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResponder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRebalancerLive
func (s *RBSuite) TestRebalancerLive(c *C) {
a, b := testutils.NewResponder("a"), testutils.NewResponder("b")
defer a.Close()
defer b.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
rb, err := NewRebalancer(lb, RebalancerBackoff(time.Millisecond), RebalancerClock(s.clock))
c.Assert(err, IsNil)
rb.UpsertServer(testutils.ParseURI(a.URL))
rb.UpsertServer(testutils.ParseURI(b.URL))
rb.UpsertServer(testutils.ParseURI("http://localhost:62345"))
proxy := httptest.NewServer(rb)
defer proxy.Close()
for i := 0; i < 1000; i += 1 {
testutils.Get(proxy.URL)
if i%10 == 0 {
s.clock.CurrentTime = s.clock.CurrentTime.Add(rb.backoffDuration + time.Second)
}
}
// load balancer changed weights
c.Assert(rb.servers[0].curWeight, Equals, FSMMaxWeight)
c.Assert(rb.servers[1].curWeight, Equals, FSMMaxWeight)
c.Assert(rb.servers[2].curWeight, Equals, 1)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:33,代码来源:rebalancer_test.go
示例2: TestRebalancerRemoveServer
func (s *RBSuite) TestRebalancerRemoveServer(c *C) {
a, b := testutils.NewResponder("a"), testutils.NewResponder("b")
defer a.Close()
defer b.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
rb, err := NewRebalancer(lb)
c.Assert(err, IsNil)
rb.UpsertServer(testutils.ParseURI(a.URL))
rb.UpsertServer(testutils.ParseURI(b.URL))
proxy := httptest.NewServer(rb)
defer proxy.Close()
c.Assert(seq(c, proxy.URL, 3), DeepEquals, []string{"a", "b", "a"})
c.Assert(rb.RemoveServer(testutils.ParseURI(a.URL)), IsNil)
c.Assert(seq(c, proxy.URL, 3), DeepEquals, []string{"b", "b", "b"})
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:25,代码来源:rebalancer_test.go
示例3: TestUpsertWeight
func (s *RRSuite) TestUpsertWeight(c *C) {
a := testutils.NewResponder("a")
defer a.Close()
b := testutils.NewResponder("b")
defer b.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
c.Assert(lb.UpsertServer(testutils.ParseURI(a.URL)), IsNil)
c.Assert(lb.UpsertServer(testutils.ParseURI(b.URL)), IsNil)
proxy := httptest.NewServer(lb)
defer proxy.Close()
c.Assert(seq(c, proxy.URL, 3), DeepEquals, []string{"a", "b", "a"})
c.Assert(lb.UpsertServer(testutils.ParseURI(b.URL), Weight(3)), IsNil)
c.Assert(seq(c, proxy.URL, 4), DeepEquals, []string{"b", "b", "a", "b"})
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:25,代码来源:rr_test.go
示例4: TestWeighted
func (s *RRSuite) TestWeighted(c *C) {
a := testutils.NewResponder("a")
defer a.Close()
b := testutils.NewResponder("b")
defer b.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
lb.UpsertServer(testutils.ParseURI(a.URL), Weight(3))
lb.UpsertServer(testutils.ParseURI(b.URL), Weight(2))
proxy := httptest.NewServer(lb)
defer proxy.Close()
c.Assert(seq(c, proxy.URL, 6), DeepEquals, []string{"a", "a", "b", "a", "b", "a"})
w, ok := lb.ServerWeight(testutils.ParseURI(a.URL))
c.Assert(w, Equals, 3)
c.Assert(ok, Equals, true)
w, ok = lb.ServerWeight(testutils.ParseURI(b.URL))
c.Assert(w, Equals, 2)
c.Assert(ok, Equals, true)
w, ok = lb.ServerWeight(testutils.ParseURI("http://caramba:4000"))
c.Assert(w, Equals, -1)
c.Assert(ok, Equals, false)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:33,代码来源:rr_test.go
示例5: TestRebalancerCascading
// Test scenario when increaing the weight on good endpoints made it worse
func (s *RBSuite) TestRebalancerCascading(c *C) {
a, b, d := testutils.NewResponder("a"), testutils.NewResponder("b"), testutils.NewResponder("d")
defer a.Close()
defer b.Close()
defer d.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
newMeter := func() (Meter, error) {
return &testMeter{}, nil
}
rb, err := NewRebalancer(lb, RebalancerMeter(newMeter), RebalancerClock(s.clock), RebalancerLogger(s.log))
c.Assert(err, IsNil)
rb.UpsertServer(testutils.ParseURI(a.URL))
rb.UpsertServer(testutils.ParseURI(b.URL))
rb.UpsertServer(testutils.ParseURI(d.URL))
rb.servers[0].meter.(*testMeter).rating = 0.3
proxy := httptest.NewServer(rb)
defer proxy.Close()
for i := 0; i < 6; i += 1 {
testutils.Get(proxy.URL)
testutils.Get(proxy.URL)
s.clock.CurrentTime = s.clock.CurrentTime.Add(rb.backoffDuration + time.Second)
}
// We have increased the load, and the situation became worse as the other servers started failing
c.Assert(rb.servers[0].curWeight, Equals, 1)
c.Assert(rb.servers[1].curWeight, Equals, FSMMaxWeight)
c.Assert(rb.servers[2].curWeight, Equals, FSMMaxWeight)
// server a is now recovering, the weights should go back to the original state
rb.servers[0].meter.(*testMeter).rating = 0.3
rb.servers[1].meter.(*testMeter).rating = 0.2
rb.servers[2].meter.(*testMeter).rating = 0.2
for i := 0; i < 6; i += 1 {
testutils.Get(proxy.URL)
testutils.Get(proxy.URL)
s.clock.CurrentTime = s.clock.CurrentTime.Add(rb.backoffDuration + time.Second)
}
// the algo reverted it back
c.Assert(rb.servers[0].curWeight, Equals, 1)
c.Assert(rb.servers[1].curWeight, Equals, 1)
c.Assert(rb.servers[2].curWeight, Equals, 1)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:54,代码来源:rebalancer_test.go
示例6: TestRebalancerRecovery
// Test scenario when one server goes down after what it recovers
func (s *RBSuite) TestRebalancerRecovery(c *C) {
a, b := testutils.NewResponder("a"), testutils.NewResponder("b")
defer a.Close()
defer b.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
newMeter := func() (Meter, error) {
return &testMeter{}, nil
}
rb, err := NewRebalancer(lb, RebalancerMeter(newMeter), RebalancerClock(s.clock), RebalancerLogger(s.log))
c.Assert(err, IsNil)
rb.UpsertServer(testutils.ParseURI(a.URL))
rb.UpsertServer(testutils.ParseURI(b.URL))
rb.servers[0].meter.(*testMeter).rating = 0.3
proxy := httptest.NewServer(rb)
defer proxy.Close()
for i := 0; i < 6; i += 1 {
testutils.Get(proxy.URL)
testutils.Get(proxy.URL)
s.clock.CurrentTime = s.clock.CurrentTime.Add(rb.backoffDuration + time.Second)
}
c.Assert(rb.servers[0].curWeight, Equals, 1)
c.Assert(rb.servers[1].curWeight, Equals, FSMMaxWeight)
c.Assert(lb.servers[0].weight, Equals, 1)
c.Assert(lb.servers[1].weight, Equals, FSMMaxWeight)
// server a is now recovering, the weights should go back to the original state
rb.servers[0].meter.(*testMeter).rating = 0
for i := 0; i < 6; i += 1 {
testutils.Get(proxy.URL)
testutils.Get(proxy.URL)
s.clock.CurrentTime = s.clock.CurrentTime.Add(rb.backoffDuration + time.Second)
}
c.Assert(rb.servers[0].curWeight, Equals, 1)
c.Assert(rb.servers[1].curWeight, Equals, 1)
// Make sure we have applied the weights to the inner load balancer
c.Assert(lb.servers[0].weight, Equals, 1)
c.Assert(lb.servers[1].weight, Equals, 1)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:53,代码来源:rebalancer_test.go
示例7: TestTakeFiles
func (s *ServerSuite) TestTakeFiles(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint 1")
defer e.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{
Addr: "localhost:41000",
Route: `Path("/")`,
URL: e.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey, Cert: localhostCert},
})
c.Assert(s.mux.UpsertHost(b.H), IsNil)
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
mux2, err := New(s.lastId, s.st, Options{})
c.Assert(err, IsNil)
e2 := testutils.NewResponder("Hi, I'm endpoint 2")
defer e2.Close()
b2 := MakeBatch(Batch{
Addr: "localhost:41000",
Route: `Path("/")`,
URL: e2.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey2, Cert: localhostCert2},
})
c.Assert(mux2.UpsertHost(b2.H), IsNil)
c.Assert(mux2.UpsertServer(b2.BK, b2.S), IsNil)
c.Assert(mux2.UpsertFrontend(b2.F), IsNil)
c.Assert(mux2.UpsertListener(b2.L), IsNil)
files, err := s.mux.GetFiles()
c.Assert(err, IsNil)
c.Assert(mux2.TakeFiles(files), IsNil)
c.Assert(mux2.Start(), IsNil)
s.mux.Stop(true)
defer mux2.Stop(true)
c.Assert(GETResponse(c, b2.FrontendURL("/")), Equals, "Hi, I'm endpoint 2")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:50,代码来源:mux_test.go
示例8: TestExpiringServer
func (s *VESuite) TestExpiringServer(c *C) {
server := testutils.NewResponder("e1")
defer server.Close()
server2 := testutils.NewResponder("e2")
defer server2.Close()
// Create backend and servers
b, url, url2 := "bk1", server.URL, server2.URL
srv, srv2 := "s1", "s2"
_, err := s.client.Set(s.path("backends", b, "backend"), `{"Type": "http"}`, 0)
c.Assert(err, IsNil)
// This one will stay
_, err = s.client.Set(s.path("backends", b, "servers", srv), fmt.Sprintf(`{"URL": "%s"}`, url), 0)
c.Assert(err, IsNil)
// This one will expire
_, err = s.client.Set(s.path("backends", b, "servers", srv2), fmt.Sprintf(`{"URL": "%s"}`, url2), 2)
c.Assert(err, IsNil)
// Add frontend
fId := "fr1"
_, err = s.client.Set(s.path("frontends", fId, "frontend"), `{"Type": "http", "BackendId": "bk1", "Route": "Path(\"/path\")"}`, 0)
c.Assert(err, IsNil)
time.Sleep(time.Second)
responses1 := make(map[string]bool)
for i := 0; i < 3; i += 1 {
response, body, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
responses1[string(body)] = true
}
c.Assert(responses1, DeepEquals, map[string]bool{"e1": true, "e2": true})
// Now the second endpoint should expire
time.Sleep(time.Second * 2)
responses2 := make(map[string]bool)
for i := 0; i < 3; i += 1 {
response, body, err := testutils.Get(fmt.Sprintf("%s%s", s.serviceUrl, "/path"))
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
responses2[string(body)] = true
}
c.Assert(responses2, DeepEquals, map[string]bool{"e1": true})
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:49,代码来源:systest_test.go
示例9: TestTransferFiles
func (s *SupervisorSuite) TestTransferFiles(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint")
defer e.Close()
b := MakeBatch(Batch{Addr: "localhost:11800", Route: `Path("/")`, URL: e.URL})
c.Assert(s.ng.UpsertBackend(b.B), IsNil)
c.Assert(s.ng.UpsertServer(b.BK, b.S, engine.NoTTL), IsNil)
c.Assert(s.ng.UpsertFrontend(b.F, engine.NoTTL), IsNil)
c.Assert(s.ng.UpsertListener(b.L), IsNil)
s.sv.Start()
time.Sleep(10 * time.Millisecond)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint")
files, err := s.sv.GetFiles()
c.Assert(err, IsNil)
errorC := make(chan error)
sv2 := New(newProxy, s.ng, errorC, Options{Clock: s.clock, Files: files})
sv2.Start()
s.sv.Stop(true)
time.Sleep(10 * time.Millisecond)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:30,代码来源:supervisor_test.go
示例10: TestHostKeyPairUpdate
func (s *ServerSuite) TestHostKeyPairUpdate(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint")
defer e.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{
Addr: "localhost:31000",
Route: `Path("/")`,
URL: e.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey, Cert: localhostCert},
})
c.Assert(s.mux.UpsertHost(b.H), IsNil)
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint")
b.H.Settings.KeyPair = &engine.KeyPair{Key: localhostKey2, Cert: localhostCert2}
c.Assert(s.mux.UpsertHost(b.H), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:25,代码来源:mux_test.go
示例11: TestListenerScopeUpdate
func (s *ServerSuite) TestListenerScopeUpdate(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint")
defer e.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{Addr: "localhost:41000", Route: `Path("/")`, URL: e.URL})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
re, body, err := testutils.Get(b.FrontendURL("/"), testutils.Host("otherhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(string(body), Equals, "Hi, I'm endpoint")
b.L.Scope = `Host("localhost")`
c.Assert(s.mux.UpsertListener(b.L), IsNil)
re, body, err = testutils.Get(b.FrontendURL("/"), testutils.Host("localhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(string(body), Equals, "Hi, I'm endpoint")
re, _, err = testutils.Get(b.FrontendURL("/"), testutils.Host("otherhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusNotFound)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:29,代码来源:mux_test.go
示例12: TestFrontendUpdateRoute
func (s *ServerSuite) TestFrontendUpdateRoute(c *C) {
c.Assert(s.mux.Start(), IsNil)
e := testutils.NewResponder("hola")
defer e.Close()
b := MakeBatch(Batch{
Addr: "localhost:31000",
Route: `Path("/")`,
URL: e.URL,
})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "hola")
b.F.Route = `Path("/new")`
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/new")), Equals, "hola")
response, _, err := testutils.Get(MakeURL(b.L, "/"))
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:27,代码来源:mux_test.go
示例13: TestPerfMon
func (s *ServerSuite) TestPerfMon(c *C) {
c.Assert(s.mux.Start(), IsNil)
e1 := testutils.NewResponder("Hi, I'm endpoint 1")
defer e1.Close()
b := MakeBatch(Batch{Addr: "localhost:11300", Route: `Path("/")`, URL: e1.URL})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
sURL, err := url.Parse(b.S.URL)
c.Assert(err, IsNil)
// Make sure server has been added to the performance monitor
c.Assert(s.mux.frontends[b.FK].watcher.hasServer(sURL), Equals, true)
c.Assert(s.mux.DeleteFrontend(b.FK), IsNil)
// Delete the backend
c.Assert(s.mux.DeleteBackend(b.BK), IsNil)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:25,代码来源:mux_test.go
示例14: TestMiddlewareCRUD
func (s *ServerSuite) TestMiddlewareCRUD(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint 1")
defer e.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{
Addr: "localhost:31000",
Route: `Path("/")`,
URL: e.URL,
})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
// 1 request per second
rl := MakeRateLimit(UID("rl"), 1, "client.ip", 1, 1)
_, err := rl.Middleware.NewHandler(nil)
c.Assert(err, IsNil)
c.Assert(s.mux.UpsertMiddleware(b.FK, rl), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
re, _, err := testutils.Get(MakeURL(b.L, "/"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, 429) // too many requests
c.Assert(s.mux.DeleteMiddleware(engine.MiddlewareKey{FrontendKey: b.FK, Id: rl.Id}), IsNil)
for i := 0; i < 3; i++ {
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
}
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:35,代码来源:mux_test.go
示例15: TestFrontendSwitchBackend
func (s *ServerSuite) TestFrontendSwitchBackend(c *C) {
c.Assert(s.mux.Start(), IsNil)
e1 := testutils.NewResponder("1")
defer e1.Close()
e2 := testutils.NewResponder("2")
defer e2.Close()
e3 := testutils.NewResponder("3")
defer e3.Close()
b := MakeBatch(Batch{
Addr: "localhost:31000",
Route: `Path("/")`,
URL: e1.URL,
})
s1, s2, s3 := MakeServer(e1.URL), MakeServer(e2.URL), MakeServer(e3.URL)
c.Assert(s.mux.UpsertServer(b.BK, s1), IsNil)
c.Assert(s.mux.UpsertServer(b.BK, s2), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
b2 := MakeBackend()
b2k := engine.BackendKey{Id: b2.Id}
c.Assert(s.mux.UpsertServer(b2k, s2), IsNil)
c.Assert(s.mux.UpsertServer(b2k, s3), IsNil)
responseSet := make(map[string]bool)
responseSet[GETResponse(c, b.FrontendURL("/"))] = true
responseSet[GETResponse(c, b.FrontendURL("/"))] = true
c.Assert(responseSet, DeepEquals, map[string]bool{"1": true, "2": true})
b.F.BackendId = b2k.Id
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
responseSet = make(map[string]bool)
responseSet[GETResponse(c, b.FrontendURL("/"))] = true
responseSet[GETResponse(c, b.FrontendURL("/"))] = true
c.Assert(responseSet, DeepEquals, map[string]bool{"2": true, "3": true})
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:46,代码来源:mux_test.go
示例16: TestGetStats
func (s *ServerSuite) TestGetStats(c *C) {
e1 := testutils.NewResponder("Hi, I'm endpoint 1")
defer e1.Close()
e2 := testutils.NewResponder("Hi, I'm endpoint 2")
defer e2.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{Addr: "localhost:11300", Route: `Path("/")`, URL: e1.URL})
srv2 := MakeServer(e2.URL)
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertServer(b.BK, srv2), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
for i := 0; i < 10; i++ {
GETResponse(c, MakeURL(b.L, "/"))
}
stats, err := s.mux.ServerStats(b.SK)
c.Assert(err, IsNil)
c.Assert(stats, NotNil)
fStats, err := s.mux.FrontendStats(b.FK)
c.Assert(fStats, NotNil)
c.Assert(err, IsNil)
bStats, err := s.mux.BackendStats(b.BK)
c.Assert(bStats, NotNil)
c.Assert(err, IsNil)
topF, err := s.mux.TopFrontends(nil)
c.Assert(err, IsNil)
c.Assert(len(topF), Equals, 1)
topServers, err := s.mux.TopServers(nil)
c.Assert(err, IsNil)
c.Assert(len(topServers), Equals, 2)
// emit stats works without errors
c.Assert(s.mux.emitMetrics(), IsNil)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:45,代码来源:mux_test.go
示例17: TestRebalancerReset
// Removing the server resets the state
func (s *RBSuite) TestRebalancerReset(c *C) {
a, b, d := testutils.NewResponder("a"), testutils.NewResponder("b"), testutils.NewResponder("d")
defer a.Close()
defer b.Close()
defer d.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
newMeter := func() (Meter, error) {
return &testMeter{}, nil
}
rb, err := NewRebalancer(lb, RebalancerMeter(newMeter), RebalancerClock(s.clock), RebalancerLogger(s.log))
c.Assert(err, IsNil)
rb.UpsertServer(testutils.ParseURI(a.URL))
rb.UpsertServer(testutils.ParseURI(b.URL))
rb.UpsertServer(testutils.ParseURI(d.URL))
rb.servers[0].meter.(*testMeter).rating = 0.3
rb.servers[1].meter.(*testMeter).rating = 0
rb.servers[2].meter.(*testMeter).rating = 0
proxy := httptest.NewServer(rb)
defer proxy.Close()
for i := 0; i < 6; i += 1 {
testutils.Get(proxy.URL)
testutils.Get(proxy.URL)
s.clock.CurrentTime = s.clock.CurrentTime.Add(rb.backoffDuration + time.Second)
}
// load balancer changed weights
c.Assert(rb.servers[0].curWeight, Equals, 1)
c.Assert(rb.servers[1].curWeight, Equals, FSMMaxWeight)
c.Assert(rb.servers[2].curWeight, Equals, FSMMaxWeight)
// Removing servers has reset the state
rb.RemoveServer(testutils.ParseURI(d.URL))
c.Assert(rb.servers[0].curWeight, Equals, 1)
c.Assert(rb.servers[1].curWeight, Equals, 1)
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:46,代码来源:rebalancer_test.go
示例18: TestSNI
func (s *ServerSuite) TestSNI(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint 1")
defer e.Close()
e2 := testutils.NewResponder("Hi, I'm endpoint 2")
defer e2.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{
Host: "localhost",
Addr: "localhost:41000",
Route: `Host("localhost") && Path("/")`,
URL: e.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey, Cert: localhostCert},
})
b2 := MakeBatch(Batch{
Host: "otherhost",
Addr: "localhost:41000",
Route: `Host("otherhost") && Path("/")`,
URL: e2.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey2, Cert: localhostCert2},
})
b2.H.Settings.Default = true
c.Assert(s.mux.UpsertHost(b.H), IsNil)
c.Assert(s.mux.UpsertHost(b2.H), IsNil)
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertServer(b2.BK, b2.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertFrontend(b2.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/"), testutils.Host("localhost")), Equals, "Hi, I'm endpoint 1")
c.Assert(GETResponse(c, b.FrontendURL("/"), testutils.Host("otherhost")), Equals, "Hi, I'm endpoint 2")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:42,代码来源:mux_test.go
示例19: TestRebalancerNormalOperation
func (s *RBSuite) TestRebalancerNormalOperation(c *C) {
a, b := testutils.NewResponder("a"), testutils.NewResponder("b")
defer a.Close()
defer b.Close()
fwd, err := forward.New()
c.Assert(err, IsNil)
lb, err := New(fwd)
c.Assert(err, IsNil)
rb, err := NewRebalancer(lb)
c.Assert(err, IsNil)
rb.UpsertServer(testutils.ParseURI(a.URL))
c.Assert(rb.Servers()[0].String(), Equals, a.URL)
proxy := httptest.NewServer(rb)
defer proxy.Close()
c.Assert(seq(c, proxy.URL, 3), DeepEquals, []string{"a", "a", "a"})
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:22,代码来源:rebalancer_test.go
示例20: TestServerUpsertURL
func (s *ServerSuite) TestServerUpsertURL(c *C) {
c.Assert(s.mux.Start(), IsNil)
e1 := testutils.NewResponder("Hi, I'm endpoint 1")
defer e1.Close()
e2 := testutils.NewResponder("Hi, I'm endpoint 2")
defer e2.Close()
b := MakeBatch(Batch{Addr: "localhost:11300", Route: `Path("/")`, URL: e1.URL})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 1")
b.S.URL = e2.URL
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/")), Equals, "Hi, I'm endpoint 2")
}
开发者ID:polyverse-security,项目名称:vulcand,代码行数:22,代码来源:mux_test.go
注:本文中的github.com/polyverse-security/vulcand/Godeps/_workspace/src/github.com/mailgun/oxy/testutils.NewResponder函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论