X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Frmrmsghandlers%2Fran_lost_connection_handler_test.go;h=52ea11d9e6b022390f469f8235611f6fecd067b2;hb=7dbe77a33d8bc8308d9d12b12f1e75f8329a2d92;hp=b1d354619f0f290eff57e5cedf77803f4759ce6e;hpb=a561a01554d9f29181595f6f9696097c2e98afc3;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go index b1d3546..52ea11d 100644 --- a/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go @@ -1,4 +1,4 @@ - //// Copyright 2019 AT&T Intellectual Property +//// Copyright 2019 AT&T Intellectual Property //// Copyright 2019 Nokia //// //// Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,41 +28,29 @@ import ( "e2mgr/models" "e2mgr/services" "encoding/json" - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" - "github.com/pkg/errors" "io/ioutil" "net/http" "testing" -) - -const ranName = "test" -const e2tAddress = "10.10.2.15:9800" - -func TestLostConnectionHandlerSuccess(t *testing.T) { - logger, _ := logger.InitLogger(logger.InfoLevel) - - notificationRequest := models.NotificationRequest{RanName: ranName} - ranDisconnectionManagerMock := &mocks.RanDisconnectionManagerMock{} - ranDisconnectionManagerMock.On("DisconnectRan", ranName).Return(nil) - handler := NewRanLostConnectionHandler(logger, ranDisconnectionManagerMock) - handler.Handle(¬ificationRequest) - ranDisconnectionManagerMock.AssertCalled(t, "DisconnectRan", ranName) -} -func TestLostConnectionHandlerFailure(t *testing.T) { - logger, _ := logger.InitLogger(logger.InfoLevel) + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "github.com/stretchr/testify/mock" +) - notificationRequest := models.NotificationRequest{RanName: ranName} - ranDisconnectionManagerMock := &mocks.RanDisconnectionManagerMock{} - ranDisconnectionManagerMock.On("DisconnectRan", ranName).Return(errors.New("error")) - handler := NewRanLostConnectionHandler(logger, ranDisconnectionManagerMock) - handler.Handle(¬ificationRequest) - ranDisconnectionManagerMock.AssertCalled(t, "DisconnectRan", ranName) -} +const ( + ranName = "test" + e2tAddress = "10.10.2.15:9800" +) -func setupLostConnectionHandlerTestWithRealDisconnectionManager(t *testing.T, isSuccessfulHttpPost bool) (RanLostConnectionHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) { - logger, _ := logger.InitLogger(logger.InfoLevel) - config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3} +func setupLostConnectionHandlerTest(isSuccessfulHttpPost bool) (*RanLostConnectionHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) { + InfoLevel := int8(3) + logger, _ := logger.InitLogger(InfoLevel) + config := &configuration.Configuration{ + RnibRetryIntervalMs: 10, + MaxRnibConnectionAttempts: 3, + RnibWriter: configuration.RnibWriterConfig{ + StateChangeMessageChannel: StateChangeMessageChannel, + }, + } readerMock := &mocks.RnibReaderMock{} writerMock := &mocks.RnibWriterMock{} @@ -70,26 +58,13 @@ func setupLostConnectionHandlerTestWithRealDisconnectionManager(t *testing.T, is e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger) httpClientMock := &mocks.HttpClientMock{} routingManagerClient := clients.NewRoutingManagerClient(logger, config, httpClientMock) - e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient) - ranDisconnectionManager := managers.NewRanDisconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, e2tAssociationManager) - handler := NewRanLostConnectionHandler(logger, ranDisconnectionManager) + ranListManager := managers.NewRanListManager(logger, rnibDataService) + ranAlarmService := services.NewRanAlarmService(logger, config) + ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(logger, rnibDataService, ranListManager, ranAlarmService) - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress} - var rnibErr error - readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) - updatedNodebInfo1 := *origNodebInfo - updatedNodebInfo1.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED - writerMock.On("UpdateNodebInfo", &updatedNodebInfo1).Return(rnibErr) - updatedNodebInfo2 := *origNodebInfo - updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED - updatedNodebInfo2.AssociatedE2TInstanceAddress = "" - writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(rnibErr) - e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}} - readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, nil) - e2tInstanceToSave := *e2tInstance - e2tInstanceToSave.AssociatedRanList = []string{} - writerMock.On("SaveE2TInstance", &e2tInstanceToSave).Return(nil) - mockHttpClient(httpClientMock, isSuccessfulHttpPost) + e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient, ranConnectStatusChangeManager) + ranDisconnectionManager := managers.NewRanDisconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, e2tAssociationManager, ranConnectStatusChangeManager) + handler := NewRanLostConnectionHandler(logger, ranDisconnectionManager) return handler, readerMock, writerMock, httpClientMock } @@ -108,24 +83,86 @@ func mockHttpClient(httpClientMock *mocks.HttpClientMock, isSuccessful bool) { httpClientMock.On("Post", clients.DissociateRanE2TInstanceApiSuffix, "application/json", body).Return(&http.Response{StatusCode: respStatusCode, Body: respBody}, nil) } -func TestLostConnectionHandlerFailureWithRealDisconnectionManager(t *testing.T) { - handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealDisconnectionManager(t, false) +func TestLostConnectionHandlerConnectingRanSuccess(t *testing.T) { + handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTest(true) + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress} + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo1 := *origNodebInfo + updatedNodebInfo1.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + writerMock.On("UpdateNodebInfo", mock.Anything).Return(rnibErr) + updatedNodebInfo2 := *origNodebInfo + updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + updatedNodebInfo2.AssociatedE2TInstanceAddress = "" + writerMock.On("UpdateNodebInfo", mock.Anything).Return(rnibErr) + e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}} + readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, nil) + e2tInstanceToSave := *e2tInstance + e2tInstanceToSave.AssociatedRanList = []string{} + writerMock.On("SaveE2TInstance", &e2tInstanceToSave).Return(nil) + mockHttpClient(httpClientMock, true) notificationRequest := models.NotificationRequest{RanName: ranName} handler.Handle(¬ificationRequest) - readerMock.AssertExpectations(t) writerMock.AssertExpectations(t) httpClientMock.AssertExpectations(t) writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) } -func TestLostConnectionHandlerSuccessWithRealDisconnectionManager(t *testing.T) { - handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealDisconnectionManager(t, true) +func TestLostConnectionHandlerConnectedRanSuccess(t *testing.T) { + handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTest(true) + origNodebInfo := &entities.NodebInfo{ + RanName: ranName, + GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + AssociatedE2TInstanceAddress: e2tAddress, + } + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo1 := *origNodebInfo + updatedNodebInfo1.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", mock.Anything, ranName+"_DISCONNECTED").Return(rnibErr) + updatedNodebInfo2 := *origNodebInfo + updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + updatedNodebInfo2.AssociatedE2TInstanceAddress = "" + writerMock.On("UpdateNodebInfo", mock.Anything).Return(rnibErr) + e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}} + readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, nil) + e2tInstanceToSave := *e2tInstance + e2tInstanceToSave.AssociatedRanList = []string{} + writerMock.On("SaveE2TInstance", &e2tInstanceToSave).Return(nil) + mockHttpClient(httpClientMock, true) notificationRequest := models.NotificationRequest{RanName: ranName} handler.Handle(¬ificationRequest) + readerMock.AssertExpectations(t) + writerMock.AssertExpectations(t) + httpClientMock.AssertExpectations(t) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) +} +func TestLostConnectionHandlerRmDissociateFailure(t *testing.T) { + handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTest(false) + + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress} + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo1 := *origNodebInfo + updatedNodebInfo1.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + writerMock.On("UpdateNodebInfo", mock.Anything).Return(rnibErr) + updatedNodebInfo2 := *origNodebInfo + updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + updatedNodebInfo2.AssociatedE2TInstanceAddress = "" + writerMock.On("UpdateNodebInfo", mock.Anything).Return(rnibErr) + e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}} + readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, nil) + e2tInstanceToSave := *e2tInstance + e2tInstanceToSave.AssociatedRanList = []string{} + writerMock.On("SaveE2TInstance", &e2tInstanceToSave).Return(nil) + mockHttpClient(httpClientMock, false) + notificationRequest := models.NotificationRequest{RanName: ranName} + handler.Handle(¬ificationRequest) readerMock.AssertExpectations(t) writerMock.AssertExpectations(t) httpClientMock.AssertExpectations(t)