+++ /dev/null
-//
-// Copyright 2019 AT&T Intellectual Property
-// Copyright 2019 Nokia
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package common
-
-import (
- "github.com/stretchr/testify/assert"
- "sync"
- "sync/atomic"
- "testing"
- "time"
-)
-
-var max int32
-var counter int32
-var poolGlob *Pool
-type instance struct{}
-
-func(instance) up(){
- tmpc := atomic.AddInt32(&counter, 1)
- swapped:= false
- for !swapped {
- tmpm := atomic.LoadInt32(&max)
- if tmpc >tmpm {
- swapped = atomic.CompareAndSwapInt32(&max, tmpm, tmpc)
- } else {
- break
- }
- }
-}
-
-func(instance) down(){
- atomic.AddInt32(&counter, - 1)
-}
-
-func TestPoolMax(t *testing.T){
- counter = 0
- max = 0
- validateMaxLimit(1, 1, t)
- counter = 0
- max = 0
- validateMaxLimit(1, 2, t)
- counter = 0
- max = 0
- validateMaxLimit(5, 10, t)
-}
-
-func validateMaxLimit(size int, iterations int, t *testing.T) {
- poolGlob = NewPool(size, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- group := sync.WaitGroup{}
- for i := 0; i < iterations; i++ {
- group.Add(1)
- go func() {
- getPutInstance()
- group.Done()
- }()
- }
- time.Sleep(time.Second)
- group.Wait()
- assert.Equal(t, int32(size), max)
-}
-
-func getPutInstance() {
- inst := poolGlob.Get().(instance)
- inst.up()
- time.Sleep(time.Millisecond*10)
- inst.down()
- poolGlob.Put(inst)
-}
-
-func TestNewPool(t *testing.T){
- size := 5
- pool := NewPool(size, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- assert.NotNil(t, pool)
- assert.NotNil(t, pool.New)
- assert.NotNil(t, pool.Destroy)
- assert.NotNil(t, pool.pool)
- assert.Equal(t, cap(pool.pool), size, "the capacity of the pool should be " + string(size))
-}
-
-func TestGetCreated(t *testing.T) {
- pool := NewPool(1, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- pool.Get()
- available, created := pool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the pool should be 0")
- assert.Equal(t, 1, created, "number of created objects in the pool should be 1")
- pool.Close()
-}
-
-func TestGetAndPut(t *testing.T) {
- pool := NewPool(1, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- pool.Put(pool.Get())
- available, created := pool.Stats()
- assert.Equal(t, 1, available, "number of available objects in the pool should be 1")
- assert.Equal(t, 1, created, "number of created objects in the pool should be 1")
- pool.Close()
-}
-
-func TestPutOutOfCapacity(t *testing.T) {
- pool := NewPool(1, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- pool.Put(pool.Get())
- pool.Put(new(instance))
- available, created := pool.Stats()
- assert.Equal(t, 1, available, "number of available objects in the pool should be 1")
- assert.Equal(t, 1, created, "number of created objects in the pool should be 1")
- pool.Close()
-}
-
-func TestNotInitializedPut(t *testing.T) {
- var poolEmpty Pool
- poolEmpty.Put(new(instance))
- available, created := poolEmpty.Stats()
- assert.Equal(t, 0, available, "number of available objects in the pool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the pool should be 0")
-}
-
-func TestPutNilObject(t *testing.T) {
- var poolEmpty Pool
- poolEmpty.Put(nil)
- available, created := poolEmpty.Stats()
- assert.Equal(t, 0, available, "number of available objects in the pool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the pool should be 0")
-}
-
-func TestGet(t *testing.T) {
- pool := NewPool(2, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- i1 := pool.Get()
- i2 := pool.Get()
- available, created := pool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the pool should be 0")
- assert.Equal(t, 2, created, "number of created objects in the pool should be 2")
- pool.Put(i1)
- pool.Put(i2)
- pool.Put(new(instance))
- available, created = pool.Stats()
- assert.Equal(t, 2, available, "number of available objects in the pool should be 2")
- assert.Equal(t, 2, created, "number of created objects in the pool should be 2")
-}
-
-func TestClose(t *testing.T) {
- pool := NewPool(3, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- i1 := pool.Get()
- i2 := pool.Get()
- i3 := pool.Get()
- available, created := pool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the pool should be 0")
- assert.Equal(t, 3, created, "number of created objects in the pool should be 3")
- pool.Put(i1)
- pool.Put(i2)
- pool.Put(i3)
- available, created = pool.Stats()
- assert.Equal(t, 3, available, "number of available objects in the pool should be 3")
- assert.Equal(t, 3, created, "number of created objects in the pool should be 3")
- pool.Close()
- i := pool.Get()
- assert.Nil(t, i)
- available, created = pool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the pool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the pool should be 0")
-}
-
-func TestPoolPutPanicsOnClosedChannel(t *testing.T){
- pool := NewPool(1, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- close(pool.pool)
- assert.Panics(t, func(){pool.Put(instance{})})
-}
-
-func TestPoolClosePanicsOnClosedChannel(t *testing.T) {
- pool := NewPool(1, func() interface{} {
- inst := instance{}
- return inst
- },
- func(obj interface{}) {
- },
- )
- close(pool.pool)
- assert.Panics(t, func(){pool.Close()})
-}
import (
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
- "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
"github.com/golang/protobuf/proto"
"reflect"
)
-var readerPool *common.Pool
-
type rNibReaderInstance struct {
- sdl *common.ISdlInstance
- namespace string
+ sdl common.ISdlInstance
}
/*
// GetCellById retrieves the cell entity from redis DB by cell type and cell Id
GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, error)
// GetListNodebIds returns the full list of Nodeb identity entities
- GetListNodebIds()([]*entities.NbIdentity, error)
+ GetListNodebIds() ([]*entities.NbIdentity, error)
// GetRanLoadInformation retrieves nodeb load information entity from redis DB by nodeb inventory name
GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, error)
}
-/*
- Init initializes the infrastructure required for the RNibReader instance
-*/
-func Init(namespace string, poolSize int) {
- initPool(poolSize,
- func() interface{} {
- var sdlI common.ISdlInstance = sdlgo.NewSdlInstance(namespace, sdlgo.NewDatabase())
- return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
- },
- func(obj interface{}) {
- i, ok := obj.(*rNibReaderInstance)
- if ok{
- (*i.sdl).Close()
- }
- })
-}
-
-func initPool(poolSize int, newObj func() interface{}, destroyObj func(interface{})) {
- readerPool = common.NewPool(poolSize, newObj, destroyObj)
-}
-
/*
GetRNibReader returns reference to RNibReader
*/
-func GetRNibReader() RNibReader {
- return &rNibReaderInstance{}
+func GetRNibReader(sdl common.ISdlInstance) RNibReader {
+ return &rNibReaderInstance{sdl: sdl}
}
-
-func (*rNibReaderInstance) GetNodeb(inventoryName string) (*entities.NodebInfo, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
+func (w *rNibReaderInstance) GetNodeb(inventoryName string) (*entities.NodebInfo, error) {
key, rNibErr := common.ValidateAndBuildNodeBNameKey(inventoryName)
if rNibErr != nil {
return nil, rNibErr
}
nbInfo := &entities.NodebInfo{}
err := w.getByKeyAndUnmarshal(key, nbInfo)
- if err!= nil{
+ if err != nil {
return nil, err
}
return nbInfo, nil
}
-func (*rNibReaderInstance) GetNodebByGlobalNbId(nodeType entities.Node_Type, globalNbId *entities.GlobalNbId) (*entities.NodebInfo, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
+func (w *rNibReaderInstance) GetNodebByGlobalNbId(nodeType entities.Node_Type, globalNbId *entities.GlobalNbId) (*entities.NodebInfo, error) {
key, rNibErr := common.ValidateAndBuildNodeBIdKey(nodeType.String(), globalNbId.GetPlmnId(), globalNbId.GetNbId())
if rNibErr != nil {
return nil, rNibErr
}
nbInfo := &entities.NodebInfo{}
err := w.getByKeyAndUnmarshal(key, nbInfo)
- if err!= nil{
+ if err != nil {
return nil, err
}
return nbInfo, nil
cells.List = &entities.Cells_ServedNrCells{ServedNrCells: &entities.ServedNRCellList{ServedCells: nb.GetGnb().GetServedNrCells()}}
return cells, nil
}
- return nil, common.NewResourceNotFoundErrorf("#rNibReader.GetCellList - served cells not found. Responding node RAN name: %s .", inventoryName)
+ return nil, common.NewResourceNotFoundErrorf("#rNibReader.GetCellList - served cells not found. Responding node RAN name: %s.", inventoryName)
}
-func (*rNibReaderInstance) GetListGnbIds() ([]*entities.NbIdentity, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
+func (w *rNibReaderInstance) GetListGnbIds() ([]*entities.NbIdentity, error) {
return w.getListNodebIdsByType(entities.Node_GNB.String())
}
-func (*rNibReaderInstance) GetListEnbIds() ([]*entities.NbIdentity, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
+func (w *rNibReaderInstance) GetListEnbIds() ([]*entities.NbIdentity, error) {
return w.getListNodebIdsByType(entities.Node_ENB.String())
}
-func (*rNibReaderInstance) GetCountGnbList() (int, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
- size, err := (*w.sdl).GroupSize(entities.Node_GNB.String())
+func (w *rNibReaderInstance) GetCountGnbList() (int, error) {
+ size, err := w.sdl.GroupSize(entities.Node_GNB.String())
if err != nil {
return 0, common.NewInternalError(err)
}
return int(size), nil
}
-func (*rNibReaderInstance) GetCell(inventoryName string, pci uint32) (*entities.Cell, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
+func (w *rNibReaderInstance) GetCell(inventoryName string, pci uint32) (*entities.Cell, error) {
key, rNibErr := common.ValidateAndBuildCellNamePciKey(inventoryName, pci)
if rNibErr != nil {
return nil, rNibErr
}
cell := &entities.Cell{}
err := w.getByKeyAndUnmarshal(key, cell)
- if err!= nil{
+ if err != nil {
return nil, err
}
return cell, err
}
-func (*rNibReaderInstance) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, error) {
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
+func (w *rNibReaderInstance) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, error) {
var key string
var rNibErr error
if cellType == entities.Cell_LTE_CELL {
}
cell := &entities.Cell{}
err := w.getByKeyAndUnmarshal(key, cell)
- if err!= nil{
+ if err != nil {
return nil, err
}
return cell, err
}
-func (*rNibReaderInstance) GetListNodebIds()([]*entities.NbIdentity, error){
- w := readerPool.Get().(*rNibReaderInstance)
- defer readerPool.Put(w)
- dataEnb, err := (*w.sdl).GetMembers(entities.Node_ENB.String())
- if err != nil{
+func (w *rNibReaderInstance) GetListNodebIds() ([]*entities.NbIdentity, error) {
+ dataEnb, err := w.sdl.GetMembers(entities.Node_ENB.String())
+ if err != nil {
return nil, common.NewInternalError(err)
}
- dataGnb, err := (*w.sdl).GetMembers(entities.Node_GNB.String())
- if err != nil{
+ dataGnb, err := w.sdl.GetMembers(entities.Node_GNB.String())
+ if err != nil {
return nil, common.NewInternalError(err)
}
- dataUnknown, err := (*w.sdl).GetMembers(entities.Node_UNKNOWN.String())
- if err != nil{
+ dataUnknown, err := w.sdl.GetMembers(entities.Node_UNKNOWN.String())
+ if err != nil {
return nil, common.NewInternalError(err)
}
allIds := append(dataEnb, dataGnb...)
return data, rnibErr
}
-func (*rNibReaderInstance) GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, error){
- w := readerPool.Get().(*rNibReaderInstance)
+func (w *rNibReaderInstance) GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, error) {
key, rNibErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
if rNibErr != nil {
return nil, rNibErr
}
loadInfo := &entities.RanLoadInformation{}
err := w.getByKeyAndUnmarshal(key, loadInfo)
- if err!= nil{
+ if err != nil {
return nil, err
}
return loadInfo, err
}
-func (w *rNibReaderInstance) getByKeyAndUnmarshal(key string, entity proto.Message)error{
- data, err := (*w.sdl).Get([]string{key})
+func (w *rNibReaderInstance) getByKeyAndUnmarshal(key string, entity proto.Message) error {
+ data, err := w.sdl.Get([]string{key})
if err != nil {
return common.NewInternalError(err)
}
}
func (w *rNibReaderInstance) getListNodebIdsByType(nbType string) ([]*entities.NbIdentity, error) {
- data, err := (*w.sdl).GetMembers(nbType)
+ data, err := w.sdl.GetMembers(nbType)
if err != nil {
return nil, common.NewInternalError(err)
}
return members, nil
}
+//Close the reader
func Close() {
- readerPool.Close()
-}
\ No newline at end of file
+ // Nothing to do
+}
var namespace = "namespace"
-func TestInit(t *testing.T) {
- readerPool = nil
- Init("", 1)
- assert.NotNil(t, readerPool)
- assert.NotNil(t, readerPool.New)
- assert.NotNil(t, readerPool.Destroy)
- available, created := readerPool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
-}
-
-func TestInitPool(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := new(MockSdlInstance)
- initPool(1, func() interface{} {
- sdlI := common.ISdlInstance(sdlInstanceMock)
- return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
- },
- func(obj interface{}) {
- },
- )
- assert.NotNil(t, readerPool)
- assert.NotNil(t, readerPool.New)
- assert.NotNil(t, readerPool.Destroy)
- available, created := readerPool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
-}
-
-func initSdlInstanceMock(namespace string, poolSize int) *MockSdlInstance {
- sdlInstanceMock := new(MockSdlInstance)
- initPool(poolSize, func() interface{} {
- sdlI := common.ISdlInstance(sdlInstanceMock)
- return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
- },
- func(obj interface{}) {
- },
- )
- return sdlInstanceMock
+func initSdlInstanceMock(namespace string) (w RNibReader, sdlInstanceMock *MockSdlInstance) {
+ sdlInstanceMock = new(MockSdlInstance)
+ w = GetRNibReader(sdlInstanceMock)
+ return
}
func TestGetNodeB(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
func TestGetNodeBNotFoundFailure(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
func TestGetNodeBUnmarshalFailure(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
ret := make(map[string]interface{}, 1)
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
name := "name"
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
e := errors.New(errMsg)
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
func TestGetNodeBCellsListEnb(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
func TestGetNodeBCellsListGnb(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
func TestGetNodeBCellsListNodeUnmarshalFailure(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
ret := make(map[string]interface{}, 1)
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
func TestGetNodeBCellsListNodeNotFoundFailure(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
func TestGetNodeBCellsListNotFoundFailureEnb(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
func TestGetNodeBCellsListNotFoundFailureGnb(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
assert.EqualValues(t, "#rNibReader.GetCellList - served cells not found. Responding node RAN name: name.", er.Error())
}
-func TestCloseOnClosedPoolFailure(t *testing.T) {
- readerPool = nil
- instanceMock := initSdlInstanceMock(namespace, 1)
- w1 := GetRNibReader()
- _, err := w1.GetNodeb("")
- if err == nil{
- t.Errorf("#rNibReader_test.TestCloseOnClosedPoolFailure - failed to validate key parameter")
- }
- readerPool.Put(w1)
- available, created := readerPool.Stats()
- assert.Equal(t, 1, available, "number of available objects in the readerPool should be 1")
- assert.Equal(t, 1, created, "number of created objects in the readerPool should be 1")
- var e error
- instanceMock.On("Close").Return(e)
- Close()
- assert.Panics(t, func() { Close() })
-}
-
-func TestCloseFailure(t *testing.T) {
- readerPool = nil
- instanceMock := initSdlInstanceMock(namespace, 2)
- w1 := GetRNibReader()
- _, err := w1.GetNodeb("")
- if err == nil{
- t.Errorf("#rNibReader_test.TestCloseFailure - failed to validate key parameter")
- }
- available, created := readerPool.Stats()
- assert.Equal(t, 1, available, "number of available objects in the readerPool should be 2")
- assert.Equal(t, 1, created, "number of created objects in the readerPool should be 1")
- e := errors.New("expected error")
- instanceMock.On("Close").Return(e)
- Close()
- available, created = readerPool.Stats()
- assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
- assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
-}
-
func TestGetListGnbIdsUnmarshalFailure(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{"data"}, e)
ids, er := w.GetListGnbIds()
func TestGetListGnbIdsSdlgoFailure(t *testing.T) {
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
e := errors.New(errMsg)
var data []string
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return(data, e)
}
func TestGetListNodesIdsGnbSdlgoFailure(t *testing.T) {
-
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
name := "name"
plmnId := "02f829"
}
func TestGetListNodesIdsEnbSdlgoFailure(t *testing.T) {
-
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
name := "name"
plmnId := "02f829"
}
func TestGetListNodesIdsSuccess(t *testing.T) {
-
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var nilError error
name := "name"
}
func TestGetListEnbIdsUnmarshalFailure(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{"data"}, e)
ids, er := w.GetListEnbIds()
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
var e error
data, err := proto.Marshal(nbIdentity)
}
func TestGetListEnbIdsNoIds(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{}, e)
ids, er := w.GetListEnbIds()
plmnId := 0x02f829
nbId := 0x4a952a0a
listSize := 3
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
idsData := make([]string, listSize)
idsEntities := make([]*entities.NbIdentity, listSize)
for i := 0; i < listSize; i++ {
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
var e error
data, err := proto.Marshal(nbIdentity)
}
func TestGetListGnbIdsNoIds(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{}, e)
ids, er := w.GetListGnbIds()
plmnId := 0x02f829
nbId := 0x4a952a0a
listSize := 3
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
idsData := make([]string, listSize)
idsEntities := make([]*entities.NbIdentity, listSize)
for i := 0; i < listSize; i++ {
func TestGetListEnbIdsSdlgoFailure(t *testing.T) {
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
e := errors.New(errMsg)
var data []string
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return(data, e)
}
func TestGetCountGnbListOneId(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
sdlInstanceMock.On("GroupSize", entities.Node_GNB.String()).Return(1, e)
count, er := w.GetCountGnbList()
}
func TestGetCountGnbList(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
sdlInstanceMock.On("GroupSize", entities.Node_GNB.String()).Return(3, e)
count, er := w.GetCountGnbList()
func TestGetCountGnbListSdlgoFailure(t *testing.T) {
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
e := errors.New(errMsg)
var count int
sdlInstanceMock.On("GroupSize", entities.Node_GNB.String()).Return(count, e)
func TestGetCell(t *testing.T) {
name := "name"
var pci uint32 = 10
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: &entities.ServedCellInfo{Pci: pci}}}
cellData, err := proto.Marshal(&cellEntity)
if err != nil {
func TestGetCellNotFoundFailure(t *testing.T) {
name := "name"
var pci uint32
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
func TestGetCellUnmarshalFailure(t *testing.T) {
name := "name"
var pci uint32
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
ret := make(map[string]interface{}, 1)
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
var pci uint32
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
e := errors.New(errMsg)
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
}
func TestGetNodebById(t *testing.T) {
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
nb := entities.NodebInfo{NodeType: entities.Node_ENB}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
func TestGetNodebByIdNotFoundFailureEnb(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
if rNibErr != nil {
func TestGetNodebByIdNotFoundFailureGnb(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_GNB.String(), plmnId, nbId)
if rNibErr != nil {
func TestGetNodeByIdUnmarshalFailure(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
nbId := "4a952a0a"
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_GNB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
func TestGetCellById(t *testing.T) {
cellId := "aaaa"
var pci uint32 = 10
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: &entities.ServedCellInfo{Pci: pci}}}
cellData, err := proto.Marshal(&cellEntity)
if err != nil {
func TestGetCellByIdNotFoundFailureEnb(t *testing.T) {
cellId := "bbbb"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildCellIdKey(cellId)
func TestGetCellByIdNotFoundFailureGnb(t *testing.T) {
cellId := "bbbb"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildNrCellIdKey(cellId)
func TestGetCellByIdTypeValidationFailure(t *testing.T) {
cellId := "dddd"
- readerPool = nil
- initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, _ := initSdlInstanceMock(namespace)
cell, er := w.GetCellById(5, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
func TestGetCellByIdValidationFailureGnb(t *testing.T) {
cellId := ""
- readerPool = nil
- initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, _ := initSdlInstanceMock(namespace)
cell, er := w.GetCellById(entities.Cell_NR_CELL, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
func TestGetCellByIdValidationFailureEnb(t *testing.T) {
cellId := ""
- readerPool = nil
- initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, _ := initSdlInstanceMock(namespace)
cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
func TestGetRanLoadInformation(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
loadInfo := generateRanLoadInformation()
var e error
data, err := proto.Marshal(loadInfo)
func TestGetRanLoadInformationValidationFailure(t *testing.T) {
name := ""
- readerPool = nil
- initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, _ := initSdlInstanceMock(namespace)
getNb, er := w.GetRanLoadInformation(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
func TestGetRanLoadInformationNotFoundFailure(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
func TestGetRanLoadInformationUnmarshalFailure(t *testing.T) {
name := "name"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
var e error
ret := make(map[string]interface{}, 1)
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
name := "name"
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
- readerPool = nil
- sdlInstanceMock := initSdlInstanceMock(namespace, 1)
- w := GetRNibReader()
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
e := errors.New(errMsg)
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
- TargetCellId:"456",
- UlHighInterferenceIndication:"xxx",
+ TargetCellId: "456",
+ UlHighInterferenceIndication: "xxx",
}
- cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation }
+ cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
- RntpPerPrb:"xxx",
- RntpThreshold:entities.RntpThreshold_NEG_4,
+ RntpPerPrb: "xxx",
+ RntpThreshold: entities.RntpThreshold_NEG_4,
NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
- PB: 1,
- PdcchInterferenceImpact:2,
+ PB: 1,
+ PdcchInterferenceImpact: 2,
EnhancedRntp: &entities.EnhancedRntp{
- EnhancedRntpBitmap:"xxx",
- RntpHighPowerThreshold:entities.RntpThreshold_NEG_2,
- EnhancedRntpStartTime: &entities.StartTime{StartSfn:500,StartSubframeNumber:5},
+ EnhancedRntpBitmap: "xxx",
+ RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
+ EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
},
}
cellLoadInformation.AbsInformation = &entities.AbsInformation{
- Mode: entities.AbsInformationMode_ABS_INFO_FDD,
- AbsPatternInfo:"xxx",
- NumberOfCellSpecificAntennaPorts:entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
- MeasurementSubset:"xxx",
+ Mode: entities.AbsInformationMode_ABS_INFO_FDD,
+ AbsPatternInfo: "xxx",
+ NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
+ MeasurementSubset: "xxx",
}
cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
- AssociatedSubframes:"xxx",
- ExtendedUlInterferenceOverloadIndications:cellLoadInformation.UlInterferenceOverloadIndications,
+ AssociatedSubframes: "xxx",
+ ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
}
compInformationItem := &entities.CompInformationItem{
CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
- BenefitMetric:50,
+ BenefitMetric: 50,
}
cellLoadInformation.CompInformation = &entities.CompInformation{
- CompInformationItems:[]*entities.CompInformationItem{compInformationItem},
- CompInformationStartTime:&entities.StartTime{StartSfn:123,StartSubframeNumber:456},
+ CompInformationItems: []*entities.CompInformationItem{compInformationItem},
+ CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
}
cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
- State: entities.NaicsState_NAICS_ACTIVE,
- TransmissionModes:"xxx",
- PB: 2,
- PAList:[]entities.PA{entities.PA_DB_NEG_3},
+ State: entities.NaicsState_NAICS_ACTIVE,
+ TransmissionModes: "xxx",
+ PB: 2,
+ PAList: []entities.PA{entities.PA_DB_NEG_3},
}
return &cellLoadInformation
// }
// assert.NotNil(t, ranLoadInformation)
// fmt.Printf("#rNibReader_test.TestGetRanLoadInformationInteg - GNB ID: %s\n", ranLoadInformation)
-//}
\ No newline at end of file
+//}