Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Moved chrono from core to pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
nqn committed Nov 16, 2015
1 parent 3c5e95c commit 44327ab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
11 changes: 5 additions & 6 deletions control/plugin/client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -26,6 +24,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/intelsdi-x/pulse/core"
"github.com/intelsdi-x/pulse/pkg/chrono"
)

// the time limit for which a cache entry is valid.
Expand Down Expand Up @@ -59,7 +58,7 @@ func (c *cache) get(ns string, version int) interface{} {
)

key := fmt.Sprintf("%v:%v", ns, version)
if cell, ok = c.table[key]; ok && core.Chrono.Now().Sub(cell.time) < GlobalCacheExpiration {
if cell, ok = c.table[key]; ok && chrono.Chrono.Now().Sub(cell.time) < GlobalCacheExpiration {
cell.hits++
cacheLog.WithFields(log.Fields{
"namespace": key,
Expand Down Expand Up @@ -92,11 +91,11 @@ func (c *cache) put(ns string, version int, m interface{}) {
switch metric := m.(type) {
case core.Metric:
if _, ok := c.table[key]; ok {
c.table[key].time = core.Chrono.Now()
c.table[key].time = chrono.Chrono.Now()
c.table[key].metric = metric
} else {
c.table[key] = &cachecell{
time: core.Chrono.Now(),
time: chrono.Chrono.Now(),
metric: metric,
}
}
Expand All @@ -106,7 +105,7 @@ func (c *cache) put(ns string, version int, m interface{}) {
c.table[key].metrics = metric
} else {
c.table[key] = &cachecell{
time: core.Chrono.Now(),
time: chrono.Chrono.Now(),
metrics: metric,
}
}
Expand Down
18 changes: 9 additions & 9 deletions control/plugin/client/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
. "github.com/smartystreets/goconvey/convey"

"github.com/intelsdi-x/pulse/control/plugin"
"github.com/intelsdi-x/pulse/core"
"github.com/intelsdi-x/pulse/pkg/chrono"
)

func TestCache(t *testing.T) {
Expand Down Expand Up @@ -78,11 +78,11 @@ func TestCache(t *testing.T) {
})
Convey("ticks miss count when a cache entry is still a hit", func() {
// Make sure global clock is restored after test.
defer core.Chrono.Reset()
defer core.Chrono.Continue()
defer chrono.Chrono.Reset()
defer chrono.Chrono.Continue()

// Use artificial time: pause to get base time.
core.Chrono.Pause()
chrono.Chrono.Pause()

mc := &cache{
table: make(map[string]*cachecell),
Expand All @@ -92,15 +92,15 @@ func TestCache(t *testing.T) {
}

mc.put("/foo/bar", 1, foo)
core.Chrono.Forward(250 * time.Millisecond)
chrono.Chrono.Forward(250 * time.Millisecond)
mc.get("/foo/bar", 1)
So(mc.table["/foo/bar:1"].hits, ShouldEqual, 1)
})
Convey("ticks miss count when a cache entry is missed", func() {
defer core.Chrono.Reset()
defer core.Chrono.Continue()
defer chrono.Chrono.Reset()
defer chrono.Chrono.Continue()

core.Chrono.Pause()
chrono.Chrono.Pause()

mc := &cache{
table: make(map[string]*cachecell),
Expand All @@ -109,7 +109,7 @@ func TestCache(t *testing.T) {
Namespace_: []string{"foo", "bar"},
}
mc.put("/foo/bar", 1, foo)
core.Chrono.Forward(301 * time.Millisecond)
chrono.Chrono.Forward(301 * time.Millisecond)
mc.get("/foo/bar", 1)
So(mc.table["/foo/bar:1"].misses, ShouldEqual, 1)
})
Expand Down
2 changes: 1 addition & 1 deletion core/chrono.go → pkg/chrono/chrono.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package core
package chrono

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion core/chrono_test.go → pkg/chrono/chrono_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package core
package chrono

import (
"testing"
Expand Down

0 comments on commit 44327ab

Please sign in to comment.