ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 AT&T Intellectual Property |
| 3 | // Copyright 2019 Nokia |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // |
| 17 | |
| 18 | package rNibWriter |
| 19 | |
| 20 | import ( |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 21 | "e2mgr/mocks" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 22 | "errors" |
| 23 | "fmt" |
is005q | 19bf35e | 2019-08-12 18:59:29 +0300 | [diff] [blame] | 24 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" |
| 25 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 26 | "github.com/golang/protobuf/proto" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 27 | "github.com/stretchr/testify/assert" |
| 28 | "testing" |
| 29 | "time" |
| 30 | ) |
| 31 | |
| 32 | func TestInitRNibWriter(t *testing.T) { |
| 33 | writerPool = nil |
| 34 | initSdlInstanceMock(namespace, 1) |
| 35 | available, created := writerPool.Stats() |
| 36 | assert.Equal(t, available, 0, "number of available objects in the writerPool should be 0") |
| 37 | assert.Equal(t, created, 0, "number of created objects in the writerPool should be 0") |
| 38 | w := GetRNibWriter() |
| 39 | assert.NotNil(t, w) |
| 40 | } |
| 41 | |
| 42 | func TestInitPool(t *testing.T) { |
| 43 | writerPool = nil |
| 44 | sdlInstanceMock := new(mocks.MockSdlInstance) |
| 45 | initPool(1, func() interface{} { |
| 46 | sdlI := common.ISdlInstance(sdlInstanceMock) |
| 47 | return &rNibWriterInstance{sdl: &sdlI, namespace: namespace} |
| 48 | }, |
| 49 | func(obj interface{}) { |
| 50 | }, |
| 51 | ) |
| 52 | assert.NotNil(t, writerPool) |
| 53 | assert.NotNil(t, writerPool.New) |
| 54 | assert.NotNil(t, writerPool.Destroy) |
| 55 | available, created := writerPool.Stats() |
| 56 | assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") |
| 57 | assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") |
| 58 | } |
| 59 | |
| 60 | var namespace = "namespace" |
| 61 | |
| 62 | func initSdlInstanceMock(namespace string, poolSize int) *mocks.MockSdlInstance { |
| 63 | sdlInstanceMock := new(mocks.MockSdlInstance) |
| 64 | initPool(poolSize, func() interface{} { |
| 65 | sdlI := common.ISdlInstance(sdlInstanceMock) |
| 66 | return &rNibWriterInstance{sdl: &sdlI, namespace: namespace} |
| 67 | }, |
| 68 | func(obj interface{}) { |
| 69 | }, |
| 70 | ) |
| 71 | return sdlInstanceMock |
| 72 | } |
| 73 | |
| 74 | func TestSaveEnb(t *testing.T) { |
| 75 | name := "name" |
| 76 | ranName := "RAN:" + name |
| 77 | writerPool = nil |
| 78 | sdlInstanceMock := initSdlInstanceMock(namespace, 1) |
| 79 | w := GetRNibWriter() |
| 80 | nb := entities.NodebInfo{} |
| 81 | nb.NodeType = entities.Node_ENB |
| 82 | nb.ConnectionStatus = 1 |
| 83 | nb.Ip = "localhost" |
| 84 | nb.Port = 5656 |
| 85 | enb := entities.Enb{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 86 | cell := &entities.ServedCellInfo{CellId:"aaff", Pci:3} |
| 87 | cellEntity := entities.Cell{Type:entities.Cell_LTE_CELL, Cell:&entities.Cell_ServedCellInfo{ServedCellInfo:cell}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 88 | enb.ServedCells = []*entities.ServedCellInfo{cell} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 89 | nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 90 | data, err := proto.Marshal(&nb) |
| 91 | if err != nil { |
| 92 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err) |
| 93 | } |
| 94 | var e error |
| 95 | |
| 96 | cellData, err := proto.Marshal(&cellEntity) |
| 97 | if err != nil { |
| 98 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err) |
| 99 | } |
| 100 | var setExpected []interface{} |
| 101 | setExpected = append(setExpected, ranName, data) |
| 102 | setExpected = append(setExpected, "ENB:02f829:4a952a0a", data) |
| 103 | setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData) |
| 104 | setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData) |
| 105 | |
| 106 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 107 | |
| 108 | nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name}) |
| 109 | if err != nil { |
| 110 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err) |
| 111 | } |
| 112 | sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e) |
| 113 | |
| 114 | nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}} |
| 115 | nbIdData, err = proto.Marshal(nbIdentity) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 116 | if err != nil { |
| 117 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err) |
| 118 | } |
| 119 | sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 120 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 121 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 122 | assert.Nil(t, rNibErr) |
| 123 | } |
| 124 | |
| 125 | func TestSaveEnbCellIdValidationFailure(t *testing.T) { |
| 126 | name := "name" |
| 127 | writerPool = nil |
| 128 | initSdlInstanceMock(namespace, 1) |
| 129 | w := GetRNibWriter() |
| 130 | nb := entities.NodebInfo{} |
| 131 | nb.NodeType = entities.Node_ENB |
| 132 | nb.ConnectionStatus = 1 |
| 133 | nb.Ip = "localhost" |
| 134 | nb.Port = 5656 |
| 135 | enb := entities.Enb{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 136 | cell := &entities.ServedCellInfo{Pci:3} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 137 | enb.ServedCells = []*entities.ServedCellInfo{cell} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 138 | nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 139 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 140 | nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 141 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 142 | assert.NotNil(t, rNibErr) |
| 143 | assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) |
| 144 | assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error()) |
| 145 | } |
| 146 | |
| 147 | func TestSaveEnbInventoryNameValidationFailure(t *testing.T) { |
| 148 | writerPool = nil |
| 149 | initSdlInstanceMock(namespace, 1) |
| 150 | w := GetRNibWriter() |
| 151 | nb := entities.NodebInfo{} |
| 152 | nb.NodeType = entities.Node_ENB |
| 153 | nb.ConnectionStatus = 1 |
| 154 | nb.Ip = "localhost" |
| 155 | nb.Port = 5656 |
| 156 | enb := entities.Enb{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 157 | cell := &entities.ServedCellInfo{CellId:"aaa",Pci:3} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 158 | enb.ServedCells = []*entities.ServedCellInfo{cell} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 159 | nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 160 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 161 | nbIdentity := &entities.NbIdentity{InventoryName:"", GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 162 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 163 | assert.NotNil(t, rNibErr) |
| 164 | assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) |
| 165 | assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error()) |
| 166 | } |
| 167 | |
| 168 | func TestSaveEnbOnClosedPool(t *testing.T) { |
| 169 | name := "name" |
| 170 | writerPool = nil |
| 171 | sdlInstanceMock := initSdlInstanceMock(namespace, 1) |
| 172 | w := GetRNibWriter() |
| 173 | nb := entities.NodebInfo{} |
| 174 | nb.NodeType = entities.Node_ENB |
| 175 | nb.ConnectionStatus = 1 |
| 176 | nb.Ip = "localhost" |
| 177 | nb.Port = 5656 |
| 178 | enb := entities.Enb{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 179 | nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 180 | data, err := proto.Marshal(&nb) |
| 181 | if err != nil { |
| 182 | t.Errorf("#rNibWriter_test.TestSaveEnbOnClosedPool - Failed to marshal NodeB entity. Error: %v", err) |
| 183 | } |
| 184 | setExpected := []interface{}{name, data} |
| 185 | var e error |
| 186 | sdlInstanceMock.On("Set", setExpected).Return(e) |
| 187 | writerPool.Close() |
| 188 | nbIdentity := &entities.NbIdentity{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 189 | assert.Panics(t, func(){w.SaveNodeb(nbIdentity, &nb)}) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | func TestSaveGnbCellIdValidationFailure(t *testing.T) { |
| 193 | name := "name" |
| 194 | writerPool = nil |
| 195 | initSdlInstanceMock(namespace, 1) |
| 196 | w := GetRNibWriter() |
| 197 | nb := entities.NodebInfo{} |
| 198 | nb.NodeType = entities.Node_GNB |
| 199 | nb.ConnectionStatus = 1 |
| 200 | nb.Ip = "localhost" |
| 201 | nb.Port = 5656 |
| 202 | gnb := entities.Gnb{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 203 | cellInfo:= &entities.ServedNRCellInformation{NrPci:2} |
| 204 | cell := &entities.ServedNRCell{ServedNrCellInformation:cellInfo} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 205 | gnb.ServedNrCells = []*entities.ServedNRCell{cell} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 206 | nb.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 207 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 208 | nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 209 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 210 | assert.NotNil(t, rNibErr) |
| 211 | assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) |
| 212 | assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error()) |
| 213 | } |
| 214 | |
| 215 | func TestSaveGnb(t *testing.T) { |
| 216 | name := "name" |
| 217 | ranName := "RAN:" + name |
| 218 | writerPool = nil |
| 219 | sdlInstanceMock := initSdlInstanceMock(namespace, 1) |
| 220 | w := GetRNibWriter() |
| 221 | nb := entities.NodebInfo{} |
| 222 | nb.NodeType = entities.Node_GNB |
| 223 | nb.ConnectionStatus = 1 |
| 224 | nb.Ip = "localhost" |
| 225 | nb.Port = 5656 |
| 226 | gnb := entities.Gnb{} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 227 | cellInfo:= &entities.ServedNRCellInformation{NrPci:2,CellId:"ccdd"} |
| 228 | cell := &entities.ServedNRCell{ServedNrCellInformation:cellInfo} |
| 229 | cellEntity := entities.Cell{Type:entities.Cell_NR_CELL, Cell:&entities.Cell_ServedNrCell{ServedNrCell:cell}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 230 | gnb.ServedNrCells = []*entities.ServedNRCell{cell} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 231 | nb.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 232 | data, err := proto.Marshal(&nb) |
| 233 | if err != nil { |
| 234 | t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err) |
| 235 | } |
| 236 | var e error |
| 237 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 238 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 239 | cellData, err := proto.Marshal(&cellEntity) |
| 240 | if err != nil { |
| 241 | t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err) |
| 242 | } |
| 243 | var setExpected []interface{} |
| 244 | setExpected = append(setExpected, ranName, data) |
| 245 | setExpected = append(setExpected, "GNB:02f829:4a952a0a", data) |
| 246 | setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData) |
| 247 | setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData) |
| 248 | |
| 249 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 250 | nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 251 | nbIdData, err := proto.Marshal(nbIdentity) |
| 252 | if err != nil { |
| 253 | t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err) |
| 254 | } |
| 255 | sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e) |
| 256 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 257 | nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name}) |
| 258 | if err != nil { |
| 259 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err) |
| 260 | } |
| 261 | sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e) |
| 262 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 263 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 264 | assert.Nil(t, rNibErr) |
| 265 | } |
| 266 | |
| 267 | func TestSaveRanLoadInformationSuccess(t *testing.T) { |
| 268 | inventoryName := "name" |
| 269 | loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName) |
| 270 | |
| 271 | if validationErr != nil { |
| 272 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr) |
| 273 | } |
| 274 | |
| 275 | writerPool = nil |
| 276 | sdlInstanceMock := initSdlInstanceMock(namespace, 1) |
| 277 | w := GetRNibWriter() |
| 278 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 279 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 280 | ranLoadInformation := generateRanLoadInformation() |
| 281 | data, err := proto.Marshal(ranLoadInformation) |
| 282 | |
| 283 | if err != nil { |
| 284 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err) |
| 285 | } |
| 286 | |
| 287 | var e error |
| 288 | var setExpected []interface{} |
| 289 | setExpected = append(setExpected, loadKey, data) |
| 290 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 291 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 292 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 293 | rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation) |
| 294 | assert.Nil(t, rNibErr) |
| 295 | } |
| 296 | |
| 297 | func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) { |
| 298 | inventoryName := "name2" |
| 299 | writerPool = nil |
| 300 | initSdlInstanceMock(namespace, 1) |
| 301 | w := GetRNibWriter() |
| 302 | |
| 303 | expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil")) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 304 | err:= w.SaveRanLoadInformation(inventoryName, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 305 | assert.Equal(t, expectedErr, err) |
| 306 | } |
| 307 | |
| 308 | func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) { |
| 309 | inventoryName := "" |
| 310 | writerPool = nil |
| 311 | initSdlInstanceMock(namespace, 1) |
| 312 | w := GetRNibWriter() |
| 313 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 314 | err:= w.SaveRanLoadInformation(inventoryName, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 315 | assert.NotNil(t, err) |
| 316 | assert.Equal(t, common.VALIDATION_ERROR, err.GetCode()) |
| 317 | } |
| 318 | |
| 319 | func TestSaveRanLoadInformationSdlFailure(t *testing.T) { |
| 320 | inventoryName := "name2" |
| 321 | |
| 322 | loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName) |
| 323 | |
| 324 | if validationErr != nil { |
| 325 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr) |
| 326 | } |
| 327 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 328 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 329 | writerPool = nil |
| 330 | sdlInstanceMock := initSdlInstanceMock(namespace, 1) |
| 331 | w := GetRNibWriter() |
| 332 | |
| 333 | ranLoadInformation := generateRanLoadInformation() |
| 334 | data, err := proto.Marshal(ranLoadInformation) |
| 335 | |
| 336 | if err != nil { |
| 337 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err) |
| 338 | } |
| 339 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 340 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 341 | expectedErr := errors.New("expected error") |
| 342 | var setExpected []interface{} |
| 343 | setExpected = append(setExpected, loadKey, data) |
| 344 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr) |
| 345 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 346 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 347 | rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation) |
| 348 | assert.NotNil(t, rNibErr) |
| 349 | assert.Equal(t, common.INTERNAL_ERROR, rNibErr.GetCode()) |
| 350 | assert.Equal(t, expectedErr, rNibErr.GetError()) |
| 351 | } |
| 352 | |
| 353 | func generateCellLoadInformation() *entities.CellLoadInformation { |
| 354 | cellLoadInformation := entities.CellLoadInformation{} |
| 355 | |
| 356 | cellLoadInformation.CellId = "123" |
| 357 | |
| 358 | ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE |
| 359 | cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication} |
| 360 | |
| 361 | ulHighInterferenceInformation := entities.UlHighInterferenceInformation{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 362 | TargetCellId:"456", |
| 363 | UlHighInterferenceIndication:"xxx", |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 364 | } |
| 365 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 366 | cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 367 | |
| 368 | cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 369 | RntpPerPrb:"xxx", |
| 370 | RntpThreshold:entities.RntpThreshold_NEG_4, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 371 | NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT, |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 372 | PB: 1, |
| 373 | PdcchInterferenceImpact:2, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 374 | EnhancedRntp: &entities.EnhancedRntp{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 375 | EnhancedRntpBitmap:"xxx", |
| 376 | RntpHighPowerThreshold:entities.RntpThreshold_NEG_2, |
| 377 | EnhancedRntpStartTime: &entities.StartTime{StartSfn:500,StartSubframeNumber:5}, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 378 | }, |
| 379 | } |
| 380 | |
| 381 | cellLoadInformation.AbsInformation = &entities.AbsInformation{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 382 | Mode: entities.AbsInformationMode_ABS_INFO_FDD, |
| 383 | AbsPatternInfo:"xxx", |
| 384 | NumberOfCellSpecificAntennaPorts:entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT, |
| 385 | MeasurementSubset:"xxx", |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION |
| 389 | |
| 390 | cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 391 | AssociatedSubframes:"xxx", |
| 392 | ExtendedUlInterferenceOverloadIndications:cellLoadInformation.UlInterferenceOverloadIndications, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | compInformationItem := &entities.CompInformationItem{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 396 | CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis:"xxx"}}, |
| 397 | BenefitMetric:50, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | cellLoadInformation.CompInformation = &entities.CompInformation{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 401 | CompInformationItems:[]*entities.CompInformationItem{compInformationItem}, |
| 402 | CompInformationStartTime:&entities.StartTime{StartSfn:123,StartSubframeNumber:456}, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{ |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 406 | State: entities.NaicsState_NAICS_ACTIVE, |
| 407 | TransmissionModes:"xxx", |
| 408 | PB: 2, |
| 409 | PAList:[]entities.PA{entities.PA_DB_NEG_3}, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | return &cellLoadInformation |
| 413 | } |
| 414 | |
| 415 | func generateRanLoadInformation() *entities.RanLoadInformation { |
| 416 | ranLoadInformation := entities.RanLoadInformation{} |
| 417 | |
is005q | 19bf35e | 2019-08-12 18:59:29 +0300 | [diff] [blame] | 418 | ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano()) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 419 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 420 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 421 | cellLoadInformation := generateCellLoadInformation() |
| 422 | ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation} |
| 423 | |
| 424 | return &ranLoadInformation |
| 425 | } |
| 426 | |
| 427 | func TestSaveNilEntityFailure(t *testing.T) { |
| 428 | writerPool = nil |
| 429 | initSdlInstanceMock(namespace, 1) |
| 430 | w := GetRNibWriter() |
| 431 | expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil")) |
| 432 | nbIdentity := &entities.NbIdentity{} |
| 433 | actualErr := w.SaveNodeb(nbIdentity, nil) |
| 434 | assert.Equal(t, expectedErr, actualErr) |
| 435 | } |
| 436 | |
| 437 | func TestSaveUnknownTypeEntityFailure(t *testing.T) { |
| 438 | writerPool = nil |
| 439 | initSdlInstanceMock(namespace, 1) |
| 440 | w := GetRNibWriter() |
| 441 | expectedErr := common.NewValidationError(errors.New("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 442 | nbIdentity := &entities.NbIdentity{InventoryName:"name", GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 443 | nb := &entities.NodebInfo{} |
| 444 | nb.Port = 5656 |
| 445 | nb.Ip = "localhost" |
| 446 | actualErr := w.SaveNodeb(nbIdentity, nb) |
| 447 | assert.Equal(t, expectedErr, actualErr) |
| 448 | } |
| 449 | |
| 450 | func TestSaveEntityFailure(t *testing.T) { |
| 451 | name := "name" |
| 452 | plmnId := "02f829" |
| 453 | nbId := "4a952a0a" |
| 454 | |
| 455 | writerPool = nil |
| 456 | sdlInstanceMock := initSdlInstanceMock(namespace, 1) |
| 457 | w := GetRNibWriter() |
| 458 | gnb := entities.NodebInfo{} |
| 459 | gnb.NodeType = entities.Node_GNB |
| 460 | data, err := proto.Marshal(&gnb) |
| 461 | if err != nil { |
| 462 | t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err) |
| 463 | } |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 464 | nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:plmnId, NbId:nbId}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 465 | setExpected := []interface{}{"RAN:" + name, data} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 466 | setExpected = append(setExpected,"GNB:" + plmnId + ":" + nbId, data) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 467 | expectedErr := errors.New("expected error") |
| 468 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr) |
| 469 | rNibErr := w.SaveNodeb(nbIdentity, &gnb) |
| 470 | assert.NotEmpty(t, rNibErr) |
| 471 | } |
| 472 | |
| 473 | func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) { |
| 474 | writerPool = nil |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 475 | assert.Panics(t, func(){GetRNibWriter()}) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | func TestGetRNibWriter(t *testing.T) { |
| 479 | writerPool = nil |
| 480 | initSdlInstanceMock(namespace, 1) |
| 481 | received := GetRNibWriter() |
| 482 | assert.NotEmpty(t, received) |
| 483 | available, created := writerPool.Stats() |
| 484 | assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") |
| 485 | assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1") |
| 486 | writerPool.Close() |
| 487 | } |
| 488 | |
| 489 | func TestClose(t *testing.T) { |
| 490 | writerPool = nil |
| 491 | instanceMock := initSdlInstanceMock(namespace, 2) |
| 492 | w1 := GetRNibWriter() |
| 493 | w2 := GetRNibWriter() |
| 494 | writerPool.Put(w1) |
| 495 | writerPool.Put(w2) |
| 496 | available, created := writerPool.Stats() |
| 497 | assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2") |
| 498 | assert.Equal(t, 2, created, "number of created objects in the writerPool should be 2") |
| 499 | var e error |
| 500 | instanceMock.On("Close").Return(e) |
| 501 | Close() |
| 502 | available, created = writerPool.Stats() |
| 503 | assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") |
| 504 | assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") |
| 505 | } |
| 506 | |
| 507 | func TestCloseOnClosedPoolFailure(t *testing.T) { |
| 508 | writerPool = nil |
| 509 | instanceMock := initSdlInstanceMock(namespace, 1) |
| 510 | w1 := GetRNibWriter() |
| 511 | writerPool.Put(w1) |
| 512 | available, created := writerPool.Stats() |
| 513 | assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1") |
| 514 | assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1") |
| 515 | var e error |
| 516 | instanceMock.On("Close").Return(e) |
| 517 | Close() |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 518 | assert.Panics(t, func(){Close()}) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | func TestCloseFailure(t *testing.T) { |
| 522 | writerPool = nil |
| 523 | instanceMock := initSdlInstanceMock(namespace, 2) |
| 524 | w1 := GetRNibWriter() |
| 525 | writerPool.Put(w1) |
| 526 | available, created := writerPool.Stats() |
| 527 | assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1") |
| 528 | assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1") |
| 529 | e := errors.New("expected error") |
| 530 | instanceMock.On("Close").Return(e) |
| 531 | Close() |
| 532 | available, created = writerPool.Stats() |
| 533 | assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") |
| 534 | assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") |
| 535 | } |
| 536 | |
| 537 | func TestInit(t *testing.T) { |
| 538 | writerPool = nil |
| 539 | Init("", 1) |
| 540 | assert.NotNil(t, writerPool) |
| 541 | assert.NotNil(t, writerPool.New) |
| 542 | assert.NotNil(t, writerPool.Destroy) |
| 543 | available, created := writerPool.Stats() |
| 544 | assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") |
| 545 | assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") |
| 546 | } |
| 547 | |
| 548 | //Integration tests |
| 549 | // |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 550 | //func TestSaveEnbGnbInteg(t *testing.T){ |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 551 | // for i := 0; i<10; i++{ |
| 552 | // Init("e2Manager", 1) |
| 553 | // w := GetRNibWriter() |
| 554 | // nb := entities.NodebInfo{} |
| 555 | // nb.NodeType = entities.Node_ENB |
| 556 | // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED |
| 557 | // nb.Ip = "localhost" |
| 558 | // nb.Port = uint32(5656 + i) |
| 559 | // enb := entities.Enb{} |
| 560 | // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)} |
| 561 | // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)} |
| 562 | // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)} |
| 563 | // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3} |
| 564 | // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb} |
| 565 | // plmnId := 0x02f828 |
| 566 | // nbId := 0x4a952a0a |
| 567 | // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}} |
| 568 | // err := w.SaveNodeb(nbIdentity, &nb) |
| 569 | // if err != nil{ |
| 570 | // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err) |
| 571 | // } |
| 572 | // |
| 573 | // nb1 := entities.NodebInfo{} |
| 574 | // nb1.NodeType = entities.Node_GNB |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 575 | // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 576 | // nb1.Ip = "localhost" |
| 577 | // nb1.Port = uint32(6565 + i) |
| 578 | // gnb := entities.Gnb{} |
| 579 | // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}} |
| 580 | // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}} |
| 581 | // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}} |
| 582 | // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,} |
| 583 | // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb} |
| 584 | // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}} |
| 585 | // err = w.SaveNodeb(nbIdentity, &nb1) |
| 586 | // if err != nil{ |
| 587 | // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err) |
| 588 | // } |
| 589 | // } |
| 590 | //} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 591 | // |
| 592 | //func TestSaveNbRanNamesInteg(t *testing.T){ |
| 593 | // for i := 0; i<10; i++{ |
| 594 | // Init("e2Manager", 1) |
| 595 | // w := GetRNibWriter() |
| 596 | // nb := entities.NodebInfo{} |
| 597 | // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING |
| 598 | // nb.Ip = "localhost" |
| 599 | // nb.Port = uint32(5656 + i) |
| 600 | // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)} |
| 601 | // err := w.SaveNodeb(nbIdentity, &nb) |
| 602 | // if err != nil{ |
| 603 | // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err) |
| 604 | // } |
| 605 | // } |
| 606 | //} |
| 607 | // |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 608 | //func TestSaveRanLoadInformationInteg(t *testing.T){ |
| 609 | // Init("e2Manager", 1) |
| 610 | // w := GetRNibWriter() |
| 611 | // ranLoadInformation := generateRanLoadInformation() |
| 612 | // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation) |
| 613 | // if err != nil{ |
| 614 | // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err) |
| 615 | // } |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame^] | 616 | //} |