Example #1
0
func newTestRouter() *Router {
	var s = `
schema :
  db : kingshard
  nodes: [node1,node2,node3,node4,node5,node6,node7,node8,node9,node10]
  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
    -
      table: test_shard_year
      key: date
      nodes: [node2, node3]
      date_range: [2012-2015,2016-2018]
      type: date_year
    -
      table: test_shard_month
      key: date
      type: date_month
      nodes: [node2, node3]
      date_range: [201512-201603,201604-201608]
    -
      table: test_shard_day
      key: date
      type: date_day
      nodes: [node2, node3]
      date_range: [20151201-20160122,20160202-20160308]
`

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

	var r *Router

	r, err = NewRouter(&cfg.Schema)
	if err != nil {
		println(err.Error())
		panic(err)
	}

	return r
}
Example #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
}
Example #3
0
func newTestDBRule() *Router {
	var s = `
schema :
  db : kingshard
  nodes: [node1,node2,node3,node4,node5,node6,node7,node8,node9,node10]
  default: node1
  shard:
    -
      table: test1
      key: id
      nodes: [node1,node2,node3]
      locations: [1,2,3]
      type: hash

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

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

	var r *Router

	r, err = NewRouter(&cfg.Schema)
	if err != nil {
		println(err.Error())
		panic(err)
	}

	return r
}