Exemple #1
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)

}
Exemple #2
0
func getRedisStore() *RedisStore {
	svr := server.NewServer("test")
	svr.LoadConfig("../../etc/faed.cf.sample")
	section, _ := svr.Conf.Section("servants.redis")
	cf := &config.ConfigRedis{}
	cf.LoadConfig(section)

	return NewRedisStore("default", cf)
}
Exemple #3
0
func TestSelectorStandardPoolServers(t *testing.T) {
	s := server.NewServer("test")
	s.LoadConfig("../../etc/faed.cf.sample")
	section, _ := s.Conf.Section("servants.mysql")
	cf := &config.ConfigMysql{}
	cf.LoadConfig(section)

	sel := newStandardServerSelector(cf)

	assert.Equal(t, 1, len(sel.PoolServers("UserShard")))
}
Exemple #4
0
func init() {
	parseFlags()

	if options.showVersion {
		server.ShowVersionAndExit()
	}

	server.SetupLogging(options.logFile, options.logLevel,
		options.crashLogFile, options.alarmLogSock, options.alarmTag)

	// thrift lib use "log", so we also need to customize its behavior
	_log.SetFlags(_log.Ldate | _log.Ltime | _log.Lshortfile)

	if options.kill {
		s := server.NewServer("fae")
		s.LoadConfig(options.configFile)
		s.Launch()

		// stop new requests
		engine.NewEngine().
			LoadConfig(s.Conf).
			UnregisterEtcd()

		// finish all outstanding RPC sessions
		if err := signal.SignalProcessByPidFile(options.lockFile,
			syscall.SIGUSR1); err != nil {
			fmt.Fprintf(os.Stderr, "stop failed: %s\n", err)
			os.Exit(1)
		}

		cleanup() // TODO wait till that faed process terminates, who will do the cleanup

		fmt.Println("faed killed")

		os.Exit(0)
	}

	if options.lockFile != "" {
		if locking.InstanceLocked(options.lockFile) {
			fmt.Fprintf(os.Stderr, "Another instance is running, exit...\n")
			os.Exit(1)
		}

		locking.LockInstance(options.lockFile)
	}

}
Exemple #5
0
func main() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
			debug.PrintStack()
		}
	}()

	s := server.NewServer("configd")
	s.LoadConfig(options.configFile)
	s.Launch()

	go server.RunSysStats(s.StartedAt,
		time.Minute*time.Duration(options.statsInterval))

	monitorForever(s.Conf)
}
Exemple #6
0
func main() {
	defer func() {
		cleanup()

		if err := recover(); err != nil {
			fmt.Println(err)
			debug.PrintStack()
		}
	}()

	if options.cpuprof || options.memprof {
		cf := &profiler.Config{
			Quiet:        true,
			ProfilePath:  "prof",
			CPUProfile:   options.cpuprof,
			MemProfile:   options.memprof,
			BlockProfile: options.blockprof,
		}

		defer profiler.Start(cf).Stop()
	}

	log.Info("%s", `
     ____      __      ____ 
    ( ___)    /__\    ( ___)
     )__)    /(__)\    )__) 
    (__)    (__)(__)  (____)`)

	s := server.NewServer("fae")
	s.LoadConfig(options.configFile)
	s.Launch()

	go server.RunSysStats(time.Now(), options.tick)

	engineRunner = engine.NewEngine()
	signal.RegisterSignalHandler(syscall.SIGINT, func(sig os.Signal) {
		shutdown()
		engineRunner.StopRpcServe()
	})

	engineRunner.LoadConfig(s.Conf).
		ServeForever()
}
Exemple #7
0
func TestCRUD(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)
	val, err = c.Get(pool, "hello")
	assert.Equal(t, ErrKeyNotExist.Error(), err.Error())

	err = c.Set(pool, "hello", "world")
	assert.Equal(t, nil, err)
	val, err = c.Get(pool, "hello")
	assert.Equal(t, nil, err)
	assert.Equal(t, "world", string(val.([]byte)))

	err = c.Del(pool, "hello")
	assert.Equal(t, nil, err)
	val, err = c.Get(pool, "hello")
	assert.Equal(t, ErrKeyNotExist, err)

	err = c.Del(pool, "hello") // del again
	assert.Equal(t, nil, err)

	var fooValue interface{}
	_, err = c.Call("SET", pool, "foo", "bar")
	assert.Equal(t, nil, err)
	fooValue, err = c.Call("GET", pool, "foo")
	assert.Equal(t, nil, err)
	assert.Equal(t, "bar", string(fooValue.([]byte)))
}