From 744b33f45b1c67269ce6595426569517cfe27cc5 Mon Sep 17 00:00:00 2001 From: AMIRmh Date: Fri, 24 May 2019 17:14:20 +0430 Subject: [PATCH 1/2] check to pass pull request --- README.md | 2 +- api/ubroker.proto | 2 +- cmd/ubroker/main.go | 6 ++-- internal/broker/core.go | 2 +- internal/broker/core_test.go | 4 +-- internal/server/grpc.go | 51 ++++++++++++++++++++++++++---- internal/server/grpc_test.go | 4 +-- internal/server/http.go | 2 +- internal/server/http_test.go | 4 +-- internal/server/moc_broker_test.go | 2 +- 10 files changed, 59 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 331a550..96aeba2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/arcana261/ubroker.svg?branch=master)](https://travis-ci.org/arcana261/ubroker) [![Join the chat at https://gitter.im/arcana261-ubroker/community](https://badges.gitter.im/arcana261-ubroker/community.svg)](https://gitter.im/arcana261-ubroker/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/AMIRmh/ubroker.svg?branch=master)](https://travis-ci.org/AMIRmh/ubroker) [![Join the chat at https://gitter.im/AMIRmh-ubroker/community](https://badges.gitter.im/AMIRmh-ubroker/community.svg)](https://gitter.im/AMIRmh-ubroker/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # ubroker diff --git a/api/ubroker.proto b/api/ubroker.proto index 7b2c23c..8c7b0aa 100644 --- a/api/ubroker.proto +++ b/api/ubroker.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package ubroker; -option go_package = "github.com/arcana261/ubroker/pkg/ubroker"; +option go_package = "github.com/AMIRmh/ubroker/pkg/ubroker"; import "google/protobuf/empty.proto"; diff --git a/cmd/ubroker/main.go b/cmd/ubroker/main.go index 95e9562..4b82418 100644 --- a/cmd/ubroker/main.go +++ b/cmd/ubroker/main.go @@ -9,11 +9,11 @@ import ( "os/signal" "time" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/pkg/ubroker" "google.golang.org/grpc" - "github.com/arcana261/ubroker/internal/broker" - "github.com/arcana261/ubroker/internal/server" + "github.com/AMIRmh/ubroker/internal/broker" + "github.com/AMIRmh/ubroker/internal/server" ) func main() { diff --git a/internal/broker/core.go b/internal/broker/core.go index c040e9b..f7c2c3a 100644 --- a/internal/broker/core.go +++ b/internal/broker/core.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/pkg/ubroker" ) // New creates a new instance of ubroker.Broker diff --git a/internal/broker/core_test.go b/internal/broker/core_test.go index 0c3780b..e8c4921 100644 --- a/internal/broker/core_test.go +++ b/internal/broker/core_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/arcana261/ubroker/internal/broker" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/internal/broker" + "github.com/AMIRmh/ubroker/pkg/ubroker" "github.com/pkg/errors" "github.com/stretchr/testify/assert" diff --git a/internal/server/grpc.go b/internal/server/grpc.go index 2b393ed..178b8b3 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -2,8 +2,7 @@ package server import ( "context" - - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/pkg/ubroker" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -20,17 +19,57 @@ func NewGRPC(broker ubroker.Broker) ubroker.BrokerServer { } func (s *grpcServicer) Fetch(stream ubroker.Broker_FetchServer) error { - return status.Error(codes.Unimplemented, "not implemented") + ctx := stream.Context() + delivery, err := s.broker.Delivery(ctx) + if err != nil { + return whyError(err) + } + + for { + _, err := stream.Recv() + if err != nil { + return whyError(err) + } + + if msg, ok := <-delivery; ok { + err := stream.Send(msg) + if err != nil { + return whyError(err) + } + } else { + return whyError(ubroker.ErrClosed) + } + } + + } func (s *grpcServicer) Acknowledge(ctx context.Context, request *ubroker.AcknowledgeRequest) (*empty.Empty, error) { - return &empty.Empty{}, status.Error(codes.Unimplemented, "not implemented") + err := s.broker.Acknowledge(ctx, request.GetId()) + return &empty.Empty{}, whyError(err) + } func (s *grpcServicer) ReQueue(ctx context.Context, request *ubroker.ReQueueRequest) (*empty.Empty, error) { - return &empty.Empty{}, status.Error(codes.Unimplemented, "not implemented") + err := s.broker.ReQueue(ctx, request.GetId()) + return &empty.Empty{}, whyError(err) } func (s *grpcServicer) Publish(ctx context.Context, request *ubroker.Message) (*empty.Empty, error) { - return &empty.Empty{}, status.Error(codes.Unimplemented, "not implemented") + err := s.broker.Publish(ctx, request) + return &empty.Empty{}, whyError(err) } + + +func whyError(err error) error { + switch err { + case nil: + return nil + case ubroker.ErrClosed: + return status.Error(codes.Unavailable, "Unavailable") + case ubroker.ErrInvalidID: + return status.Error(codes.InvalidArgument, "InvalidArgument") + default: + return status.Error(codes.Unknown, "Unknown!") + } +} \ No newline at end of file diff --git a/internal/server/grpc_test.go b/internal/server/grpc_test.go index ec28f00..e0268c2 100644 --- a/internal/server/grpc_test.go +++ b/internal/server/grpc_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/mock" - "github.com/arcana261/ubroker/internal/server" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/internal/server" + "github.com/AMIRmh/ubroker/pkg/ubroker" "github.com/phayes/freeport" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/internal/server/http.go b/internal/server/http.go index 1badf2c..d154129 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -17,7 +17,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/pkg/ubroker" "github.com/pkg/errors" ) diff --git a/internal/server/http_test.go b/internal/server/http_test.go index aff3746..94756f9 100644 --- a/internal/server/http_test.go +++ b/internal/server/http_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" - "github.com/arcana261/ubroker/internal/server" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/internal/server" + "github.com/AMIRmh/ubroker/pkg/ubroker" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" ) diff --git a/internal/server/moc_broker_test.go b/internal/server/moc_broker_test.go index d3a0fa4..b2577aa 100644 --- a/internal/server/moc_broker_test.go +++ b/internal/server/moc_broker_test.go @@ -3,7 +3,7 @@ package server_test import ( "context" - "github.com/arcana261/ubroker/pkg/ubroker" + "github.com/AMIRmh/ubroker/pkg/ubroker" "github.com/stretchr/testify/mock" ) From 0e1fc45b7cf29d7c9a8129ae461f717456a33a47 Mon Sep 17 00:00:00 2001 From: AMIRmh Date: Fri, 24 May 2019 17:16:30 +0430 Subject: [PATCH 2/2] arcana261 name changed --- README.md | 2 +- api/ubroker.proto | 2 +- cmd/ubroker/main.go | 6 +++--- internal/broker/core.go | 2 +- internal/broker/core_test.go | 4 ++-- internal/server/grpc.go | 2 +- internal/server/grpc_test.go | 4 ++-- internal/server/http.go | 2 +- internal/server/http_test.go | 4 ++-- internal/server/moc_broker_test.go | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 96aeba2..331a550 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/AMIRmh/ubroker.svg?branch=master)](https://travis-ci.org/AMIRmh/ubroker) [![Join the chat at https://gitter.im/AMIRmh-ubroker/community](https://badges.gitter.im/AMIRmh-ubroker/community.svg)](https://gitter.im/AMIRmh-ubroker/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/arcana261/ubroker.svg?branch=master)](https://travis-ci.org/arcana261/ubroker) [![Join the chat at https://gitter.im/arcana261-ubroker/community](https://badges.gitter.im/arcana261-ubroker/community.svg)](https://gitter.im/arcana261-ubroker/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # ubroker diff --git a/api/ubroker.proto b/api/ubroker.proto index 8c7b0aa..7b2c23c 100644 --- a/api/ubroker.proto +++ b/api/ubroker.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package ubroker; -option go_package = "github.com/AMIRmh/ubroker/pkg/ubroker"; +option go_package = "github.com/arcana261/ubroker/pkg/ubroker"; import "google/protobuf/empty.proto"; diff --git a/cmd/ubroker/main.go b/cmd/ubroker/main.go index 4b82418..95e9562 100644 --- a/cmd/ubroker/main.go +++ b/cmd/ubroker/main.go @@ -9,11 +9,11 @@ import ( "os/signal" "time" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/pkg/ubroker" "google.golang.org/grpc" - "github.com/AMIRmh/ubroker/internal/broker" - "github.com/AMIRmh/ubroker/internal/server" + "github.com/arcana261/ubroker/internal/broker" + "github.com/arcana261/ubroker/internal/server" ) func main() { diff --git a/internal/broker/core.go b/internal/broker/core.go index f7c2c3a..c040e9b 100644 --- a/internal/broker/core.go +++ b/internal/broker/core.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/pkg/ubroker" ) // New creates a new instance of ubroker.Broker diff --git a/internal/broker/core_test.go b/internal/broker/core_test.go index e8c4921..0c3780b 100644 --- a/internal/broker/core_test.go +++ b/internal/broker/core_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/AMIRmh/ubroker/internal/broker" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/internal/broker" + "github.com/arcana261/ubroker/pkg/ubroker" "github.com/pkg/errors" "github.com/stretchr/testify/assert" diff --git a/internal/server/grpc.go b/internal/server/grpc.go index 178b8b3..fd66e35 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -2,7 +2,7 @@ package server import ( "context" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/pkg/ubroker" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/internal/server/grpc_test.go b/internal/server/grpc_test.go index e0268c2..ec28f00 100644 --- a/internal/server/grpc_test.go +++ b/internal/server/grpc_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/mock" - "github.com/AMIRmh/ubroker/internal/server" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/internal/server" + "github.com/arcana261/ubroker/pkg/ubroker" "github.com/phayes/freeport" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/internal/server/http.go b/internal/server/http.go index d154129..1badf2c 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -17,7 +17,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/pkg/ubroker" "github.com/pkg/errors" ) diff --git a/internal/server/http_test.go b/internal/server/http_test.go index 94756f9..aff3746 100644 --- a/internal/server/http_test.go +++ b/internal/server/http_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" - "github.com/AMIRmh/ubroker/internal/server" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/internal/server" + "github.com/arcana261/ubroker/pkg/ubroker" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" ) diff --git a/internal/server/moc_broker_test.go b/internal/server/moc_broker_test.go index b2577aa..d3a0fa4 100644 --- a/internal/server/moc_broker_test.go +++ b/internal/server/moc_broker_test.go @@ -3,7 +3,7 @@ package server_test import ( "context" - "github.com/AMIRmh/ubroker/pkg/ubroker" + "github.com/arcana261/ubroker/pkg/ubroker" "github.com/stretchr/testify/mock" )