Skip to content

Commit

Permalink
Revert "调整链路追踪的字段"
Browse files Browse the repository at this point in the history
This reverts commit 11f9841.
  • Loading branch information
steden committed Dec 26, 2023
1 parent 11f9841 commit b0f984e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internalContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (receiver *internalContext) Original() *elastic.Client {
func RegisterInternalContext(name string, configString string) {
config := configure.ParseString[EsConfig](configString)
if config.Server == "" {
panic("[farseer.yaml]ElasticSearch." + name + ".ConsumerServer,没有正确配置")
panic("[farseer.yaml]ElasticSearch." + name + ".Server,没有正确配置")
}
if config.RefreshInterval == 0 {
config.RefreshInterval = 1
Expand Down
4 changes: 2 additions & 2 deletions test/esContext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type UserPO struct {

func TestNewContext(t *testing.T) {
// 设置配置默认值,模拟配置文件
configure.SetDefault("ElasticSearch.test", "ConsumerServer=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.test", "Server=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("test")
context.User.SetIndexName("user_index_01", "user_index_alis_01")
assert.Equal(t, "user_index_01", context.User.GetIndexName())
Expand All @@ -50,7 +50,7 @@ func TestInitContext(t *testing.T) {
fmt.Printf("%d-%02d-%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second)
flog.Println(year, month, day, hour, minute, second)
// 设置配置默认值,模拟配置文件
configure.SetDefault("ElasticSearch.test", "ConsumerServer=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.test", "Server=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")

var context TestEsContext
elasticSearch.InitContext(&context, "test")
Expand Down
30 changes: 15 additions & 15 deletions test/indexSet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func TestIndexSet_Init(t *testing.T) {
}

func TestIndexSet_Insert(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
po := UserPO{Name: "小强", Age: 10, Id: 12}
err := context.User.Insert(po)
assert.Equal(t, err, nil)
}

func TestIndexSet_InsertArray(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
var array []UserPO
po := UserPO{Name: "小强2", Age: 10, Id: 13}
Expand All @@ -60,15 +60,15 @@ func TestIndexSet_InsertArray(t *testing.T) {
}

func TestIndexSet_InsertList(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
list := collections.NewList(UserPO{Name: "小丽", Age: 20, Id: 2}, UserPO{Name: "小王", Age: 30, Id: 3})
err := context.User.InsertList(list)
assert.Equal(t, err, nil)
}

func TestIndexSet_Select(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
context.User.SetIndexName("user_select_index_01", "user_select_alis_index_01")
list := collections.NewList(UserPO{Name: "小丽", Age: 20, Id: 2}, UserPO{Name: "小王", Age: 30, Id: 3})
Expand All @@ -80,35 +80,35 @@ func TestIndexSet_Select(t *testing.T) {
}
}
func TestIndexSet_Asc(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
getList := context.User.Asc("Id").ToList()
assert.Equal(t, getList.First().Name, "小丽")
}

func TestIndexSet_Desc(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
list := context.User.Desc("Id").ToList()
assert.Equal(t, list.First().Name, "小王")
}

func TestIndexSet_GetIndexName(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
name := context.User.GetIndexName()
assert.Equal(t, name, context.User.GetIndexName())
}

func TestIndexSet_ToList(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
list := context.User.ToList()
assert.Equal(t, list.Count(), 5)
}

func TestIndexSet_ToPageList(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
context.User.SetIndexName("user_page_index_01", "user_page_alis_index_01")
list := collections.NewList(UserPO{Name: "小丽", Age: 20, Id: 2}, UserPO{Name: "小王", Age: 30, Id: 3}, UserPO{Name: "小王2", Age: 30, Id: 3})
Expand All @@ -118,15 +118,15 @@ func TestIndexSet_ToPageList(t *testing.T) {
}

func TestIndexSet_Where(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
po := UserPO{Name: "小王", Age: 30, Id: 14}
_ = context.User.Insert(po)
list2 := context.User.Where("Age", "30").Where("Id", 14).ToList()
assert.Equal(t, list2.First().Name, "小王")
}
func TestIndexSet_DelIndex(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
context.User.SetIndexName("user_111", "user_alis_111")
po := UserPO{Name: "小强", Age: 10, Id: 12}
Expand All @@ -135,15 +135,15 @@ func TestIndexSet_DelIndex(t *testing.T) {
assert.Equal(t, err, nil)
}
func TestIndexSet_DelData(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
po := UserPO{Name: "小强", Age: 10, Id: 888}
_ = context.User.Insert(po)
err := context.User.Delete("888")
assert.Equal(t, err, nil)
}
func TestIndexSet_SetAliasesName(t *testing.T) {
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
context := elasticSearch.NewContext[TestEsContext]("log_es")
context.User.SetIndexName("test_11", "test_alis_11")
_ = context.User.SetAliasesName("test_alis_22")
Expand All @@ -152,9 +152,9 @@ func TestIndexSet_SetAliasesName(t *testing.T) {
assert.Equal(t, err, nil)
}
func TestIndexSet_Data(t *testing.T) {
//configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
//configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
//context := elasticSearch.NewContext[TestEsContext]("log_es")
//context.User.esContext.esConfig.ConsumerServer = "0.0.0.0"
//context.User.esContext.esConfig.Server = "0.0.0.0"
//assert.Panics(t, func() {
// _ = context.User.SetAliasesName("test_alis_223")
//})
Expand Down
2 changes: 1 addition & 1 deletion test/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (

func init() {
// 设置配置默认值,模拟配置文件
configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM")
fs.Initialize[elasticSearch.Module]("test es")
}

0 comments on commit b0f984e

Please sign in to comment.