Skip to content

Commit

Permalink
feat(dial): add dial testing for blobstore
Browse files Browse the repository at this point in the history
Signed-off-by: slasher <[email protected]>
  • Loading branch information
sejust committed Jul 20, 2023
1 parent ca609d6 commit c3db761
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
68 changes: 68 additions & 0 deletions blobstore/testing/dial/dial.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2023 The CubeFS Authors.
//
// Licensed 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 dial

import (
"net/http"

"github.com/cubefs/cubefs/blobstore/cmd"
"github.com/cubefs/cubefs/blobstore/common/config"
"github.com/cubefs/cubefs/blobstore/common/rpc"
"github.com/cubefs/cubefs/blobstore/common/trace"
)

var (
gService *serviceDial
gConfig serviceConfig
)

func init() {
trace.RequestIDKey = "request-id"
trace.PrefixBaggage = "baggage-"
trace.FieldKeyTraceID = "trace-id"
trace.FieldKeySpanID = "span-id"
}

func init() {
cmd.RegisterModule(&cmd.Module{
Name: "DialTest",
InitConfig: initConfig,
SetUp: setUp,
TearDown: tearDown,
})
}

func initConfig(args []string) (*cmd.Config, error) {
config.Init("f", "", "dial.conf")
if err := config.Load(&gConfig); err != nil {
return nil, err
}
return &gConfig.Config, nil
}

func setUp() (*rpc.Router, []rpc.ProgressHandler) {
gService = newService(gConfig)
return newHandler(gService), nil
}

func tearDown() {
gService.Close()
}

func newHandler(service *serviceDial) *rpc.Router {
router := rpc.New()
router.Handle(http.MethodGet, "/status", service.Status)
return router
}
8 changes: 8 additions & 0 deletions blobstore/testing/dial/main/dial.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"max_procs": 4,
"bind_addr": ":9590",
"log": {
"level": "debug",
"filename": "/tmp/dial.log"
}
}
26 changes: 26 additions & 0 deletions blobstore/testing/dial/main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 The CubeFS Authors.
//
// Licensed 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 (
"os"

"github.com/cubefs/cubefs/blobstore/cmd"
_ "github.com/cubefs/cubefs/blobstore/testing/dial"
)

func main() {
cmd.Main(os.Args)
}
15 changes: 15 additions & 0 deletions blobstore/testing/dial/metric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 The CubeFS Authors.
//
// Licensed 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 dial
48 changes: 48 additions & 0 deletions blobstore/testing/dial/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 The CubeFS Authors.
//
// Licensed 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 dial

import (
"github.com/cubefs/cubefs/blobstore/cmd"
"github.com/cubefs/cubefs/blobstore/common/rpc"
"github.com/cubefs/cubefs/blobstore/common/trace"
"github.com/cubefs/cubefs/blobstore/util/closer"
)

type (
serviceConfig struct {
cmd.Config

dials []dialConfig
}
serviceDial struct {
closer.Closer
}

dialConfig struct {
}
)

func newService(cfg serviceConfig) *serviceDial {
return &serviceDial{
Closer: closer.New(),
}
}

func (s *serviceDial) Status(c *rpc.Context) {
span := trace.SpanFromContextSafe(c.Request.Context())
span.Info("hello.")
c.Respond()
}

0 comments on commit c3db761

Please sign in to comment.