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

Commit

Permalink
Updated dummy to mock
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay committed Nov 9, 2015
1 parent 50a0f03 commit c8b23f7
Show file tree
Hide file tree
Showing 44 changed files with 218 additions and 217 deletions.
4 changes: 2 additions & 2 deletions cmd/pulsectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ $PULSE_PATH/bin/pulsed

```
$PULSE_PATH/bin/pulsectl plugin load $PULSE_PATH/plugin/pulse-collector-psutil
$PULSE_PATH/bin/pulsectl plugin load $PULSE_PATH/plugin/pulse-collector-dummy1
$PULSE_PATH/bin/pulsectl plugin load $PULSE_PATH/plugin/pulse-collector-mock1
$PULSE_PATH/bin/pulsectl plugin load $PULSE_PATH/plugin/pulse-processor-passthru
$PULSE_PATH/bin/pulsectl plugin load $PULSE_PATH/plugin/pulse-publisher-influxdb
$PULSE_PATH/bin/pulsectl plugin load $PULSE_PATH/plugin/pulse-publisher-file
$PULSE_PATH/bin/pulsectl plugin list
$PULSE_PATH/bin/pulsectl task create -t $PULSE_PATH/../cmd/pulsectl/sample/psutil-influx.json
$PULSE_PATH/bin/pulsectl task list
$PULSE_PATH/bin/pulsectl plugin unload -n psutil -v 1
```
```
8 changes: 4 additions & 4 deletions cmd/pulsectl/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func listMetrics(ctx *cli.Context) {

/*
NAMESPACE VERSION
/intel/dummy/foo 1,2
/intel/dummy/bar 1
/intel/mock/foo 1,2
/intel/mock/bar 1
*/
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
metsByVer := make(map[string][]string)
Expand Down Expand Up @@ -97,9 +97,9 @@ func getMetric(ctx *cli.Context) {

/*
NAMESPACE VERSION LAST ADVERTISED TIME
/intel/dummy/foo 2 Wed, 09 Sep 2015 10:01:04 PDT
/intel/mock/foo 2 Wed, 09 Sep 2015 10:01:04 PDT
Rules for collecting /intel/dummy/foo:
Rules for collecting /intel/mock/foo:
NAME TYPE DEFAULT REQUIRED MINIMUM MAXIMUM
name string bob false
Expand Down
2 changes: 1 addition & 1 deletion cmd/pulsectl/sample/psutil-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"/psutil/vm/wired": {}
},
"config": {
"/intel/dummy": {
"/intel/mock": {
"password": "secret",
"user": "root"
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pulsectl/sample/psutil-influx.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"/psutil/vm/wired": {}
},
"config": {
"/intel/dummy": {
"/intel/mock": {
"password": "secret",
"user": "root"
}
Expand Down
64 changes: 32 additions & 32 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func TestSwapPlugin(t *testing.T) {
Convey("Should not error", func() {
So(e, ShouldBeNil)
})
Convey("First plugin in catalog should have name dummy2", func() {
So(c.PluginCatalog()[0].Name(), ShouldEqual, "dummy2")
Convey("First plugin in catalog should have name mock2", func() {
So(c.PluginCatalog()[0].Name(), ShouldEqual, "mock2")
})
})
dummy1Path := strings.Replace(PluginPath, "pulse-collector-dummy2", "pulse-collector-dummy1", 1)
err := c.SwapPlugins(dummy1Path, c.PluginCatalog()[0])
mock1Path := strings.Replace(PluginPath, "pulse-collector-mock2", "pulse-collector-mock1", 1)
err := c.SwapPlugins(mock1Path, c.PluginCatalog()[0])
<-lpe.done

// Swap plugin that was loaded with a different plugin
Expand All @@ -140,17 +140,17 @@ func TestSwapPlugin(t *testing.T) {
So(err, ShouldBeNil)
})
Convey("Should generate a swapped plugins event", func() {
Convey("So first plugin in catalog after swap should have name dummy1", func() {
So(c.PluginCatalog()[0].Name(), ShouldEqual, "dummy1")
Convey("So first plugin in catalog after swap should have name mock1", func() {
So(c.PluginCatalog()[0].Name(), ShouldEqual, "mock1")
})
Convey("So swapped plugins event should show loaded plugin name as dummy1", func() {
So(lpe.plugin.LoadedPluginName, ShouldEqual, "dummy1")
Convey("So swapped plugins event should show loaded plugin name as mock1", func() {
So(lpe.plugin.LoadedPluginName, ShouldEqual, "mock1")
})
Convey("So swapped plugins event should show loaded plugin version as 1", func() {
So(lpe.plugin.LoadedPluginVersion, ShouldEqual, 1)
})
Convey("So swapped plugins event should show unloaded plugin name as dummy2", func() {
So(lpe.plugin.UnloadedPluginName, ShouldEqual, "dummy2")
Convey("So swapped plugins event should show unloaded plugin name as mock2", func() {
So(lpe.plugin.UnloadedPluginName, ShouldEqual, "mock2")
})
Convey("So swapped plugins event should show unloaded plugin version as 2", func() {
So(lpe.plugin.UnloadedPluginVersion, ShouldEqual, 2)
Expand All @@ -167,8 +167,8 @@ func TestSwapPlugin(t *testing.T) {
Convey("Should throw an error", func() {
So(err, ShouldNotBeNil)
})
Convey("Plugin in catalog should still be dummy1", func() {
So(c.PluginCatalog()[0].Name(), ShouldEqual, "dummy1")
Convey("Plugin in catalog should still be mock1", func() {
So(c.PluginCatalog()[0].Name(), ShouldEqual, "mock1")
})
})

Expand All @@ -184,7 +184,7 @@ func TestSwapPlugin(t *testing.T) {
pm.ExistingPlugin = lp
c.pluginManager = pm

err := c.SwapPlugins(dummy1Path, lp)
err := c.SwapPlugins(mock1Path, lp)
Convey("So err should be received if rollback fails", func() {
So(err, ShouldNotBeNil)
})
Expand Down Expand Up @@ -242,7 +242,7 @@ func (l *listenToPluginEvent) HandleGomitEvent(e gomit.Event) {

var (
AciPath = path.Join(strings.TrimRight(PulsePath, "build"), "pkg/unpackage/")
AciFile = "pulse-collector-plugin-dummy1.darwin-x86_64.aci"
AciFile = "pulse-collector-plugin-mock1.darwin-x86_64.aci"
)

type mocksigningManager struct {
Expand All @@ -256,7 +256,7 @@ func (ps *mocksigningManager) ValidateSignature(string, string, string) error {
return errors.New("fake")
}

// Uses the dummy collector plugin to simulate Loading
// Uses the mock collector plugin to simulate Loading
func TestLoad(t *testing.T) {
// These tests only work if PULSE_PATH is known.
// It is the responsibility of the testing framework to
Expand All @@ -275,7 +275,7 @@ func TestLoad(t *testing.T) {
})
})

// Start pluginControl and load our dummy plugin
// Start pluginControl and load our mock plugin
c.Start()
time.Sleep(100 * time.Millisecond)
lpe := newListenToPluginEvent()
Expand All @@ -288,8 +288,8 @@ func TestLoad(t *testing.T) {
So(err, ShouldBeNil)
})
Convey("should emit a plugin event message", func() {
Convey("with loaded plugin name is dummy2", func() {
So(lpe.plugin.LoadedPluginName, ShouldEqual, "dummy2")
Convey("with loaded plugin name is mock2", func() {
So(lpe.plugin.LoadedPluginName, ShouldEqual, "mock2")
})

Convey("with loaded plugin version as 2", func() {
Expand All @@ -311,7 +311,7 @@ func TestLoad(t *testing.T) {

//Unpackaging
Convey("pluginControl.Load on untar error with package", t, func() {
PackagePath := path.Join(AciPath, "dummy.aci")
PackagePath := path.Join(AciPath, "mock.aci")
_, err := c.Load(PackagePath)
Convey("should return an error", func() {
So(err, ShouldNotBeNil)
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestLoadWithSignedPlugins(t *testing.T) {
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
c.Start()
time.Sleep(100 * time.Millisecond)
_, err := load(c, PluginPath, "dummy.asc")
_, err := load(c, PluginPath, "mock.asc")
<-lpe.done
Convey("so error on loading a signed plugin should be nil", func() {
So(err, ShouldBeNil)
Expand Down Expand Up @@ -417,8 +417,8 @@ func TestUnload(t *testing.T) {
So(err, ShouldBeNil)
})
Convey("should generate an unloaded plugin event", func() {
Convey("where unloaded plugin name is dummy2", func() {
So(lpe.plugin.UnloadedPluginName, ShouldEqual, "dummy2")
Convey("where unloaded plugin name is mock2", func() {
So(lpe.plugin.UnloadedPluginName, ShouldEqual, "mock2")
})
Convey("where unloaded plugin version should equal 2", func() {
So(lpe.plugin.UnloadedPluginVersion, ShouldEqual, 2)
Expand Down Expand Up @@ -748,7 +748,7 @@ func TestMetricConfig(t *testing.T) {
<-lpe.done
cd := cdata.NewNode()
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
namespace: []string{"intel", "mock", "foo"},
}
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should not be valid without config", func() {
Expand All @@ -775,7 +775,7 @@ func TestMetricConfig(t *testing.T) {
<-lpe.done
var cd *cdata.ConfigDataNode
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
namespace: []string{"intel", "mock", "foo"},
}
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should be valid with config", func() {
Expand All @@ -796,7 +796,7 @@ func TestMetricConfig(t *testing.T) {
<-lpe.done
cd := cdata.NewNode()
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
namespace: []string{"intel", "mock", "foo"},
}
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should be valid with config", func() {
Expand Down Expand Up @@ -826,7 +826,7 @@ func TestCollectMetrics(t *testing.T) {
time.Sleep(100 * time.Millisecond)

// Add a global plugin config
c.Config.Plugins.Collector.Plugins["dummy1"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
c.Config.Plugins.Collector.Plugins["mock1"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))

// Load plugin
load(c, JSONRPC_PluginPath)
Expand All @@ -840,23 +840,23 @@ func TestCollectMetrics(t *testing.T) {

m := []core.Metric{}
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
namespace: []string{"intel", "mock", "foo"},
cfg: cd,
}
m2 := MockMetricType{
namespace: []string{"intel", "dummy", "bar"},
namespace: []string{"intel", "mock", "bar"},
cfg: cd,
}
m3 := MockMetricType{
namespace: []string{"intel", "dummy", "test"},
namespace: []string{"intel", "mock", "test"},
cfg: cd,
}

// retrieve loaded plugin
lp, err := c.pluginManager.get("collector:dummy1:1")
lp, err := c.pluginManager.get("collector:mock1:1")
So(err, ShouldBeNil)
So(lp, ShouldNotBeNil)
pool, errp := c.pluginRunner.AvailablePlugins().getOrCreatePool("collector:dummy1:1")
pool, errp := c.pluginRunner.AvailablePlugins().getOrCreatePool("collector:mock1:1")
So(errp, ShouldBeNil)
pool.subscribe("1", unboundSubscriptionType)
err = c.pluginRunner.runPlugin(lp.Path)
Expand All @@ -868,7 +868,7 @@ func TestCollectMetrics(t *testing.T) {
cr, err := c.CollectMetrics(m, time.Now().Add(time.Second*60))
So(err, ShouldBeNil)
for i := range cr {
So(cr[i].Data(), ShouldContainSubstring, "The dummy collected data!")
So(cr[i].Data(), ShouldContainSubstring, "The mock collected data!")
So(cr[i].Data(), ShouldContainSubstring, "test=true")
}
}
Expand Down
12 changes: 6 additions & 6 deletions control/plugin/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

var (
PluginName = "pulse-collector-dummy2"
PluginName = "pulse-collector-mock2"
PulsePath = os.Getenv("PULSE_PATH")
PluginPath = path.Join(PulsePath, "plugin", PluginName)
)
Expand Down Expand Up @@ -176,14 +176,14 @@ func TestWaitForPluginResponse(t *testing.T) {
So(err.Error(), ShouldEqual, "timeout waiting for response")
})

// These tests don't mock and directly use dummy collector plugin
// These tests don't mock and directly use mock collector plugin
// They require pulse path being set and a recent build of the plugin
// WIP
if PluginPath != "" {
Convey("dummy", func() {
Convey("mock", func() {
m := new(MockController)
a := m.GenerateArgs()
a.PluginLogPath = "/tmp/pulse-dummy.log"
a.PluginLogPath = "/tmp/pulse-mock.log"
ex, err := NewExecutablePlugin(a, PluginPath)
if err != nil {
panic(err)
Expand All @@ -200,10 +200,10 @@ func TestWaitForPluginResponse(t *testing.T) {

})

Convey("dummy2", func() {
Convey("mock2", func() {
m := new(MockController)
a := m.GenerateArgs()
a.PluginLogPath = "/tmp/pulse-dummy.log"
a.PluginLogPath = "/tmp/pulse-mock.log"
ex, err := NewExecutablePlugin(a, PluginPath)
if err != nil {
panic(err)
Expand Down
16 changes: 8 additions & 8 deletions control/plugin_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import (
)

var (
PluginName = "pulse-collector-dummy2"
PluginName = "pulse-collector-mock2"
PulsePath = os.Getenv("PULSE_PATH")
PluginPath = path.Join(PulsePath, "plugin", PluginName)

JSONRPC_PluginName = "pulse-collector-dummy1"
JSONRPC_PluginName = "pulse-collector-mock1"
JSONRPC_PluginPath = path.Join(PulsePath, "plugin", JSONRPC_PluginName)
)

Expand Down Expand Up @@ -90,7 +90,7 @@ func loadPlugin(p *pluginManager, path string) (*loadedPlugin, perror.PulseError
return lp, nil
}

// Uses the dummy collector plugin to simulate loading
// Uses the mock collector plugin to simulate loading
func TestLoadPlugin(t *testing.T) {
// These tests only work if PULSE_PATH is known
// It is the responsibility of the testing framework to
Expand All @@ -112,7 +112,7 @@ func TestLoadPlugin(t *testing.T) {

Convey("with a plugin config a plugin loads successfully", func() {
cfg := NewConfig()
cfg.Plugins.Collector.Plugins["dummy2"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
cfg.Plugins.Collector.Plugins["mock2"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
p := newPluginManager(OptSetPluginConfig(cfg.Plugins))
p.SetMetricCatalog(newMetricCatalog())
lp, err := loadPlugin(p, PluginPath)
Expand All @@ -128,7 +128,7 @@ func TestLoadPlugin(t *testing.T) {

Convey("for a plugin requiring a config an incomplete config will result in a load failure", func() {
cfg := NewConfig()
cfg.Plugins.Collector.Plugins["dummy2"] = newPluginConfigItem(optAddPluginConfigItem("test-fail", ctypes.ConfigValueBool{Value: true}))
cfg.Plugins.Collector.Plugins["mock2"] = newPluginConfigItem(optAddPluginConfigItem("test-fail", ctypes.ConfigValueBool{Value: true}))
p := newPluginManager(OptSetPluginConfig(cfg.Plugins))
p.SetMetricCatalog(newMetricCatalog())
lp, err := loadPlugin(p, PluginPath)
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestUnloadPlugin(t *testing.T) {

numPluginsLoaded := len(p.all())
So(numPluginsLoaded, ShouldEqual, 1)
lp, _ := p.get("collector:dummy2:2")
lp, _ := p.get("collector:mock2:2")
_, err = p.UnloadPlugin(lp)

So(err, ShouldBeNil)
Expand All @@ -192,7 +192,7 @@ func TestUnloadPlugin(t *testing.T) {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
lp, err := loadPlugin(p, PluginPath)
glp, err2 := p.get("collector:dummy2:2")
glp, err2 := p.get("collector:mock2:2")
So(err2, ShouldBeNil)
glp.State = DetectedState
_, err = p.UnloadPlugin(lp)
Expand All @@ -206,7 +206,7 @@ func TestUnloadPlugin(t *testing.T) {
p.SetMetricCatalog(newMetricCatalog())
_, err := loadPlugin(p, PluginPath)

lp, err2 := p.get("collector:dummy2:2")
lp, err2 := p.get("collector:mock2:2")
So(err2, ShouldBeNil)
_, err = p.UnloadPlugin(lp)

Expand Down
2 changes: 1 addition & 1 deletion control/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestRunnerPluginRunning(t *testing.T) {
Convey("Runner", func() {
Convey("startPlugin", func() {

// These tests only work if Pulse Path is known to discover dummy plugin used for testing
// These tests only work if Pulse Path is known to discover mock plugin used for testing
if PulsePath != "" {
Convey("should return an AvailablePlugin", func() {
r := newRunner(&routing.RoundRobinStrategy{})
Expand Down
2 changes: 1 addition & 1 deletion examples/influxdb-grafana/grafana/pcm-psutil.json
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,4 @@
"links": []

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"workflow": {
"collect": {
"metrics": {
"/intel/dummy/foo": {},
"/intel/dummy/bar": {}
"/intel/mock/foo": {},
"/intel/mock/bar": {}
},
"config": {
"/intel/dummy": {
"/intel/mock": {
"user": "root",
"password": "secret"
}
Expand Down
Loading

0 comments on commit c8b23f7

Please sign in to comment.