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 TestUpdateNodebInfoMissingGlobalNbIdFailure(t *testing.T) {
135 inventoryName := "name"
139 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
141 nodebInfo := &entities.NodebInfo{}
142 nodebInfo.RanName = inventoryName
143 data, err := proto.Marshal(nodebInfo)
145 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
148 var setExpected []interface{}
150 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
151 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
152 setExpected = append(setExpected, nodebNameKey, data)
153 setExpected = append(setExpected, nodebIdKey, data)
155 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
157 rNibErr := w.UpdateNodebInfo(nodebInfo)
159 assert.NotNil(t, rNibErr)
160 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
163 func TestSaveEnb(t *testing.T) {
165 ranName := "RAN:" + name
167 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
169 nb := entities.NodebInfo{}
170 nb.NodeType = entities.Node_ENB
171 nb.ConnectionStatus = 1
174 enb := entities.Enb{}
175 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
176 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
177 enb.ServedCells = []*entities.ServedCellInfo{cell}
178 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
179 data, err := proto.Marshal(&nb)
181 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
185 cellData, err := proto.Marshal(&cellEntity)
187 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
189 var setExpected []interface{}
190 setExpected = append(setExpected, ranName, data)
191 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
192 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
193 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
195 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
197 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
199 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
201 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
203 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
204 nbIdData, err = proto.Marshal(nbIdentity)
206 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
208 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
210 rNibErr := w.SaveNodeb(nbIdentity, &nb)
211 assert.Nil(t, rNibErr)
214 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
217 initSdlInstanceMock(namespace, 1)
219 nb := entities.NodebInfo{}
220 nb.NodeType = entities.Node_ENB
221 nb.ConnectionStatus = 1
224 enb := entities.Enb{}
225 cell := &entities.ServedCellInfo{Pci: 3}
226 enb.ServedCells = []*entities.ServedCellInfo{cell}
227 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
229 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
230 rNibErr := w.SaveNodeb(nbIdentity, &nb)
231 assert.NotNil(t, rNibErr)
232 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
233 assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
236 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
238 initSdlInstanceMock(namespace, 1)
240 nb := entities.NodebInfo{}
241 nb.NodeType = entities.Node_ENB
242 nb.ConnectionStatus = 1
245 enb := entities.Enb{}
246 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
247 enb.ServedCells = []*entities.ServedCellInfo{cell}
248 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
250 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
251 rNibErr := w.SaveNodeb(nbIdentity, &nb)
252 assert.NotNil(t, rNibErr)
253 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
254 assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
257 func TestSaveEnbOnClosedPool(t *testing.T) {
260 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
262 nb := entities.NodebInfo{}
263 nb.NodeType = entities.Node_ENB
264 nb.ConnectionStatus = 1
267 enb := entities.Enb{}
268 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
269 data, err := proto.Marshal(&nb)
271 t.Errorf("#rNibWriter_test.TestSaveEnbOnClosedPool - Failed to marshal NodeB entity. Error: %v", err)
273 setExpected := []interface{}{name, data}
275 sdlInstanceMock.On("Set", setExpected).Return(e)
277 nbIdentity := &entities.NbIdentity{}
278 assert.Panics(t, func() { w.SaveNodeb(nbIdentity, &nb) })
281 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
284 initSdlInstanceMock(namespace, 1)
286 nb := entities.NodebInfo{}
287 nb.NodeType = entities.Node_GNB
288 nb.ConnectionStatus = 1
291 gnb := entities.Gnb{}
292 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
293 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
294 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
295 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
297 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
298 rNibErr := w.SaveNodeb(nbIdentity, &nb)
299 assert.NotNil(t, rNibErr)
300 assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
301 assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
304 func TestSaveGnb(t *testing.T) {
306 ranName := "RAN:" + name
308 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
310 nb := entities.NodebInfo{}
311 nb.NodeType = entities.Node_GNB
312 nb.ConnectionStatus = 1
315 gnb := entities.Gnb{}
316 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
317 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
318 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
319 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
320 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
321 data, err := proto.Marshal(&nb)
323 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
327 cellData, err := proto.Marshal(&cellEntity)
329 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
331 var setExpected []interface{}
332 setExpected = append(setExpected, ranName, data)
333 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
334 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
335 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
337 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
338 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
339 nbIdData, err := proto.Marshal(nbIdentity)
341 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
343 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
345 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
347 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
349 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
351 rNibErr := w.SaveNodeb(nbIdentity, &nb)
352 assert.Nil(t, rNibErr)
355 func TestSaveRanLoadInformationSuccess(t *testing.T) {
356 inventoryName := "name"
357 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
359 if validationErr != nil {
360 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
364 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
367 ranLoadInformation := generateRanLoadInformation()
368 data, err := proto.Marshal(ranLoadInformation)
371 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
375 var setExpected []interface{}
376 setExpected = append(setExpected, loadKey, data)
377 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
379 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
380 assert.Nil(t, rNibErr)
383 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
384 inventoryName := "name2"
386 initSdlInstanceMock(namespace, 1)
389 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
390 err := w.SaveRanLoadInformation(inventoryName, nil)
391 assert.Equal(t, expectedErr, err)
394 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
397 initSdlInstanceMock(namespace, 1)
400 err := w.SaveRanLoadInformation(inventoryName, nil)
401 assert.NotNil(t, err)
402 assert.Equal(t, common.VALIDATION_ERROR, err.GetCode())
405 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
406 inventoryName := "name2"
408 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
410 if validationErr != nil {
411 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
415 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
418 ranLoadInformation := generateRanLoadInformation()
419 data, err := proto.Marshal(ranLoadInformation)
422 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
425 expectedErr := errors.New("expected error")
426 var setExpected []interface{}
427 setExpected = append(setExpected, loadKey, data)
428 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
430 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
431 assert.NotNil(t, rNibErr)
432 assert.Equal(t, common.INTERNAL_ERROR, rNibErr.GetCode())
433 assert.Equal(t, expectedErr, rNibErr.GetError())
436 func generateCellLoadInformation() *entities.CellLoadInformation {
437 cellLoadInformation := entities.CellLoadInformation{}
439 cellLoadInformation.CellId = "123"
441 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
442 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
444 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
446 UlHighInterferenceIndication: "xxx",
449 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
451 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
453 RntpThreshold: entities.RntpThreshold_NEG_4,
454 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
456 PdcchInterferenceImpact: 2,
457 EnhancedRntp: &entities.EnhancedRntp{
458 EnhancedRntpBitmap: "xxx",
459 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
460 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
464 cellLoadInformation.AbsInformation = &entities.AbsInformation{
465 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
466 AbsPatternInfo: "xxx",
467 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
468 MeasurementSubset: "xxx",
471 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
473 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
474 AssociatedSubframes: "xxx",
475 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
478 compInformationItem := &entities.CompInformationItem{
479 CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}},
483 cellLoadInformation.CompInformation = &entities.CompInformation{
484 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
485 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
488 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
489 State: entities.NaicsState_NAICS_ACTIVE,
490 TransmissionModes: "xxx",
492 PAList: []entities.PA{entities.PA_DB_NEG_3},
495 return &cellLoadInformation
498 func generateRanLoadInformation() *entities.RanLoadInformation {
499 ranLoadInformation := entities.RanLoadInformation{}
501 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
503 cellLoadInformation := generateCellLoadInformation()
504 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
506 return &ranLoadInformation
509 func TestSaveNilEntityFailure(t *testing.T) {
511 initSdlInstanceMock(namespace, 1)
513 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
514 nbIdentity := &entities.NbIdentity{}
515 actualErr := w.SaveNodeb(nbIdentity, nil)
516 assert.Equal(t, expectedErr, actualErr)
519 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
521 initSdlInstanceMock(namespace, 1)
523 expectedErr := common.NewValidationError(errors.New("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 "))
524 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
525 nb := &entities.NodebInfo{}
528 actualErr := w.SaveNodeb(nbIdentity, nb)
529 assert.Equal(t, expectedErr, actualErr)
532 func TestSaveEntityFailure(t *testing.T) {
538 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
540 gnb := entities.NodebInfo{}
541 gnb.NodeType = entities.Node_GNB
542 data, err := proto.Marshal(&gnb)
544 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
546 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
547 setExpected := []interface{}{"RAN:" + name, data}
548 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
549 expectedErr := errors.New("expected error")
550 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
551 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
552 assert.NotEmpty(t, rNibErr)
555 func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) {
557 assert.Panics(t, func() { GetRNibWriter() })
560 func TestGetRNibWriter(t *testing.T) {
562 initSdlInstanceMock(namespace, 1)
563 received := GetRNibWriter()
564 assert.NotEmpty(t, received)
565 available, created := writerPool.Stats()
566 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
567 assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
571 func TestClose(t *testing.T) {
573 instanceMock := initSdlInstanceMock(namespace, 2)
574 w1 := GetRNibWriter()
575 w2 := GetRNibWriter()
578 available, created := writerPool.Stats()
579 assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2")
580 assert.Equal(t, 2, created, "number of created objects in the writerPool should be 2")
582 instanceMock.On("Close").Return(e)
584 available, created = writerPool.Stats()
585 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
586 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
589 func TestCloseOnClosedPoolFailure(t *testing.T) {
591 instanceMock := initSdlInstanceMock(namespace, 1)
592 w1 := GetRNibWriter()
594 available, created := writerPool.Stats()
595 assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
596 assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
598 instanceMock.On("Close").Return(e)
600 assert.Panics(t, func() { Close() })
603 func TestCloseFailure(t *testing.T) {
605 instanceMock := initSdlInstanceMock(namespace, 2)
606 w1 := GetRNibWriter()
608 available, created := writerPool.Stats()
609 assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
610 assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
611 e := errors.New("expected error")
612 instanceMock.On("Close").Return(e)
614 available, created = writerPool.Stats()
615 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
616 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
619 func TestInit(t *testing.T) {
622 assert.NotNil(t, writerPool)
623 assert.NotNil(t, writerPool.New)
624 assert.NotNil(t, writerPool.Destroy)
625 available, created := writerPool.Stats()
626 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
627 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
632 //func TestSaveEnbGnbInteg(t *testing.T){
633 // for i := 0; i<10; i++{
634 // Init("e2Manager", 1)
635 // w := GetRNibWriter()
636 // nb := entities.NodebInfo{}
637 // nb.NodeType = entities.Node_ENB
638 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
639 // nb.Ip = "localhost"
640 // nb.Port = uint32(5656 + i)
641 // enb := entities.Enb{}
642 // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
643 // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
644 // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
645 // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
646 // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
647 // plmnId := 0x02f828
648 // nbId := 0x4a952a0a
649 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
650 // err := w.SaveNodeb(nbIdentity, &nb)
652 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
655 // nb1 := entities.NodebInfo{}
656 // nb1.NodeType = entities.Node_GNB
657 // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
658 // nb1.Ip = "localhost"
659 // nb1.Port = uint32(6565 + i)
660 // gnb := entities.Gnb{}
661 // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
662 // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
663 // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
664 // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
665 // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
666 // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
667 // err = w.SaveNodeb(nbIdentity, &nb1)
669 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
674 //func TestSaveNbRanNamesInteg(t *testing.T){
675 // for i := 0; i<10; i++{
676 // Init("e2Manager", 1)
677 // w := GetRNibWriter()
678 // nb := entities.NodebInfo{}
679 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
680 // nb.Ip = "localhost"
681 // nb.Port = uint32(5656 + i)
682 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
683 // err := w.SaveNodeb(nbIdentity, &nb)
685 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
690 //func TestSaveRanLoadInformationInteg(t *testing.T){
691 // Init("e2Manager", 1)
692 // w := GetRNibWriter()
693 // ranLoadInformation := generateRanLoadInformation()
694 // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
696 // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)