From dc18f7cadb7408977c22092faaa60a114d273503 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Thu, 1 Jul 2021 23:56:38 +0800 Subject: [PATCH 01/13] add more test case --- .../dubbogo/simple/body/test/pixiu_test.go | 36 ++- .../simple/mix/docker/docker-compose.yml | 27 ++ .../simple/mix/{ => pixiu}/api_config.yaml | 0 .../dubbogo/simple/mix/{ => pixiu}/conf.yaml | 0 .../dubbogo/simple/mix/server/app/server.go | 74 +++++ samples/dubbogo/simple/mix/server/app/user.go | 270 ++++++++++++++++++ .../dubbogo/simple/mix/server/app/version.go | 21 ++ .../simple/mix/server/profiles/dev/log.yml | 45 +++ .../simple/mix/server/profiles/dev/server.yml | 73 +++++ .../mix/server/profiles/release/log.yml | 45 +++ .../mix/server/profiles/release/server.yml | 77 +++++ .../simple/mix/server/profiles/test/log.yml | 45 +++ .../mix/server/profiles/test/server.yml | 76 +++++ samples/dubbogo/simple/mix/test/pixiu_test.go | 66 +++++ .../simple/proxy/docker/docker-compose.yml | 27 ++ .../simple/proxy/{ => pixiu}/api_config.yaml | 0 .../simple/proxy/{ => pixiu}/conf.yaml | 0 .../dubbogo/simple/proxy/server/app/server.go | 74 +++++ .../dubbogo/simple/proxy/server/app/user.go | 270 ++++++++++++++++++ .../simple/proxy/server/app/version.go | 21 ++ .../simple/proxy/server/profiles/dev/log.yml | 45 +++ .../proxy/server/profiles/dev/server.yml | 73 +++++ .../proxy/server/profiles/release/log.yml | 45 +++ .../proxy/server/profiles/release/server.yml | 77 +++++ .../simple/proxy/server/profiles/test/log.yml | 45 +++ .../proxy/server/profiles/test/server.yml | 76 +++++ .../dubbogo/simple/proxy/test/pixiu_test.go | 68 +++++ .../simple/query/docker/docker-compose.yml | 27 ++ .../simple/query/{ => pixiu}/api_config.yaml | 0 .../simple/query/{ => pixiu}/conf.yaml | 0 .../dubbogo/simple/query/server/app/server.go | 74 +++++ .../dubbogo/simple/query/server/app/user.go | 270 ++++++++++++++++++ .../simple/query/server/app/version.go | 21 ++ .../simple/query/server/profiles/dev/log.yml | 45 +++ .../query/server/profiles/dev/server.yml | 73 +++++ .../query/server/profiles/release/log.yml | 45 +++ .../query/server/profiles/release/server.yml | 77 +++++ .../simple/query/server/profiles/test/log.yml | 45 +++ .../query/server/profiles/test/server.yml | 76 +++++ .../dubbogo/simple/query/test/pixiu_test.go | 61 ++++ .../simple/uri/docker/docker-compose.yml | 27 ++ .../dubbogo/simple/uri/pixiu/api_config.yaml | 98 +++++++ samples/dubbogo/simple/uri/pixiu/conf.yaml | 47 +++ .../dubbogo/simple/uri/server/app/server.go | 74 +++++ samples/dubbogo/simple/uri/server/app/user.go | 270 ++++++++++++++++++ .../dubbogo/simple/uri/server/app/version.go | 21 ++ .../simple/uri/server/profiles/dev/log.yml | 45 +++ .../simple/uri/server/profiles/dev/server.yml | 73 +++++ .../uri/server/profiles/release/log.yml | 45 +++ .../uri/server/profiles/release/server.yml | 77 +++++ .../simple/uri/server/profiles/test/log.yml | 45 +++ .../uri/server/profiles/test/server.yml | 76 +++++ samples/dubbogo/simple/uri/test/pixiu_test.go | 61 ++++ 53 files changed, 3445 insertions(+), 4 deletions(-) create mode 100644 samples/dubbogo/simple/mix/docker/docker-compose.yml rename samples/dubbogo/simple/mix/{ => pixiu}/api_config.yaml (100%) rename samples/dubbogo/simple/mix/{ => pixiu}/conf.yaml (100%) create mode 100644 samples/dubbogo/simple/mix/server/app/server.go create mode 100644 samples/dubbogo/simple/mix/server/app/user.go create mode 100644 samples/dubbogo/simple/mix/server/app/version.go create mode 100644 samples/dubbogo/simple/mix/server/profiles/dev/log.yml create mode 100644 samples/dubbogo/simple/mix/server/profiles/dev/server.yml create mode 100644 samples/dubbogo/simple/mix/server/profiles/release/log.yml create mode 100644 samples/dubbogo/simple/mix/server/profiles/release/server.yml create mode 100644 samples/dubbogo/simple/mix/server/profiles/test/log.yml create mode 100644 samples/dubbogo/simple/mix/server/profiles/test/server.yml create mode 100644 samples/dubbogo/simple/mix/test/pixiu_test.go create mode 100644 samples/dubbogo/simple/proxy/docker/docker-compose.yml rename samples/dubbogo/simple/proxy/{ => pixiu}/api_config.yaml (100%) rename samples/dubbogo/simple/proxy/{ => pixiu}/conf.yaml (100%) create mode 100644 samples/dubbogo/simple/proxy/server/app/server.go create mode 100644 samples/dubbogo/simple/proxy/server/app/user.go create mode 100644 samples/dubbogo/simple/proxy/server/app/version.go create mode 100644 samples/dubbogo/simple/proxy/server/profiles/dev/log.yml create mode 100644 samples/dubbogo/simple/proxy/server/profiles/dev/server.yml create mode 100644 samples/dubbogo/simple/proxy/server/profiles/release/log.yml create mode 100644 samples/dubbogo/simple/proxy/server/profiles/release/server.yml create mode 100644 samples/dubbogo/simple/proxy/server/profiles/test/log.yml create mode 100644 samples/dubbogo/simple/proxy/server/profiles/test/server.yml create mode 100644 samples/dubbogo/simple/proxy/test/pixiu_test.go create mode 100644 samples/dubbogo/simple/query/docker/docker-compose.yml rename samples/dubbogo/simple/query/{ => pixiu}/api_config.yaml (100%) rename samples/dubbogo/simple/query/{ => pixiu}/conf.yaml (100%) create mode 100644 samples/dubbogo/simple/query/server/app/server.go create mode 100644 samples/dubbogo/simple/query/server/app/user.go create mode 100644 samples/dubbogo/simple/query/server/app/version.go create mode 100644 samples/dubbogo/simple/query/server/profiles/dev/log.yml create mode 100644 samples/dubbogo/simple/query/server/profiles/dev/server.yml create mode 100644 samples/dubbogo/simple/query/server/profiles/release/log.yml create mode 100644 samples/dubbogo/simple/query/server/profiles/release/server.yml create mode 100644 samples/dubbogo/simple/query/server/profiles/test/log.yml create mode 100644 samples/dubbogo/simple/query/server/profiles/test/server.yml create mode 100644 samples/dubbogo/simple/query/test/pixiu_test.go create mode 100644 samples/dubbogo/simple/uri/docker/docker-compose.yml create mode 100644 samples/dubbogo/simple/uri/pixiu/api_config.yaml create mode 100644 samples/dubbogo/simple/uri/pixiu/conf.yaml create mode 100644 samples/dubbogo/simple/uri/server/app/server.go create mode 100644 samples/dubbogo/simple/uri/server/app/user.go create mode 100644 samples/dubbogo/simple/uri/server/app/version.go create mode 100644 samples/dubbogo/simple/uri/server/profiles/dev/log.yml create mode 100644 samples/dubbogo/simple/uri/server/profiles/dev/server.yml create mode 100644 samples/dubbogo/simple/uri/server/profiles/release/log.yml create mode 100644 samples/dubbogo/simple/uri/server/profiles/release/server.yml create mode 100644 samples/dubbogo/simple/uri/server/profiles/test/log.yml create mode 100644 samples/dubbogo/simple/uri/server/profiles/test/server.yml create mode 100644 samples/dubbogo/simple/uri/test/pixiu_test.go diff --git a/samples/dubbogo/simple/body/test/pixiu_test.go b/samples/dubbogo/simple/body/test/pixiu_test.go index 67469faaf..2b4475dbf 100644 --- a/samples/dubbogo/simple/body/test/pixiu_test.go +++ b/samples/dubbogo/simple/body/test/pixiu_test.go @@ -18,8 +18,8 @@ package test import ( - "bytes" "net/http" + "strings" "testing" "time" ) @@ -29,11 +29,39 @@ import ( ) func TestPost(t *testing.T) { - var url = "http://localhost:8881/api/v1/test-dubbo/user" + url := "http://localhost:8881/api/v1/test-dubbo/user" data := "{\"id\":\"0003\",\"code\":3,\"name\":\"dubbogo\",\"age\":99}" - contentType := "application/json" client := &http.Client{Timeout: 5 * time.Second} - resp, err := client.Post(url, contentType, bytes.NewBufferString(data)) + req, err := http.NewRequest("POST", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestPut1(t *testing.T) { + url := "http://localhost:8881/api/v1/test-dubbo/user" + data := "{\"id\":\"0003\",\"code\":3,\"name\":\"dubbogo\",\"age\":77}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("PUT", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestPut2(t *testing.T) { + url := "http://localhost:8881/api/v1/test-dubbo/user2" + data := "{\"name\":\"dubbogo\",\"user\":{\"id\":\"0003\",\"code\":3,\"name\":\"dubbogo\",\"age\":88}}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("PUT", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) assert.NoError(t, err) assert.NotNil(t, resp) assert.Equal(t, 200, resp.StatusCode) diff --git a/samples/dubbogo/simple/mix/docker/docker-compose.yml b/samples/dubbogo/simple/mix/docker/docker-compose.yml new file mode 100644 index 000000000..7ca8ee583 --- /dev/null +++ b/samples/dubbogo/simple/mix/docker/docker-compose.yml @@ -0,0 +1,27 @@ +# +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +version: '3' + +services: + zookeeper: + image: zookeeper + ports: + - 2181:2181 + restart: on-failure diff --git a/samples/dubbogo/simple/mix/api_config.yaml b/samples/dubbogo/simple/mix/pixiu/api_config.yaml similarity index 100% rename from samples/dubbogo/simple/mix/api_config.yaml rename to samples/dubbogo/simple/mix/pixiu/api_config.yaml diff --git a/samples/dubbogo/simple/mix/conf.yaml b/samples/dubbogo/simple/mix/pixiu/conf.yaml similarity index 100% rename from samples/dubbogo/simple/mix/conf.yaml rename to samples/dubbogo/simple/mix/pixiu/conf.yaml diff --git a/samples/dubbogo/simple/mix/server/app/server.go b/samples/dubbogo/simple/mix/server/app/server.go new file mode 100644 index 000000000..87ab7628f --- /dev/null +++ b/samples/dubbogo/simple/mix/server/app/server.go @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + _ "github.com/apache/dubbo-go/filter/filter_impl" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var survivalTimeout = int(3e9) + +// they are necessary: +// export CONF_PROVIDER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" +func main() { + config.Load() + logger.Info("dubbo version is: %s", Version) + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} diff --git a/samples/dubbogo/simple/mix/server/app/user.go b/samples/dubbogo/simple/mix/server/app/user.go new file mode 100644 index 000000000..e0f2b7da5 --- /dev/null +++ b/samples/dubbogo/simple/mix/server/app/user.go @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "errors" + "fmt" + "sync" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" +) + +func init() { + config.SetProviderService(new(UserProvider)) + // ------for hessian2------ + hessian.RegisterPOJO(&User{}) + + cache = &UserDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } + + cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) + cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) +} + +var cache *UserDB + +// UserDB cache user. +type UserDB struct { + // key is name, value is user obj + nameIndex map[string]*User + // key is code, value is user obj + codeIndex map[int64]*User + lock sync.Mutex +} + +// nolint +func (db *UserDB) Add(u *User) bool { + db.lock.Lock() + defer db.lock.Unlock() + + if u.Name == "" || u.Code <= 0 { + return false + } + + if !db.existName(u.Name) && !db.existCode(u.Code) { + return db.AddForName(u) && db.AddForCode(u) + } + + return false +} + +// nolint +func (db *UserDB) AddForName(u *User) bool { + if len(u.Name) == 0 { + return false + } + + if _, ok := db.nameIndex[u.Name]; ok { + return false + } + + db.nameIndex[u.Name] = u + return true +} + +// nolint +func (db *UserDB) AddForCode(u *User) bool { + if u.Code <= 0 { + return false + } + + if _, ok := db.codeIndex[u.Code]; ok { + return false + } + + db.codeIndex[u.Code] = u + return true +} + +// nolint +func (db *UserDB) GetByName(n string) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.nameIndex[n] + return r, ok +} + +// nolint +func (db *UserDB) GetByCode(n int64) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.codeIndex[n] + return r, ok +} + +func (db *UserDB) existName(name string) bool { + if len(name) <= 0 { + return false + } + + _, ok := db.nameIndex[name] + if ok { + return true + } + + return false +} + +func (db *UserDB) existCode(code int64) bool { + if code <= 0 { + return false + } + + _, ok := db.codeIndex[code] + if ok { + return true + } + + return false +} + +// User user obj. +type User struct { + ID string `json:"id,omitempty"` + Code int64 `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Age int32 `json:"age,omitempty"` + Time time.Time `json:"time,omitempty"` +} + +// UserProvider the dubbo provider. +// like: version: 1.0.0 group: test +type UserProvider struct{} + +// CreateUser new user, PX config POST. +func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) { + outLn("Req CreateUser data:%#v", user) + if user == nil { + return nil, errors.New("not found") + } + _, ok := cache.GetByName(user.Name) + if ok { + return nil, errors.New("data is exist") + } + + b := cache.Add(user) + if b { + return user, nil + } + + return nil, errors.New("add error") +} + +// GetUserByName query by name, single param, PX config GET. +func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByCode query by code, single param, PX config GET. +func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) { + outLn("Req GetUserByCode name:%#v", code) + r, ok := cache.GetByCode(code) + if ok { + outLn("Req GetUserByCode result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserTimeout query by name, will timeout for pixiu. +func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + // sleep 10s, pixiu config less than 10s. + time.Sleep(10 * time.Second) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByNameAndAge query by name and age, two params, PX config GET. +func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) { + outLn("Req GetUserByNameAndAge name:%s, age:%d", name, age) + r, ok := cache.GetByName(name) + if ok && r.Age == age { + outLn("Req GetUserByNameAndAge result:%#v", r) + return r, nil + } + return r, nil +} + +// UpdateUser update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) { + outLn("Req UpdateUser data:%#v", user) + r, ok := cache.GetByName(user.Name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// UpdateUserByName update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUserByName(ctx context.Context, name string, user *User) (bool, error) { + outLn("Req UpdateUserByName data:%#v", user) + r, ok := cache.GetByName(name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// nolint +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +// nolint +func (u User) JavaClassName() string { + return "com.dubbogo.pixiu.User" +} + +// nolint +func outLn(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/samples/dubbogo/simple/mix/server/app/version.go b/samples/dubbogo/simple/mix/server/app/version.go new file mode 100644 index 000000000..04a3f7801 --- /dev/null +++ b/samples/dubbogo/simple/mix/server/app/version.go @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +// Version dubbo version +const Version = "2.7.5" diff --git a/samples/dubbogo/simple/mix/server/profiles/dev/log.yml b/samples/dubbogo/simple/mix/server/profiles/dev/log.yml new file mode 100644 index 000000000..9330cda17 --- /dev/null +++ b/samples/dubbogo/simple/mix/server/profiles/dev/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/mix/server/profiles/dev/server.yml b/samples/dubbogo/simple/mix/server/profiles/dev/server.yml new file mode 100644 index 000000000..66d8f949c --- /dev/null +++ b/samples/dubbogo/simple/mix/server/profiles/dev/server.yml @@ -0,0 +1,73 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "dev" + +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + +services: + "UserProvider": + registry: "demoZk" + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.pixiu.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + group: test + version: 1.0.0 + methods: + - name: "CreateUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + port: 20000 + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/mix/server/profiles/release/log.yml b/samples/dubbogo/simple/mix/server/profiles/release/log.yml new file mode 100644 index 000000000..e2835d8f2 --- /dev/null +++ b/samples/dubbogo/simple/mix/server/profiles/release/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/mix/server/profiles/release/server.yml b/samples/dubbogo/simple/mix/server/profiles/release/server.yml new file mode 100644 index 000000000..e4ebf01d1 --- /dev/null +++ b/samples/dubbogo/simple/mix/server/profiles/release/server.yml @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "release" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/mix/server/profiles/test/log.yml b/samples/dubbogo/simple/mix/server/profiles/test/log.yml new file mode 100644 index 000000000..26d0a76ea --- /dev/null +++ b/samples/dubbogo/simple/mix/server/profiles/test/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/mix/server/profiles/test/server.yml b/samples/dubbogo/simple/mix/server/profiles/test/server.yml new file mode 100644 index 000000000..cba0212be --- /dev/null +++ b/samples/dubbogo/simple/mix/server/profiles/test/server.yml @@ -0,0 +1,76 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "test" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/mix/test/pixiu_test.go b/samples/dubbogo/simple/mix/test/pixiu_test.go new file mode 100644 index 000000000..f2288ce30 --- /dev/null +++ b/samples/dubbogo/simple/mix/test/pixiu_test.go @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test + +import ( + "net/http" + "strings" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGet(t *testing.T) { + url := "http://localhost:8882/api/v1/test-dubbo/user/tc?age=99" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestPut1(t *testing.T) { + url := "http://localhost:8882/api/v1/test-dubbo/user/tc" + data := "{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":66}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("PUT", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestPut2(t *testing.T) { + url := "http://localhost:8882/api/v1/test-dubbo/user?name=tc" + data := "{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":55}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("PUT", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} diff --git a/samples/dubbogo/simple/proxy/docker/docker-compose.yml b/samples/dubbogo/simple/proxy/docker/docker-compose.yml new file mode 100644 index 000000000..7ca8ee583 --- /dev/null +++ b/samples/dubbogo/simple/proxy/docker/docker-compose.yml @@ -0,0 +1,27 @@ +# +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +version: '3' + +services: + zookeeper: + image: zookeeper + ports: + - 2181:2181 + restart: on-failure diff --git a/samples/dubbogo/simple/proxy/api_config.yaml b/samples/dubbogo/simple/proxy/pixiu/api_config.yaml similarity index 100% rename from samples/dubbogo/simple/proxy/api_config.yaml rename to samples/dubbogo/simple/proxy/pixiu/api_config.yaml diff --git a/samples/dubbogo/simple/proxy/conf.yaml b/samples/dubbogo/simple/proxy/pixiu/conf.yaml similarity index 100% rename from samples/dubbogo/simple/proxy/conf.yaml rename to samples/dubbogo/simple/proxy/pixiu/conf.yaml diff --git a/samples/dubbogo/simple/proxy/server/app/server.go b/samples/dubbogo/simple/proxy/server/app/server.go new file mode 100644 index 000000000..87ab7628f --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/app/server.go @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + _ "github.com/apache/dubbo-go/filter/filter_impl" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var survivalTimeout = int(3e9) + +// they are necessary: +// export CONF_PROVIDER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" +func main() { + config.Load() + logger.Info("dubbo version is: %s", Version) + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} diff --git a/samples/dubbogo/simple/proxy/server/app/user.go b/samples/dubbogo/simple/proxy/server/app/user.go new file mode 100644 index 000000000..e0f2b7da5 --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/app/user.go @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "errors" + "fmt" + "sync" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" +) + +func init() { + config.SetProviderService(new(UserProvider)) + // ------for hessian2------ + hessian.RegisterPOJO(&User{}) + + cache = &UserDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } + + cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) + cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) +} + +var cache *UserDB + +// UserDB cache user. +type UserDB struct { + // key is name, value is user obj + nameIndex map[string]*User + // key is code, value is user obj + codeIndex map[int64]*User + lock sync.Mutex +} + +// nolint +func (db *UserDB) Add(u *User) bool { + db.lock.Lock() + defer db.lock.Unlock() + + if u.Name == "" || u.Code <= 0 { + return false + } + + if !db.existName(u.Name) && !db.existCode(u.Code) { + return db.AddForName(u) && db.AddForCode(u) + } + + return false +} + +// nolint +func (db *UserDB) AddForName(u *User) bool { + if len(u.Name) == 0 { + return false + } + + if _, ok := db.nameIndex[u.Name]; ok { + return false + } + + db.nameIndex[u.Name] = u + return true +} + +// nolint +func (db *UserDB) AddForCode(u *User) bool { + if u.Code <= 0 { + return false + } + + if _, ok := db.codeIndex[u.Code]; ok { + return false + } + + db.codeIndex[u.Code] = u + return true +} + +// nolint +func (db *UserDB) GetByName(n string) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.nameIndex[n] + return r, ok +} + +// nolint +func (db *UserDB) GetByCode(n int64) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.codeIndex[n] + return r, ok +} + +func (db *UserDB) existName(name string) bool { + if len(name) <= 0 { + return false + } + + _, ok := db.nameIndex[name] + if ok { + return true + } + + return false +} + +func (db *UserDB) existCode(code int64) bool { + if code <= 0 { + return false + } + + _, ok := db.codeIndex[code] + if ok { + return true + } + + return false +} + +// User user obj. +type User struct { + ID string `json:"id,omitempty"` + Code int64 `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Age int32 `json:"age,omitempty"` + Time time.Time `json:"time,omitempty"` +} + +// UserProvider the dubbo provider. +// like: version: 1.0.0 group: test +type UserProvider struct{} + +// CreateUser new user, PX config POST. +func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) { + outLn("Req CreateUser data:%#v", user) + if user == nil { + return nil, errors.New("not found") + } + _, ok := cache.GetByName(user.Name) + if ok { + return nil, errors.New("data is exist") + } + + b := cache.Add(user) + if b { + return user, nil + } + + return nil, errors.New("add error") +} + +// GetUserByName query by name, single param, PX config GET. +func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByCode query by code, single param, PX config GET. +func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) { + outLn("Req GetUserByCode name:%#v", code) + r, ok := cache.GetByCode(code) + if ok { + outLn("Req GetUserByCode result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserTimeout query by name, will timeout for pixiu. +func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + // sleep 10s, pixiu config less than 10s. + time.Sleep(10 * time.Second) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByNameAndAge query by name and age, two params, PX config GET. +func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) { + outLn("Req GetUserByNameAndAge name:%s, age:%d", name, age) + r, ok := cache.GetByName(name) + if ok && r.Age == age { + outLn("Req GetUserByNameAndAge result:%#v", r) + return r, nil + } + return r, nil +} + +// UpdateUser update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) { + outLn("Req UpdateUser data:%#v", user) + r, ok := cache.GetByName(user.Name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// UpdateUserByName update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUserByName(ctx context.Context, name string, user *User) (bool, error) { + outLn("Req UpdateUserByName data:%#v", user) + r, ok := cache.GetByName(name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// nolint +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +// nolint +func (u User) JavaClassName() string { + return "com.dubbogo.pixiu.User" +} + +// nolint +func outLn(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/samples/dubbogo/simple/proxy/server/app/version.go b/samples/dubbogo/simple/proxy/server/app/version.go new file mode 100644 index 000000000..04a3f7801 --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/app/version.go @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +// Version dubbo version +const Version = "2.7.5" diff --git a/samples/dubbogo/simple/proxy/server/profiles/dev/log.yml b/samples/dubbogo/simple/proxy/server/profiles/dev/log.yml new file mode 100644 index 000000000..9330cda17 --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/profiles/dev/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/proxy/server/profiles/dev/server.yml b/samples/dubbogo/simple/proxy/server/profiles/dev/server.yml new file mode 100644 index 000000000..66d8f949c --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/profiles/dev/server.yml @@ -0,0 +1,73 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "dev" + +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + +services: + "UserProvider": + registry: "demoZk" + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.pixiu.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + group: test + version: 1.0.0 + methods: + - name: "CreateUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + port: 20000 + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/proxy/server/profiles/release/log.yml b/samples/dubbogo/simple/proxy/server/profiles/release/log.yml new file mode 100644 index 000000000..e2835d8f2 --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/profiles/release/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/proxy/server/profiles/release/server.yml b/samples/dubbogo/simple/proxy/server/profiles/release/server.yml new file mode 100644 index 000000000..e4ebf01d1 --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/profiles/release/server.yml @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "release" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/proxy/server/profiles/test/log.yml b/samples/dubbogo/simple/proxy/server/profiles/test/log.yml new file mode 100644 index 000000000..26d0a76ea --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/profiles/test/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/proxy/server/profiles/test/server.yml b/samples/dubbogo/simple/proxy/server/profiles/test/server.yml new file mode 100644 index 000000000..cba0212be --- /dev/null +++ b/samples/dubbogo/simple/proxy/server/profiles/test/server.yml @@ -0,0 +1,76 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "test" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/proxy/test/pixiu_test.go b/samples/dubbogo/simple/proxy/test/pixiu_test.go new file mode 100644 index 000000000..a31338b2f --- /dev/null +++ b/samples/dubbogo/simple/proxy/test/pixiu_test.go @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test + +import ( + "net/http" + "strings" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestPost1(t *testing.T) { + url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByName" + data := "{\"types\":[\"string\"],\"values\":\"tc\"}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("POST", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestPost2(t *testing.T) { + url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=UpdateUserByName" + data := "{\"types\":[\"string\",\"body\"],\"values\":[\"tc\",{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":15}]}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("POST", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestPost3(t *testing.T) { + url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByCode" + data := "{\"types\":[\"int\"],\"values\":1}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("POST", url, strings.NewReader(data)) + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} diff --git a/samples/dubbogo/simple/query/docker/docker-compose.yml b/samples/dubbogo/simple/query/docker/docker-compose.yml new file mode 100644 index 000000000..7ca8ee583 --- /dev/null +++ b/samples/dubbogo/simple/query/docker/docker-compose.yml @@ -0,0 +1,27 @@ +# +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +version: '3' + +services: + zookeeper: + image: zookeeper + ports: + - 2181:2181 + restart: on-failure diff --git a/samples/dubbogo/simple/query/api_config.yaml b/samples/dubbogo/simple/query/pixiu/api_config.yaml similarity index 100% rename from samples/dubbogo/simple/query/api_config.yaml rename to samples/dubbogo/simple/query/pixiu/api_config.yaml diff --git a/samples/dubbogo/simple/query/conf.yaml b/samples/dubbogo/simple/query/pixiu/conf.yaml similarity index 100% rename from samples/dubbogo/simple/query/conf.yaml rename to samples/dubbogo/simple/query/pixiu/conf.yaml diff --git a/samples/dubbogo/simple/query/server/app/server.go b/samples/dubbogo/simple/query/server/app/server.go new file mode 100644 index 000000000..87ab7628f --- /dev/null +++ b/samples/dubbogo/simple/query/server/app/server.go @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + _ "github.com/apache/dubbo-go/filter/filter_impl" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var survivalTimeout = int(3e9) + +// they are necessary: +// export CONF_PROVIDER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" +func main() { + config.Load() + logger.Info("dubbo version is: %s", Version) + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} diff --git a/samples/dubbogo/simple/query/server/app/user.go b/samples/dubbogo/simple/query/server/app/user.go new file mode 100644 index 000000000..e0f2b7da5 --- /dev/null +++ b/samples/dubbogo/simple/query/server/app/user.go @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "errors" + "fmt" + "sync" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" +) + +func init() { + config.SetProviderService(new(UserProvider)) + // ------for hessian2------ + hessian.RegisterPOJO(&User{}) + + cache = &UserDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } + + cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) + cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) +} + +var cache *UserDB + +// UserDB cache user. +type UserDB struct { + // key is name, value is user obj + nameIndex map[string]*User + // key is code, value is user obj + codeIndex map[int64]*User + lock sync.Mutex +} + +// nolint +func (db *UserDB) Add(u *User) bool { + db.lock.Lock() + defer db.lock.Unlock() + + if u.Name == "" || u.Code <= 0 { + return false + } + + if !db.existName(u.Name) && !db.existCode(u.Code) { + return db.AddForName(u) && db.AddForCode(u) + } + + return false +} + +// nolint +func (db *UserDB) AddForName(u *User) bool { + if len(u.Name) == 0 { + return false + } + + if _, ok := db.nameIndex[u.Name]; ok { + return false + } + + db.nameIndex[u.Name] = u + return true +} + +// nolint +func (db *UserDB) AddForCode(u *User) bool { + if u.Code <= 0 { + return false + } + + if _, ok := db.codeIndex[u.Code]; ok { + return false + } + + db.codeIndex[u.Code] = u + return true +} + +// nolint +func (db *UserDB) GetByName(n string) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.nameIndex[n] + return r, ok +} + +// nolint +func (db *UserDB) GetByCode(n int64) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.codeIndex[n] + return r, ok +} + +func (db *UserDB) existName(name string) bool { + if len(name) <= 0 { + return false + } + + _, ok := db.nameIndex[name] + if ok { + return true + } + + return false +} + +func (db *UserDB) existCode(code int64) bool { + if code <= 0 { + return false + } + + _, ok := db.codeIndex[code] + if ok { + return true + } + + return false +} + +// User user obj. +type User struct { + ID string `json:"id,omitempty"` + Code int64 `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Age int32 `json:"age,omitempty"` + Time time.Time `json:"time,omitempty"` +} + +// UserProvider the dubbo provider. +// like: version: 1.0.0 group: test +type UserProvider struct{} + +// CreateUser new user, PX config POST. +func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) { + outLn("Req CreateUser data:%#v", user) + if user == nil { + return nil, errors.New("not found") + } + _, ok := cache.GetByName(user.Name) + if ok { + return nil, errors.New("data is exist") + } + + b := cache.Add(user) + if b { + return user, nil + } + + return nil, errors.New("add error") +} + +// GetUserByName query by name, single param, PX config GET. +func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByCode query by code, single param, PX config GET. +func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) { + outLn("Req GetUserByCode name:%#v", code) + r, ok := cache.GetByCode(code) + if ok { + outLn("Req GetUserByCode result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserTimeout query by name, will timeout for pixiu. +func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + // sleep 10s, pixiu config less than 10s. + time.Sleep(10 * time.Second) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByNameAndAge query by name and age, two params, PX config GET. +func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) { + outLn("Req GetUserByNameAndAge name:%s, age:%d", name, age) + r, ok := cache.GetByName(name) + if ok && r.Age == age { + outLn("Req GetUserByNameAndAge result:%#v", r) + return r, nil + } + return r, nil +} + +// UpdateUser update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) { + outLn("Req UpdateUser data:%#v", user) + r, ok := cache.GetByName(user.Name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// UpdateUserByName update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUserByName(ctx context.Context, name string, user *User) (bool, error) { + outLn("Req UpdateUserByName data:%#v", user) + r, ok := cache.GetByName(name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// nolint +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +// nolint +func (u User) JavaClassName() string { + return "com.dubbogo.pixiu.User" +} + +// nolint +func outLn(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/samples/dubbogo/simple/query/server/app/version.go b/samples/dubbogo/simple/query/server/app/version.go new file mode 100644 index 000000000..04a3f7801 --- /dev/null +++ b/samples/dubbogo/simple/query/server/app/version.go @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +// Version dubbo version +const Version = "2.7.5" diff --git a/samples/dubbogo/simple/query/server/profiles/dev/log.yml b/samples/dubbogo/simple/query/server/profiles/dev/log.yml new file mode 100644 index 000000000..9330cda17 --- /dev/null +++ b/samples/dubbogo/simple/query/server/profiles/dev/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/query/server/profiles/dev/server.yml b/samples/dubbogo/simple/query/server/profiles/dev/server.yml new file mode 100644 index 000000000..66d8f949c --- /dev/null +++ b/samples/dubbogo/simple/query/server/profiles/dev/server.yml @@ -0,0 +1,73 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "dev" + +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + +services: + "UserProvider": + registry: "demoZk" + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.pixiu.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + group: test + version: 1.0.0 + methods: + - name: "CreateUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + port: 20000 + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/query/server/profiles/release/log.yml b/samples/dubbogo/simple/query/server/profiles/release/log.yml new file mode 100644 index 000000000..e2835d8f2 --- /dev/null +++ b/samples/dubbogo/simple/query/server/profiles/release/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/query/server/profiles/release/server.yml b/samples/dubbogo/simple/query/server/profiles/release/server.yml new file mode 100644 index 000000000..e4ebf01d1 --- /dev/null +++ b/samples/dubbogo/simple/query/server/profiles/release/server.yml @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "release" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/query/server/profiles/test/log.yml b/samples/dubbogo/simple/query/server/profiles/test/log.yml new file mode 100644 index 000000000..26d0a76ea --- /dev/null +++ b/samples/dubbogo/simple/query/server/profiles/test/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/query/server/profiles/test/server.yml b/samples/dubbogo/simple/query/server/profiles/test/server.yml new file mode 100644 index 000000000..cba0212be --- /dev/null +++ b/samples/dubbogo/simple/query/server/profiles/test/server.yml @@ -0,0 +1,76 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "test" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/query/test/pixiu_test.go b/samples/dubbogo/simple/query/test/pixiu_test.go new file mode 100644 index 000000000..1a6d58f3b --- /dev/null +++ b/samples/dubbogo/simple/query/test/pixiu_test.go @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test + +import ( + "net/http" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGet1(t *testing.T) { + url := "http://localhost:8884/api/v1/test-dubbo/userByName?name=tc" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestGet2(t *testing.T) { + url := "http://localhost:8884/api/v1/test-dubbo/userByCode?code=1" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestGet3(t *testing.T) { + url := "http://localhost:8884/api/v1/test-dubbo/userByNameAndAge?name=tc&age=99" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} diff --git a/samples/dubbogo/simple/uri/docker/docker-compose.yml b/samples/dubbogo/simple/uri/docker/docker-compose.yml new file mode 100644 index 000000000..7ca8ee583 --- /dev/null +++ b/samples/dubbogo/simple/uri/docker/docker-compose.yml @@ -0,0 +1,27 @@ +# +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +version: '3' + +services: + zookeeper: + image: zookeeper + ports: + - 2181:2181 + restart: on-failure diff --git a/samples/dubbogo/simple/uri/pixiu/api_config.yaml b/samples/dubbogo/simple/uri/pixiu/api_config.yaml new file mode 100644 index 000000000..f1effb978 --- /dev/null +++ b/samples/dubbogo/simple/uri/pixiu/api_config.yaml @@ -0,0 +1,98 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +name: pixiu +description: pixiu sample +resources: + - path: '/api/v1/test-dubbo/user/name/:name' + type: restful + description: user + methods: + - httpVerb: GET + onAir: true + timeout: 1000ms + inboundRequest: + requestType: http + uri: + - name: name + required: true + integrationRequest: + requestType: dubbo + mappingParams: + - name: uri.name + mapTo: 0 + mapType: "string" + applicationName: "UserProvider" + interface: "com.dubbogo.pixiu.UserService" + method: "GetUserByName" + group: "test" + version: 1.0.0 + clusterName: "test_dubbo" + - path: '/api/v1/test-dubbo/user/code/:code' + type: restful + description: user + methods: + - httpVerb: GET + onAir: true + timeout: 1000ms + inboundRequest: + requestType: http + uri: + - name: code + required: true + integrationRequest: + requestType: dubbo + mappingParams: + - name: uri.code + mapTo: 0 + mapType: "int" + applicationName: "UserProvider" + interface: "com.dubbogo.pixiu.UserService" + method: "GetUserByCode" + group: "test" + version: 1.0.0 + clusterName: "test_dubbo" + - path: '/api/v1/test-dubbo/user/name/:name/age/:age' + type: restful + description: user + methods: + - httpVerb: GET + onAir: true + timeout: 1000ms + inboundRequest: + requestType: http + uri: + - name: name + required: true + - name: age + required: true + integrationRequest: + requestType: dubbo + mappingParams: + - name: uri.name + mapTo: 0 + mapType: "string" + - name: uri.age + mapTo: 1 + mapType: "int" + applicationName: "UserProvider" + interface: "com.dubbogo.pixiu.UserService" + method: "GetUserByNameAndAge" + group: "test" + version: 1.0.0 + clusterName: "test_dubbo" \ No newline at end of file diff --git a/samples/dubbogo/simple/uri/pixiu/conf.yaml b/samples/dubbogo/simple/uri/pixiu/conf.yaml new file mode 100644 index 000000000..af60e205d --- /dev/null +++ b/samples/dubbogo/simple/uri/pixiu/conf.yaml @@ -0,0 +1,47 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +--- +static_resources: + listeners: + - name: "net/http" + address: + socket_address: + protocol_type: "HTTP" + address: "0.0.0.0" + port: 8885 + config: + idle_timeout: 5s + read_timeout: 5s + write_timeout: 5s + clusters: + - name: "test_dubbo" + lb_policy: "RoundRobin" + registries: + "zookeeper": + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" + shutdown_config: + timeout: "60s" + step_timeout: "10s" + reject_policy: "immediacy" \ No newline at end of file diff --git a/samples/dubbogo/simple/uri/server/app/server.go b/samples/dubbogo/simple/uri/server/app/server.go new file mode 100644 index 000000000..87ab7628f --- /dev/null +++ b/samples/dubbogo/simple/uri/server/app/server.go @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + _ "github.com/apache/dubbo-go/filter/filter_impl" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var survivalTimeout = int(3e9) + +// they are necessary: +// export CONF_PROVIDER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" +func main() { + config.Load() + logger.Info("dubbo version is: %s", Version) + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} diff --git a/samples/dubbogo/simple/uri/server/app/user.go b/samples/dubbogo/simple/uri/server/app/user.go new file mode 100644 index 000000000..e0f2b7da5 --- /dev/null +++ b/samples/dubbogo/simple/uri/server/app/user.go @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "context" + "errors" + "fmt" + "sync" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" +) + +func init() { + config.SetProviderService(new(UserProvider)) + // ------for hessian2------ + hessian.RegisterPOJO(&User{}) + + cache = &UserDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } + + cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) + cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) +} + +var cache *UserDB + +// UserDB cache user. +type UserDB struct { + // key is name, value is user obj + nameIndex map[string]*User + // key is code, value is user obj + codeIndex map[int64]*User + lock sync.Mutex +} + +// nolint +func (db *UserDB) Add(u *User) bool { + db.lock.Lock() + defer db.lock.Unlock() + + if u.Name == "" || u.Code <= 0 { + return false + } + + if !db.existName(u.Name) && !db.existCode(u.Code) { + return db.AddForName(u) && db.AddForCode(u) + } + + return false +} + +// nolint +func (db *UserDB) AddForName(u *User) bool { + if len(u.Name) == 0 { + return false + } + + if _, ok := db.nameIndex[u.Name]; ok { + return false + } + + db.nameIndex[u.Name] = u + return true +} + +// nolint +func (db *UserDB) AddForCode(u *User) bool { + if u.Code <= 0 { + return false + } + + if _, ok := db.codeIndex[u.Code]; ok { + return false + } + + db.codeIndex[u.Code] = u + return true +} + +// nolint +func (db *UserDB) GetByName(n string) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.nameIndex[n] + return r, ok +} + +// nolint +func (db *UserDB) GetByCode(n int64) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.codeIndex[n] + return r, ok +} + +func (db *UserDB) existName(name string) bool { + if len(name) <= 0 { + return false + } + + _, ok := db.nameIndex[name] + if ok { + return true + } + + return false +} + +func (db *UserDB) existCode(code int64) bool { + if code <= 0 { + return false + } + + _, ok := db.codeIndex[code] + if ok { + return true + } + + return false +} + +// User user obj. +type User struct { + ID string `json:"id,omitempty"` + Code int64 `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Age int32 `json:"age,omitempty"` + Time time.Time `json:"time,omitempty"` +} + +// UserProvider the dubbo provider. +// like: version: 1.0.0 group: test +type UserProvider struct{} + +// CreateUser new user, PX config POST. +func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) { + outLn("Req CreateUser data:%#v", user) + if user == nil { + return nil, errors.New("not found") + } + _, ok := cache.GetByName(user.Name) + if ok { + return nil, errors.New("data is exist") + } + + b := cache.Add(user) + if b { + return user, nil + } + + return nil, errors.New("add error") +} + +// GetUserByName query by name, single param, PX config GET. +func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByCode query by code, single param, PX config GET. +func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) { + outLn("Req GetUserByCode name:%#v", code) + r, ok := cache.GetByCode(code) + if ok { + outLn("Req GetUserByCode result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserTimeout query by name, will timeout for pixiu. +func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + // sleep 10s, pixiu config less than 10s. + time.Sleep(10 * time.Second) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByNameAndAge query by name and age, two params, PX config GET. +func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) { + outLn("Req GetUserByNameAndAge name:%s, age:%d", name, age) + r, ok := cache.GetByName(name) + if ok && r.Age == age { + outLn("Req GetUserByNameAndAge result:%#v", r) + return r, nil + } + return r, nil +} + +// UpdateUser update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) { + outLn("Req UpdateUser data:%#v", user) + r, ok := cache.GetByName(user.Name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// UpdateUserByName update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUserByName(ctx context.Context, name string, user *User) (bool, error) { + outLn("Req UpdateUserByName data:%#v", user) + r, ok := cache.GetByName(name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// nolint +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +// nolint +func (u User) JavaClassName() string { + return "com.dubbogo.pixiu.User" +} + +// nolint +func outLn(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/samples/dubbogo/simple/uri/server/app/version.go b/samples/dubbogo/simple/uri/server/app/version.go new file mode 100644 index 000000000..04a3f7801 --- /dev/null +++ b/samples/dubbogo/simple/uri/server/app/version.go @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +// Version dubbo version +const Version = "2.7.5" diff --git a/samples/dubbogo/simple/uri/server/profiles/dev/log.yml b/samples/dubbogo/simple/uri/server/profiles/dev/log.yml new file mode 100644 index 000000000..9330cda17 --- /dev/null +++ b/samples/dubbogo/simple/uri/server/profiles/dev/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/uri/server/profiles/dev/server.yml b/samples/dubbogo/simple/uri/server/profiles/dev/server.yml new file mode 100644 index 000000000..66d8f949c --- /dev/null +++ b/samples/dubbogo/simple/uri/server/profiles/dev/server.yml @@ -0,0 +1,73 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "dev" + +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + +services: + "UserProvider": + registry: "demoZk" + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.pixiu.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + group: test + version: 1.0.0 + methods: + - name: "CreateUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + port: 20000 + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/uri/server/profiles/release/log.yml b/samples/dubbogo/simple/uri/server/profiles/release/log.yml new file mode 100644 index 000000000..e2835d8f2 --- /dev/null +++ b/samples/dubbogo/simple/uri/server/profiles/release/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/uri/server/profiles/release/server.yml b/samples/dubbogo/simple/uri/server/profiles/release/server.yml new file mode 100644 index 000000000..e4ebf01d1 --- /dev/null +++ b/samples/dubbogo/simple/uri/server/profiles/release/server.yml @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "release" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/uri/server/profiles/test/log.yml b/samples/dubbogo/simple/uri/server/profiles/test/log.yml new file mode 100644 index 000000000..26d0a76ea --- /dev/null +++ b/samples/dubbogo/simple/uri/server/profiles/test/log.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/samples/dubbogo/simple/uri/server/profiles/test/server.yml b/samples/dubbogo/simple/uri/server/profiles/test/server.yml new file mode 100644 index 000000000..cba0212be --- /dev/null +++ b/samples/dubbogo/simple/uri/server/profiles/test/server.yml @@ -0,0 +1,76 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# dubbo server yaml configure file + + +# application config +application: + organization: "dubbogopixiu.com" + name: "BDTService" + module: "dubbogo user-info server" + version: "0.0.1" + owner: "ZX" + environment: "test" + +registries: + "hangzhouzk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +services: + "UserProvider": + protocol: "dubbo" + # Equivalent to the interface in the dubbo.xml file + interface: "com.dubbogo.UserService" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: + "dubbo": + name: "dubbo" + # ip : "127.0.0.1" + port: 20000 + + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "20s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" \ No newline at end of file diff --git a/samples/dubbogo/simple/uri/test/pixiu_test.go b/samples/dubbogo/simple/uri/test/pixiu_test.go new file mode 100644 index 000000000..162c1459b --- /dev/null +++ b/samples/dubbogo/simple/uri/test/pixiu_test.go @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test + +import ( + "net/http" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGet1(t *testing.T) { + url := "http://localhost:8885/api/v1/test-dubbo/user/name/tc" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestGet2(t *testing.T) { + url := "http://localhost:8885/api/v1/test-dubbo/user/code/1" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} + +func TestGet3(t *testing.T) { + url := "http://localhost:8885/api/v1/test-dubbo/user/name/tc/age/99" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("GET", url, nil) + assert.NoError(t, err) + resp, err := client.Do(req) + assert.NoError(t, err) + assert.NotNil(t, resp) + assert.Equal(t, 200, resp.StatusCode) +} From 52b5d09a7823e08415b9b0fe20a5d2f0213bd414 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Fri, 2 Jul 2021 10:27:57 +0800 Subject: [PATCH 02/13] add more test case --- start_integrate_test.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/start_integrate_test.sh b/start_integrate_test.sh index 625b65357..1283ede0a 100644 --- a/start_integrate_test.sh +++ b/start_integrate_test.sh @@ -15,11 +15,10 @@ # limitations under the License. array=("samples/dubbogo/simple/body") -#array+=("samples/dubbogo/simple/mix") -#array+=("samples/dubbogo/simple/proxy") -#array+=("samples/dubbogo/simple/query") -#array+=("samples/dubbogo/simple/server") -#array+=("samples/dubbogo/simple/uri") +array+=("samples/dubbogo/simple/mix") +array+=("samples/dubbogo/simple/proxy") +array+=("samples/dubbogo/simple/query") +array+=("samples/dubbogo/simple/uri") #http From c87220732f986c6e938fb68f6a87b5e4706bfe10 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Fri, 2 Jul 2021 13:13:49 +0800 Subject: [PATCH 03/13] add more test case --- samples/dubbogo/simple/proxy/test/pixiu_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/dubbogo/simple/proxy/test/pixiu_test.go b/samples/dubbogo/simple/proxy/test/pixiu_test.go index a31338b2f..dc8a2e10a 100644 --- a/samples/dubbogo/simple/proxy/test/pixiu_test.go +++ b/samples/dubbogo/simple/proxy/test/pixiu_test.go @@ -30,7 +30,7 @@ import ( func TestPost1(t *testing.T) { url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByName" - data := "{\"types\":[\"string\"],\"values\":\"tc\"}" + data := "{\"types\":\"string\",\"values\":\"tc\"}" client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("POST", url, strings.NewReader(data)) assert.NoError(t, err) @@ -43,7 +43,7 @@ func TestPost1(t *testing.T) { func TestPost2(t *testing.T) { url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=UpdateUserByName" - data := "{\"types\":[\"string\",\"body\"],\"values\":[\"tc\",{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":15}]}" + data := "{\"types\":\"string,body\",\"values\":[\"tc\",{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":15}]}" client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("POST", url, strings.NewReader(data)) assert.NoError(t, err) @@ -56,7 +56,7 @@ func TestPost2(t *testing.T) { func TestPost3(t *testing.T) { url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByCode" - data := "{\"types\":[\"int\"],\"values\":1}" + data := "{\"types\":\"int\",\"values\":1}" client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("POST", url, strings.NewReader(data)) assert.NoError(t, err) From 7ed70d49bf1810b5a820b2b63cc56e6a7966563d Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Fri, 2 Jul 2021 13:30:04 +0800 Subject: [PATCH 04/13] add more test case --- samples/dubbogo/simple/proxy/test/pixiu_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/dubbogo/simple/proxy/test/pixiu_test.go b/samples/dubbogo/simple/proxy/test/pixiu_test.go index dc8a2e10a..dfe00319e 100644 --- a/samples/dubbogo/simple/proxy/test/pixiu_test.go +++ b/samples/dubbogo/simple/proxy/test/pixiu_test.go @@ -43,7 +43,7 @@ func TestPost1(t *testing.T) { func TestPost2(t *testing.T) { url := "http://localhost:8883/api/v1/test-dubbo/UserService/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=UpdateUserByName" - data := "{\"types\":\"string,body\",\"values\":[\"tc\",{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":15}]}" + data := "{\"types\":\"string,object\",\"values\":[\"tc\",{\"id\":\"0001\",\"code\":1,\"name\":\"tc\",\"age\":15}]}" client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("POST", url, strings.NewReader(data)) assert.NoError(t, err) From fcfe255d541ce176d3ec47b529d595b347fd58b1 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Mon, 5 Jul 2021 08:48:04 +0800 Subject: [PATCH 05/13] add more test case --- .../dubbogo/simple/body/server/app/user.go | 35 +++++++++++-------- samples/dubbogo/simple/mix/server/app/user.go | 35 +++++++++++-------- .../dubbogo/simple/proxy/server/app/user.go | 35 +++++++++++-------- .../dubbogo/simple/query/server/app/user.go | 35 +++++++++++-------- samples/dubbogo/simple/uri/server/app/user.go | 35 +++++++++++-------- 5 files changed, 100 insertions(+), 75 deletions(-) diff --git a/samples/dubbogo/simple/body/server/app/user.go b/samples/dubbogo/simple/body/server/app/user.go index e0f2b7da5..01d3d2481 100644 --- a/samples/dubbogo/simple/body/server/app/user.go +++ b/samples/dubbogo/simple/body/server/app/user.go @@ -35,20 +35,16 @@ func init() { // ------for hessian2------ hessian.RegisterPOJO(&User{}) - cache = &UserDB{ - nameIndex: make(map[string]*User, 16), - codeIndex: make(map[int64]*User, 16), - lock: sync.Mutex{}, - } + cache = newUserDB() cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) } -var cache *UserDB +var cache *userDB -// UserDB cache user. -type UserDB struct { +// userDB cache user. +type userDB struct { // key is name, value is user obj nameIndex map[string]*User // key is code, value is user obj @@ -56,8 +52,17 @@ type UserDB struct { lock sync.Mutex } +// userDB create func +func newUserDB() *userDB { + return &userDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } +} + // nolint -func (db *UserDB) Add(u *User) bool { +func (db *userDB) Add(u *User) bool { db.lock.Lock() defer db.lock.Unlock() @@ -73,7 +78,7 @@ func (db *UserDB) Add(u *User) bool { } // nolint -func (db *UserDB) AddForName(u *User) bool { +func (db *userDB) AddForName(u *User) bool { if len(u.Name) == 0 { return false } @@ -87,7 +92,7 @@ func (db *UserDB) AddForName(u *User) bool { } // nolint -func (db *UserDB) AddForCode(u *User) bool { +func (db *userDB) AddForCode(u *User) bool { if u.Code <= 0 { return false } @@ -101,7 +106,7 @@ func (db *UserDB) AddForCode(u *User) bool { } // nolint -func (db *UserDB) GetByName(n string) (*User, bool) { +func (db *userDB) GetByName(n string) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -110,7 +115,7 @@ func (db *UserDB) GetByName(n string) (*User, bool) { } // nolint -func (db *UserDB) GetByCode(n int64) (*User, bool) { +func (db *userDB) GetByCode(n int64) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -118,7 +123,7 @@ func (db *UserDB) GetByCode(n int64) (*User, bool) { return r, ok } -func (db *UserDB) existName(name string) bool { +func (db *userDB) existName(name string) bool { if len(name) <= 0 { return false } @@ -131,7 +136,7 @@ func (db *UserDB) existName(name string) bool { return false } -func (db *UserDB) existCode(code int64) bool { +func (db *userDB) existCode(code int64) bool { if code <= 0 { return false } diff --git a/samples/dubbogo/simple/mix/server/app/user.go b/samples/dubbogo/simple/mix/server/app/user.go index e0f2b7da5..01d3d2481 100644 --- a/samples/dubbogo/simple/mix/server/app/user.go +++ b/samples/dubbogo/simple/mix/server/app/user.go @@ -35,20 +35,16 @@ func init() { // ------for hessian2------ hessian.RegisterPOJO(&User{}) - cache = &UserDB{ - nameIndex: make(map[string]*User, 16), - codeIndex: make(map[int64]*User, 16), - lock: sync.Mutex{}, - } + cache = newUserDB() cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) } -var cache *UserDB +var cache *userDB -// UserDB cache user. -type UserDB struct { +// userDB cache user. +type userDB struct { // key is name, value is user obj nameIndex map[string]*User // key is code, value is user obj @@ -56,8 +52,17 @@ type UserDB struct { lock sync.Mutex } +// userDB create func +func newUserDB() *userDB { + return &userDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } +} + // nolint -func (db *UserDB) Add(u *User) bool { +func (db *userDB) Add(u *User) bool { db.lock.Lock() defer db.lock.Unlock() @@ -73,7 +78,7 @@ func (db *UserDB) Add(u *User) bool { } // nolint -func (db *UserDB) AddForName(u *User) bool { +func (db *userDB) AddForName(u *User) bool { if len(u.Name) == 0 { return false } @@ -87,7 +92,7 @@ func (db *UserDB) AddForName(u *User) bool { } // nolint -func (db *UserDB) AddForCode(u *User) bool { +func (db *userDB) AddForCode(u *User) bool { if u.Code <= 0 { return false } @@ -101,7 +106,7 @@ func (db *UserDB) AddForCode(u *User) bool { } // nolint -func (db *UserDB) GetByName(n string) (*User, bool) { +func (db *userDB) GetByName(n string) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -110,7 +115,7 @@ func (db *UserDB) GetByName(n string) (*User, bool) { } // nolint -func (db *UserDB) GetByCode(n int64) (*User, bool) { +func (db *userDB) GetByCode(n int64) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -118,7 +123,7 @@ func (db *UserDB) GetByCode(n int64) (*User, bool) { return r, ok } -func (db *UserDB) existName(name string) bool { +func (db *userDB) existName(name string) bool { if len(name) <= 0 { return false } @@ -131,7 +136,7 @@ func (db *UserDB) existName(name string) bool { return false } -func (db *UserDB) existCode(code int64) bool { +func (db *userDB) existCode(code int64) bool { if code <= 0 { return false } diff --git a/samples/dubbogo/simple/proxy/server/app/user.go b/samples/dubbogo/simple/proxy/server/app/user.go index e0f2b7da5..01d3d2481 100644 --- a/samples/dubbogo/simple/proxy/server/app/user.go +++ b/samples/dubbogo/simple/proxy/server/app/user.go @@ -35,20 +35,16 @@ func init() { // ------for hessian2------ hessian.RegisterPOJO(&User{}) - cache = &UserDB{ - nameIndex: make(map[string]*User, 16), - codeIndex: make(map[int64]*User, 16), - lock: sync.Mutex{}, - } + cache = newUserDB() cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) } -var cache *UserDB +var cache *userDB -// UserDB cache user. -type UserDB struct { +// userDB cache user. +type userDB struct { // key is name, value is user obj nameIndex map[string]*User // key is code, value is user obj @@ -56,8 +52,17 @@ type UserDB struct { lock sync.Mutex } +// userDB create func +func newUserDB() *userDB { + return &userDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } +} + // nolint -func (db *UserDB) Add(u *User) bool { +func (db *userDB) Add(u *User) bool { db.lock.Lock() defer db.lock.Unlock() @@ -73,7 +78,7 @@ func (db *UserDB) Add(u *User) bool { } // nolint -func (db *UserDB) AddForName(u *User) bool { +func (db *userDB) AddForName(u *User) bool { if len(u.Name) == 0 { return false } @@ -87,7 +92,7 @@ func (db *UserDB) AddForName(u *User) bool { } // nolint -func (db *UserDB) AddForCode(u *User) bool { +func (db *userDB) AddForCode(u *User) bool { if u.Code <= 0 { return false } @@ -101,7 +106,7 @@ func (db *UserDB) AddForCode(u *User) bool { } // nolint -func (db *UserDB) GetByName(n string) (*User, bool) { +func (db *userDB) GetByName(n string) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -110,7 +115,7 @@ func (db *UserDB) GetByName(n string) (*User, bool) { } // nolint -func (db *UserDB) GetByCode(n int64) (*User, bool) { +func (db *userDB) GetByCode(n int64) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -118,7 +123,7 @@ func (db *UserDB) GetByCode(n int64) (*User, bool) { return r, ok } -func (db *UserDB) existName(name string) bool { +func (db *userDB) existName(name string) bool { if len(name) <= 0 { return false } @@ -131,7 +136,7 @@ func (db *UserDB) existName(name string) bool { return false } -func (db *UserDB) existCode(code int64) bool { +func (db *userDB) existCode(code int64) bool { if code <= 0 { return false } diff --git a/samples/dubbogo/simple/query/server/app/user.go b/samples/dubbogo/simple/query/server/app/user.go index e0f2b7da5..01d3d2481 100644 --- a/samples/dubbogo/simple/query/server/app/user.go +++ b/samples/dubbogo/simple/query/server/app/user.go @@ -35,20 +35,16 @@ func init() { // ------for hessian2------ hessian.RegisterPOJO(&User{}) - cache = &UserDB{ - nameIndex: make(map[string]*User, 16), - codeIndex: make(map[int64]*User, 16), - lock: sync.Mutex{}, - } + cache = newUserDB() cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) } -var cache *UserDB +var cache *userDB -// UserDB cache user. -type UserDB struct { +// userDB cache user. +type userDB struct { // key is name, value is user obj nameIndex map[string]*User // key is code, value is user obj @@ -56,8 +52,17 @@ type UserDB struct { lock sync.Mutex } +// userDB create func +func newUserDB() *userDB { + return &userDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } +} + // nolint -func (db *UserDB) Add(u *User) bool { +func (db *userDB) Add(u *User) bool { db.lock.Lock() defer db.lock.Unlock() @@ -73,7 +78,7 @@ func (db *UserDB) Add(u *User) bool { } // nolint -func (db *UserDB) AddForName(u *User) bool { +func (db *userDB) AddForName(u *User) bool { if len(u.Name) == 0 { return false } @@ -87,7 +92,7 @@ func (db *UserDB) AddForName(u *User) bool { } // nolint -func (db *UserDB) AddForCode(u *User) bool { +func (db *userDB) AddForCode(u *User) bool { if u.Code <= 0 { return false } @@ -101,7 +106,7 @@ func (db *UserDB) AddForCode(u *User) bool { } // nolint -func (db *UserDB) GetByName(n string) (*User, bool) { +func (db *userDB) GetByName(n string) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -110,7 +115,7 @@ func (db *UserDB) GetByName(n string) (*User, bool) { } // nolint -func (db *UserDB) GetByCode(n int64) (*User, bool) { +func (db *userDB) GetByCode(n int64) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -118,7 +123,7 @@ func (db *UserDB) GetByCode(n int64) (*User, bool) { return r, ok } -func (db *UserDB) existName(name string) bool { +func (db *userDB) existName(name string) bool { if len(name) <= 0 { return false } @@ -131,7 +136,7 @@ func (db *UserDB) existName(name string) bool { return false } -func (db *UserDB) existCode(code int64) bool { +func (db *userDB) existCode(code int64) bool { if code <= 0 { return false } diff --git a/samples/dubbogo/simple/uri/server/app/user.go b/samples/dubbogo/simple/uri/server/app/user.go index e0f2b7da5..01d3d2481 100644 --- a/samples/dubbogo/simple/uri/server/app/user.go +++ b/samples/dubbogo/simple/uri/server/app/user.go @@ -35,20 +35,16 @@ func init() { // ------for hessian2------ hessian.RegisterPOJO(&User{}) - cache = &UserDB{ - nameIndex: make(map[string]*User, 16), - codeIndex: make(map[int64]*User, 16), - lock: sync.Mutex{}, - } + cache = newUserDB() cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: time.Now()}) cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: time.Now()}) } -var cache *UserDB +var cache *userDB -// UserDB cache user. -type UserDB struct { +// userDB cache user. +type userDB struct { // key is name, value is user obj nameIndex map[string]*User // key is code, value is user obj @@ -56,8 +52,17 @@ type UserDB struct { lock sync.Mutex } +// userDB create func +func newUserDB() *userDB { + return &userDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } +} + // nolint -func (db *UserDB) Add(u *User) bool { +func (db *userDB) Add(u *User) bool { db.lock.Lock() defer db.lock.Unlock() @@ -73,7 +78,7 @@ func (db *UserDB) Add(u *User) bool { } // nolint -func (db *UserDB) AddForName(u *User) bool { +func (db *userDB) AddForName(u *User) bool { if len(u.Name) == 0 { return false } @@ -87,7 +92,7 @@ func (db *UserDB) AddForName(u *User) bool { } // nolint -func (db *UserDB) AddForCode(u *User) bool { +func (db *userDB) AddForCode(u *User) bool { if u.Code <= 0 { return false } @@ -101,7 +106,7 @@ func (db *UserDB) AddForCode(u *User) bool { } // nolint -func (db *UserDB) GetByName(n string) (*User, bool) { +func (db *userDB) GetByName(n string) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -110,7 +115,7 @@ func (db *UserDB) GetByName(n string) (*User, bool) { } // nolint -func (db *UserDB) GetByCode(n int64) (*User, bool) { +func (db *userDB) GetByCode(n int64) (*User, bool) { db.lock.Lock() defer db.lock.Unlock() @@ -118,7 +123,7 @@ func (db *UserDB) GetByCode(n int64) (*User, bool) { return r, ok } -func (db *UserDB) existName(name string) bool { +func (db *userDB) existName(name string) bool { if len(name) <= 0 { return false } @@ -131,7 +136,7 @@ func (db *UserDB) existName(name string) bool { return false } -func (db *UserDB) existCode(code int64) bool { +func (db *userDB) existCode(code int64) bool { if code <= 0 { return false } From 0134b8d7e8146617d815bca60c166500705430a1 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Mon, 5 Jul 2021 17:49:25 +0800 Subject: [PATCH 06/13] add sleep time --- pkg/client/dubbo/dubbo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/dubbo/dubbo.go b/pkg/client/dubbo/dubbo.go index 510c3d6d3..4431d2ddf 100644 --- a/pkg/client/dubbo/dubbo.go +++ b/pkg/client/dubbo/dubbo.go @@ -262,7 +262,7 @@ func (dc *Client) create(key string, irequest fc.IntegrationRequest) *dg.Generic referenceConfig.GenericLoad(key) //TODO: fix it later // sleep to wait invoker create - time.Sleep(500 * time.Millisecond) + time.Sleep(800 * time.Millisecond) clientService := referenceConfig.GetRPCService().(*dg.GenericService) dc.GenericServicePool[key] = clientService From 7a9f94f31577be63e3e418dfadd915a74c6a8d4b Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Mon, 5 Jul 2021 22:19:10 +0800 Subject: [PATCH 07/13] add sleep time --- pkg/client/dubbo/dubbo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/dubbo/dubbo.go b/pkg/client/dubbo/dubbo.go index 4431d2ddf..8c6badb29 100644 --- a/pkg/client/dubbo/dubbo.go +++ b/pkg/client/dubbo/dubbo.go @@ -262,7 +262,7 @@ func (dc *Client) create(key string, irequest fc.IntegrationRequest) *dg.Generic referenceConfig.GenericLoad(key) //TODO: fix it later // sleep to wait invoker create - time.Sleep(800 * time.Millisecond) + time.Sleep(1000 * time.Millisecond) clientService := referenceConfig.GetRPCService().(*dg.GenericService) dc.GenericServicePool[key] = clientService From 30617b473f801cb417ef6f0a63c6775292f9de73 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Tue, 6 Jul 2021 08:58:49 +0800 Subject: [PATCH 08/13] sub sleep time --- pkg/client/dubbo/dubbo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/dubbo/dubbo.go b/pkg/client/dubbo/dubbo.go index 8c6badb29..510c3d6d3 100644 --- a/pkg/client/dubbo/dubbo.go +++ b/pkg/client/dubbo/dubbo.go @@ -262,7 +262,7 @@ func (dc *Client) create(key string, irequest fc.IntegrationRequest) *dg.Generic referenceConfig.GenericLoad(key) //TODO: fix it later // sleep to wait invoker create - time.Sleep(1000 * time.Millisecond) + time.Sleep(500 * time.Millisecond) clientService := referenceConfig.GetRPCService().(*dg.GenericService) dc.GenericServicePool[key] = clientService From e92d5222c443dc296cd1ca70f00c5a72f13dad41 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Tue, 6 Jul 2021 09:16:28 +0800 Subject: [PATCH 09/13] modify timeout --- samples/dubbogo/simple/mix/pixiu/api_config.yaml | 6 +++--- samples/dubbogo/simple/query/pixiu/api_config.yaml | 6 +++--- samples/dubbogo/simple/uri/pixiu/api_config.yaml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/dubbogo/simple/mix/pixiu/api_config.yaml b/samples/dubbogo/simple/mix/pixiu/api_config.yaml index 9900188fd..ae9be8aa4 100644 --- a/samples/dubbogo/simple/mix/pixiu/api_config.yaml +++ b/samples/dubbogo/simple/mix/pixiu/api_config.yaml @@ -25,7 +25,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http integrationRequest: @@ -45,7 +45,7 @@ resources: clusterName: "test_dubbo" - httpVerb: PUT onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http integrationRequest: @@ -71,7 +71,7 @@ resources: methods: - httpVerb: PUT onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http integrationRequest: diff --git a/samples/dubbogo/simple/query/pixiu/api_config.yaml b/samples/dubbogo/simple/query/pixiu/api_config.yaml index a1f16c9c6..ab1b77850 100644 --- a/samples/dubbogo/simple/query/pixiu/api_config.yaml +++ b/samples/dubbogo/simple/query/pixiu/api_config.yaml @@ -25,7 +25,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http integrationRequest: @@ -46,7 +46,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http integrationRequest: @@ -70,7 +70,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http integrationRequest: diff --git a/samples/dubbogo/simple/uri/pixiu/api_config.yaml b/samples/dubbogo/simple/uri/pixiu/api_config.yaml index f1effb978..044225ef4 100644 --- a/samples/dubbogo/simple/uri/pixiu/api_config.yaml +++ b/samples/dubbogo/simple/uri/pixiu/api_config.yaml @@ -25,7 +25,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http uri: @@ -49,7 +49,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http uri: @@ -73,7 +73,7 @@ resources: methods: - httpVerb: GET onAir: true - timeout: 1000ms + timeout: 100s inboundRequest: requestType: http uri: From 13a46c736fac3475b93ddc5f77828d031da55180 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Tue, 6 Jul 2021 10:11:30 +0800 Subject: [PATCH 10/13] modify timeout --- build/Makefile | 2 -- integrate_test.sh | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/Makefile b/build/Makefile index c27129cb7..9cefb11c4 100644 --- a/build/Makefile +++ b/build/Makefile @@ -144,8 +144,6 @@ stop: ## integration: Run integration test for this application .PHONY: integration -integration: export CONF_CONSUMER_FILE_PATH ?= $(OUT_DIR)/conf/client.yml -integration: export CONF_ROUTER_FILE_PATH ?= $(OUT_DIR)/conf/router_config.yml integration: $(info > Running integration test for application $(PROJECT_NAME)) @go clean -testcache diff --git a/integrate_test.sh b/integrate_test.sh index e7bb01773..bf00bbb0e 100644 --- a/integrate_test.sh +++ b/integrate_test.sh @@ -26,8 +26,10 @@ make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BAS # start server make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile start +sleep 500 # start pixiu make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile buildPixiu +sleep 500 # start integration make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile integration result=$? From 596c41c9485139825df01421fc68f916d3883a33 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Tue, 6 Jul 2021 10:22:54 +0800 Subject: [PATCH 11/13] wait dubbgo startup --- integrate_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrate_test.sh b/integrate_test.sh index bf00bbb0e..6e1e2d2d8 100644 --- a/integrate_test.sh +++ b/integrate_test.sh @@ -26,10 +26,10 @@ make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BAS # start server make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile start -sleep 500 +sleep 0.5 # start pixiu make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile buildPixiu -sleep 500 +sleep 0.5 # start integration make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile integration result=$? From 813c9e91b0084d9989fdf346e1c146f2183c2611 Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Tue, 6 Jul 2021 18:27:37 +0800 Subject: [PATCH 12/13] sort go version --- .github/workflows/github-actions.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 2327a6e94..9b781daf0 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -35,8 +35,9 @@ jobs: # If you want to matrix build , you can append the following list. matrix: go_version: - - 1.15 - 1.14 + - 1.15 + os: - ubuntu-latest From 06c49b17e1e4f7fde5d5306d9e46154709c6755e Mon Sep 17 00:00:00 2001 From: xun zhang <18721825717@163.com> Date: Tue, 6 Jul 2021 18:36:23 +0800 Subject: [PATCH 13/13] use 1.14 go version --- .asf.yaml | 2 +- .github/workflows/github-actions.yml | 1 - .travis.yml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.asf.yaml b/.asf.yaml index 45b0f53ca..080f7fb05 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -22,7 +22,7 @@ github: required_status_checks: strict: true contexts: - - "ubuntu-latest - Go 1.15" + - "ubuntu-latest - Go 1.14" notifications: commits: commits@dubbo.apache.org diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 9b781daf0..b84ce26a8 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -36,7 +36,6 @@ jobs: matrix: go_version: - 1.14 - - 1.15 os: - ubuntu-latest diff --git a/.travis.yml b/.travis.yml index 74a6d487d..35c51be26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ language: go go: - - "1.15" + - "1.14" env: - GO111MODULE=on