Esempio n. 1
0
func TestEngineConfig(t *testing.T) {
	e := NewEngine()
	e.LoadConfigFile("../etc/faed.cf")
	assert.Equal(t, ":9001", e.conf.rpc.listenAddr)
	assert.NotEqual(t, 0, len(e.conf.memcaches))
	assert.NotEqual(t, 0, len(e.conf.mongos))
}
Esempio n. 2
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. 3
0
func TestFlockAndFunlock(t *testing.T) {
	filepath := ".lk"
	f, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0644)
	if err != nil {
		t.Fatal(err)
	}

	err = Flock(f, time.Second)
	assert.Equal(t, nil, err)
	err = Flock(f, time.Second)
	assert.NotEqual(t, nil, err)

	assert.Equal(t, nil, Funlock(f))

	syscall.Unlink(filepath)
}
Esempio n. 4
0
func TestHostPool(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	dummyErr := errors.New("Dummy Error")

	p := New([]string{"a", "b", "c"})
	assert.Equal(t, p.Get().Host(), "a")
	assert.Equal(t, p.Get().Host(), "b")
	assert.Equal(t, p.Get().Host(), "c")
	respA := p.Get()
	assert.Equal(t, respA.Host(), "a")

	respA.Mark(dummyErr)
	respB := p.Get()
	respB.Mark(dummyErr)
	respC := p.Get()
	assert.Equal(t, respC.Host(), "c")
	respC.Mark(nil)
	// get again, and verify that it's still c
	assert.Equal(t, p.Get().Host(), "c")
	// now try to mark b as success; should fail because already marked
	respB.Mark(nil)
	assert.Equal(t, p.Get().Host(), "c") // would be b if it were not dead
	// now restore a
	respA = &standardHostPoolResponse{host: "a", pool: p}
	respA.Mark(nil)
	assert.Equal(t, p.Get().Host(), "a")
	assert.Equal(t, p.Get().Host(), "c")

	// ensure that we get *something* back when all hosts fail
	for _, host := range []string{"a", "b", "c"} {
		response := &standardHostPoolResponse{host: host, pool: p}
		response.Mark(dummyErr)
	}
	resp := p.Get()
	assert.NotEqual(t, resp, nil)
}
Esempio n. 5
0
func TestConfigValidate(t *testing.T) {
	cfg := DefaultConfig()
	assert.NotEqual(t, nil, cfg.Validate())
}