mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
compilable version
This commit is contained in:
@@ -25,14 +25,18 @@ import (
|
||||
//"log"
|
||||
)
|
||||
|
||||
func init() {
|
||||
sg, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
SetStorageGetter(sg)
|
||||
}
|
||||
|
||||
func TestApRestoreKyoto(t *testing.T) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
|
||||
cd := &CallDescriptor{Tenant: "vdf",
|
||||
Subject: "rif",
|
||||
Destination: "0257",
|
||||
storageGetter: getter}
|
||||
Subject: "rif",
|
||||
Destination: "0257"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 2 {
|
||||
t.Error("Error restoring activation periods: ", cd.ActivationPeriods)
|
||||
@@ -44,9 +48,8 @@ func TestApRestoreRedis(t *testing.T) {
|
||||
defer getter.Close()
|
||||
|
||||
cd := &CallDescriptor{Tenant: "vdf",
|
||||
Subject: "rif",
|
||||
Destination: "0257",
|
||||
storageGetter: getter}
|
||||
Subject: "rif",
|
||||
Destination: "0257"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 2 {
|
||||
t.Error("Error restoring activation periods: ", cd.ActivationPeriods)
|
||||
@@ -78,7 +81,7 @@ func TestFallbackDirect(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0745", storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0745"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 1 {
|
||||
t.Error("Error restoring activation periods: ", cd.ActivationPeriods)
|
||||
@@ -89,7 +92,7 @@ func TestFallbackWithBackTrace(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0745121", storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0745121"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 1 {
|
||||
t.Error("Error restoring activation periods: ", cd.ActivationPeriods)
|
||||
@@ -100,7 +103,7 @@ func TestFallbackDefault(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "00000", storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "00000"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 1 {
|
||||
t.Error("Error restoring activation periods: ", cd.ActivationPeriods)
|
||||
@@ -111,7 +114,7 @@ func TestFallbackNoInfiniteLoop(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0721", storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0721"}
|
||||
cd.SearchStorageForPrefix()
|
||||
if len(cd.ActivationPeriods) != 0 {
|
||||
t.Error("Error restoring activation periods: ", cd.ActivationPeriods)
|
||||
|
||||
@@ -29,14 +29,14 @@ func TestSingleResultMerge(t *testing.T) {
|
||||
defer getter.Close()
|
||||
t1 := time.Date(2012, time.February, 2, 17, 00, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 17, 01, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 17, 01, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 17, 02, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc2.Cost)
|
||||
@@ -55,14 +55,14 @@ func TestMultipleResultMerge(t *testing.T) {
|
||||
defer getter.Close()
|
||||
t1 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 00, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 18, 00, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 6 {
|
||||
t.Errorf("expected 6 was %v", cc2.Cost)
|
||||
@@ -81,14 +81,14 @@ func TestMultipleInputLeftMerge(t *testing.T) {
|
||||
defer getter.Close()
|
||||
t1 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 18 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 18, 02, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 6 {
|
||||
t.Errorf("expected 6 was %v", cc2.Cost)
|
||||
@@ -107,14 +107,14 @@ func TestMultipleInputRightMerge(t *testing.T) {
|
||||
defer getter.Close()
|
||||
t1 := time.Date(2012, time.February, 2, 17, 58, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc1, _ := cd.GetCost()
|
||||
if cc1.Cost != 12 {
|
||||
t.Errorf("expected 12 was %v", cc1.Cost)
|
||||
}
|
||||
t1 = time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
|
||||
t2 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cc2, _ := cd.GetCost()
|
||||
if cc2.Cost != 18 {
|
||||
t.Errorf("expected 18 was %v", cc2.Cost)
|
||||
|
||||
@@ -380,12 +380,12 @@ in the user's tariff plan is reached then the received call balance is reseted a
|
||||
specified in the tariff plan is applied.
|
||||
The amount filed has to be filled in call descriptor.
|
||||
*/
|
||||
func (cd *CallDescriptor) AddRecievedCallSeconds() (err error) {
|
||||
if userBalance, err := cd.getUserBalance(); err == nil && userBalance != nil {
|
||||
return userBalance.addReceivedCallSeconds(INBOUND, cd.TOR, cd.Destination, cd.Amount)
|
||||
}
|
||||
return err
|
||||
}
|
||||
// func (cd *CallDescriptor) AddRecievedCallSeconds() (err error) {
|
||||
// if userBalance, err := cd.getUserBalance(); err == nil && userBalance != nil {
|
||||
// return userBalance.addReceivedCallSeconds(INBOUND, cd.TOR, cd.Destination, cd.Amount)
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
/*
|
||||
Resets user balances value to the amounts specified in the tariff plan.
|
||||
|
||||
@@ -34,13 +34,18 @@ BenchmarkRedisGetCost 10000 258751 ns/op
|
||||
BenchmarkKyotoGetCost 50000 38449 ns/op
|
||||
*/
|
||||
|
||||
func init() {
|
||||
sg, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
SetStorageGetter(sg)
|
||||
}
|
||||
|
||||
func TestKyotoSplitSpans(t *testing.T) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
|
||||
cd.SearchStorageForPrefix()
|
||||
timespans := cd.splitInTimeSpans()
|
||||
@@ -56,7 +61,7 @@ func TestRedisSplitSpans(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257", TimeStart: t1, TimeEnd: t2}
|
||||
|
||||
cd.SearchStorageForPrefix()
|
||||
timespans := cd.splitInTimeSpans()
|
||||
@@ -72,13 +77,13 @@ func TestKyotoGetCost(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0256", Cost: 540, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
t.Errorf("Expected %v was %v", expected, result)
|
||||
}
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd = &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ = cd.GetCost()
|
||||
expected = &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0257", Cost: 540, ConnectFee: 0}
|
||||
}
|
||||
@@ -89,7 +94,7 @@ func TestRedisGetCost(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0256", Cost: 540, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -106,7 +111,7 @@ func TestMongoGetCost(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0256", Cost: 540, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -120,7 +125,7 @@ func TestFullDestNotFound(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256308200", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256308200", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0256", Cost: 540, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -135,7 +140,7 @@ func TestMultipleActivationPeriods(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 8, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257308200", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257308200", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0257", Cost: 330, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -150,7 +155,7 @@ func TestSpansMultipleActivationPeriods(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 7, 23, 50, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 0, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257308200", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257308200", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0257", Cost: 360, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -164,7 +169,7 @@ func TestLessThanAMinute(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 8, 23, 50, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 23, 50, 30, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257308200", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0257308200", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0257", Cost: 0.5, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -178,7 +183,7 @@ func TestUniquePrice(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 23, 50, 21, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723045326", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723045326", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0723", Cost: 60.35, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -192,7 +197,7 @@ func TestPresentSecodCost(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 23, 50, 21, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.getPresentSecondCost()
|
||||
expected := 0.016
|
||||
if result != expected {
|
||||
@@ -206,7 +211,7 @@ func TestMinutesCost(t *testing.T) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 22, 51, 50, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Cost: 0.1, ConnectFee: 0}
|
||||
if result.Cost != expected.Cost || result.ConnectFee != expected.ConnectFee {
|
||||
@@ -218,7 +223,7 @@ func TestMinutesCost(t *testing.T) {
|
||||
func TestMaxSessionTimeNoUserBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723", storageGetter: getter, Amount: 1000}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723", Amount: 1000}
|
||||
result, err := cd.GetMaxSessionTime()
|
||||
if result != 1000 || err != nil {
|
||||
t.Errorf("Expected %v was %v", 1000, result)
|
||||
@@ -228,7 +233,7 @@ func TestMaxSessionTimeNoUserBalance(t *testing.T) {
|
||||
func TestMaxSessionTimeWithUserBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 5400}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 5400}
|
||||
result, err := cd.GetMaxSessionTime()
|
||||
if result != 1080 || err != nil {
|
||||
t.Errorf("Expected %v was %v", 1080, result)
|
||||
@@ -238,14 +243,14 @@ func TestMaxSessionTimeWithUserBalance(t *testing.T) {
|
||||
func TestMaxSessionTimeNoCredit(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "broker", Destination: "0723", storageGetter: getter, Amount: 5400}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "broker", Destination: "0723", Amount: 5400}
|
||||
result, err := cd.GetMaxSessionTime()
|
||||
if result != 100 || err != nil {
|
||||
t.Errorf("Expected %v was %v", 100, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCostWithVolumeDiscount(t *testing.T) {
|
||||
/*func TestGetCostWithVolumeDiscount(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
vd1 := &VolumeDiscount{100, 10}
|
||||
@@ -254,12 +259,13 @@ func TestGetCostWithVolumeDiscount(t *testing.T) {
|
||||
rifsBalance := &UserBalance{Id: "rif", Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10, VolumeDiscountSeconds: 105}
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723", TimeStart: t1, TimeEnd: t2, storageGetter: getter, userBalance: rifsBalance}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0723", TimeStart: t1, TimeEnd: t2, userBalance: rifsBalance}
|
||||
callCost, err := cd.GetCost()
|
||||
if callCost.Cost != 54.0 || err != nil {
|
||||
t.Errorf("Expected %v was %v", 54.0, callCost)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*********************************** BENCHMARKS ***************************************/
|
||||
func BenchmarkRedisGetting(b *testing.B) {
|
||||
@@ -283,7 +289,7 @@ func BenchmarkRedisRestoring(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.SearchStorageForPrefix()
|
||||
@@ -297,7 +303,7 @@ func BenchmarkRedisGetCost(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetCost()
|
||||
@@ -311,7 +317,7 @@ func BenchmarkKyotoGetting(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
key := cd.GetKey()
|
||||
@@ -326,7 +332,7 @@ func BenchmarkKyotoRestoring(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.SearchStorageForPrefix()
|
||||
@@ -340,7 +346,7 @@ func BenchmarkSplitting(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd.SearchStorageForPrefix()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -355,7 +361,7 @@ func BenchmarkKyotoGetCost(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetCost()
|
||||
@@ -383,7 +389,7 @@ func BenchmarkMongoGetCost(b *testing.B) {
|
||||
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 18, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, storageGetter: getter}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetCost()
|
||||
@@ -394,7 +400,7 @@ func BenchmarkKyotoSingleGetSessionTime(b *testing.B) {
|
||||
b.StopTimer()
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 100}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 100}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetMaxSessionTime()
|
||||
@@ -405,7 +411,7 @@ func BenchmarkKyotoMultipleGetSessionTime(b *testing.B) {
|
||||
b.StopTimer()
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 5400}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 5400}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetMaxSessionTime()
|
||||
@@ -416,7 +422,7 @@ func BenchmarkRedisSingleGetSessionTime(b *testing.B) {
|
||||
b.StopTimer()
|
||||
getter, _ := NewRedisStorage("", 10)
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 100}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 100}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetMaxSessionTime()
|
||||
@@ -427,7 +433,7 @@ func BenchmarkRedisMultipleGetSessionTime(b *testing.B) {
|
||||
b.StopTimer()
|
||||
getter, _ := NewRedisStorage("", 10)
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 5400}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 5400}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetMaxSessionTime()
|
||||
@@ -438,7 +444,7 @@ func BenchmarkMongoSingleGetSessionTime(b *testing.B) {
|
||||
b.StopTimer()
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 100}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 100}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetMaxSessionTime()
|
||||
@@ -449,7 +455,7 @@ func BenchmarkMongoMultipleGetSessionTime(b *testing.B) {
|
||||
b.StopTimer()
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", storageGetter: getter, Amount: 5400}
|
||||
cd := &CallDescriptor{Tenant: "vdf", Subject: "minutosu", Destination: "0723", Amount: 5400}
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cd.GetMaxSessionTime()
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func TestDestinationStoreRestore(t *testing.T) {
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
s := nationale.store()
|
||||
d1 := &Destination{Id: "nat"}
|
||||
d1.restore(s)
|
||||
@@ -36,7 +36,7 @@ func TestDestinationStoreRestore(t *testing.T) {
|
||||
func TestDestinationKyotoStore(t *testing.T) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
getter.SetDestination(nationale)
|
||||
result, _ := getter.GetDestination(nationale.Id)
|
||||
if !reflect.DeepEqual(nationale, result) {
|
||||
@@ -50,7 +50,7 @@ func TestDestinationRedisStore(t *testing.T) {
|
||||
return
|
||||
}
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
getter.SetDestination(nationale)
|
||||
result, _ := getter.GetDestination(nationale.Id)
|
||||
if !reflect.DeepEqual(nationale, result) {
|
||||
@@ -64,7 +64,7 @@ func TestDestinationMongoStore(t *testing.T) {
|
||||
return
|
||||
}
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
getter.SetDestination(nationale)
|
||||
result, _ := getter.GetDestination(nationale.Id)
|
||||
if !reflect.DeepEqual(nationale, result) {
|
||||
@@ -75,7 +75,7 @@ func TestDestinationMongoStore(t *testing.T) {
|
||||
func TestDestinationContainsPrefix(t *testing.T) {
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
contains, precision := nationale.containsPrefix("0256")
|
||||
if !contains || precision != len("0256") {
|
||||
t.Error("Should contain prefix: ", nationale)
|
||||
@@ -88,7 +88,7 @@ func TestDestinationContainsPrefix(t *testing.T) {
|
||||
func BenchmarkDestinationKyotoStoreRestore(b *testing.B) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
for i := 0; i < b.N; i++ {
|
||||
getter.SetDestination(nationale)
|
||||
getter.GetDestination(nationale.Id)
|
||||
@@ -98,7 +98,7 @@ func BenchmarkDestinationKyotoStoreRestore(b *testing.B) {
|
||||
func BenchmarkDestinationRedisStoreRestore(b *testing.B) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
for i := 0; i < b.N; i++ {
|
||||
getter.SetDestination(nationale)
|
||||
getter.GetDestination(nationale.Id)
|
||||
@@ -108,7 +108,7 @@ func BenchmarkDestinationRedisStoreRestore(b *testing.B) {
|
||||
func BenchmarkDestinationMongoStoreRestore(b *testing.B) {
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}}
|
||||
for i := 0; i < b.N; i++ {
|
||||
getter.SetDestination(nationale)
|
||||
getter.GetDestination(nationale.Id)
|
||||
|
||||
@@ -23,36 +23,32 @@ import (
|
||||
)
|
||||
|
||||
func TestGetDestination(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
mb := &MinuteBucket{DestinationId: "nationale"}
|
||||
d := mb.getDestination(getter)
|
||||
d := mb.getDestination()
|
||||
if d == nil || d.Id != "nationale" || len(d.Prefixes) != 4 {
|
||||
t.Error("Got wrong destination: ", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleGetDestination(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
mb := &MinuteBucket{DestinationId: "nationale"}
|
||||
d := mb.getDestination(getter)
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination(getter)
|
||||
d := mb.getDestination()
|
||||
d = mb.getDestination()
|
||||
d = mb.getDestination()
|
||||
if d == nil || d.Id != "nationale" || len(d.Prefixes) != 4 {
|
||||
t.Error("Got wrong destination: ", d)
|
||||
}
|
||||
mb = &MinuteBucket{DestinationId: "retea"}
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination()
|
||||
d = mb.getDestination()
|
||||
d = mb.getDestination()
|
||||
if d == nil || d.Id != "retea" || len(d.Prefixes) != 2 {
|
||||
t.Error("Got wrong destination: ", d)
|
||||
}
|
||||
mb = &MinuteBucket{DestinationId: "mobil"}
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination(getter)
|
||||
d = mb.getDestination()
|
||||
d = mb.getDestination()
|
||||
d = mb.getDestination()
|
||||
if d == nil || d.Id != "mobil" || len(d.Prefixes) != 2 {
|
||||
t.Error("Got wrong destination: ", d)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ these numbers to the user balance every month.
|
||||
*/
|
||||
type TariffPlan struct {
|
||||
Id string
|
||||
balanceMap map[string]float64
|
||||
BalanceMap map[string]float64
|
||||
Actions []*Action
|
||||
MinuteBuckets []*MinuteBucket
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package timespans
|
||||
|
||||
import (
|
||||
/*import (
|
||||
// "log"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTariffPlanStoreRestore(t *testing.T) {
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rcb := &RecivedCallBonus{Credit: 100}
|
||||
vd := &VolumeDiscount{100, 10}
|
||||
seara := &TariffPlan{Id: "seara_voo",
|
||||
@@ -46,8 +46,8 @@ func TestTariffPlanStoreRestore(t *testing.T) {
|
||||
func TestTariffPlanKyotoStore(t *testing.T) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
vd := &VolumeDiscount{100, 10}
|
||||
seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, ReceivedCallSecondsLimit: 0,
|
||||
MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}}
|
||||
@@ -61,8 +61,8 @@ func TestTariffPlanKyotoStore(t *testing.T) {
|
||||
func TestTariffPlanRedisStore(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
vd := &VolumeDiscount{100, 10}
|
||||
seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, ReceivedCallSecondsLimit: 0,
|
||||
MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}}
|
||||
@@ -76,8 +76,8 @@ func TestTariffPlanRedisStore(t *testing.T) {
|
||||
func TestTariffPlanMongoStore(t *testing.T) {
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
vd := &VolumeDiscount{100, 10}
|
||||
seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, ReceivedCallSecondsLimit: 0,
|
||||
MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}}
|
||||
@@ -88,15 +88,15 @@ func TestTariffPlanMongoStore(t *testing.T) {
|
||||
t.Log(result)
|
||||
t.Errorf("Expected %v was %v", seara.VolumeDiscountThresholds, result.VolumeDiscountThresholds)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/********************************* Benchmarks **********************************/
|
||||
|
||||
func BenchmarkTariffPlanKyotoStoreRestore(b *testing.B) {
|
||||
/*func BenchmarkTariffPlanKyotoStoreRestore(b *testing.B) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara_other", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
for i := 0; i < b.N; i++ {
|
||||
getter.SetTariffPlan(seara)
|
||||
@@ -107,8 +107,8 @@ func BenchmarkTariffPlanKyotoStoreRestore(b *testing.B) {
|
||||
func BenchmarkTariffPlanRedisStoreRestore(b *testing.B) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara_other", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
for i := 0; i < b.N; i++ {
|
||||
getter.SetTariffPlan(seara)
|
||||
@@ -119,11 +119,12 @@ func BenchmarkTariffPlanRedisStoreRestore(b *testing.B) {
|
||||
func BenchmarkTariffPlanMongoStoreRestore(b *testing.B) {
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara_other", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
for i := 0; i < b.N; i++ {
|
||||
getter.SetTariffPlan(seara)
|
||||
getter.GetTariffPlan(seara.Id)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -185,12 +185,10 @@ func TestSplitByActivationTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTimespanGetCost(t *testing.T) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
t1 := time.Date(2012, time.February, 5, 17, 45, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 5, 17, 55, 0, 0, time.UTC)
|
||||
ts1 := TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
cd := &CallDescriptor{Subject: "other", storageGetter: getter}
|
||||
cd := &CallDescriptor{Subject: "other"}
|
||||
if ts1.getCost(cd) != 0 {
|
||||
t.Error("No interval and still kicking")
|
||||
}
|
||||
|
||||
@@ -213,30 +213,29 @@ func (ub *UserBalance) debitSMSBuget(amount float64) (float64, error) {
|
||||
/*
|
||||
Adds the specified amount of seconds.
|
||||
*/
|
||||
func (ub *UserBalance) addReceivedCallSeconds(direction, tor, destination string, amount float64) error {
|
||||
ub.mux.Lock()
|
||||
defer ub.mux.Unlock()
|
||||
for
|
||||
ub.ReceivedCallSeconds += amount
|
||||
if tariffPlan, err := ub.getTariffPlan(); tariffPlan != nil && err == nil {
|
||||
if ub.ReceivedCallSeconds >= tariffPlan.ReceivedCallSecondsLimit {
|
||||
ub.ReceivedCallSeconds -= tariffPlan.ReceivedCallSecondsLimit
|
||||
if tariffPlan.RecivedCallBonus != nil { // apply the bonus
|
||||
ub.BalanceMap[CREDIT] += tariffPlan.RecivedCallBonus.Credit
|
||||
ub.BalanceMap[SMS] += tariffPlan.RecivedCallBonus.SmsCredit
|
||||
ub.BalanceMap[TRAFFIC] += tariffPlan.RecivedCallBonus.Traffic
|
||||
if tariffPlan.RecivedCallBonus.MinuteBucket != nil {
|
||||
for _, mb := range ub.MinuteBuckets {
|
||||
if mb.DestinationId == tariffPlan.RecivedCallBonus.MinuteBucket.DestinationId {
|
||||
mb.Seconds += tariffPlan.RecivedCallBonus.MinuteBucket.Seconds
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return storageGetter.SetUserBalance(ub)
|
||||
}
|
||||
// func (ub *UserBalance) addReceivedCallSeconds(direction, tor, destination string, amount float64) error {
|
||||
// ub.mux.Lock()
|
||||
// defer ub.mux.Unlock()
|
||||
// ub.ReceivedCallSeconds += amount
|
||||
// if tariffPlan, err := ub.getTariffPlan(); tariffPlan != nil && err == nil {
|
||||
// if ub.ReceivedCallSeconds >= tariffPlan.ReceivedCallSecondsLimit {
|
||||
// ub.ReceivedCallSeconds -= tariffPlan.ReceivedCallSecondsLimit
|
||||
// if tariffPlan.RecivedCallBonus != nil { // apply the bonus
|
||||
// ub.BalanceMap[CREDIT] += tariffPlan.RecivedCallBonus.Credit
|
||||
// ub.BalanceMap[SMS] += tariffPlan.RecivedCallBonus.SmsCredit
|
||||
// ub.BalanceMap[TRAFFIC] += tariffPlan.RecivedCallBonus.Traffic
|
||||
// if tariffPlan.RecivedCallBonus.MinuteBucket != nil {
|
||||
// for _, mb := range ub.MinuteBuckets {
|
||||
// if mb.DestinationId == tariffPlan.RecivedCallBonus.MinuteBucket.DestinationId {
|
||||
// mb.Seconds += tariffPlan.RecivedCallBonus.MinuteBucket.Seconds
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return storageGetter.SetUserBalance(ub)
|
||||
// }
|
||||
|
||||
/*
|
||||
Resets the user balance items to their tariff plan values.
|
||||
@@ -244,13 +243,14 @@ Resets the user balance items to their tariff plan values.
|
||||
func (ub *UserBalance) resetUserBalance() (err error) {
|
||||
ub.mux.Lock()
|
||||
defer ub.mux.Unlock()
|
||||
if tp, err := ub.getTariffPlan(storageGetter); err == nil {
|
||||
ub.SmsCredit = tp.SmsCredit
|
||||
ub.Traffic = tp.Traffic
|
||||
if tp, err := ub.getTariffPlan(); err == nil {
|
||||
for k, _ := range ub.BalanceMap {
|
||||
ub.BalanceMap[k] = tp.BalanceMap[k]
|
||||
}
|
||||
ub.MinuteBuckets = make([]*MinuteBucket, 0)
|
||||
for _, bucket := range tp.MinuteBuckets {
|
||||
mb := &MinuteBucket{Seconds: bucket.Seconds,
|
||||
Priority: bucket.Priority,
|
||||
Weight: bucket.Weight,
|
||||
Price: bucket.Price,
|
||||
DestinationId: bucket.DestinationId}
|
||||
ub.MinuteBuckets = append(ub.MinuteBuckets, mb)
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package timespans
|
||||
|
||||
import (
|
||||
/*import (
|
||||
// "log"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -30,8 +30,8 @@ var (
|
||||
)
|
||||
|
||||
func TestUserBalanceStoreRestore(t *testing.T) {
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10}
|
||||
s := rifsBalance.store()
|
||||
@@ -43,27 +43,27 @@ func TestUserBalanceStoreRestore(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSecondsForPrefix(t *testing.T) {
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, destination: retea}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, destination: retea}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBalance{Id: "rif", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 200, tariffPlan: tf1, ResetDayOfTheMonth: 10}
|
||||
seconds, bucketList := ub1.getSecondsForPrefix(nil, "0723")
|
||||
expected := 110.0
|
||||
if seconds != expected || bucketList[0].Priority < bucketList[1].Priority {
|
||||
if seconds != expected || bucketList[0].Weight < bucketList[1].Weight {
|
||||
t.Errorf("Expected %v was %v", expected, seconds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPricedSeconds(t *testing.T) {
|
||||
b1 := &MinuteBucket{Seconds: 10, Price: 10, Priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Price: 1, Priority: 20, destination: retea}
|
||||
b1 := &MinuteBucket{Seconds: 10, Price: 10, Weight: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Price: 1, Weight: 20, destination: retea}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBalance{Id: "rif", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: tf1, ResetDayOfTheMonth: 10}
|
||||
seconds, bucketList := ub1.getSecondsForPrefix(nil, "0723")
|
||||
expected := 21.0
|
||||
if seconds != expected || bucketList[0].Priority < bucketList[1].Priority {
|
||||
if seconds != expected || bucketList[0].Weight < bucketList[1].Weight {
|
||||
t.Errorf("Expected %v was %v", expected, seconds)
|
||||
}
|
||||
}
|
||||
@@ -71,8 +71,8 @@ func TestGetPricedSeconds(t *testing.T) {
|
||||
func TestUserBalanceKyotoStore(t *testing.T) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
getter.SetUserBalance(rifsBalance)
|
||||
result, _ := getter.GetUserBalance(rifsBalance.Id)
|
||||
@@ -86,8 +86,8 @@ func TestUserBalanceKyotoStore(t *testing.T) {
|
||||
func TestUserBalanceRedisStore(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
getter.SetUserBalance(rifsBalance)
|
||||
result, _ := getter.GetUserBalance(rifsBalance.Id)
|
||||
@@ -102,8 +102,8 @@ func TestUserBalanceMongoStore(t *testing.T) {
|
||||
return
|
||||
}
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
getter.SetUserBalance(rifsBalance)
|
||||
result, _ := getter.GetUserBalance(rifsBalance.Id)
|
||||
@@ -115,8 +115,8 @@ func TestUserBalanceMongoStore(t *testing.T) {
|
||||
func TestDebitMoneyBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "o4her", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
result := rifsBalance.debitMoneyBalance(getter, 6)
|
||||
if rifsBalance.Credit != 15 || result != rifsBalance.Credit {
|
||||
@@ -127,8 +127,8 @@ func TestDebitMoneyBalance(t *testing.T) {
|
||||
func TestDebitAllMoneyBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
rifsBalance.debitMoneyBalance(getter, 21)
|
||||
result := rifsBalance.debitMoneyBalance(getter, 0)
|
||||
@@ -140,8 +140,8 @@ func TestDebitAllMoneyBalance(t *testing.T) {
|
||||
func TestDebitMoreMoneyBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
result := rifsBalance.debitMoneyBalance(getter, 22)
|
||||
if rifsBalance.Credit != -1 || result != rifsBalance.Credit {
|
||||
@@ -152,8 +152,8 @@ func TestDebitMoreMoneyBalance(t *testing.T) {
|
||||
func TestDebitNegativeMoneyBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
result := rifsBalance.debitMoneyBalance(getter, -15)
|
||||
if rifsBalance.Credit != 36 || result != rifsBalance.Credit {
|
||||
@@ -164,8 +164,8 @@ func TestDebitNegativeMoneyBalance(t *testing.T) {
|
||||
func TestDebitMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 6, "0723")
|
||||
if b2.Seconds != 94 || err != nil {
|
||||
@@ -177,8 +177,8 @@ func TestDebitMinuteBalance(t *testing.T) {
|
||||
func TestDebitMultipleBucketsMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 105, "0723")
|
||||
if b2.Seconds != 0 || b1.Seconds != 5 || err != nil {
|
||||
@@ -190,8 +190,8 @@ func TestDebitMultipleBucketsMinuteBalance(t *testing.T) {
|
||||
func TestDebitAllMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 110, "0723")
|
||||
if b2.Seconds != 0 || b1.Seconds != 0 || err != nil {
|
||||
@@ -202,8 +202,8 @@ func TestDebitAllMinuteBalance(t *testing.T) {
|
||||
func TestDebitMoreMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 115, "0723")
|
||||
if b2.Seconds != 100 || b1.Seconds != 10 || err == nil {
|
||||
@@ -214,8 +214,8 @@ func TestDebitMoreMinuteBalance(t *testing.T) {
|
||||
func TestDebitPriceMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 1.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 1.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 5, "0723")
|
||||
if b2.Seconds != 95 || b1.Seconds != 10 || err != nil || rifsBalance.Credit != 16 {
|
||||
@@ -227,8 +227,8 @@ func TestDebitPriceMinuteBalance(t *testing.T) {
|
||||
func TestDebitPriceAllMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 1.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 1.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 21, "0723")
|
||||
if b2.Seconds != 79 || b1.Seconds != 10 || err != nil || rifsBalance.Credit != 0 {
|
||||
@@ -239,8 +239,8 @@ func TestDebitPriceAllMinuteBalance(t *testing.T) {
|
||||
func TestDebitPriceMoreMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 1.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 1.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, 25, "0723")
|
||||
if b2.Seconds != 100 || b1.Seconds != 10 || err == nil || rifsBalance.Credit != 21 {
|
||||
@@ -252,8 +252,8 @@ func TestDebitPriceMoreMinuteBalance(t *testing.T) {
|
||||
func TestDebitPriceNegativeMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 1.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 1.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, -15, "0723")
|
||||
if b2.Seconds != 115 || b1.Seconds != 10 || err != nil || rifsBalance.Credit != 36 {
|
||||
@@ -265,8 +265,8 @@ func TestDebitPriceNegativeMinuteBalance(t *testing.T) {
|
||||
func TestDebitNegativeMinuteBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10}
|
||||
err := rifsBalance.debitMinutesBalance(getter, -15, "0723")
|
||||
if b2.Seconds != 115 || b1.Seconds != 10 || err != nil || rifsBalance.Credit != 21 {
|
||||
@@ -278,8 +278,8 @@ func TestDebitNegativeMinuteBalance(t *testing.T) {
|
||||
func TestDebitSMSBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, SmsCredit: 100, ResetDayOfTheMonth: 10}
|
||||
result, err := rifsBalance.debitSMSBuget(getter, 12)
|
||||
if rifsBalance.SmsCredit != 88 || result != rifsBalance.SmsCredit || err != nil {
|
||||
@@ -290,8 +290,8 @@ func TestDebitSMSBalance(t *testing.T) {
|
||||
func TestDebitAllSMSBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, SmsCredit: 100, ResetDayOfTheMonth: 10}
|
||||
result, err := rifsBalance.debitSMSBuget(getter, 100)
|
||||
if rifsBalance.SmsCredit != 0 || result != rifsBalance.SmsCredit || err != nil {
|
||||
@@ -302,8 +302,8 @@ func TestDebitAllSMSBalance(t *testing.T) {
|
||||
func TestDebitMoreSMSBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, SmsCredit: 100, ResetDayOfTheMonth: 10}
|
||||
result, err := rifsBalance.debitSMSBuget(getter, 110)
|
||||
if rifsBalance.SmsCredit != 100 || result != rifsBalance.SmsCredit || err == nil {
|
||||
@@ -314,8 +314,8 @@ func TestDebitMoreSMSBalance(t *testing.T) {
|
||||
func TestDebitNegativeSMSBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.0, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, SmsCredit: 100, ResetDayOfTheMonth: 10}
|
||||
result, err := rifsBalance.debitSMSBuget(getter, -15)
|
||||
if rifsBalance.SmsCredit != 115 || result != rifsBalance.SmsCredit || err != nil {
|
||||
@@ -326,8 +326,8 @@ func TestDebitNegativeSMSBalance(t *testing.T) {
|
||||
func TestResetUserBalance(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10}
|
||||
rifsBalance.MinuteBuckets[0].Seconds, rifsBalance.MinuteBuckets[1].Seconds = 0.0, 0.0
|
||||
@@ -387,14 +387,14 @@ func TestRecivedCallsBonus(t *testing.T) {
|
||||
if err != nil || rifsBalance.Credit != 121 || rifsBalance.ReceivedCallSeconds != 3 {
|
||||
t.Error("Wrong Received call bonus procedure: ", rifsBalance)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*********************************** Benchmarks *******************************/
|
||||
|
||||
func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
/*func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
b.StopTimer()
|
||||
b1 := &MinuteBucket{Seconds: 10, Price: 10, Priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Price: 1, Priority: 20, destination: retea}
|
||||
b1 := &MinuteBucket{Seconds: 10, Price: 10, Weight: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Price: 1, Weight: 20, destination: retea}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: tf1, ResetDayOfTheMonth: 10}
|
||||
@@ -407,8 +407,8 @@ func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
func BenchmarkUserBalanceKyotoStoreRestore(b *testing.B) {
|
||||
getter, _ := NewKyotoStorage("../data/test.kch")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10}
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -420,8 +420,8 @@ func BenchmarkUserBalanceKyotoStoreRestore(b *testing.B) {
|
||||
func BenchmarkUserBalanceRedisStoreRestore(b *testing.B) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10}
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -433,8 +433,8 @@ func BenchmarkUserBalanceRedisStoreRestore(b *testing.B) {
|
||||
func BenchmarkUserBalanceMongoStoreRestore(b *testing.B) {
|
||||
getter, _ := NewMongoStorage("127.0.0.1", "test")
|
||||
defer getter.Close()
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, Price: 0.01, DestinationId: "nationale"}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, Price: 0.0, DestinationId: "retea"}
|
||||
seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
rifsBalance := &UserBalance{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10}
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -444,8 +444,8 @@ func BenchmarkUserBalanceMongoStoreRestore(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkGetSecondsForPrefix(b *testing.B) {
|
||||
b1 := &MinuteBucket{Seconds: 10, Priority: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Priority: 20, destination: retea}
|
||||
b1 := &MinuteBucket{Seconds: 10, Weight: 10, destination: nationale}
|
||||
b2 := &MinuteBucket{Seconds: 100, Weight: 20, destination: retea}
|
||||
tf1 := &TariffPlan{MinuteBuckets: []*MinuteBucket{b1, b2}}
|
||||
|
||||
ub1 := &UserBalance{Id: "rif", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 200, tariffPlan: tf1, ResetDayOfTheMonth: 10}
|
||||
@@ -453,3 +453,4 @@ func BenchmarkGetSecondsForPrefix(b *testing.B) {
|
||||
ub1.getSecondsForPrefix(nil, "0723")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user