本文整理汇总了Golang中github.com/hashicorp/serf/testutil.GetBindAddr函数的典型用法代码示例。如果您正苦于以下问题:Golang GetBindAddr函数的具体用法?Golang GetBindAddr怎么用?Golang GetBindAddr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetBindAddr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEncrypt
func TestEncrypt(t *testing.T) {
shutdownCh := make(chan struct{})
defer close(shutdownCh)
ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-node", "test1",
"-server",
"-tag", "role=test",
"-encrypt", "kPpdjphiipNSsjd4QHWbkA==",
"-log-level", logLevel,
}
go a.Run(args)
time.Sleep(2 * time.Second)
assert.True(t, a.serf.EncryptionEnabled())
shutdownCh <- struct{}{}
}
示例2: testConfig
func testConfig() *Config {
config := DefaultConfig()
config.Init()
config.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
// Set probe intervals that are aggressive for finding bad nodes
config.MemberlistConfig.GossipInterval = 5 * time.Millisecond
config.MemberlistConfig.ProbeInterval = 50 * time.Millisecond
config.MemberlistConfig.ProbeTimeout = 25 * time.Millisecond
config.MemberlistConfig.SuspicionMult = 1
config.NodeName = fmt.Sprintf("Node %s", config.MemberlistConfig.BindAddr)
// Set a short reap interval so that it can run during the test
config.ReapInterval = 1 * time.Second
// Set a short reconnect interval so that it can run a lot during tests
config.ReconnectInterval = 100 * time.Millisecond
// Set basically zero on the reconnect/tombstone timeouts so that
// they're removed on the first ReapInterval.
config.ReconnectTimeout = 1 * time.Microsecond
config.TombstoneTimeout = 1 * time.Microsecond
return config
}
示例3: setupAPITest
func setupAPITest(t *testing.T) (chan<- struct{}, <-chan int) {
log.Level = logrus.FatalLevel
shutdownCh := make(chan struct{})
// defer close(shutdownCh)
ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-http-addr", "127.0.0.1:8090",
"-node", "test",
"-server",
}
resultCh := make(chan int)
go func() {
resultCh <- a.Run(args)
}()
time.Sleep(10 * time.Millisecond)
return shutdownCh, resultCh
}
示例4: TestEncrypt
func TestEncrypt(t *testing.T) {
log.Level = logrus.ErrorLevel
shutdownCh := make(chan struct{})
defer close(shutdownCh)
ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-node", "test1",
"-server",
"-tag", "role=test",
"-encrypt", "kPpdjphiipNSsjd4QHWbkA==",
}
go func() {
a.Run(args)
}()
time.Sleep(2 * time.Second)
if !a.serf.EncryptionEnabled() {
t.Fatal("Encryption not enabled for serf")
}
shutdownCh <- struct{}{}
}
示例5: Test_getRPCAddr
func Test_getRPCAddr(t *testing.T) {
shutdownCh := make(chan struct{})
defer close(shutdownCh)
ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}
a1Addr := testutil.GetBindAddr()
args := []string{
"-bind", a1Addr.String() + ":5000",
"-node", "test1",
"-server",
"-tag", "role=test",
}
go a.Run(args)
time.Sleep(2 * time.Second)
getRPCAddr := a.getRPCAddr()
exRPCAddr := a1Addr.String() + ":6868"
if exRPCAddr != getRPCAddr {
t.Fatalf("Expected address was: %s got %s", exRPCAddr, getRPCAddr)
}
shutdownCh <- struct{}{}
}
示例6: Test_getRPCAddr
func Test_getRPCAddr(t *testing.T) {
shutdownCh := make(chan struct{})
defer close(shutdownCh)
ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}
a1Addr := testutil.GetBindAddr()
args := []string{
"-bind", a1Addr.String() + ":5000",
"-node", "test1",
"-server",
"-tag", "role=test",
"-log-level", logLevel,
}
go a.Run(args)
time.Sleep(2 * time.Second)
getRPCAddr := a.getRPCAddr()
exRPCAddr := a1Addr.String() + ":6868"
assert.Equal(t, exRPCAddr, getRPCAddr)
shutdownCh <- struct{}{}
}
示例7: TestCommandRun_joinFail
func TestCommandRun_joinFail(t *testing.T) {
shutdownCh := make(chan struct{})
defer close(shutdownCh)
c := &Command{
ShutdownCh: shutdownCh,
Ui: new(cli.MockUi),
}
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-join", testutil.GetBindAddr().String(),
}
code := c.Run(args)
if code == 0 {
t.Fatal("should fail")
}
}
示例8: TestCommandRun_advertiseAddr
func TestCommandRun_advertiseAddr(t *testing.T) {
doneCh := make(chan struct{})
shutdownCh := make(chan struct{})
defer func() {
close(shutdownCh)
<-doneCh
}()
c := &Command{
ShutdownCh: shutdownCh,
Ui: new(cli.MockUi),
}
rpcAddr := getRPCAddr()
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-rpc-addr", rpcAddr,
"-advertise", "127.0.0.10:12345",
}
go func() {
code := c.Run(args)
if code != 0 {
log.Printf("bad: %d", code)
}
close(doneCh)
}()
testutil.Yield()
client, err := rpc.NewClient(rpcAddr)
if err != nil {
t.Fatalf("err: %s", err)
}
defer client.Close()
members, err := client.Members()
if err != nil {
t.Fatalf("err: %s", err)
}
if len(members) != 1 {
t.Fatalf("bad: %#v", members)
}
// Check the addr and port is as advertised!
m := members[0]
if bytes.Compare(m.Addr, []byte{127, 0, 0, 10}) != 0 {
t.Fatalf("bad: %#v", m)
}
if m.Port != 12345 {
t.Fatalf("bad: %#v", m)
}
}
示例9: testAgent
func testAgent() *Agent {
config := serf.DefaultConfig()
config.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
config.NodeName = config.MemberlistConfig.BindAddr
agent := &Agent{
RPCAddr: getRPCAddr(),
SerfConfig: config,
}
return agent
}
示例10: TestAgentConfig
func TestAgentConfig(t *testing.T) {
shutdownCh := make(chan struct{})
defer close(shutdownCh)
ui := new(cli.MockUi)
a := &AgentCommand{
Ui: ui,
ShutdownCh: shutdownCh,
}
advAddr := testutil.GetBindAddr().String()
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-advertise", advAddr,
"-log-level", logLevel,
}
resultCh := make(chan int)
go func() {
resultCh <- a.Run(args)
}()
time.Sleep(2 * time.Second)
assert.NotEqual(t, a.config.AdvertiseAddr, a.config.BindAddr)
assert.NotEmpty(t, a.config.AdvertiseAddr)
assert.Equal(t, advAddr, a.config.AdvertiseAddr)
// Send a shutdown request
shutdownCh <- struct{}{}
select {
case code := <-resultCh:
if code != 0 {
t.Fatalf("bad code: %d", code)
}
case <-time.After(100 * time.Millisecond):
t.Fatalf("timeout")
}
}
示例11: testAgent
func testAgent(logOutput io.Writer) *Agent {
if logOutput == nil {
logOutput = os.Stderr
}
config := serf.DefaultConfig()
config.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
config.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
config.NodeName = config.MemberlistConfig.BindAddr
agent, err := Create(config, logOutput)
if err != nil {
panic(err)
}
return agent
}
示例12: testAgentWithConfig
func testAgentWithConfig(agentConfig *Config, serfConfig *serf.Config,
logOutput io.Writer) *Agent {
if logOutput == nil {
logOutput = os.Stderr
}
serfConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
serfConfig.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
serfConfig.NodeName = serfConfig.MemberlistConfig.BindAddr
agent, err := Create(agentConfig, serfConfig, logOutput)
if err != nil {
panic(err)
}
return agent
}
示例13: testAgent
func testAgent(t *testing.T) *agent.Agent {
config := serf.DefaultConfig()
config.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
config.NodeName = config.MemberlistConfig.BindAddr
agent := &agent.Agent{
RPCAddr: getRPCAddr(),
SerfConfig: config,
}
if err := agent.Start(); err != nil {
t.Fatalf("err: %s", err)
}
return agent
}
示例14: TestCommandRun_rpc
func TestCommandRun_rpc(t *testing.T) {
doneCh := make(chan struct{})
shutdownCh := make(chan struct{})
defer func() {
close(shutdownCh)
<-doneCh
}()
c := &Command{
ShutdownCh: shutdownCh,
Ui: new(cli.MockUi),
}
rpcAddr := getRPCAddr()
args := []string{
"-bind", testutil.GetBindAddr().String(),
"-rpc-addr", rpcAddr,
}
go func() {
code := c.Run(args)
if code != 0 {
log.Printf("bad: %d", code)
}
close(doneCh)
}()
testutil.Yield()
client, err := rpc.NewClient(rpcAddr)
if err != nil {
t.Fatalf("err: %s", err)
}
defer client.Close()
members, err := client.Members()
if err != nil {
t.Fatalf("err: %s", err)
}
if len(members) != 1 {
t.Fatalf("bad: %#v", members)
}
}
示例15: testAgent
func testAgent(t *testing.T) *agent.Agent {
config := serf.DefaultConfig()
config.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
config.MemberlistConfig.ProbeInterval = 50 * time.Millisecond
config.MemberlistConfig.ProbeTimeout = 25 * time.Millisecond
config.MemberlistConfig.SuspicionMult = 1
config.NodeName = config.MemberlistConfig.BindAddr
agent := &agent.Agent{
RPCAddr: getRPCAddr(),
SerfConfig: config,
}
if err := agent.Start(); err != nil {
t.Fatalf("err: %s", err)
}
return agent
}