diff --git a/services/freeswitchagent_test.go b/services/freeswitchagent_test.go
index 5e568ea85..bfe268f21 100644
--- a/services/freeswitchagent_test.go
+++ b/services/freeswitchagent_test.go
@@ -1 +1,85 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "runtime"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestFreeSwitchAgentCoverage for cover testing
+func TestFreeSwitchAgentCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ cfg.SessionSCfg().Enabled = true
+ cfg.SessionSCfg().ListenBijson = ""
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ cacheSChan := make(chan rpcclient.ClientConnector, 1)
+ cacheSChan <- chS
+
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1),
+ shdChan, nil, nil, anz, srvDep)
+ srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(srv, sS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Fatal(err)
+ }
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "fs_evsock", "cgrates", "etc", "cgrates"),
+ Section: config.FreeSWITCHAgentJSN,
+ }, &reply); err != nil {
+ t.Fatal(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ // the engine should be stoped as we could not connect to freeswich
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ runtime.Gosched()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/httpagent_test.go b/services/httpagent_test.go
index 73374d286..b1c7b20ba 100644
--- a/services/httpagent_test.go
+++ b/services/httpagent_test.go
@@ -1,5 +1,3 @@
-// +build integration
-
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
diff --git a/services/kamailioagent_test.go b/services/kamailioagent_test.go
index 5e568ea85..f6093c5bc 100644
--- a/services/kamailioagent_test.go
+++ b/services/kamailioagent_test.go
@@ -1 +1,86 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "runtime"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestKamailioAgentCoverage for cover testing
+func TestKamailioAgentCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ cfg.SessionSCfg().Enabled = true
+ cfg.SessionSCfg().ListenBijson = ""
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+
+ cacheSChan := make(chan rpcclient.ClientConnector, 1)
+ cacheSChan <- chS
+
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1),
+ shdChan, nil, nil, anz, srvDep)
+ srv := NewKamailioAgent(cfg, shdChan, nil, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(srv, sS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Fatal(err)
+ }
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "kamevapi", "cgrates", "etc", "cgrates"),
+ Section: config.KamailioAgentJSN,
+ }, &reply); err != nil {
+ t.Fatal(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ runtime.Gosched()
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ // the engine should be stoped as we could not connect to kamailio
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/loaders_test.go b/services/loaders_test.go
index 5e568ea85..213c96299 100644
--- a/services/loaders_test.go
+++ b/services/loaders_test.go
@@ -1 +1,72 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "reflect"
+ "sync"
+ "testing"
+
+ "github.com/cgrates/cgrates/loaders"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestLoaderSCoverage for cover testing
+func TestLoaderSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+ shdChan := utils.NewSyncedChan()
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ server := cores.NewServer(nil)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ internalLoaderSChan := make(chan rpcclient.ClientConnector, 1)
+ rpcInternal := map[string]chan rpcclient.ClientConnector{}
+ cM := engine.NewConnManager(cfg, rpcInternal)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ srv := NewLoaderService(cfg, db,
+ filterSChan, server, internalLoaderSChan,
+ cM, anz, srvDep)
+ if srv == nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(srv))
+ }
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ srv.ldrs = loaders.NewLoaderService(&engine.DataManager{}, []*config.LoaderSCfg{{
+ ID: "test_id",
+ Enabled: true,
+ }},
+ "test", &engine.FilterS{}, &engine.ConnManager{})
+ if !srv.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !reflect.DeepEqual(srv.GetLoaderS(), srv.ldrs) {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", srv.ldrs, srv.GetLoaderS())
+ }
+ errStart := srv.Start()
+ if errStart == nil || errStart != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, errStart)
+ }
+
+}
diff --git a/services/radiusagent_test.go b/services/radiusagent_test.go
index 5e568ea85..1a1492d3a 100644
--- a/services/radiusagent_test.go
+++ b/services/radiusagent_test.go
@@ -1 +1,96 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestLoaderSCoverage for cover testing
+func TestRadiusAgentCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ cfg.SessionSCfg().Enabled = true
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+
+ cacheSChan := make(chan rpcclient.ClientConnector, 1)
+ cacheSChan <- chS
+
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1),
+ shdChan, nil, nil, anz, srvDep)
+ srv := NewRadiusAgent(cfg, filterSChan, shdChan, nil, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(srv, sS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Fatal(err)
+ }
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "radagent_mysql"),
+ Section: config.RA_JSN,
+ }, &reply); err != nil {
+ t.Fatal(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !srv.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := srv.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = srv.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.RadiusAgentCfg().Enabled = false
+ cfg.GetReloadChan(config.RA_JSN) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/rals_test.go b/services/rals_test.go
index 5e568ea85..6d3e9fb61 100644
--- a/services/rals_test.go
+++ b/services/rals_test.go
@@ -1 +1,131 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestRalsCoverage for cover testing
+func TestRalsCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ close(chS.GetPrecacheChannel(utils.CacheThresholdProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheThresholds))
+ close(chS.GetPrecacheChannel(utils.CacheThresholdFilterIndexes))
+
+ close(chS.GetPrecacheChannel(utils.CacheDestinations))
+ close(chS.GetPrecacheChannel(utils.CacheReverseDestinations))
+ close(chS.GetPrecacheChannel(utils.CacheRatingPlans))
+ close(chS.GetPrecacheChannel(utils.CacheRatingProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheActions))
+ close(chS.GetPrecacheChannel(utils.CacheActionPlans))
+ close(chS.GetPrecacheChannel(utils.CacheAccountActionPlans))
+ close(chS.GetPrecacheChannel(utils.CacheActionTriggers))
+ close(chS.GetPrecacheChannel(utils.CacheSharedGroups))
+ close(chS.GetPrecacheChannel(utils.CacheTimings))
+
+ cfg.ThresholdSCfg().Enabled = true
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ cfg.StorDbCfg().Type = utils.INTERNAL
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ stordb := NewStorDBService(cfg, srvDep)
+ schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
+ ralS := NewRalService(cfg, chS, server,
+ make(chan rpcclient.ClientConnector, 1),
+ make(chan rpcclient.ClientConnector, 1),
+ shdChan, nil, anz, srvDep)
+ srvMngr.AddServices(ralS, schS, tS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if ralS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if stordb.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"),
+ Section: config.RALS_JSN,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !ralS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+
+ if resp := ralS.GetResponder(); !resp.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !stordb.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := ralS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = ralS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.RalsCfg().Enabled = false
+ cfg.GetReloadChan(config.RALS_JSN) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if ralS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if resp := ralS.GetResponder(); resp.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/rates_test.go b/services/rates_test.go
index 5e568ea85..4510b5ea7 100644
--- a/services/rates_test.go
+++ b/services/rates_test.go
@@ -1 +1,92 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/rpcclient"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+)
+
+//TestRateSCoverage for cover testing
+func TestRateSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ close(chS.GetPrecacheChannel(utils.CacheRateProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheRateProfilesFilterIndexes))
+ close(chS.GetPrecacheChannel(utils.CacheRateFilterIndexes))
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ rS := NewRateService(cfg, chS, filterSChan, db, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
+ srvMngr.AddServices(rS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if rS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "rates"),
+ Section: config.RateSJson,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !rS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := rS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = rS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.RateSCfg().Enabled = false
+ cfg.GetReloadChan(config.RateSJson) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if rS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/resources_test.go b/services/resources_test.go
index 5e568ea85..2d0850fd6 100644
--- a/services/resources_test.go
+++ b/services/resources_test.go
@@ -1 +1,105 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/rpcclient"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+)
+
+//TestResourceSCoverage for cover testing
+func TestResourceSCoverage(t *testing.T) {
+ // utils.Logger.SetLogLevel(7)
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ cfg.ThresholdSCfg().Enabled = true
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ close(chS.GetPrecacheChannel(utils.CacheThresholdProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheThresholds))
+ close(chS.GetPrecacheChannel(utils.CacheThresholdFilterIndexes))
+ close(chS.GetPrecacheChannel(utils.CacheResourceProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheResources))
+ close(chS.GetPrecacheChannel(utils.CacheResourceFilterIndexes))
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ db := NewDataDBService(cfg, nil, srvDep)
+ tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
+ reS := NewResourceService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(tS, reS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if reS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"),
+ Section: config.RESOURCES_JSON,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !reS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := reS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = reS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.ResourceSCfg().Enabled = false
+ cfg.GetReloadChan(config.RESOURCES_JSON) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if reS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/responders_test.go b/services/responders_test.go
index 5e568ea85..37dff4b19 100644
--- a/services/responders_test.go
+++ b/services/responders_test.go
@@ -1 +1,74 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "reflect"
+ "sync"
+ "testing"
+
+ "github.com/cgrates/cgrates/engine"
+
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+
+ "github.com/cgrates/cgrates/cores"
+
+ "github.com/cgrates/cgrates/config"
+)
+
+//TestResponderCoverage for cover testing
+func TestResponderCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+ server := cores.NewServer(nil)
+ internalChan := make(chan rpcclient.ClientConnector, 1)
+ shdChan := utils.NewSyncedChan()
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ anz := NewAnalyzerService(cfg, server, filterSChan,
+ shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ srv := NewResponderService(cfg, server, internalChan,
+ shdChan, anz, srvDep)
+ if srv == nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(srv))
+ }
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ srv.resp = &engine.Responder{}
+ if !srv.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := srv.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ serviceName := srv.ServiceName()
+ if !reflect.DeepEqual(serviceName, utils.ResponderS) {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ResponderS, serviceName)
+ }
+ getResponder := srv.GetResponder()
+ if !reflect.DeepEqual(getResponder, srv.resp) {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", srv.resp, getResponder)
+ }
+ shouldRun := srv.ShouldRun()
+ if !reflect.DeepEqual(shouldRun, false) {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun)
+ }
+}
diff --git a/services/routes_test.go b/services/routes_test.go
index 5e568ea85..f2cffac57 100644
--- a/services/routes_test.go
+++ b/services/routes_test.go
@@ -1 +1,103 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/rpcclient"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+)
+
+//TestSupplierSCoverage for cover testing
+func TestSupplierSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ cfg.StatSCfg().Enabled = true
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ close(chS.GetPrecacheChannel(utils.CacheRouteProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheRouteFilterIndexes))
+ close(chS.GetPrecacheChannel(utils.CacheStatQueueProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheStatQueues))
+ close(chS.GetPrecacheChannel(utils.CacheStatFilterIndexes))
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ sts := NewStatService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ supS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(supS, sts,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if supS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"),
+ Section: config.RouteSJson,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !supS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := supS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = supS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.RouteSCfg().Enabled = false
+ cfg.GetReloadChan(config.RouteSJson) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if supS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/schedulers_test.go b/services/schedulers_test.go
index 5e568ea85..96b207093 100644
--- a/services/schedulers_test.go
+++ b/services/schedulers_test.go
@@ -1 +1,101 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
package services
+
+import (
+ "path"
+ "reflect"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestSchedulerSCoverage for cover testing
+func TestSchedulerSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ close(chS.GetPrecacheChannel(utils.CacheActionPlans))
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(schS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if schS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"),
+ Section: config.SCHEDULER_JSN,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !schS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := schS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = schS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ getScheduler := schS.GetScheduler()
+ if !reflect.DeepEqual(schS.schS, getScheduler) {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(schS.schS), utils.ToJSON(getScheduler))
+ }
+ cfg.SchedulerCfg().Enabled = false
+ cfg.GetReloadChan(config.SCHEDULER_JSN) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if schS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/sessions_test.go b/services/sessions_test.go
new file mode 100644
index 000000000..1dcaf22d1
--- /dev/null
+++ b/services/sessions_test.go
@@ -0,0 +1,131 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+ "github.com/cgrates/rpcclient"
+)
+
+//TestSessionSCoverage for cover testing
+func TestSessionSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ cfg.ChargerSCfg().Enabled = true
+ cfg.RalsCfg().Enabled = true
+ cfg.CdrsCfg().Enabled = true
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+
+ close(chS.GetPrecacheChannel(utils.CacheChargerProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheChargerFilterIndexes))
+
+ close(chS.GetPrecacheChannel(utils.CacheDestinations))
+ close(chS.GetPrecacheChannel(utils.CacheReverseDestinations))
+ close(chS.GetPrecacheChannel(utils.CacheRatingPlans))
+ close(chS.GetPrecacheChannel(utils.CacheRatingProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheActions))
+ close(chS.GetPrecacheChannel(utils.CacheActionPlans))
+ close(chS.GetPrecacheChannel(utils.CacheAccountActionPlans))
+ close(chS.GetPrecacheChannel(utils.CacheActionTriggers))
+ close(chS.GetPrecacheChannel(utils.CacheSharedGroups))
+ close(chS.GetPrecacheChannel(utils.CacheTimings))
+
+ internalChan := make(chan rpcclient.ClientConnector, 1)
+ internalChan <- nil
+ cacheSChan := make(chan rpcclient.ClientConnector, 1)
+ cacheSChan <- chS
+
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ db := NewDataDBService(cfg, nil, srvDep)
+ cfg.StorDbCfg().Type = utils.INTERNAL
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ stordb := NewStorDBService(cfg, srvDep)
+ chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ ralS := NewRalService(cfg, chS, server,
+ make(chan rpcclient.ClientConnector, 1), make(chan rpcclient.ClientConnector, 1),
+ shdChan, nil, anz, srvDep)
+ cdrS := NewCDRServer(cfg, db, stordb, filterSChan, server,
+ make(chan rpcclient.ClientConnector, 1),
+ nil, anz, srvDep)
+ srv := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), shdChan, nil, nil, anz, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(srv, chrS, schS, ralS, cdrS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if stordb.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"),
+ Section: config.SessionSJson,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !srv.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := srv.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = srv.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.SessionSCfg().Enabled = false
+ cfg.GetReloadChan(config.SessionSJson) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/sipagent_test.go b/services/sipagent_test.go
index 5bad53819..31ab198bf 100644
--- a/services/sipagent_test.go
+++ b/services/sipagent_test.go
@@ -14,17 +14,19 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
-
-package services
*/
package services
import (
+ "path"
"sync"
"testing"
+ "time"
"github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -32,25 +34,63 @@ import (
//TestSIPAgentCoverage for cover testing
func TestSIPAgentCoverage(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
+
cfg.SessionSCfg().Enabled = true
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
chS := engine.NewCacheS(cfg, nil, nil)
+
cacheSChan := make(chan rpcclient.ClientConnector, 1)
cacheSChan <- chS
+
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
- srv := &SIPAgent{
- RWMutex: sync.RWMutex{},
- cfg: cfg,
- filterSChan: filterSChan,
- shdChan: shdChan,
- connMgr: nil,
- srvDep: srvDep,
- oldListen: "",
+ db := NewDataDBService(cfg, nil, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1),
+ shdChan, nil, nil, anz, srvDep)
+ srv := NewSIPAgent(cfg, filterSChan, shdChan, nil, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(srv, sS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Fatal(err)
}
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
-
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "sipagent_mysql"),
+ Section: config.SIPAgentJson,
+ }, &reply); err != nil {
+ t.Fatal(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !srv.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ srvStart := srv.Start()
+ if srvStart != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, srvStart)
+ }
+ err := srv.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.SIPAgentCfg().Enabled = false
+ cfg.GetReloadChan(config.SIPAgentJson) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if srv.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
}
diff --git a/services/stats_test.go b/services/stats_test.go
new file mode 100644
index 000000000..cc1501aaf
--- /dev/null
+++ b/services/stats_test.go
@@ -0,0 +1,105 @@
+/*
+Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
+Copyright (C) ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+package services
+
+import (
+ "path"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/cgrates/rpcclient"
+
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+)
+
+//TestStatSCoverage for cover testing
+func TestStatSCoverage(t *testing.T) {
+ // utils.Logger.SetLogLevel(7)
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ cfg.ThresholdSCfg().Enabled = true
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ close(chS.GetPrecacheChannel(utils.CacheThresholdProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheThresholds))
+ close(chS.GetPrecacheChannel(utils.CacheThresholdFilterIndexes))
+ close(chS.GetPrecacheChannel(utils.CacheStatQueueProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheStatQueues))
+ close(chS.GetPrecacheChannel(utils.CacheStatFilterIndexes))
+ server := cores.NewServer(nil)
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ db := NewDataDBService(cfg, nil, srvDep)
+ tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
+ sS := NewStatService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(tS, sS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if sS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"),
+ Section: config.STATS_JSON,
+ }, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Expecting OK ,received %s", reply)
+ }
+ time.Sleep(10 * time.Millisecond) //need to switch to gorutine
+ if !sS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := sS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = sS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.StatSCfg().Enabled = false
+ cfg.GetReloadChan(config.STATS_JSON) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if sS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/stordb_it_test.go b/services/stordb_test.go
similarity index 98%
rename from services/stordb_it_test.go
rename to services/stordb_test.go
index 62fc94740..c41939144 100644
--- a/services/stordb_it_test.go
+++ b/services/stordb_test.go
@@ -1,5 +1,3 @@
-// +build integration
-
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
diff --git a/services/asteriskagent_it_test.go b/services/thresholds_test.go
similarity index 69%
rename from services/asteriskagent_it_test.go
rename to services/thresholds_test.go
index 467b8036a..3b622ea7c 100644
--- a/services/asteriskagent_it_test.go
+++ b/services/thresholds_test.go
@@ -1,5 +1,3 @@
-// +build integration
-
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
@@ -33,63 +31,63 @@ import (
"github.com/cgrates/rpcclient"
)
-func TestAsteriskAgentReload(t *testing.T) {
+//TestThresholdSCoverage for cover testing
+func TestThresholdSCoverage(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
-
- cfg.SessionSCfg().Enabled = true
- utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
- utils.Logger.SetLogLevel(7)
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
shdChan := utils.NewSyncedChan()
shdWg := new(sync.WaitGroup)
chS := engine.NewCacheS(cfg, nil, nil)
-
- cacheSChan := make(chan rpcclient.ClientConnector, 1)
- cacheSChan <- chS
-
+ close(chS.GetPrecacheChannel(utils.CacheThresholdProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheThresholds))
+ close(chS.GetPrecacheChannel(utils.CacheThresholdFilterIndexes))
server := cores.NewServer(nil)
srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
- db := NewDataDBService(cfg, nil, srvDep)
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
- sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1),
- shdChan, nil, nil, anz, srvDep)
- srv := NewAsteriskAgent(cfg, shdChan, nil, srvDep)
+ db := NewDataDBService(cfg, nil, srvDep)
+ tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
engine.NewConnManager(cfg, nil)
- srvMngr.AddServices(srv, sS,
+ srvMngr.AddServices(tS,
NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
if err := srvMngr.StartServices(); err != nil {
- t.Fatal(err)
+ t.Error(err)
}
- if srv.IsRunning() {
+ if tS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ if db.IsRunning() {
t.Errorf("Expected service to be down")
}
var reply string
if err := cfg.V1ReloadConfig(&config.ReloadArgs{
- Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "asterisk_ari", "cgrates", "etc", "cgrates"),
- Section: config.AsteriskAgentJSN,
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"),
+ Section: config.THRESHOLDS_JSON,
}, &reply); err != nil {
- t.Fatal(err)
+ t.Error(err)
} else if reply != utils.OK {
t.Errorf("Expecting OK ,received %s", reply)
}
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
- if !srv.IsRunning() {
+ if !tS.IsRunning() {
t.Errorf("Expected service to be running")
}
- srvReload := srv.Reload()
- if srvReload != nil {
- t.Errorf("\nExpecting ,\n Received <%+v>", srvReload)
+ if !db.IsRunning() {
+ t.Errorf("Expected service to be running")
}
- err := srv.Start()
- if err != utils.ErrServiceAlreadyRunning {
+ err := tS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
}
- cfg.AsteriskAgentCfg().Enabled = false
- cfg.GetReloadChan(config.AsteriskAgentJSN) <- struct{}{}
+ err = tS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.ThresholdSCfg().Enabled = false
+ cfg.GetReloadChan(config.THRESHOLDS_JSON) <- struct{}{}
time.Sleep(10 * time.Millisecond)
- if srv.IsRunning() {
+ if tS.IsRunning() {
t.Errorf("Expected service to be down")
}
shdChan.CloseOnce()