Esempio n. 1
0
func TestMkdirIfNotExist(t *testing.T) {
	dir := "xxx"
	defer os.Remove(dir)

	assert.Equal(t, nil, mkdirIfNotExist(dir))
	assert.Equal(t, nil, mkdirIfNotExist(dir))
}
Esempio n. 2
0
func TestPatternMatched(t *testing.T) {
	assert.Equal(t, true, patternMatched("orderstatus", "order"))
	assert.Equal(t, false, patternMatched("orderstatus", "~order"))
	assert.Equal(t, true, patternMatched("flashtrade_web", "~svc_hippo"))
	assert.Equal(t, false, patternMatched("34.StrollSearchRuleMsg.v1", "laxinRiskControl"))
	assert.Equal(t, true, patternMatched("34.laxinRiskControl.v1", "laxinRiskControl"))
}
Esempio n. 3
0
func TestConsumerZnode(t *testing.T) {
	c := newConsumerZnode("cloudparkingGroup_orderMsg_BJS0-D134-018-1447657979158-fa9d1dc8")
	assert.Equal(t, "BJS0-D134-018", c.Host())

	c = newConsumerZnode("[email protected]:33f3a781-1dd5-488d-84fa-f8d3febce170")
	assert.Equal(t, "192.168.10.134", c.ClientRealIP())
}
Esempio n. 4
0
func TestValidateGroupName(t *testing.T) {
	type fixture struct {
		ok    bool
		group string
	}

	fixtures := []fixture{
		fixture{false, ""}, // group cannot be empty
		fixture{true, "testA"},
		fixture{true, "te_stA"},
		fixture{true, "a"},
		fixture{true, "111111"},
		fixture{true, "Zb44444444"},
		fixture{false, "a b"},
		fixture{false, "a.adsf"},
		fixture{false, "a.a.bbb3"},
		fixture{false, "(xxx)"},
		fixture{false, "[asdf"},
		fixture{false, "'asdfasdf"},
		fixture{false, "&asdf"},
		fixture{false, ">adsf"},
		fixture{false, "adf/asdf"},
		fixture{false, "a+b4"},
		fixture{true, "4-2323"},
		fixture{false, "__smoketest__"},
	}
	m := mysqlStore{}
	for _, f := range fixtures {
		assert.Equal(t, f.ok, m.ValidateGroupName(nil, f.group), f.group)
	}

	var h = make(http.Header)
	h.Set("X-Origin", "smoketest")
	assert.Equal(t, true, m.ValidateGroupName(h, "__smoketest__"))
}
Esempio n. 5
0
func TestPickServer(t *testing.T) {
	cf := setupConfig()
	picker := NewStandardServerSelector(1000)
	picker.SetServers(cf.Servers)

	addr, err := picker.PickServer("db", 23)
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_1/", addr)
	assert.Equal(t, nil, err)

	addr, err = picker.PickServer("invalid", 23)
	assert.Equal(t, "", addr)
	assert.Equal(t, ErrServerNotFound, err)

	addr, err = picker.PickServer("db", 2300) // too big for 1000
	assert.Equal(t, "", addr)
	assert.Equal(t, ErrServerNotFound, err)

	addr, err = picker.PickServer("default", 1<<30) // too big for 1000
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_0/", addr)
	assert.Equal(t, nil, err)

	addr, err = picker.PickServer("log", 1<<30) // too big for 1000
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_log/", addr)
	assert.Equal(t, nil, err)
}
Esempio n. 6
0
func TestComplexDataType(t *testing.T) {
	s := server.NewServer("test")
	s.LoadConfig("../../etc/faed.cf.sample")
	section, _ := s.Conf.Section("servants.redis")
	cf := &config.ConfigRedis{}
	cf.LoadConfig(section)

	var (
		pool = "default"
		//val  interface{}
		err error
	)

	c := New(cf)
	name := "funky.gao"
	data := customType{X: 12, Y: 87, Name: name}
	encodedData, err := msgpack.Marshal(data)
	assert.Equal(t, nil, err)
	key := "custome_complex_data_type"
	err = c.Set(pool, key, encodedData)
	assert.Equal(t, nil, err)
	val, err := c.Get(pool, key)
	assert.Equal(t, nil, err)
	var val1 customType
	msgpack.Unmarshal(val.([]byte), &val1)
	assert.Equal(t, name, val1.Name)

}
Esempio n. 7
0
func TestSyslogStatsParser(t *testing.T) {
	msg := "Jan 26 21:30:37 ip-172-31-13-40 syslog-ng[2156]: Log statistics; dropped='program(/mnt/htdocs/als/forward.php)=0', dropped='program(/mnt/htdocs/als/bigdata_forward.php)=0', processed='center(queued)=1699039', processed='center(received)=1699039', processed='destination(d_als_prog)=1697379', processed='destination(d_boot)=0', processed='destination(d_auth)=0', processed='destination(d_cron)=1426', processed='destination(d_mlal)=0', processed='destination(d_als_file)=0', processed='destination(d_mesg)=229', processed='destination(d_bigdata_prog)=0', processed='destination(d_haproxy)=0', processed='destination(d_cons)=0', processed='destination(d_spol)=0', processed='destination(d_mail)=5', processed='source(s_udp)=0', processed='source(s_bigdata)=0', processed='source(s_sys)=1660', processed='source(s_als)=1697379', suppressed='program(/mnt/htdocs/als/forward.php)=0', suppressed='program(/mnt/htdocs/als/bigdata_forward.php)=0'"
	assert.Equal(t, "", parseSyslogNgStats(msg))

	msg = "Jan 26 21:30:37 ip-172-31-13-40 syslog-ng[2156]: Log statistics; dropped='program(/mnt/htdocs/als/forward.php)=56', dropped='program(/mnt/htdocs/als/bigdata_forward.php)=20', processed='center(queued)=1699039', processed='center(received)=1699039', processed='destination(d_als_prog)=1697379', processed='destination(d_boot)=0', processed='destination(d_auth)=0', processed='destination(d_cron)=1426', processed='destination(d_mlal)=0', processed='destination(d_als_file)=0', processed='destination(d_mesg)=229', processed='destination(d_bigdata_prog)=0', processed='destination(d_haproxy)=0', processed='destination(d_cons)=0', processed='destination(d_spol)=0', processed='destination(d_mail)=5', processed='source(s_udp)=0', processed='source(s_bigdata)=0', processed='source(s_sys)=1660', processed='source(s_als)=1697379', suppressed='program(/mnt/htdocs/als/forward.php)=0', suppressed='program(/mnt/htdocs/als/bigdata_forward.php)=0'"
	assert.Equal(t, " [/mnt/htdocs/als/forward.php]dropped:56 [/mnt/htdocs/als/bigdata_forward.php]dropped:20", parseSyslogNgStats(msg))
}
Esempio n. 8
0
func TestLegacyServerSelector(t *testing.T) {
	cf := setupConfig()
	picker := NewLegacyServerSelector(1000)
	picker.SetServers(cf.Servers)

	addr, err := picker.PickServer("db", 23)
	assert.Equal(t, ErrServerNotFound, err)

	addr, err = picker.PickServer("invalid", 23)
	assert.Equal(t, ErrServerNotFound, err)

	addr, err = picker.PickServer("db1", 2300)
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_1/", addr.Uri())
	assert.Equal(t, nil, err)

	addr, err = picker.PickServer("db1", 1<<30) // has nothing to do with shardId
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_1/", addr.Uri())
	assert.Equal(t, nil, err)

	addr, err = picker.PickServer("default", 1<<30) // too big for 1000
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_0/", addr.Uri())
	assert.Equal(t, nil, err)

	addr, err = picker.PickServer("log", 1<<30) // too big for 1000
	assert.Equal(t, "mongodb://127.0.0.1:27017/qa_royal_log/", addr.Uri())
	assert.Equal(t, nil, err)
}
Esempio n. 9
0
func TestDecodeMessageSetMultiMessage(t *testing.T) {
	w := bytes.NewBuffer(make([]byte, 0))
	partition1, offset1, msg1 := int32(1), int64(9087), []byte("hello world")
	partition2, offset2, msg2 := int32(0), int64(1298), []byte("good morning")

	buf := make([]byte, 8)

	// msg1
	writeI32(w, buf, partition1)
	writeI64(w, buf, offset1)
	writeI32(w, buf, int32(len(msg1)))
	w.Write(msg1)

	// msg2
	writeI32(w, buf, partition2)
	writeI64(w, buf, offset2)
	writeI32(w, buf, int32(len(msg2)))
	w.Write(msg2)

	msgSet := DecodeMessageSet(w.Bytes())

	assert.Equal(t, 2, len(msgSet))
	assert.Equal(t, partition1, msgSet[0].Partition)
	assert.Equal(t, offset2, msgSet[1].Offset)
	assert.Equal(t, msg2, msgSet[1].Value)
}
Esempio n. 10
0
func TestMessageUsage(t *testing.T) {
	m := NewMessage(1029)
	msg := "hello world"
	m.Body = m.Body[:len(msg)]
	copy(m.Body, msg)
	assert.Equal(t, msg, string(m.Body))
	assert.Equal(t, len(msg), len(m.Body))
}
Esempio n. 11
0
func TestIndexName(t *testing.T) {
	date, _ := time.Parse("2006-01-02 15:04", "2011-01-19 22:15")
	p := &engine.ConfProject{IndexPrefix: "rs"}
	assert.Equal(t, "fun_rs_2011_01", indexName(p, "@ym", date))
	assert.Equal(t, "fun_rs_2011_01_19", indexName(p, "@ymd", date))
	assert.Equal(t, "fun_rs_2011_w03", indexName(p, "@ymw", date))
	assert.Equal(t, "fun_foo", indexName(p, "foo", date))
}
Esempio n. 12
0
func TestLruCacheLenAndPurge(t *testing.T) {
	lru := NewLruCache(0)
	assert.Equal(t, 0, lru.Len())
	lru.Set("myKey", 1234)
	assert.Equal(t, 1, lru.Len())
	lru.Purge()
	assert.Equal(t, 0, lru.Len())
}
Esempio n. 13
0
func TestRealTopicsDumb(t *testing.T) {
	cf := DefaultConfig()
	topics := []string{"t1", "t2", "__consumer_offsets"}
	assert.Equal(t, []string{"t1", "t2"}, cf.realTopics(topics))

	topics = []string{}
	assert.Equal(t, topics, cf.realTopics(topics))
}
Esempio n. 14
0
func TestAssignResourcesToActors_ActorMoreThanJobQueues(t *testing.T) {
	jobs := zk.ResourceList([]string{"job1"})
	actors := zk.ActorList([]string{"1", "2"})

	decision := assignResourcesToActors(actors, jobs)
	t.Logf("%+v", decision)
	assert.Equal(t, 0, len(decision["2"]))
	assert.Equal(t, 1, len(decision["1"]))
}
Esempio n. 15
0
func TestNormalize(t *testing.T) {
	msg := "batch token error! pre: leuw53.1e2t2j; current: 2m2w1z.1e2sz5 (1)"
	b := normalizers["batch_token"].ReplaceAll([]byte(msg), []byte("?"))
	assert.Equal(t, "batch token error! ?", string(b))

	msg = "user id: 34343434 adfasf"
	m := normalizers["digit"].ReplaceAll([]byte(msg), []byte("?"))
	assert.Equal(t, "user id: ? adfasf", string(m))
}
Esempio n. 16
0
func TestNextIdWithTagError(t *testing.T) {
	_, err := NewIdGenerator(32)
	assert.Equal(t, ErrorInvalidWorkerId, err)
	id, err := NewIdGenerator(31)
	assert.Equal(t, nil, err)
	val, err := id.NextWithTag(32)
	assert.Equal(t, int64(0), val)
	assert.Equal(t, ErrorInvalidTag, err)
}
Esempio n. 17
0
func TestAssignResourcesToActors_Normal(t *testing.T) {
	jobs := zk.ResourceList([]string{"a", "b", "c", "d", "e"})
	actors := zk.ActorList([]string{"1", "2"})

	decision := assignResourcesToActors(actors, jobs)
	t.Logf("%+v", decision)
	assert.Equal(t, 3, len(decision["1"]))
	assert.Equal(t, 2, len(decision["2"]))
}
Esempio n. 18
0
func TestRingBuffer(t *testing.T) {
	rb := New()
	rb.Write("hello")
	rb.Write(189)
	v1 := rb.Read().(string)
	assert.Equal(t, "hello", v1)
	v2 := rb.Read().(int)
	assert.Equal(t, 189, v2)
}
Esempio n. 19
0
func TestJwtToken(t *testing.T) {
	token, err := jwtToken("appid", "secret")
	assert.Equal(t, nil, err)
	assert.Equal(t, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBpZCI6ImFwcGlkIn0.YaURi84SXE2SYFgVnJzN8MW5PdN2xgHRqdNzPF_-usY", token)

	appid, err := tokenDecode(token)
	assert.Equal(t, nil, err)
	assert.Equal(t, "exp", appid)
}
Esempio n. 20
0
func TestBasic(t *testing.T) {
	sm := NewSortedMap()
	sm.Set("foo", 34)
	sm.Inc("foo", 3)
	assert.Equal(t, 37, sm.Get("foo"))
	sm.Inc("foo", -2)
	assert.Equal(t, 35, sm.Get("foo"))
	assert.Equal(t, 5, sm.Inc("non-exist", 5))
}
Esempio n. 21
0
func TestBlockBasic(t *testing.T) {
	b := block{
		magic: currentMagic,
		key:   []byte("abc"),
		value: []byte("12345678"),
	}

	assert.Equal(t, uint32(3), b.keyLen())
	assert.Equal(t, uint32(8), b.valueLen())
}
Esempio n. 22
0
func TestAll(t *testing.T) {
	s := New("/bin/ls")
	err := s.Open()
	assert.Equal(t, nil, err)
	r := s.Reader()
	line, _, err := r.ReadLine()
	s.Close()
	assert.Equal(t, nil, err)
	assert.Equal(t, "stream.go", string(line)) // current dir fist 'ls' output line is stream.go
}
Esempio n. 23
0
func TestSlaDumpForAlterTopic(t *testing.T) {
	sla := DefaultSla()
	sla.Replicas = 3
	sla.RetentionHours = 2
	assert.Equal(t, "--config retention.ms=7200000", strings.Join(sla.DumpForAlterTopic(), " "))
	sla.RetentionHours = -1 // invalid setter, restore to default
	assert.Equal(t, 0, len(sla.DumpForAlterTopic()), " ")
	sla.RetentionBytes = 10 << 20
	assert.Equal(t, "--config retention.bytes=10485760", strings.Join(sla.DumpForAlterTopic(), " "))
}
Esempio n. 24
0
func TestIsIoError(t *testing.T) {
	err := errors.New("EOF")
	assert.Equal(t, true, IsIoError(err))
	err = errors.New("broken pipe")
	assert.Equal(t, true, IsIoError(err))
	err = errors.New("blah")
	assert.Equal(t, false, IsIoError(err))
	err = errors.New("connection reset by peer")
	assert.Equal(t, true, IsIoError(err))
}
Esempio n. 25
0
func TestRealTopicsOnly(t *testing.T) {
	cf := DefaultConfig()
	cf.TopicsOnly = map[string]struct{}{
		"t1": struct{}{},
	}
	topics := []string{"t1", "t2", "__consumer_offsets"}
	assert.Equal(t, []string{"t1"}, cf.realTopics(topics))

	topics = []string{}
	assert.Equal(t, topics, cf.realTopics(topics))
}
Esempio n. 26
0
func TestParseConsumerHost(t *testing.T) {
	host := hostOfConsumer("console-consumer-48389_mac-2.local-1449108222694-9f9b7aa7")
	assert.Equal(t, "mac-2.local", host)

	host = hostOfConsumer("mac-2.local:ab3373df-02c7-4074-adc0-49078af110ff")
	assert.Equal(t, "mac-2.local", host)

	// FIXME add more robust test case
	host = hostOfConsumer("mac-2.local-invalid")
	assert.Equal(t, "mac", host)
}
Esempio n. 27
0
func TestIsSystemError(t *testing.T) {
	m := &mysql{}
	assert.NotEqual(t, nil, t)
	err := errors.New("Error Connection failed")
	assert.Equal(t, true, m.isSystemError(err))
	err = errors.New("Error 1054: Unknown column 'curve_internal_id' in 'field list'")
	t.Logf("prefix(%s)", err.Error()[6:])
	assert.Equal(t, false, m.isSystemError(err))
	err = errors.New("Error 1062: Duplicate entry '1' for key 'PRIMARY'")
	assert.Equal(t, false, m.isSystemError(err))
}
Esempio n. 28
0
func TestAll(t *testing.T) {
	vb := New(1024).SetNodes([]string{"1.1.1.1:9001", "1.1.1.2:9001", "1.1.1.1:9001"})
	t.Logf("%#v", *vb)
	assert.Equal(t, "1.1.1.1:9001", vb.Node("user:1"))

	vb.SetNodes([]string{"1.1.1.1:9001", "1.1.1.2:9001"})
	assert.Equal(t, "1.1.1.2:9001", vb.Node("user:1"))
	assert.Equal(t, "1.1.1.1:9001", vb.Node("user:2"))

	assert.Equal(t, uint32(0x3a5), vb.Hash("user:1"))
	assert.Equal(t, uint32(0x2ac), vb.Hash("user:2"))
}
Esempio n. 29
0
func TestSlaDumpForCreateTopic(t *testing.T) {
	sla := DefaultSla()
	sla.Replicas = 2 // still the default val
	sla.RetentionHours = 2
	t.Logf("%v", sla.DumpForCreateTopic())
	assert.Equal(t, "--partitions 1 --replication-factor 2", strings.Join(sla.DumpForCreateTopic(), " "))
	sla.Replicas = 3
	assert.Equal(t, "--partitions 1 --replication-factor 3", strings.Join(sla.DumpForCreateTopic(), " "))

	sla.Partitions = -1 // invalid setter
	assert.Equal(t, "--partitions 1 --replication-factor 3", strings.Join(sla.DumpForCreateTopic(), " "))
}
Esempio n. 30
0
func TestEndian(t *testing.T) {
	if EndianIsLittle() {
		t.Log("current os is little endian")
	} else {
		t.Log("current os is big endian")
	}

	var val uint16 = 6 << 8
	low, high := SafeSplitUint16(val)
	assert.Equal(t, uint8(0), low)
	assert.Equal(t, uint8(0x6), high)
}