From 1c7a8d37e80e4a7cdeea898954453dc88281a9a7 Mon Sep 17 00:00:00 2001 From: adragusin Date: Thu, 5 Mar 2020 18:52:10 +0200 Subject: [PATCH] Added it test for replicator --- data/tariffplans/dispatchers/Attributes.csv | 1 + .../dispatchers_gob/Attributes.csv | 1 + dispatchers/replicator_it_test.go | 107 ++++++++++++++++++ services/dispatchers.go | 3 + 4 files changed, 112 insertions(+) create mode 100644 dispatchers/replicator_it_test.go diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index 038e7c153..3b6852b04 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -20,3 +20,4 @@ cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,*req.APIMeth cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,*req.APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,*req.APIMethods,*constant,APIerSv1.GetAttributeProfile&APIerSv1.SetAttributeProfile,false,20 cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,*req.APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 +cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.APIKey:repl12345,,,*req.APIMethods,*constant,ReplicatorSv1.Ping,false,20 diff --git a/data/tariffplans/dispatchers_gob/Attributes.csv b/data/tariffplans/dispatchers_gob/Attributes.csv index cfc93aded..91c779da4 100644 --- a/data/tariffplans/dispatchers_gob/Attributes.csv +++ b/data/tariffplans/dispatchers_gob/Attributes.csv @@ -20,3 +20,4 @@ cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,*req.APIMeth cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,*req.APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,*req.APIMethods,*constant,APIerSv1.GetAttributeProfile&APIerSv1.SetAttributeProfile,false,20 cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,*req.APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 +cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.APIKey:repl12345,,,*req.APIMethods,*constant,ReplicatorSv1.Ping,false,20 \ No newline at end of file diff --git a/dispatchers/replicator_it_test.go b/dispatchers/replicator_it_test.go new file mode 100644 index 000000000..62f086a32 --- /dev/null +++ b/dispatchers/replicator_it_test.go @@ -0,0 +1,107 @@ +// +build integration + +/* +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 dispatchers + +import ( + "testing" + + "github.com/cgrates/cgrates/utils" +) + +var sTestsDspRpl = []func(t *testing.T){ + testDspRplPingFailover, +} + +//Test start here +func TestDspReplicator(t *testing.T) { + var config1, config2, config3 string + switch *dbType { + case utils.MetaInternal: + t.SkipNow() + case utils.MetaMySQL: + config1 = "all_mysql" + config2 = "all2_mysql" + config3 = "dispatchers_mysql" + case utils.MetaMongo: + config1 = "all_mongo" + config2 = "all2_mongo" + config3 = "dispatchers_mongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } + + dispDIR := "dispatchers" + if *encoding == utils.MetaGOB { + dispDIR += "_gob" + } + testDsp(t, sTestsDspRpl, "TestDspReplicator", config1, config2, config3, "tutorial", "oldtutorial", dispDIR) +} + +func testDspRplPingFailover(t *testing.T) { + var reply string + if err := allEngine.RPC.Call(utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil { + t.Error(err) + } else if reply != utils.Pong { + t.Errorf("Received: %s", reply) + } + reply = utils.EmptyString + if err := allEngine2.RPC.Call(utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil { + t.Error(err) + } else if reply != utils.Pong { + t.Errorf("Received: %s", reply) + } + reply = utils.EmptyString + ev := utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + }, + ArgDispatcher: &utils.ArgDispatcher{ + APIKey: utils.StringPointer("repl12345"), + }, + } + if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err != nil { + t.Error(err) + } else if reply != utils.Pong { + t.Errorf("Received: %s", reply) + } + allEngine.stopEngine(t) + reply = utils.EmptyString + if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err != nil { + t.Error(err) + } else if reply != utils.Pong { + t.Errorf("Received: %s", reply) + } + allEngine2.stopEngine(t) + reply = utils.EmptyString + if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err == nil { + t.Errorf("Expected error but recived %v and reply %v\n", err, reply) + } + allEngine.startEngine(t) + allEngine2.startEngine(t) + reply = utils.EmptyString + if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err != nil { + t.Error(err) + } else if reply != utils.Pong { + t.Errorf("Received: %s", reply) + } +} diff --git a/services/dispatchers.go b/services/dispatchers.go index 4b6ec29fa..65aace610 100644 --- a/services/dispatchers.go +++ b/services/dispatchers.go @@ -135,6 +135,9 @@ func (dspS *DispatcherService) Start() (err error) { dspS.server.RpcRegisterName(utils.RALsV1, v1.NewDispatcherRALsV1(dspS.dspS)) + dspS.server.RpcRegisterName(utils.ReplicatorSv1, + v1.NewDispatcherReplicatorSv1(dspS.dspS)) + dspS.connChan <- dspS.dspS return