Added it test for replicator

This commit is contained in:
adragusin
2020-03-05 18:52:10 +02:00
committed by Dan Christian Bogos
parent a27db26c2e
commit 1c7a8d37e8
4 changed files with 112 additions and 0 deletions

View File

@@ -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
1 #Tenant ID Contexts FilterIDs ActivationInterval AttributeFilterIDs Path Type Value Blocker Weight
20 cgrates.org ATTR_API_CFG_AUTH *auth *string:~*req.APIKey:cfg12345 *req.APIMethods *constant ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig false 20
21 cgrates.org ATTR_API_APIER_AUTH *auth *string:~*req.APIKey:apier12345 *req.APIMethods *constant APIerSv1.GetAttributeProfile&APIerSv1.SetAttributeProfile false 20
22 cgrates.org ATTR_API_RALS_AUTH *auth *string:~*req.APIKey:rals12345 *req.APIMethods *constant RALsV1.Ping&RALsV1.GetRatingPlansCost false 20
23 cgrates.org ATTR_API_REPLICATOR_AUTH *auth *string:~*req.APIKey:repl12345 *req.APIMethods *constant ReplicatorSv1.Ping false 20

View File

@@ -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
1 #Tenant ID Contexts FilterIDs ActivationInterval AttributeFilterIDs Path Type Value Blocker Weight
20 cgrates.org ATTR_API_CFG_AUTH *auth *string:~*req.APIKey:cfg12345 *req.APIMethods *constant ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig false 20
21 cgrates.org ATTR_API_APIER_AUTH *auth *string:~*req.APIKey:apier12345 *req.APIMethods *constant APIerSv1.GetAttributeProfile&APIerSv1.SetAttributeProfile false 20
22 cgrates.org ATTR_API_RALS_AUTH *auth *string:~*req.APIKey:rals12345 *req.APIMethods *constant RALsV1.Ping&RALsV1.GetRatingPlansCost false 20
23 cgrates.org ATTR_API_REPLICATOR_AUTH *auth *string:~*req.APIKey:repl12345 *req.APIMethods *constant ReplicatorSv1.Ping false 20

View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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)
}
}

View File

@@ -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