示例#1
0
func newTestRouter() *Router {
	var s = `
schemas :
-
  db : kingshard
  nodes: [node1,node2,node3,node4,node5,node6,node7,node8,node9,node10]
  rules:
    default: node1
    shard:
      -
        table: test1
        key: id
        nodes: [node1,node2,node3]
        locations: [4,4,4]
        type: hash

      -
        table: test2
        key: id
        type: range
        nodes: [node1,node2,node3]
        locations: [4,4,4]
        table_row_limit: 10000
`

	cfg, err := config.ParseConfigData([]byte(s))
	if err != nil {
		println(err.Error())
		panic(err)
	}

	var r *Router

	r, err = NewRouter(&cfg.Schemas[0])
	if err != nil {
		println(err.Error())
		panic(err)
	}

	return r
}
示例#2
0
func newTestServer(t *testing.T) *Server {
	f := func() {
		cfg, err := config.ParseConfigData(testConfigData)
		if err != nil {
			t.Fatal(err.Error())
		}

		testServer, err = NewServer(cfg)
		if err != nil {
			t.Fatal(err)
		}

		go testServer.Run()

		time.Sleep(1 * time.Second)
	}

	testServerOnce.Do(f)

	return testServer
}