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 }
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 - table: test3 key: recdate type: sep_range nodes: [node1,node2,node3] locations: [2,2,2] seps: [2015-01-01, 2015-02-01, 2015-03-01, 2015-04-01, 2015-05-01] key_type: string ` 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 }
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 }
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 }