// TestServiceMemberIdentification checks that a client can register with the serviceproxy.
func TestServiceMemberIdentification(t *testing.T) {
	// register proxy
	serfagent := register.NewAgent("proxy", 15333)
	serfagent.RegisterService("")

	// make sure service is up
	time.Sleep(1 * time.Second)

	// register dummy adder service
	serfagent2 := register.NewAgent("adder", 23230)
	hname, _ := os.Hostname()
	serfagent2.RegisterService(hname + ":7946")

	// make sure service is up
	time.Sleep(1 * time.Second)

	var registry proxy.Registry
	registry.UpdateRegistry()
	members := registry.GetServicesSlice()

	if len(members) != 1 {
		t.Errorf("Number service members %d (should be 1)", len(members))
		return
	}

	if members[0] != "adder" {
		t.Errorf("adder should be the service member")
		return
	}
}
示例#2
0
// Run creates the serf agent and launches the http server
func (proxy *ServiceProxy) Run() error {
	// create agent and launch (no join node is specified)
	serfagent := register.NewAgent("proxy", proxy.Port)
	serfagent.Debug = proxy.Debug
	serfagent.RegisterService("")

	hname, _ := os.Hostname()
	serfaddr := hname + ":" + strconv.Itoa(serfagent.GetSerfPort())

	// address for clients to register (port does not need to be specified
	// by the client if using the Go register interface)
	fmt.Printf("Registry address: %s\n", serfaddr)

	// exit server if user presses Ctrl-C
	go func() {
		sigch := make(chan os.Signal)
		signal.Notify(sigch, os.Interrupt, syscall.SIGTERM)
		<-sigch
		fmt.Println("Exiting...")
		os.Exit(0)
	}()

	// create web server
	return Serve(proxy.Port)
}
// TestServiceRegister checks that a client can be registered as a serf agent.
func TestServiceRegister(t *testing.T) {
	// register proxy
	serfagent := register.NewAgent("adder", 23230)
	err := serfagent.RegisterService("")

	// make sure service is up
	time.Sleep(1 * time.Second)

	if err != nil {
		t.Errorf("Error when registering")
		return
	}

	port := serfagent.GetSerfPort()
	if port <= 25000 {
		t.Errorf("Service port not found in correct range")
		return
	}

	// TODO check that service is alive

	err = serfagent.UnRegisterService()
	if err != nil {
		t.Errorf("Failed to unregister service")
		return
	}
}
// TestProxyRegister checks that serviceproxy can be registered as a serf agent.
func TestProxyRegister(t *testing.T) {
	// register proxy
	serfagent := register.NewAgent("proxy", 15333)
	err := serfagent.RegisterService("")

	// make sure service is up
	time.Sleep(1 * time.Second)

	if err != nil {
		t.Errorf("Error when registering")
		return
	}

	port := serfagent.GetSerfPort()
	if port != 7946 {
		t.Errorf("Proxy not registered at port 7946")
		return
	}

	// TODO: check that service is alive

	err = serfagent.UnRegisterService()
	if err != nil {
		t.Errorf("Failed to unregister proxy")
		return
	}
}
func main() {
	flag.BoolVar(showHelp, "h", false, "Show help message")
	flag.Parse()

	if *showHelp {
		fmt.Printf(helpMessage)
		os.Exit(0)
	}

	if *registry != "" {
		// creates adder service and points to first argument
		serfagent := register.NewAgent("calcoverlap", *portNum)
		serfagent.RegisterService(*registry)
	}

	overlap.Serve(*proxy, *portNum)
}
func main() {
	flag.BoolVar(showHelp, "h", false, "Show help message")
	flag.Parse()

	if *showHelp {
		fmt.Printf(helpMessage)
		os.Exit(0)
	}

	// register service
	if flag.NArg() != 1 {
		fmt.Printf("Must provide registry address")
		fmt.Printf(helpMessage)
		os.Exit(0)
	}

	// creates adder service and points to first argument
	serfagent := register.NewAgent("adder", *portNum)
	serfagent.RegisterService(flag.Arg(0))

	Serve(*portNum)
}
func main() {
	flag.BoolVar(showHelp, "h", false, "Show help message")
	flag.Parse()

	if *showHelp {
		fmt.Printf(helpMessage)
		os.Exit(0)
	}

	if flag.NArg() != 1 {
		fmt.Println("Must provide a directory for temporary segmentation data")
		fmt.Println(helpMessage)
		os.Exit(0)
	}

	if *registry != "" {
		// creates adder service and points to first argument
		serfagent := register.NewAgent("clustercompute", *portNum)
		serfagent.RegisterService(*registry)
	}

	calclabels.Serve(*proxy, *portNum, *configFile, flag.Arg(0))
}