@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package gobreaker
|
||||
@@ -7,10 +8,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/sony/gobreaker"
|
||||
"github.com/unistack-org/micro/register/memory"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"go.unistack.org/micro/register/memory"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
)
|
||||
|
||||
func TestBreaker(t *testing.T) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package hystrix
|
||||
@@ -7,10 +8,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/afex/hystrix-go/hystrix"
|
||||
rrouter "github.com/unistack-org/micro-router-register/v3"
|
||||
"github.com/unistack-org/micro/register/memory"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
rrouter "go.unistack.org/micro-router-register/v3"
|
||||
"go.unistack.org/micro/register/memory"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
)
|
||||
|
||||
func TestBreaker(t *testing.T) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package prometheus_test
|
||||
@@ -9,17 +10,17 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
cli "github.com/unistack-org/micro-client-grpc/v3"
|
||||
jsoncodec "github.com/unistack-org/micro-codec-json/v3"
|
||||
promwrapper "github.com/unistack-org/micro-metrics-prometheus/v3"
|
||||
rrouter "github.com/unistack-org/micro-router-register/v3"
|
||||
srv "github.com/unistack-org/micro-server-grpc/v3"
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
cli "go.unistack.org/micro-client-grpc/v3"
|
||||
jsoncodec "go.unistack.org/micro-codec-json/v3"
|
||||
promwrapper "go.unistack.org/micro-metrics-prometheus/v3"
|
||||
rrouter "go.unistack.org/micro-router-register/v3"
|
||||
srv "go.unistack.org/micro-server-grpc/v3"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type Test interface {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package ratelimit
|
||||
@@ -9,18 +10,20 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/juju/ratelimit"
|
||||
rrouter "github.com/unistack-org/micro-router-register/v3"
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
rrouter "go.unistack.org/micro-router-register/v3"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type testHandler struct{}
|
||||
type TestRequest struct{}
|
||||
type TestResponse struct{}
|
||||
type (
|
||||
testHandler struct{}
|
||||
TestRequest struct{}
|
||||
TestResponse struct{}
|
||||
)
|
||||
|
||||
func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestResponse) error {
|
||||
return nil
|
||||
@@ -89,7 +92,7 @@ func TestRateServerLimit(t *testing.T) {
|
||||
server.Register(r),
|
||||
server.Transport(tr),
|
||||
// add broker
|
||||
//server.Broker(b),
|
||||
// server.Broker(b),
|
||||
// add the breaker wrapper
|
||||
server.WrapHandler(NewHandlerWrapper(br, false)),
|
||||
)
|
||||
|
@@ -5,17 +5,17 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
cli "github.com/unistack-org/micro-client-grpc/v3"
|
||||
jsoncodec "github.com/unistack-org/micro-codec-json/v3"
|
||||
rrouter "github.com/unistack-org/micro-router-register/v3"
|
||||
srv "github.com/unistack-org/micro-server-grpc/v3"
|
||||
recwrapper "github.com/unistack-org/micro-wrapper-recovery/v3"
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
cli "go.unistack.org/micro-client-grpc/v3"
|
||||
jsoncodec "go.unistack.org/micro-codec-json/v3"
|
||||
rrouter "go.unistack.org/micro-router-register/v3"
|
||||
srv "go.unistack.org/micro-server-grpc/v3"
|
||||
recwrapper "go.unistack.org/micro-wrapper-recovery/v3"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type Test interface {
|
||||
|
@@ -1,25 +1,25 @@
|
||||
// +build ignore
|
||||
|
||||
package wrapper_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"database/sql"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
//_ "github.com/mattn/go-sqlite3"
|
||||
wrapper "github.com/unistack-org/micro-wrapper-sql"
|
||||
vmeter "go.unistack.org/micro-meter-victoriametrics/v3"
|
||||
wrapper "go.unistack.org/micro-wrapper-sql/v3"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"modernc.org/sqlite"
|
||||
)
|
||||
|
||||
var (
|
||||
schema = `
|
||||
var schema = `
|
||||
CREATE TABLE IF NOT EXISTS person (
|
||||
first_name text,
|
||||
last_name text,
|
||||
email text
|
||||
);`
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
FirstName string `db:"first_name"`
|
||||
@@ -28,25 +28,51 @@ type Person struct {
|
||||
}
|
||||
|
||||
func TestWrapper(t *testing.T) {
|
||||
db, err := sqlx.Connect("sqlite3", "test.db")
|
||||
wrapper.DefaultMeterStatsInterval = 100 * time.Millisecond
|
||||
meter.DefaultMeter = vmeter.NewMeter()
|
||||
|
||||
sql.Register("micro-wrapper-sql", wrapper.NewWrapper(&sqlite.Driver{}))
|
||||
wdb, err := sql.Open("micro-wrapper-sql", ":memory:")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
w := wrapper.NewWrapper(db)
|
||||
defer w.Close()
|
||||
ctx := context.Background()
|
||||
db := sqlx.NewDb(wdb, "sqlite")
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
db.MustExec(schema)
|
||||
|
||||
tx := db.MustBegin()
|
||||
//tx.NamedExec("INSERT OR REPLACE INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Jane", "Citizen", "jane.citzen@example.com"})
|
||||
tx.Commit()
|
||||
|
||||
people := &Person{}
|
||||
if err := sqlx.GetContext(ctx, w, people, "SELECT * FROM person limit 1"); err != nil {
|
||||
wrapper.NewStatsMeter(ctx, db, wrapper.DatabaseHost("localhost"), wrapper.DatabaseName("memory"))
|
||||
if _, err := db.Exec(schema); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%#+v\n", people)
|
||||
tx, err := db.BeginTxx(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := tx.NamedExec("INSERT OR REPLACE INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Fist1", "Last1", "Email1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := tx.NamedExec("INSERT OR REPLACE INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Fist2", "Last2", "Email2"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var peoples []*Person
|
||||
if err := sqlx.SelectContext(ctx, db, &peoples, "SELECT * FROM person limit 2"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_ = peoples
|
||||
time.Sleep(1 * time.Second)
|
||||
buf := bytes.NewBuffer(nil)
|
||||
_ = meter.DefaultMeter.Write(buf, meter.WriteProcessMetrics(true))
|
||||
|
||||
if !bytes.Contains(buf.Bytes(), []byte(`micro_sql_idle_connections`)) {
|
||||
t.Fatalf("micro-wrapper-sql output contains invalid output: %s", buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package datadog
|
||||
@@ -8,18 +9,18 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
rrouter "github.com/unistack-org/micro-router-register/v3"
|
||||
"github.com/unistack-org/micro/register/memory"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
microerr "github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
rrouter "go.unistack.org/micro-router-register/v3"
|
||||
"go.unistack.org/micro/register/memory"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
microerr "go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
|
||||
|
||||
cli "github.com/unistack-org/micro/v3/client"
|
||||
srv "github.com/unistack-org/micro/v3/server"
|
||||
cli "go.unistack.org/micro/v3/client"
|
||||
srv "go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type Test interface {
|
||||
@@ -29,6 +30,7 @@ type Test interface {
|
||||
type TestRequest struct {
|
||||
IsError bool
|
||||
}
|
||||
|
||||
type TestResponse struct {
|
||||
Message string
|
||||
}
|
||||
|
@@ -7,17 +7,17 @@ import (
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/opentracing/opentracing-go/mocktracer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
cli "github.com/unistack-org/micro-client-grpc/v3"
|
||||
jsoncodec "github.com/unistack-org/micro-codec-json/v3"
|
||||
rrouter "github.com/unistack-org/micro-router-register/v3"
|
||||
srv "github.com/unistack-org/micro-server-grpc/v3"
|
||||
otwrapper "github.com/unistack-org/micro-wrapper-trace-opentracing/v3"
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
cli "go.unistack.org/micro-client-grpc/v3"
|
||||
jsoncodec "go.unistack.org/micro-codec-json/v3"
|
||||
rrouter "go.unistack.org/micro-router-register/v3"
|
||||
srv "go.unistack.org/micro-server-grpc/v3"
|
||||
otwrapper "go.unistack.org/micro-wrapper-trace-opentracing/v3"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type Test interface {
|
||||
@@ -27,6 +27,7 @@ type Test interface {
|
||||
type TestRequest struct {
|
||||
IsError bool
|
||||
}
|
||||
|
||||
type TestResponse struct {
|
||||
Message string
|
||||
}
|
||||
|
Reference in New Issue
Block a user