diff --git a/services/datadb_test.go b/services/datadb_test.go
new file mode 100644
index 000000000..e9227943c
--- /dev/null
+++ b/services/datadb_test.go
@@ -0,0 +1,197 @@
+/*
+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/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"
+)
+
+//TestDataDBCoverage for cover testing
+func TestDataDBCoverage(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.CacheAttributeProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheAttributeFilterIndexes))
+ server := cores.NewServer(nil)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ cM := engine.NewConnManager(cfg, nil)
+ db := NewDataDBService(cfg, cM, srvDep)
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ srvMngr.AddServices(NewAttributeService(cfg, db,
+ chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep),
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ var reply string
+ cfg.AttributeSCfg().Enabled = true
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"),
+ Section: config.DATADB_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 !db.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ getDm := db.GetDM()
+ if !reflect.DeepEqual(getDm, db.dm) {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", db.dm, getDm)
+ }
+ oldcfg := &config.DataDbCfg{
+ DataDbType: utils.MONGO,
+ DataDbHost: "127.0.0.1",
+ DataDbPort: "27017",
+ DataDbName: "10",
+ DataDbUser: "cgrates",
+ Opts: map[string]interface{}{
+ utils.QueryTimeoutCfg: "10s",
+ utils.RedisClusterOnDownDelayCfg: "0",
+ utils.RedisClusterSyncCfg: "5s",
+ utils.RedisClusterCfg: false,
+ utils.RedisSentinelNameCfg: "",
+ utils.RedisTLS: false,
+ utils.RedisClientCertificate: "",
+ utils.RedisClientKey: "",
+ utils.RedisCACertificate: "",
+ },
+ RmtConns: []string{},
+ RplConns: []string{},
+ Items: map[string]*config.ItemOpt{
+ utils.MetaAccounts: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaReverseDestinations: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaDestinations: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaRatingPlans: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaRatingProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaActions: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaActionPlans: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaAccountActionPlans: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaActionTriggers: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaSharedGroups: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaTimings: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaResourceProfile: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaStatQueues: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaResources: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaStatQueueProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaThresholds: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaThresholdProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaFilters: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaRouteProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaAttributeProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaDispatcherHosts: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaChargerProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaDispatcherProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaLoadIDs: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaIndexes: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaRateProfiles: {
+ Replicate: false,
+ Remote: false},
+ utils.MetaActionProfiles: {
+ Replicate: false,
+ Remote: false},
+ },
+ }
+ if !reflect.DeepEqual(oldcfg, db.oldDBCfg) {
+ t.Errorf("Expected %s \n received:%s", utils.ToJSON(oldcfg), utils.ToJSON(db.oldDBCfg))
+ }
+ cfg.AttributeSCfg().Enabled = false
+ cfg.GetReloadChan(config.DATADB_JSN) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if db.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/diameteragent_test.go b/services/diameteragent_test.go
new file mode 100644
index 000000000..3f15df830
--- /dev/null
+++ b/services/diameteragent_test.go
@@ -0,0 +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"
+)
+
+//TestDiameterAgentCoverage for cover testing
+func TestDiameterAgentCoverage(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)
+ srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
+ srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
+ 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 := NewDiameterAgent(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", "diamagent_mysql"),
+ Section: config.DA_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.DiameterAgentCfg().Enabled = false
+ cfg.GetReloadChan(config.DA_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/dispatcherh_it_test.go b/services/dispatcherh_test.go
similarity index 99%
rename from services/dispatcherh_it_test.go
rename to services/dispatcherh_test.go
index 25d4995f7..5fe234b23 100644
--- a/services/dispatcherh_it_test.go
+++ b/services/dispatcherh_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/dispatchers_test.go b/services/dispatchers_test.go
new file mode 100644
index 000000000..50b27555f
--- /dev/null
+++ b/services/dispatchers_test.go
@@ -0,0 +1,106 @@
+/*
+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"
+)
+
+//TestDispatcherSCoverage for cover testing
+func TestDispatcherSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ cfg.AttributeSCfg().Enabled = true
+ shdChan := utils.NewSyncedChan()
+ shdWg := new(sync.WaitGroup)
+ chS := engine.NewCacheS(cfg, nil, nil)
+ close(chS.GetPrecacheChannel(utils.CacheAttributeProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheAttributeFilterIndexes))
+ close(chS.GetPrecacheChannel(utils.CacheDispatcherProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheDispatcherHosts))
+ close(chS.GetPrecacheChannel(utils.CacheDispatcherFilterIndexes))
+ filterSChan := make(chan *engine.FilterS, 1)
+ filterSChan <- nil
+ 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)
+ attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
+ srv := NewDispatcherService(cfg, db, chS, filterSChan, server,
+ make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(attrS, srv,
+ NewLoaderService(cfg, db, filterSChan, server,
+ make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ 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")
+ }
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dispatchers", "dispatchers_mysql"),
+
+ Section: config.DispatcherSJson,
+ }, &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.DispatcherSCfg().Enabled = false
+ cfg.GetReloadChan(config.DispatcherSJson) <- 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/dnsagent_test.go b/services/dnsagent_test.go
new file mode 100644
index 000000000..209f6bd88
--- /dev/null
+++ b/services/dnsagent_test.go
@@ -0,0 +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"
+)
+
+//TestDNSAgentCoverage for cover testing
+func TestDNSAgentCoverage(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 := NewDNSAgent(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", "dnsagent_reload"),
+ Section: config.DNSAgentJson,
+ }, &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.DNSAgentCfg().Enabled = false
+ cfg.GetReloadChan(config.DNSAgentJson) <- 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/ees_test.go b/services/ees_test.go
new file mode 100644
index 000000000..1feefd566
--- /dev/null
+++ b/services/ees_test.go
@@ -0,0 +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"
+)
+
+//TestEventExporterSCoverage for cover testing
+func TestEventExporterSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ cfg.AttributeSCfg().Enabled = true
+ 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.CacheAttributeProfiles))
+ close(chS.GetPrecacheChannel(utils.CacheAttributeFilterIndexes))
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ attrS := NewAttributeService(cfg, db,
+ chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1),
+ anz, srvDep)
+ ees := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
+ srvMngr.AddServices(ees, attrS,
+ NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
+ if err := srvMngr.StartServices(); err != nil {
+ t.Error(err)
+ }
+ if ees.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ fcTmp := &config.FCTemplate{Tag: "TenantID",
+ Path: "Tenant",
+ Type: utils.MetaVariable,
+ Value: config.NewRSRParsersMustCompile("~*req.0", utils.INFIELD_SEP),
+ Mandatory: true,
+ Layout: time.RFC3339,
+ }
+ fcTmp.ComputePath()
+ cfg.TemplatesCfg()["requiredFields"] = []*config.FCTemplate{fcTmp}
+ var reply string
+ if err := cfg.V1ReloadConfig(&config.ReloadArgs{
+ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ees"),
+ Section: config.EEsJson,
+ }, &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 !ees.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := ees.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = ees.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.EEsCfg().Enabled = false
+ cfg.GetReloadChan(config.EEsJson) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if ees.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}
diff --git a/services/ers_test.go b/services/ers_test.go
new file mode 100644
index 000000000..40b4ccb76
--- /dev/null
+++ b/services/ers_test.go
@@ -0,0 +1,91 @@
+/*
+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"
+)
+
+//TestEventReaderSCoverage for cover testing
+func TestEventReaderSCoverage(t *testing.T) {
+ cfg := config.NewDefaultCGRConfig()
+
+ utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
+ utils.Logger.SetLogLevel(7)
+ cfg.SessionSCfg().Enabled = true
+ 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)}
+ anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
+ db := NewDataDBService(cfg, nil, srvDep)
+ sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), shdChan, nil, nil, anz, srvDep)
+ attrS := NewEventReaderService(cfg, filterSChan, shdChan, nil, srvDep)
+ engine.NewConnManager(cfg, nil)
+ srvMngr.AddServices(attrS, 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 attrS.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", "ers_reload", "internal"),
+ Section: config.ERsJson,
+ }, &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 !attrS.IsRunning() {
+ t.Errorf("Expected service to be running")
+ }
+ err := attrS.Start()
+ if err == nil || err != utils.ErrServiceAlreadyRunning {
+ t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
+ }
+ err = attrS.Reload()
+ if err != nil {
+ t.Errorf("\nExpecting ,\n Received <%+v>", err)
+ }
+ cfg.ERsCfg().Enabled = false
+ cfg.GetReloadChan(config.ERsJson) <- struct{}{}
+ time.Sleep(10 * time.Millisecond)
+ if attrS.IsRunning() {
+ t.Errorf("Expected service to be down")
+ }
+ shdChan.CloseOnce()
+ time.Sleep(10 * time.Millisecond)
+}