From a10a9528796617a1dea7fbeb26e11394792d4736 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 8 Feb 2012 22:40:33 +0200 Subject: [PATCH] small corrections anc code formatting --- cmd/inquirer/inquirer.go | 4 ++-- cmd/inquirer/registration.go | 2 +- cmd/inquirer/responder.go | 2 +- cmd/stresstest/stresstest.go | 20 +++++++++----------- timespans/calldesc.go | 7 ++++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cmd/inquirer/inquirer.go b/cmd/inquirer/inquirer.go index 6e4fa258c..9ab64aed6 100644 --- a/cmd/inquirer/inquirer.go +++ b/cmd/inquirer/inquirer.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "github.com/rif/cgrates/timespans" "log" "net" "net/http" @@ -11,7 +12,6 @@ import ( "runtime" "sync" "time" - "github.com/rif/cgrates/timespans" ) var ( @@ -82,7 +82,7 @@ func CallRater(key *timespans.CallDescriptor) (reply *timespans.CallCost) { time.Sleep(1 * time.Second) // wait one second and retry } else { reply = ×pans.CallCost{} - err = client.Call("Storage.GetCost", *key, reply) + err = client.Call("Storage.GetCost", *key, reply) if err != nil { log.Printf("Got en error from rater: %v", err) } diff --git a/cmd/inquirer/registration.go b/cmd/inquirer/registration.go index dca223448..67fa83916 100644 --- a/cmd/inquirer/registration.go +++ b/cmd/inquirer/registration.go @@ -1,11 +1,11 @@ package main import ( + "exp/signal" "fmt" "log" "net/rpc" "os" - "exp/signal" "syscall" "time" ) diff --git a/cmd/inquirer/responder.go b/cmd/inquirer/responder.go index 2b7c6aff0..ee0eabb94 100644 --- a/cmd/inquirer/responder.go +++ b/cmd/inquirer/responder.go @@ -1,7 +1,7 @@ package main import ( - "github.com/rif/cgrates/timespans" + "github.com/rif/cgrates/timespans" ) type Responder byte diff --git a/cmd/stresstest/stresstest.go b/cmd/stresstest/stresstest.go index 9bf05448a..56ef2eaad 100644 --- a/cmd/stresstest/stresstest.go +++ b/cmd/stresstest/stresstest.go @@ -1,35 +1,33 @@ package main import ( - "net/rpc/jsonrpc" - "log" "github.com/rif/cgrates/timespans" + "log" + "net/rpc/jsonrpc" "time" -) +) -func main(){ +func main() { t1 := time.Date(2012, time.February, 02, 17, 30, 0, 0, time.UTC) t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC) cd := timespans.CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0256", TimeStart: t1, TimeEnd: t2} result := timespans.CallCost{} client, _ := jsonrpc.Dial("tcp", "localhost:5090") - runs := int(5 * 1e4); - i:= 0 + runs := int(5 * 1e4) + i := 0 c := make(chan string) for ; i < runs; i++ { - go func(){ + go func() { var reply string client.Call("Responder.Get", cd, &result) c <- reply }() - //time.Sleep(1*time.Second) + //time.Sleep(1*time.Second) } - for j:=0; j < runs; j++ { + for j := 0; j < runs; j++ { <-c } log.Println(result) log.Println(i) client.Close() } - - diff --git a/timespans/calldesc.go b/timespans/calldesc.go index 0983ee9ee..ee9c9000f 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -56,8 +56,9 @@ func (cd *CallDescriptor) splitInTimeSpans() (timespans []*TimeSpan) { ts1 := &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd} ts1.ActivationPeriod = cd.ActivationPeriods[0] + // split on activation periods timespans = append(timespans, ts1) - afterStart, afterEnd := false, false + afterStart, afterEnd := false, false //optimization for multiple activation periods for _, ap := range cd.ActivationPeriods { if !afterStart && !afterEnd && ap.ActivationTime.Before(cd.TimeStart) { ts1.ActivationPeriod = ap @@ -74,7 +75,7 @@ func (cd *CallDescriptor) splitInTimeSpans() (timespans []*TimeSpan) { } } } - + // split on price intervals for i := 0; i < len(timespans); i++ { for _, interval := range timespans[i].ActivationPeriod.Intervals { newTs := timespans[i].SplitByInterval(interval) @@ -88,7 +89,7 @@ func (cd *CallDescriptor) splitInTimeSpans() (timespans []*TimeSpan) { } func (cd *CallDescriptor) RestoreFromStorage(sg StorageGetter) (destPrefix string, err error) { - cd.ActivationPeriods = make([]*ActivationPeriod, 2) + cd.ActivationPeriods = make([]*ActivationPeriod, 0) base := fmt.Sprintf("%s:%s:", cd.CstmId, cd.Subject) destPrefix = cd.DestinationPrefix key := base + destPrefix