예제 #1
0
파일: eureka_test.go 프로젝트: ruo91/spigo
// Test the discovery process by writing and reading back service information
func TestDiscovery(t *testing.T) {
	fmt.Println("eureka_test start")
	listener := make(chan gotocol.Message)
	edda.Logchan = make(chan gotocol.Message, 10) // buffered channel
	archaius.Conf.Msglog = true
	archaius.Conf.GraphjsonFile = "test"
	archaius.Conf.GraphmlFile = "test"
	go edda.Start("test.edda")
	eureka := make(chan gotocol.Message, 10)
	go Start(eureka, "test.eureka")
	// stack up a series of requests in the buffered channel
	eureka <- gotocol.Message{gotocol.Hello, listener, time.Now(), "test0" + " " + "test"}
	eureka <- gotocol.Message{gotocol.Hello, listener, time.Now(), "test1" + " " + "test"}
	eureka <- gotocol.Message{gotocol.Hello, listener, time.Now(), "thing0" + " " + "thing"}
	eureka <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), "test0"}
	eureka <- gotocol.Message{gotocol.Goodbye, listener, time.Now(), ""}
	// pick up responses until we see the Goodbye response
	for {
		msg := <-listener
		if archaius.Conf.Msglog {
			fmt.Printf("test_eureka: %v\n", msg)
		}
		if msg.Imposition == gotocol.Goodbye {
			break
		}
		switch msg.Imposition {
		case gotocol.GetResponse:
			if msg.Intention != "test" {
				t.Fail()
			}
		}
	}
	if edda.Logchan != nil {
		close(edda.Logchan)
	}
	//wait until edda and eureka finish flushing and close files
	Wg.Wait()
	edda.Wg.Wait()
	fmt.Println("eureka_test end")
}
예제 #2
0
파일: spigo.go 프로젝트: dberkholz/spigo
// main handles command line flags and starts up an architecture
func main() {
	flag.StringVar(&archaius.Conf.Arch, "a", "netflixoss", "Architecture to create or read, fsm, lamp, migration, netflixoss or json/????_arch.json")
	flag.IntVar(&archaius.Conf.Population, "p", 100, "Pirate population for fsm or scale factor % for netflixoss etc.")
	flag.IntVar(&duration, "d", 10, "Simulation duration in seconds")
	flag.IntVar(&archaius.Conf.Regions, "w", 1, "Wide area regions")
	flag.BoolVar(&graphmlEnabled, "g", false, "Enable GraphML logging of nodes and edges to <arch>.graphml")
	flag.BoolVar(&graphjsonEnabled, "j", false, "Enable GraphJSON logging of nodes and edges to <arch>.json")
	flag.BoolVar(&archaius.Conf.Msglog, "m", false, "Enable console logging of every message")
	flag.BoolVar(&reload, "r", false, "Reload json/<arch>.json to setup architecture")
	flag.BoolVar(&archaius.Conf.Collect, "c", false, "Collect metrics to json/<arch>_metrics.json and via http:")
	flag.IntVar(&archaius.Conf.StopStep, "s", 0, "Stop creating microservices at this step, 0 = don't stop")
	flag.StringVar(&archaius.Conf.EurekaPoll, "u", "1s", "Polling interval for Eureka name service")
	flag.BoolVar(&archaius.Conf.Filter, "f", false, "Filter output names to simplify graph")
	flag.IntVar(&cpucount, "cpus", runtime.NumCPU(), "Number of CPUs for Go runtime")
	runtime.GOMAXPROCS(cpucount)
	var cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to file")
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	if archaius.Conf.Collect {
		collect.Serve(8123) // start web server at port
	}
	if graphjsonEnabled || graphmlEnabled {
		if graphjsonEnabled {
			archaius.Conf.GraphjsonFile = archaius.Conf.Arch
		}
		if graphmlEnabled {
			archaius.Conf.GraphmlFile = archaius.Conf.Arch
		}
		// make a buffered channel so logging can start before edda is scheduled
		edda.Logchan = make(chan gotocol.Message, 100)
	}
	archaius.Conf.RunDuration = time.Duration(duration) * time.Second
	// start up the selected architecture
	go edda.Start(archaius.Conf.Arch + ".edda") // start edda first
	if reload {
		asgard.Run(asgard.Reload(archaius.Conf.Arch), "")
	} else {
		switch archaius.Conf.Arch {
		case "fsm":
			fsm.Start()
		//case "netflixoss":  replaced by json_arch/netflixoss_arch.json
		//	netflixoss.Start()
		//case "lamp":  replaced by json_arch/lamp_arch.json
		//	lamp.Start()
		case "migration":
			migration.Start() // step by step from lamp to netflixoss
		default:
			a := architecture.ReadArch(archaius.Conf.Arch)
			if a == nil {
				log.Fatal("Architecture " + archaius.Conf.Arch + " isn't recognized")
			} else {
				architecture.Start(a)
			}
		}
	}
	log.Println("spigo: complete")
	// stop edda if it's running and wait for edda to flush messages
	if edda.Logchan != nil {
		close(edda.Logchan)
	}
	edda.Wg.Wait()
	flow.Shutdown()
}