ranDisconnectionManagerMock.AssertCalled(t, "DisconnectRan", ranName)
}
-func setupLostConnectionHandlerTestWithRealReconnectionManager(t *testing.T, isSuccessfulHttpPost bool) (RanLostConnectionHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) {
+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}
ranDisconnectionManager := managers.NewRanDisconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, e2tAssociationManager)
handler := NewRanLostConnectionHandler(logger, ranDisconnectionManager)
- origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20, AssociatedE2TInstanceAddress: e2tAddress}
+ 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
httpClientMock.On("Post", clients.DissociateRanE2TInstanceApiSuffix, "application/json", body).Return(&http.Response{StatusCode: respStatusCode, Body: respBody}, nil)
}
-func TestLostConnectionHandlerFailureWithRealReconnectionManager(t *testing.T) {
- handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealReconnectionManager(t, false)
+func TestLostConnectionHandlerFailureWithRealDisconnectionManager(t *testing.T) {
+ handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealDisconnectionManager(t, false)
notificationRequest := models.NotificationRequest{RanName: ranName}
handler.Handle(¬ificationRequest)
writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
}
-func TestLostConnectionHandlerSuccessWithRealReconnectionManager(t *testing.T) {
- handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealReconnectionManager(t, true)
+func TestLostConnectionHandlerSuccessWithRealDisconnectionManager(t *testing.T) {
+ handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealDisconnectionManager(t, true)
notificationRequest := models.NotificationRequest{RanName: ranName}
handler.Handle(¬ificationRequest)
return logger, rmrMessengerMock, readerMock, writerMock, ranDisconnectionManager, httpClient
}
-func TestRanReconnectionGetNodebFailure(t *testing.T) {
+func TestRanDisconnectionGetNodebFailure(t *testing.T) {
_, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
var nodebInfo *entities.NodebInfo
writerMock.AssertNotCalled(t, "UpdateNodebInfo")
}
-func TestShutdownRanReconnection(t *testing.T) {
+func TestShutdownRan(t *testing.T) {
_, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}
writerMock.AssertNotCalled(t, "UpdateNodebInfo")
}
-func TestShuttingdownRanReconnection(t *testing.T) {
+func TestShuttingdownRan(t *testing.T) {
_, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
}
-func TestConnectingRanDissociateSucceeds(t *testing.T) {
+func TestShuttingDownRanUpdateNodebInfoFailure(t *testing.T) {
+ _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
+
+ origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
+ var rnibErr error
+ readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+ updatedNodebInfo := *origNodebInfo
+ updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
+ writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+ err := ranDisconnectionManager.DisconnectRan(ranName)
+ assert.NotNil(t, err)
+ readerMock.AssertCalled(t, "GetNodeb", ranName)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+}
+
+func TestConnectingRanUpdateNodebInfoFailure(t *testing.T) {
+ _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
+
+ origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING}
+ var rnibErr error
+ readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+ updatedNodebInfo := *origNodebInfo
+ updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+ writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+ err := ranDisconnectionManager.DisconnectRan(ranName)
+ assert.NotNil(t, err)
+ readerMock.AssertCalled(t, "GetNodeb", ranName)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+}
+
+func TestConnectingRanDisconnectSucceeds(t *testing.T) {
_, _, readerMock, writerMock, ranDisconnectionManager, httpClient := initRanLostConnectionTest(t)
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: E2TAddress}
writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
}
-func TestConnectingRanDissociateFails(t *testing.T) {
- _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
+func TestConnectingRanDissociateFailsRmError(t *testing.T) {
+ _, _, readerMock, writerMock, ranDisconnectionManager, httpClient := initRanLostConnectionTest(t)
- origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress}
+ 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
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, common.NewInternalError(errors.New("Error")))
+ 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(httpClient, clients.DissociateRanE2TInstanceApiSuffix, false)
err := ranDisconnectionManager.DisconnectRan(ranName)
- assert.NotNil(t, err)
+ assert.Nil(t, err)
readerMock.AssertCalled(t, "GetNodeb", ranName)
writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
- writerMock.AssertNotCalled(t, "SaveE2TInstance", )
}
-func TestShuttingDownRanUpdateNodebInfoFailure(t *testing.T) {
+func TestConnectingRanDissociateFailsDbError(t *testing.T) {
_, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
- origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
- var rnibErr error
- readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
- updatedNodebInfo := *origNodebInfo
- updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
- writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
- err := ranDisconnectionManager.DisconnectRan(ranName)
- assert.NotNil(t, err)
- readerMock.AssertCalled(t, "GetNodeb", ranName)
- writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
-}
-
-func TestRanDisconnectedUpdateNodebInfoFailure(t *testing.T) {
- _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t)
-
- origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING}
+ 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)
- updatedNodebInfo := *origNodebInfo
- updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
- writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+ 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, common.NewInternalError(errors.New("Error")))
err := ranDisconnectionManager.DisconnectRan(ranName)
assert.NotNil(t, err)
readerMock.AssertCalled(t, "GetNodeb", ranName)
- writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
+ writerMock.AssertNotCalled(t, "SaveE2TInstance", )
}
func initRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender {