Skip to content

Commit

Permalink
AddRooms req/res and RemoveRooms req/res should be removed (#494)
Browse files Browse the repository at this point in the history
* deletes remove/add-rooms-res/req operation from proto

* runs make generate

* deletes addroom/removeroom from scheduler files
  • Loading branch information
mflilian authored Jul 15, 2022
1 parent e86dea1 commit 9b0851b
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 788 deletions.
30 changes: 0 additions & 30 deletions internal/core/ports/mock/scheduler_ports_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions internal/core/ports/scheduler_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type SchedulerManager interface {
GetSchedulerVersions(ctx context.Context, schedulerName string) ([]*entities.SchedulerVersion, error)
DeleteScheduler(ctx context.Context, schedulerName string) error
PatchSchedulerAndCreateNewSchedulerVersionOperation(ctx context.Context, schedulerName string, patchMap map[string]interface{}) (*operation.Operation, error)
AddRooms(ctx context.Context, schedulerName string, amount int32) (*operation.Operation, error)
RemoveRooms(ctx context.Context, schedulerName string, amount int) (*operation.Operation, error)
GetSchedulersWithFilter(ctx context.Context, schedulerFilter *filters.SchedulerFilter) ([]*entities.Scheduler, error)
GetScheduler(ctx context.Context, schedulerName, version string) (*entities.Scheduler, error)
EnqueueNewSchedulerVersionOperation(ctx context.Context, scheduler *entities.Scheduler) (*operation.Operation, error)
Expand Down
36 changes: 0 additions & 36 deletions internal/core/services/scheduler_manager/scheduler_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ import (
"github.com/topfreegames/maestro/internal/core/entities"
"github.com/topfreegames/maestro/internal/core/entities/operation"
"github.com/topfreegames/maestro/internal/core/filters"
"github.com/topfreegames/maestro/internal/core/operations/add_rooms"
"github.com/topfreegames/maestro/internal/core/operations/create_scheduler"
"github.com/topfreegames/maestro/internal/core/operations/remove_rooms"
"github.com/topfreegames/maestro/internal/core/ports"
portsErrors "github.com/topfreegames/maestro/internal/core/ports/errors"
"go.uber.org/zap"
Expand Down Expand Up @@ -190,40 +188,6 @@ func (s *SchedulerManager) GetSchedulerVersions(ctx context.Context, schedulerNa
return s.schedulerStorage.GetSchedulerVersions(ctx, schedulerName)
}

func (s *SchedulerManager) AddRooms(ctx context.Context, schedulerName string, amount int32) (*operation.Operation, error) {

_, err := s.schedulerStorage.GetScheduler(ctx, schedulerName)
if err != nil {
return nil, fmt.Errorf("no scheduler found to add rooms on it: %w", err)
}

op, err := s.operationManager.CreateOperation(ctx, schedulerName, &add_rooms.AddRoomsDefinition{
Amount: amount,
})
if err != nil {
return nil, fmt.Errorf("not able to schedule the 'add rooms' operation: %w", err)
}

return op, nil
}

func (s *SchedulerManager) RemoveRooms(ctx context.Context, schedulerName string, amount int) (*operation.Operation, error) {

_, err := s.schedulerStorage.GetScheduler(ctx, schedulerName)
if err != nil {
return nil, fmt.Errorf("no scheduler found for removing rooms: %w", err)
}

op, err := s.operationManager.CreateOperation(ctx, schedulerName, &remove_rooms.RemoveRoomsDefinition{
Amount: amount,
})
if err != nil {
return nil, fmt.Errorf("not able to schedule the 'remove rooms' operation: %w", err)
}

return op, nil
}

func (s *SchedulerManager) EnqueueNewSchedulerVersionOperation(ctx context.Context, scheduler *entities.Scheduler) (*operation.Operation, error) {
currentScheduler, err := s.schedulerStorage.GetScheduler(ctx, scheduler.Name)
if err != nil {
Expand Down
110 changes: 0 additions & 110 deletions internal/core/services/scheduler_manager/scheduler_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,116 +157,6 @@ func TestCreateNewSchedulerVersion(t *testing.T) {

}

func TestAddRooms(t *testing.T) {
schedulerName := "scheduler-name-1"
mockCtrl := gomock.NewController(t)

t.Run("with success", func(t *testing.T) {

ctx := context.Background()

schedulerStorage := mockports.NewMockSchedulerStorage(mockCtrl)
operationManager := mock.NewMockOperationManager(mockCtrl)
roomStorage := mockports.NewMockRoomStorage(mockCtrl)
schedulerCache := mockports.NewMockSchedulerCache(mockCtrl)
schedulerManager := NewSchedulerManager(schedulerStorage, schedulerCache, operationManager, roomStorage)

operationManager.EXPECT().CreateOperation(ctx, schedulerName, gomock.Any()).Return(&operation.Operation{}, nil)

schedulerStorage.EXPECT().GetScheduler(ctx, schedulerName).Return(nil, nil)

op, err := schedulerManager.AddRooms(ctx, schedulerName, 10)
require.NoError(t, err)
require.NotNil(t, op)
require.NotNil(t, op.ID)
})

t.Run("fails when scheduler does not exists", func(t *testing.T) {
ctx := context.Background()
schedulerStorage := mockports.NewMockSchedulerStorage(mockCtrl)
schedulerManager := NewSchedulerManager(schedulerStorage, nil, nil, nil)

schedulerStorage.EXPECT().GetScheduler(ctx, schedulerName).Return(nil, errors.NewErrNotFound("err"))

op, err := schedulerManager.AddRooms(ctx, schedulerName, 10)
require.Nil(t, op)
require.ErrorIs(t, err, errors.ErrNotFound)
require.Contains(t, err.Error(), "no scheduler found to add rooms on it: err")
})

t.Run("fails when operation enqueue fails", func(t *testing.T) {
ctx := context.Background()
schedulerStorage := mockports.NewMockSchedulerStorage(mockCtrl)
operationManager := mock.NewMockOperationManager(mockCtrl)
roomStorage := mockports.NewMockRoomStorage(mockCtrl)
schedulerCache := mockports.NewMockSchedulerCache(mockCtrl)
schedulerManager := NewSchedulerManager(schedulerStorage, schedulerCache, operationManager, roomStorage)

schedulerStorage.EXPECT().GetScheduler(ctx, schedulerName).Return(nil, nil)
operationManager.EXPECT().CreateOperation(ctx, schedulerName, gomock.Any()).Return(nil, errors.NewErrUnexpected("storage offline"))

op, err := schedulerManager.AddRooms(ctx, schedulerName, 10)
require.Nil(t, op)
require.ErrorIs(t, err, errors.ErrUnexpected)
require.Contains(t, err.Error(), "not able to schedule the 'add rooms' operation: storage offline")
})
}

func TestRemoveRooms(t *testing.T) {
mockCtrl := gomock.NewController(t)

schedulerName := "scheduler-name-1"

t.Run("with success", func(t *testing.T) {

ctx := context.Background()
schedulerStorage := mockports.NewMockSchedulerStorage(mockCtrl)
operationManager := mock.NewMockOperationManager(mockCtrl)
roomStorage := mockports.NewMockRoomStorage(mockCtrl)
schedulerCache := mockports.NewMockSchedulerCache(mockCtrl)
schedulerManager := NewSchedulerManager(schedulerStorage, schedulerCache, operationManager, roomStorage)

operationManager.EXPECT().CreateOperation(ctx, schedulerName, gomock.Any()).Return(&operation.Operation{}, nil)
schedulerStorage.EXPECT().GetScheduler(ctx, schedulerName).Return(nil, nil)

op, err := schedulerManager.RemoveRooms(ctx, schedulerName, 10)
require.NoError(t, err)
require.NotNil(t, op)
require.NotNil(t, op.ID)
})

t.Run("fails when scheduler does not exists", func(t *testing.T) {
ctx := context.Background()
schedulerStorage := mockports.NewMockSchedulerStorage(mockCtrl)
roomStorage := mockports.NewMockRoomStorage(mockCtrl)
schedulerManager := NewSchedulerManager(schedulerStorage, nil, nil, roomStorage)

schedulerStorage.EXPECT().GetScheduler(ctx, schedulerName).Return(nil, errors.NewErrNotFound("err"))

op, err := schedulerManager.RemoveRooms(ctx, schedulerName, 10)
require.Nil(t, op)
require.ErrorIs(t, err, errors.ErrNotFound)
require.Contains(t, err.Error(), "no scheduler found for removing rooms: err")
})

t.Run("fails when operation enqueue fails", func(t *testing.T) {
ctx := context.Background()
schedulerStorage := mockports.NewMockSchedulerStorage(mockCtrl)
operationManager := mock.NewMockOperationManager(mockCtrl)
roomStorage := mockports.NewMockRoomStorage(mockCtrl)
schedulerCache := mockports.NewMockSchedulerCache(mockCtrl)
schedulerManager := NewSchedulerManager(schedulerStorage, schedulerCache, operationManager, roomStorage)

schedulerStorage.EXPECT().GetScheduler(ctx, schedulerName).Return(nil, nil)
operationManager.EXPECT().CreateOperation(ctx, schedulerName, gomock.Any()).Return(nil, errors.NewErrUnexpected("storage offline"))

op, err := schedulerManager.RemoveRooms(ctx, schedulerName, 10)
require.Nil(t, op)
require.ErrorIs(t, err, errors.ErrUnexpected)
require.Contains(t, err.Error(), "not able to schedule the 'remove rooms' operation: storage offline")
})
}

func TestEnqueueNewSchedulerVersionOperation(t *testing.T) {
mockCtrl := gomock.NewController(t)

Expand Down
Loading

0 comments on commit 9b0851b

Please sign in to comment.