Skip to content

Commit

Permalink
Updated internalDB integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trial97 committed Jun 29, 2020
1 parent 2e38389 commit f4fe295
Show file tree
Hide file tree
Showing 53 changed files with 952 additions and 1,067 deletions.
27 changes: 18 additions & 9 deletions apier/v1/apier.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func (apiv1 *APIerSv1) LoadDestination(attrs *AttrLoadDestination, reply *string
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone, apiv1.Config.ApierCfg().CachesConns,
apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down Expand Up @@ -251,7 +252,8 @@ func (apiv1 *APIerSv1) LoadRatingPlan(attrs *AttrLoadRatingPlan, reply *string)
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand All @@ -271,7 +273,8 @@ func (apiv1 *APIerSv1) LoadRatingProfile(attrs *utils.TPRatingProfile, reply *st
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand All @@ -294,7 +297,8 @@ func (apiv1 *APIerSv1) LoadSharedGroup(attrs *AttrLoadSharedGroup, reply *string
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand All @@ -320,7 +324,8 @@ func (apiv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb, rep
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down Expand Up @@ -887,7 +892,8 @@ func (apiv1 *APIerSv1) LoadAccountActions(attrs *utils.TPAccountActions, reply *
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down Expand Up @@ -925,7 +931,8 @@ func (apiv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
loader, err := engine.NewTpReader(apiv1.DataManager.DataDB(),
engine.NewFileCSVStorage(utils.CSV_SEP, attrs.FolderPath),
"", apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down Expand Up @@ -990,7 +997,8 @@ func (apiv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder, rep
// create the TpReader
loader, err := engine.NewTpReader(apiv1.DataManager.DataDB(),
engine.NewFileCSVStorage(utils.CSV_SEP, attrs.FolderPath), "", apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down Expand Up @@ -1043,7 +1051,8 @@ func (apiv1 *APIerSv1) RemoveTPFromStorDB(attrs *AttrLoadTpFromStorDb, reply *st
}
dbReader, err := engine.NewTpReader(apiv1.DataManager.DataDB(), apiv1.StorDb,
attrs.TPid, apiv1.Config.GeneralCfg().DefaultTimezone,
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns)
apiv1.Config.ApierCfg().CachesConns, apiv1.Config.ApierCfg().SchedulerConns,
apiv1.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down
3 changes: 3 additions & 0 deletions apier/v1/attributes_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,9 @@ func testAttributeSRemAlsPrf(t *testing.T) {
} else if resp != utils.OK {
t.Error("Unexpected reply returned", resp)
}
if alsPrfConfigDIR == "tutinternal" { // do not double remove the profile
return
}
var reply *engine.AttributeProfile
if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}},
Expand Down
6 changes: 3 additions & 3 deletions apier/v1/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ func (APIerSv1 *APIerSv1) GetDispatcherHost(arg *utils.TenantID, reply *engine.D
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if dpp, err := APIerSv1.DataManager.GetDispatcherHost(arg.Tenant, arg.ID, true, false, utils.NonTransactional); err != nil {
dpp, err := APIerSv1.DataManager.GetDispatcherHost(arg.Tenant, arg.ID, true, false, utils.NonTransactional)
if err != nil {
return utils.APIErrorHandler(err)
} else {
*reply = *dpp
}
*reply = *dpp
return nil
}

Expand Down
9 changes: 6 additions & 3 deletions apier/v1/dispatcher_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ func testDispatcherSSetDispatcherHost(t *testing.T) {
Tenant: "cgrates.org",
ID: "DspHst1",
Conns: []*config.RemoteHost{
&config.RemoteHost{
{
Address: "*internal",
},
&config.RemoteHost{
{
Address: ":2012",
Transport: utils.MetaJSON,
TLS: true,
Expand Down Expand Up @@ -322,11 +322,14 @@ func testDispatcherSUpdateDispatcherHost(t *testing.T) {
}

func testDispatcherSGetDispatcherHostCache(t *testing.T) {
if dispatcherConfigDIR == "tutinternal" {
t.SkipNow()
}
var rcvStats map[string]*ltcache.CacheStats
if err := dispatcherRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithArgDispatcher{}, &rcvStats); err != nil {
t.Error(err)
} else if rcvStats[utils.CacheDispatcherHosts].Items != 0 {
t.Errorf("Expecting: 0 DispatcherProfiles, received: %+v", rcvStats[utils.CacheDispatcherProfiles])
t.Errorf("Expecting: 0 DispatcherProfiles, received: %+v", rcvStats[utils.CacheDispatcherHosts])
}
}

Expand Down
43 changes: 34 additions & 9 deletions apier/v1/precache_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,40 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
Items: 7,
Groups: 0,
},
utils.CacheTimings: {},
utils.CacheDiameterMessages: {},
utils.CacheClosedSessions: {},
utils.CacheLoadIDs: {},
utils.CacheRPCConnections: {},
utils.CacheCDRIDs: {},
utils.CacheRatingProfilesTmp: {},
utils.CacheUCH: {},
utils.CacheReverseFilterIndexes: {},
utils.CacheTimings: {},
utils.CacheDiameterMessages: {},
utils.CacheClosedSessions: {},
utils.CacheLoadIDs: {},
utils.CacheRPCConnections: {},
utils.CacheCDRIDs: {},
utils.CacheRatingProfilesTmp: {},
utils.CacheUCH: {},
utils.CacheReverseFilterIndexes: {},
utils.CacheAccounts: {},
utils.CacheVersions: {},
utils.CacheTBLTPTimings: {},
utils.CacheTBLTPDestinations: {},
utils.CacheTBLTPRates: {},
utils.CacheTBLTPDestinationRates: {},
utils.CacheTBLTPRatingPlans: {},
utils.CacheTBLTPRatingProfiles: {},
utils.CacheTBLTPSharedGroups: {},
utils.CacheTBLTPActions: {},
utils.CacheTBLTPActionPlans: {},
utils.CacheTBLTPActionTriggers: {},
utils.CacheTBLTPAccountActions: {},
utils.CacheTBLTPResources: {},
utils.CacheTBLTPStats: {},
utils.CacheTBLTPThresholds: {},
utils.CacheTBLTPFilters: {},
utils.CacheSessionCostsTBL: {},
utils.CacheCDRsTBL: {},
utils.CacheTBLTPRoutes: {},
utils.CacheTBLTPAttributes: {},
utils.CacheTBLTPChargers: {},
utils.CacheTBLTPDispatchers: {},
utils.CacheTBLTPDispatcherHosts: {},
utils.CacheTBLTPRateProfiles: {},
}
if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil {
t.Error(err.Error())
Expand Down
9 changes: 6 additions & 3 deletions apier/v1/resourcesv1_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func testV1RsDBStore(t *testing.T) {
func testV1RsGetResourceProfileBeforeSet(t *testing.T) {
var reply *string
if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
&utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"},
&utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"},
&reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
Expand Down Expand Up @@ -656,10 +656,13 @@ func testV1RsSetResourceProfile(t *testing.T) {

func testV1RsGetResourceProfileIDs(t *testing.T) {
expected := []string{"ResGroup2", "ResGroup1", "ResGroup3", "RES_GR_TEST"}
sort.Strings(expected)
var result []string
if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &result); err != nil {
t.Error(err)
} else if len(expected) != len(result) {
}
sort.Strings(result)
if !reflect.DeepEqual(expected, result) {
t.Errorf("Expecting : %+v, received: %+v", expected, result)
}
}
Expand Down Expand Up @@ -715,7 +718,7 @@ func testV1RsRemResourceProfile(t *testing.T) {
func testV1RsGetResourceProfileAfterDelete(t *testing.T) {
var reply *string
if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
&utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"},
&utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"},
&reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
Expand Down
9 changes: 6 additions & 3 deletions apier/v2/apier.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func (apiv2 *APIerSv2) LoadRatingProfile(attrs *AttrLoadRatingProfile, reply *st
}
dbReader, err := engine.NewTpReader(apiv2.DataManager.DataDB(), apiv2.StorDb,
attrs.TPid, apiv2.Config.GeneralCfg().DefaultTimezone,
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().SchedulerConns)
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().SchedulerConns,
apiv2.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand All @@ -79,7 +80,8 @@ func (apiv2 *APIerSv2) LoadAccountActions(attrs *AttrLoadAccountActions, reply *
}
dbReader, err := engine.NewTpReader(apiv2.DataManager.DataDB(), apiv2.StorDb,
attrs.TPid, apiv2.Config.GeneralCfg().DefaultTimezone,
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().SchedulerConns)
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().SchedulerConns,
apiv2.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down Expand Up @@ -112,7 +114,8 @@ func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
}
loader, err := engine.NewTpReader(apiv2.DataManager.DataDB(),
engine.NewFileCSVStorage(utils.CSV_SEP, attrs.FolderPath), "", apiv2.Config.GeneralCfg().DefaultTimezone,
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().SchedulerConns)
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().SchedulerConns,
apiv2.Config.DataDbCfg().DataDbType == utils.INTERNAL)
if err != nil {
return utils.NewErrServerError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cgr-loader/cgr-loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func main() {
if tpReader, err = engine.NewTpReader(dataDB, loader,
ldrCfg.LoaderCgrCfg().TpID, ldrCfg.GeneralCfg().DefaultTimezone,
ldrCfg.LoaderCgrCfg().CachesConns,
ldrCfg.LoaderCgrCfg().SchedulerConns); err != nil {
ldrCfg.LoaderCgrCfg().SchedulerConns, false); err != nil {
log.Fatal(err)
}
if err = tpReader.LoadAll(); err != nil {
Expand Down
Loading

0 comments on commit f4fe295

Please sign in to comment.