2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
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"
26 "github.com/golang/protobuf/proto"
27 "github.com/stretchr/testify/assert"
32 func TestInitRNibWriter(t *testing.T) {
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")
42 func TestInitPool(t *testing.T) {
44 sdlInstanceMock := new(mocks.MockSdlInstance)
45 initPool(1, func() interface{} {
46 sdlI := common.ISdlInstance(sdlInstanceMock)
47 return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
49 func(obj interface{}) {
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")
60 var namespace = "namespace"
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}
68 func(obj interface{}) {
71 return sdlInstanceMock
74 func TestUpdateNodebInfoSuccess(t *testing.T) {
75 inventoryName := "name"
79 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
81 nodebInfo := &entities.NodebInfo{}
82 nodebInfo.RanName = inventoryName
83 nodebInfo.GlobalNbId = &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
84 nodebInfo.NodeType = entities.Node_ENB
85 nodebInfo.ConnectionStatus = 1
87 nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
88 data, err := proto.Marshal(nodebInfo)
90 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
93 var setExpected []interface{}
95 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
96 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
97 setExpected = append(setExpected, nodebNameKey, data)
98 setExpected = append(setExpected, nodebIdKey, data)
100 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
102 rNibErr := w.UpdateNodebInfo(nodebInfo)
103 assert.Nil(t, rNibErr)
106 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
107 inventoryName := "name"
111 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
113 nodebInfo := &entities.NodebInfo{}
114 data, err := proto.Marshal(nodebInfo)
116 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
119 var setExpected []interface{}
121 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
122 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
123 setExpected = append(setExpected, nodebNameKey, data)
124 setExpected = append(setExpected, nodebIdKey, data)
126 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
128 rNibErr := w.UpdateNodebInfo(nodebInfo)
130 assert.NotNil(t, rNibErr)
131 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
134 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
135 inventoryName := "name"
137 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
139 nodebInfo := &entities.NodebInfo{}
140 nodebInfo.RanName = inventoryName
141 data, err := proto.Marshal(nodebInfo)
143 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
146 var setExpected []interface{}
148 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
149 setExpected = append(setExpected, nodebNameKey, data)
150 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
152 rNibErr := w.UpdateNodebInfo(nodebInfo)
154 assert.Nil(t, rNibErr)
157 func TestSaveEnb(t *testing.T) {
159 ranName := "RAN:" + name
161 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
163 nb := entities.NodebInfo{}
164 nb.NodeType = entities.Node_ENB
165 nb.ConnectionStatus = 1
168 enb := entities.Enb{}
169 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
170 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
171 enb.ServedCells = []*entities.ServedCellInfo{cell}
172 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
173 data, err := proto.Marshal(&nb)
175 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
179 cellData, err := proto.Marshal(&cellEntity)
181 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
183 var setExpected []interface{}
184 setExpected = append(setExpected, ranName, data)
185 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
186 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
187 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
189 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
191 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
193 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
195 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
197 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
198 nbIdData, err = proto.Marshal(nbIdentity)
200 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
202 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
204 rNibErr := w.SaveNodeb(nbIdentity, &nb)
205 assert.Nil(t, rNibErr)
208 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
211 initSdlInstanceMock(namespace, 1)
213 nb := entities.NodebInfo{}
214 nb.NodeType = entities.Node_ENB
215 nb.ConnectionStatus = 1
218 enb := entities.Enb{}
219 cell := &entities.ServedCellInfo{Pci: 3}
220 enb.ServedCells = []*entities.ServedCellInfo{cell}
221 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
223 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
224 rNibErr := w.SaveNodeb(nbIdentity, &nb)
225 assert.NotNil(t, rNibErr)
226 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
227 assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
230 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
232 initSdlInstanceMock(namespace, 1)
234 nb := entities.NodebInfo{}
235 nb.NodeType = entities.Node_ENB
236 nb.ConnectionStatus = 1
239 enb := entities.Enb{}
240 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
241 enb.ServedCells = []*entities.ServedCellInfo{cell}
242 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
244 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
245 rNibErr := w.SaveNodeb(nbIdentity, &nb)
246 assert.NotNil(t, rNibErr)
247 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
248 assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
251 func TestSaveEnbOnClosedPool(t *testing.T) {
254 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
256 nb := entities.NodebInfo{}
257 nb.NodeType = entities.Node_ENB
258 nb.ConnectionStatus = 1
261 enb := entities.Enb{}
262 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
263 data, err := proto.Marshal(&nb)
265 t.Errorf("#rNibWriter_test.TestSaveEnbOnClosedPool - Failed to marshal NodeB entity. Error: %v", err)
267 setExpected := []interface{}{name, data}
269 sdlInstanceMock.On("Set", setExpected).Return(e)
271 nbIdentity := &entities.NbIdentity{}
272 assert.Panics(t, func() { w.SaveNodeb(nbIdentity, &nb) })
275 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
278 initSdlInstanceMock(namespace, 1)
280 nb := entities.NodebInfo{}
281 nb.NodeType = entities.Node_GNB
282 nb.ConnectionStatus = 1
285 gnb := entities.Gnb{}
286 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
287 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
288 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
289 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
291 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
292 rNibErr := w.SaveNodeb(nbIdentity, &nb)
293 assert.NotNil(t, rNibErr)
294 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
295 assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
298 func TestSaveGnb(t *testing.T) {
300 ranName := "RAN:" + name
302 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
304 nb := entities.NodebInfo{}
305 nb.NodeType = entities.Node_GNB
306 nb.ConnectionStatus = 1
309 gnb := entities.Gnb{}
310 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
311 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
312 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
313 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
314 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
315 data, err := proto.Marshal(&nb)
317 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
321 cellData, err := proto.Marshal(&cellEntity)
323 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
325 var setExpected []interface{}
326 setExpected = append(setExpected, ranName, data)
327 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
328 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
329 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
331 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
332 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
333 nbIdData, err := proto.Marshal(nbIdentity)
335 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
337 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
339 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
341 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
343 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
345 rNibErr := w.SaveNodeb(nbIdentity, &nb)
346 assert.Nil(t, rNibErr)
349 func TestSaveRanLoadInformationSuccess(t *testing.T) {
350 inventoryName := "name"
351 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
353 if validationErr != nil {
354 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
358 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
361 ranLoadInformation := generateRanLoadInformation()
362 data, err := proto.Marshal(ranLoadInformation)
365 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
369 var setExpected []interface{}
370 setExpected = append(setExpected, loadKey, data)
371 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
373 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
374 assert.Nil(t, rNibErr)
377 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
378 inventoryName := "name2"
380 initSdlInstanceMock(namespace, 1)
383 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
384 err := w.SaveRanLoadInformation(inventoryName, nil)
385 assert.Equal(t, expectedErr, err)
388 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
391 initSdlInstanceMock(namespace, 1)
394 err := w.SaveRanLoadInformation(inventoryName, nil)
395 assert.NotNil(t, err)
396 assert.Equal(t, common.VALIDATION_ERROR, err.GetCode())
399 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
400 inventoryName := "name2"
402 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
404 if validationErr != nil {
405 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
409 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
412 ranLoadInformation := generateRanLoadInformation()
413 data, err := proto.Marshal(ranLoadInformation)
416 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
419 expectedErr := errors.New("expected error")
420 var setExpected []interface{}
421 setExpected = append(setExpected, loadKey, data)
422 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
424 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
425 assert.NotNil(t, rNibErr)
426 assert.Equal(t, common.INTERNAL_ERROR, rNibErr.GetCode())
427 assert.Equal(t, expectedErr, rNibErr.GetError())
430 func generateCellLoadInformation() *entities.CellLoadInformation {
431 cellLoadInformation := entities.CellLoadInformation{}
433 cellLoadInformation.CellId = "123"
435 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
436 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
438 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
440 UlHighInterferenceIndication: "xxx",
443 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
445 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
447 RntpThreshold: entities.RntpThreshold_NEG_4,
448 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
450 PdcchInterferenceImpact: 2,
451 EnhancedRntp: &entities.EnhancedRntp{
452 EnhancedRntpBitmap: "xxx",
453 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
454 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
458 cellLoadInformation.AbsInformation = &entities.AbsInformation{
459 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
460 AbsPatternInfo: "xxx",
461 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
462 MeasurementSubset: "xxx",
465 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
467 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
468 AssociatedSubframes: "xxx",
469 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
472 compInformationItem := &entities.CompInformationItem{
473 CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}},
477 cellLoadInformation.CompInformation = &entities.CompInformation{
478 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
479 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
482 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
483 State: entities.NaicsState_NAICS_ACTIVE,
484 TransmissionModes: "xxx",
486 PAList: []entities.PA{entities.PA_DB_NEG_3},
489 return &cellLoadInformation
492 func generateRanLoadInformation() *entities.RanLoadInformation {
493 ranLoadInformation := entities.RanLoadInformation{}
495 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
497 cellLoadInformation := generateCellLoadInformation()
498 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
500 return &ranLoadInformation
503 func TestSaveNilEntityFailure(t *testing.T) {
505 initSdlInstanceMock(namespace, 1)
507 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
508 nbIdentity := &entities.NbIdentity{}
509 actualErr := w.SaveNodeb(nbIdentity, nil)
510 assert.Equal(t, expectedErr, actualErr)
513 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
515 initSdlInstanceMock(namespace, 1)
517 expectedErr := common.NewValidationError(errors.New("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 "))
518 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
519 nb := &entities.NodebInfo{}
522 actualErr := w.SaveNodeb(nbIdentity, nb)
523 assert.Equal(t, expectedErr, actualErr)
526 func TestSaveEntityFailure(t *testing.T) {
532 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
534 gnb := entities.NodebInfo{}
535 gnb.NodeType = entities.Node_GNB
536 data, err := proto.Marshal(&gnb)
538 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
540 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
541 setExpected := []interface{}{"RAN:" + name, data}
542 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
543 expectedErr := errors.New("expected error")
544 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
545 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
546 assert.NotEmpty(t, rNibErr)
549 func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) {
551 assert.Panics(t, func() { GetRNibWriter() })
554 func TestGetRNibWriter(t *testing.T) {
556 initSdlInstanceMock(namespace, 1)
557 received := GetRNibWriter()
558 assert.NotEmpty(t, received)
559 available, created := writerPool.Stats()
560 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
561 assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
565 func TestClose(t *testing.T) {
567 instanceMock := initSdlInstanceMock(namespace, 2)
568 w1 := GetRNibWriter()
569 w2 := GetRNibWriter()
572 available, created := writerPool.Stats()
573 assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2")
574 assert.Equal(t, 2, created, "number of created objects in the writerPool should be 2")
576 instanceMock.On("Close").Return(e)
578 available, created = writerPool.Stats()
579 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
580 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
583 func TestCloseOnClosedPoolFailure(t *testing.T) {
585 instanceMock := initSdlInstanceMock(namespace, 1)
586 w1 := GetRNibWriter()
588 available, created := writerPool.Stats()
589 assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
590 assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
592 instanceMock.On("Close").Return(e)
594 assert.Panics(t, func() { Close() })
597 func TestCloseFailure(t *testing.T) {
599 instanceMock := initSdlInstanceMock(namespace, 2)
600 w1 := GetRNibWriter()
602 available, created := writerPool.Stats()
603 assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
604 assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
605 e := errors.New("expected error")
606 instanceMock.On("Close").Return(e)
608 available, created = writerPool.Stats()
609 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
610 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
613 func TestInit(t *testing.T) {
616 assert.NotNil(t, writerPool)
617 assert.NotNil(t, writerPool.New)
618 assert.NotNil(t, writerPool.Destroy)
619 available, created := writerPool.Stats()
620 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
621 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
626 //func TestSaveEnbGnbInteg(t *testing.T){
627 // for i := 0; i<10; i++{
628 // Init("e2Manager", 1)
629 // w := GetRNibWriter()
630 // nb := entities.NodebInfo{}
631 // nb.NodeType = entities.Node_ENB
632 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
633 // nb.Ip = "localhost"
634 // nb.Port = uint32(5656 + i)
635 // enb := entities.Enb{}
636 // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
637 // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
638 // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
639 // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
640 // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
641 // plmnId := 0x02f828
642 // nbId := 0x4a952a0a
643 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
644 // err := w.SaveNodeb(nbIdentity, &nb)
646 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
649 // nb1 := entities.NodebInfo{}
650 // nb1.NodeType = entities.Node_GNB
651 // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
652 // nb1.Ip = "localhost"
653 // nb1.Port = uint32(6565 + i)
654 // gnb := entities.Gnb{}
655 // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
656 // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
657 // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
658 // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
659 // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
660 // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
661 // err = w.SaveNodeb(nbIdentity, &nb1)
663 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
668 //func TestSaveNbRanNamesInteg(t *testing.T){
669 // for i := 0; i<10; i++{
670 // Init("e2Manager", 1)
671 // w := GetRNibWriter()
672 // nb := entities.NodebInfo{}
673 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
674 // nb.Ip = "localhost"
675 // nb.Port = uint32(5656 + i)
676 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
677 // err := w.SaveNodeb(nbIdentity, &nb)
679 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
684 //func TestSaveRanLoadInformationInteg(t *testing.T){
685 // Init("e2Manager", 1)
686 // w := GetRNibWriter()
687 // ranLoadInformation := generateRanLoadInformation()
688 // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
690 // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)