Пример #1
0
func TestRouter(t *testing.T) {
	r := MakeRouter()
	c := make(chan gotocol.Message)
	n := names.Make("test", "us", "a", "add", "staash", 0)
	now := time.Now()

	r.Add(n, c, now)
	if r.Random() != c {
		t.Errorf("Random failed to get the right channel back for %v", n)
	}
	if r.Named(n) != c {
		t.Errorf("Name failed to get the right channel back for %v", n)
	}
	if r.Pick("staash") != c {
		t.Errorf("Pick failed to get the right channel back for %v", n)
	}
	if r.Pick("junk") != nil {
		t.Errorf("Pick failed to return nil for junk")
	}
	if r.NameChan(c) != n {
		t.Errorf("NameChan failed to return %v for chan", n)
	}

	r.Remove(n)
	if r.Pick("staash") != nil {
		t.Errorf("Pick failed to return nil after removing staash")
	}
	for i := 0; i < 5; i++ {
		r.Add(names.Make("test", "us", "a", "j", "junk", i), nil, now)
	}
	for i := 0; i < 5; i++ {
		r.Add(names.Make("test", "us", "a", "s", "staash", i), c, now)
	}
	fmt.Println(r.Len(), r)
	for i := 0; i < 10; i++ {
		if r.Pick("staash") != c {
			t.Errorf("Pick failed to get the right channel back for %v", n)
		}
		if r.Pick("junk") != nil {
			t.Errorf("Pick failed to return nil for junk")
		}
		fmt.Printf("Random found staash: %v\n", c == r.Random())
	}
}
Пример #2
0
// Create a tier and specify any dependencies, return the full name of the last node created
func Create(servicename, packagename string, regions, count int, dependencies ...string) string {
	var name string
	arch := archaius.Conf.Arch
	rnames := archaius.Conf.RegionNames
	znames := archaius.Conf.ZoneNames
	if regions == 0 { // for dns that isn't in a region or zone
		//log.Printf("Create cross region: " + servicename)
		name = names.Make(arch, "*", "*", servicename, packagename, 0)
		StartNode(name, dependencies...)
	}
	for r := 0; r < regions; r++ {
		if count == 0 { // for AWS services that are cross zone like elb and S3
			//log.Printf("Create cross zone: " + servicename)
			name = names.Make(arch, rnames[r], "*", servicename, packagename, 0)
			StartNode(name, dependencies...)
		} else {
			//log.Printf("Create service: " + servicename)
			cass := make(map[string]mapchan) // for token distribution
			for i := r * count; i < (r+1)*count; i++ {
				name = names.Make(arch, rnames[r], znames[i%len(archaius.Conf.ZoneNames)], servicename, packagename, i)
				//log.Println(dependencies)
				StartNode(name, dependencies...)
				if packagename == "priamCassandra" {
					rz := names.RegionZone(name)
					if cass[rz] == nil {
						cass[rz] = make(mapchan)
					}
					cass[rz][name] = noodles[name] // remember the nodes
				}
			}
			if packagename == "priamCassandra" {
				// split by zone
				for _, v := range cass {
					priamCassandra.Distribute(v) // returns a string if it needs logging
				}
			}
		}
	}
	return name
}
Пример #3
0
// Start fsm and create new pirates
func Start() {
	listener = make(chan gotocol.Message) // listener for fsm
	if archaius.Conf.Population < 2 {
		log.Fatal("fsm: can't create less than 2 pirates")
	}
	// create map of channels and a name index to select randoml nodes from
	noodles = make(map[string]chan gotocol.Message, archaius.Conf.Population)
	pnames = make([]string, archaius.Conf.Population) // indexable name list
	log.Println("fsm: population", archaius.Conf.Population, "pirates")
	for i := 1; i <= archaius.Conf.Population; i++ {
		name := names.Make(archaius.Conf.Arch, "atlantic", "bermuda", "blackbeard", "pirate", i)
		noodles[name] = make(chan gotocol.Message)
		go pirate.Start(noodles[name])
	}
	i := 0
	msgcount := 1
	start := time.Now()
	for name, noodle := range noodles {
		pnames[i] = name
		i++
		// tell the pirate it's name and how to talk back to it's fsm
		// this must be the first message the pirate sees
		noodle <- gotocol.Message{gotocol.Hello, listener, time.Now(), gotocol.NilContext, name}
		if edda.Logchan != nil {
			// tell the pirate to report itself and new edges to the logger
			noodle <- gotocol.Message{gotocol.Inform, edda.Logchan, time.Now(), gotocol.NilContext, ""}
			msgcount = 2
		}
	}
	log.Println("fsm: Talk amongst yourselves for", archaius.Conf.RunDuration)
	rand.Seed(int64(len(noodles)))
	for _, name := range pnames {
		// for each pirate tell them about two other random pirates
		noodle := noodles[name] // lookup the channel
		// pick a first random pirate to tell this one about
		talkto := pnames[rand.Intn(len(pnames))]
		noodle <- gotocol.Message{gotocol.NameDrop, noodles[talkto], time.Now(), gotocol.NewTrace(), talkto}
		// pick a second random pirate to tell this one about
		talkto = pnames[rand.Intn(len(pnames))]
		noodle <- gotocol.Message{gotocol.NameDrop, noodles[talkto], time.Now(), gotocol.NewTrace(), talkto}
		// anonymously send this pirate a random amount of GoldCoin up to 100
		gold := fmt.Sprintf("%d", rand.Intn(100))
		noodle <- gotocol.Message{gotocol.GoldCoin, nil, time.Now(), gotocol.NewTrace(), gold}
		// tell this pirate to start chatting with friends every 0.1 to 10 secs
		delay := fmt.Sprintf("%dms", 100+rand.Intn(9900))
		noodle <- gotocol.Message{gotocol.Chat, nil, time.Now(), gotocol.NewTrace(), delay}
	}
	msgcount += 4
	d := time.Since(start)
	log.Println("fsm: Delivered", msgcount*len(pnames), "messages in", d)
	shutdown()
}
Пример #4
0
func TestConf(t *testing.T) {
	Conf.Arch = "testarch"
	Conf.GraphmlFile = "graphml"
	Conf.GraphjsonFile = "graphjson"
	Conf.RunDuration = 10 * time.Second
	Conf.Dunbar = 100
	Conf.Population = 100
	Conf.Msglog = true
	Conf.Regions = 2
	Conf.Collect = true
	Conf.StopStep = 2
	Conf.EurekaPoll = "1s"
	for _, r := range Conf.RegionNames {
		for i, z := range Conf.ZoneNames {
			// make two different names to make sure the IP is unique and make sure it is stored
			n1 := names.Make(Conf.Arch, r, z, "lookup", "dhcp", i)
			fmt.Println(n1, Lookup(n1))
			n2 := names.Make(Conf.Arch, r, z, "lookup", "dhcp", 100+i)
			fmt.Println(n2, Lookup(n2))
			fmt.Println(n2, Lookup(n2)) // check stored lookup returns the same thing
		}
	}
}
Пример #5
0
// reader parses graphjson
func TestGraph(t *testing.T) {
	testNeo := `
	  CREATE (test_mysql00:test:store:mysql {name:"mysql00", node:"test.us-east-1.zoneA..mysql00...mysql.store", timestamp:"2016-04-17T13:40:05.938437713-07:00", ip:"54.198.0.1", region:"us-east-1", zone: "zoneA"}),
          (test_mysql01:test:store:mysql {name:"mysql01", node:"test.us-east-1.zoneA..mysql01...mysql.store", timestamp:"2016-04-17T13:40:05.938513762-07:00", ip:"54.221.0.1", region:"us-east-1", zone: "zoneA"}),
          (test_mysql00)-[:CONN]->(test_mysql01)
          `
	archaius.Conf.Arch = "test"
	Setup("localhost:7474")
	Write(testNeo)
	dal0 := names.Make("test", "us-east-1", "ZoneA", "dal", "staash", 0)
	WriteNode(dal0+" staash", time.Now())
	WriteEdge(dal0+" test.us-east-1.zoneA..mysql00...mysql.store", time.Now())
	WriteEdge(dal0+" test.us-east-1.zoneA..mysql01...mysql.store", time.Now())
	WriteFlow(dal0, "test.us-east-1.zoneA..mysql00...mysql.store", "Put", 100, 1)
	Close()
}