本文整理汇总了Golang中github.com/percona/percona-agent/test.IsDeeply函数的典型用法代码示例。如果您正苦于以下问题:Golang IsDeeply函数的具体用法?Golang IsDeeply怎么用?Golang IsDeeply使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsDeeply函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetConfig
func (s *AgentTestSuite) TestGetConfig(t *C) {
cmd := &proto.Cmd{
Ts: time.Now(),
User: "daniel",
Cmd: "GetConfig",
Service: "agent",
}
s.sendChan <- cmd
got := test.WaitReply(s.recvChan)
t.Assert(len(got), Equals, 1)
gotConfig := []proto.AgentConfig{}
if err := json.Unmarshal(got[0].Data, &gotConfig); err != nil {
t.Fatal(err)
}
config := *s.config
config.Links = nil
bytes, _ := json.Marshal(config)
expect := []proto.AgentConfig{
{
InternalService: "agent",
Config: string(bytes),
Running: true,
},
}
if ok, diff := test.IsDeeply(gotConfig, expect); !ok {
t.Logf("%+v", gotConfig)
t.Error(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:32,代码来源:agent_test.go
示例2: TestC002
func (s *AggregatorTestSuite) TestC002(t *C) {
interval := int64(300)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c002-1 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
for i := 1; i <= 5; i++ {
file := fmt.Sprintf("%s/c002-%d.json", sample, i)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
}
// Next interval causes 1st to be reported.
file := fmt.Sprintf("%s/c002-n.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c002r.json", expect); err != nil {
t.Fatal("c002r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
t.Fatal(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:34,代码来源:mm_test.go
示例3: TestAddWatcher
func (s *ManagerTestSuite) TestAddWatcher(t *check.C) {
now = int64(1380330697385120263) // Fri Sep 27 18:11:37.385120 -0700 PDT 2013
s.tickerFactory.Set([]ticker.Ticker{s.mockTicker})
m := ticker.NewClock(s.tickerFactory, nowFunc)
c := make(chan time.Time)
m.Add(c, 79, true)
if !test.WaitState(s.mockTicker.RunningChan) {
t.Error("Starts ticker")
}
if ok, diff := test.IsDeeply(s.tickerFactory.Made, []uint{79}); !ok {
t.Errorf("Make 79s ticker, got %#v", diff)
}
if len(s.mockTicker.Added) == 0 {
t.Error("Ticker added watcher")
}
// Manager should call ticker's ETA() to return time to next tick.
d := m.ETA(c)
if d != 0.1 {
t.Error("clock.Manager.ETA()")
}
m.Remove(c)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:29,代码来源:ticker_test.go
示例4: TestProcMeminfo001
func (s *ProcMeminfoTestSuite) TestProcMeminfo001(t *C) {
m := system.NewMonitor("", &system.Config{}, s.logger)
content, err := ioutil.ReadFile(sample + "/proc/meminfo001.txt")
if err != nil {
t.Fatal(err)
}
got, err := m.ProcMeminfo(content)
if err != nil {
t.Fatal(err)
}
// Remember: the order of this array must match order in which each
// stat appears in the input file:
expect := []mm.Metric{
{Name: "memory/MemTotal", Type: "gauge", Number: 8046892}, // ok
{Name: "memory/MemFree", Type: "gauge", Number: 5273644}, // ok
{Name: "memory/Buffers", Type: "gauge", Number: 300684}, // ok
{Name: "memory/Cached", Type: "gauge", Number: 946852}, // ok
{Name: "memory/SwapCached", Type: "gauge", Number: 0}, // ok
{Name: "memory/Active", Type: "gauge", Number: 1936436}, // ok
{Name: "memory/Inactive", Type: "gauge", Number: 598916}, // ok
{Name: "memory/SwapTotal", Type: "gauge", Number: 8253436}, // ok
{Name: "memory/SwapFree", Type: "gauge", Number: 8253436}, // ok
{Name: "memory/Dirty", Type: "gauge", Number: 0}, // ok
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:29,代码来源:system_test.go
示例5: TestProcVmstat001
func (s *ProcVmstatTestSuite) TestProcVmstat001(t *C) {
m := system.NewMonitor("", &system.Config{}, s.logger)
content, err := ioutil.ReadFile(sample + "/proc/vmstat001.txt")
if err != nil {
t.Fatal(err)
}
got, err := m.ProcVmstat(content)
if err != nil {
t.Fatal(err)
}
// Remember: the order of this array must match order in which each
// stat appears in the input file:
expect := []mm.Metric{
{Name: "vmstat/numa_hit", Type: "counter", Number: 42594095}, // ok
{Name: "vmstat/numa_miss", Type: "counter", Number: 0}, // ok
{Name: "vmstat/numa_foreign", Type: "counter", Number: 0}, // ok
{Name: "vmstat/numa_interleave", Type: "counter", Number: 7297}, // ok
{Name: "vmstat/numa_local", Type: "counter", Number: 42594095}, // ok
{Name: "vmstat/numa_other", Type: "counter", Number: 0}, // ok
{Name: "vmstat/pgpgin", Type: "counter", Number: 646645}, // ok
{Name: "vmstat/pgpgout", Type: "counter", Number: 5401659}, // ok
{Name: "vmstat/pswpin", Type: "counter", Number: 0}, // ok
{Name: "vmstat/pswpout", Type: "counter", Number: 0}, // ok
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:29,代码来源:system_test.go
示例6: TestInit
func (s *RepoTestSuite) TestInit(t *C) {
im := instance.NewRepo(s.logger, s.configDir, s.api)
t.Assert(im, NotNil)
err := im.Init()
t.Check(err, IsNil)
err = test.CopyFile(test.RootDir+"/mm/config/mysql-1.conf", s.configDir)
t.Assert(err, IsNil)
err = im.Init()
t.Assert(err, IsNil)
mysqlIt := &proto.MySQLInstance{}
err = im.Get("mysql", 1, mysqlIt)
t.Assert(err, IsNil)
expect := &proto.MySQLInstance{
Id: 1,
Hostname: "db1",
DSN: "user:[email protected]:(127.0.0.1:3306)",
Distro: "Percona Server",
Version: "5.6.16",
}
if same, diff := test.IsDeeply(mysqlIt, expect); !same {
test.Dump(mysqlIt)
test.Dump(expect)
t.Error(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:30,代码来源:instance_test.go
示例7: TestC000
// All zero values
func (s *AggregatorTestSuite) TestC000(t *C) {
interval := int64(60)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c000 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
file := sample + "/c000.json"
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
file = sample + "/c000-n.json"
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c000r.json", expect); err != nil {
t.Fatal("c000r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
t.Fatal(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:32,代码来源:mm_test.go
示例8: TestStartStopManager
func (s *ManagerTestSuite) TestStartStopManager(t *C) {
/**
* mm is a proxy manager for monitors, so it's always running.
* It should implement the service manager interface anyway,
* but it doesn't actually start or stop. Its main work is done
* in Handle, starting and stopping monitors (tested later).
*/
mrm := mock.NewMrmsMonitor()
m := mm.NewManager(s.logger, s.factory, s.clock, s.spool, s.im, mrm)
if m == nil {
t.Fatal("Make new mm.Manager")
}
// It shouldn't have added a tickChan yet.
if len(s.clock.Added) != 0 {
t.Error("tickChan not added yet")
}
// First the API marshals an mm.Config.
config := &mm.Config{
ServiceInstance: proto.ServiceInstance{
Service: "mysql",
InstanceId: 1,
},
Collect: 1,
Report: 60,
// No monitor-specific config
}
err := pct.Basedir.WriteConfig("mm-mysql-1", config)
t.Assert(err, IsNil)
// The agent calls mm.Start().
err = m.Start()
t.Assert(err, IsNil)
// There is a monitor so there should be tickers.
if ok, diff := test.IsDeeply(s.clock.Added, []uint{1}); !ok {
test.Dump(s.clock.Added)
t.Errorf("Does not add tickChan, got %#v", diff)
}
// Its status should be "Running".
status := m.Status()
t.Check(status["mm"], Equals, "Running")
// Can't start mm twice.
err = m.Start()
t.Check(err, Not(Equals), "")
// Stopping should be idempotent.
err = m.Stop()
t.Check(err, IsNil)
err = m.Stop()
t.Check(err, IsNil)
status = m.Status()
t.Check(status["mm"], Equals, "Stopped")
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:58,代码来源:mm_test.go
示例9: TestLoadConfig
func (s *AgentTestSuite) TestLoadConfig(t *C) {
// Load a partial config to make sure LoadConfig() works in general but also
// when the config has missing options (which is normal).
os.Remove(s.configFile)
test.CopyFile(sample+"/config001.json", s.configFile)
bytes, err := agent.LoadConfig()
t.Assert(err, IsNil)
got := &agent.Config{}
if err := json.Unmarshal(bytes, got); err != nil {
t.Fatal(err)
}
expect := &agent.Config{
AgentUuid: "abc-123-def",
ApiHostname: agent.DEFAULT_API_HOSTNAME,
ApiKey: "123",
Keepalive: agent.DEFAULT_KEEPALIVE,
PidFile: agent.DEFAULT_PIDFILE,
}
if same, diff := test.IsDeeply(got, expect); !same {
// @todo: if expect is not ptr, IsDeeply dies with "got ptr, expected struct"
test.Dump(got)
t.Error(diff)
}
// Load a config with all options to make sure LoadConfig() hasn't missed any.
os.Remove(s.configFile)
test.CopyFile(sample+"/full_config.json", s.configFile)
bytes, err = agent.LoadConfig()
t.Assert(err, IsNil)
got = &agent.Config{}
if err := json.Unmarshal(bytes, got); err != nil {
t.Fatal(err)
}
expect = &agent.Config{
ApiHostname: "agent hostname",
ApiKey: "api key",
AgentUuid: "agent uuid",
Keepalive: agent.DEFAULT_KEEPALIVE,
PidFile: "pid file",
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:45,代码来源:agent_test.go
示例10: TestOfflineBuffering
func (s *RelayTestSuite) TestOfflineBuffering(t *C) {
l := s.logger
// We're going to cause the relay's client Recv() to get an error
// which will cause the relay to connect again. We block this 2nd
// connect by blocking this chan. End result: relay remains offline.
s.client.SetConnectChan(s.connectChan)
doneChan := make(chan bool, 1)
go func() {
s.client.RecvError <- io.EOF
doneChan <- true
}()
// Wait for the relay to recv the recv error.
<-doneChan
// Wait for the relay to call client.Connect().
<-s.connectChan
// Double-check that relay is offline.
if !test.WaitStatus(1, s.relay, "ws", "Disconnected") {
t.Fatal("Relay connects")
}
// Relay is offline and trying to connect again in another goroutine.
// These entries should therefore not be sent. There's a minor race
// condition: when relay goes offline, it sends an internal log entry.
// Sometimes we get that here (Service="log") and sometimes not
// (len(got)==0). Either condition is correct for this test.
l.Error("err1")
l.Error("err2")
got := test.WaitLog(s.recvChan, 0)
if len(got) > 0 && got[0].Service != "log" {
t.Errorf("Log entries are not sent while offline: %+v", got)
}
// Unblock the relay's connect attempt.
s.connectChan <- true
if !test.WaitStatus(1, s.relay, "ws", "Connected") {
t.Fatal("Relay connects")
}
// Wait for the relay resend what it had ^ buffered.
got = test.WaitLog(s.recvChan, 3)
expect := []proto.LogEntry{
{Ts: test.Ts, Level: proto.LOG_WARNING, Service: "log", Msg: "connected: false"},
{Ts: test.Ts, Level: proto.LOG_ERROR, Service: "test", Msg: "err1"},
{Ts: test.Ts, Level: proto.LOG_ERROR, Service: "test", Msg: "err2"},
{Ts: test.Ts, Level: proto.LOG_WARNING, Service: "log", Msg: "connected: true"},
}
if same, diff := test.IsDeeply(got, expect); !same {
t.Error(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:53,代码来源:log_test.go
示例11: TestAddRemove
func (s *RepoTestSuite) TestAddRemove(t *C) {
im := instance.NewRepo(s.logger, s.configDir, s.api)
t.Assert(im, NotNil)
t.Check(test.FileExists(s.configDir+"/mysql-1.conf"), Equals, false)
mysqlIt := &proto.MySQLInstance{
Id: 1,
Hostname: "db1",
DSN: "user:[email protected]:(127.0.0.1:3306)",
Distro: "Percona Server",
Version: "5.6.16",
}
data, err := json.Marshal(mysqlIt)
t.Assert(err, IsNil)
err = im.Add("mysql", 1, data, true)
t.Assert(err, IsNil)
t.Check(test.FileExists(s.configDir+"/mysql-1.conf"), Equals, true)
got := &proto.MySQLInstance{}
err = im.Get("mysql", 1, got)
t.Assert(err, IsNil)
if same, diff := test.IsDeeply(got, mysqlIt); !same {
t.Error(diff)
}
data, err = ioutil.ReadFile(s.configDir + "/mysql-1.conf")
t.Assert(err, IsNil)
got = &proto.MySQLInstance{}
err = json.Unmarshal(data, got)
t.Assert(err, IsNil)
if same, diff := test.IsDeeply(got, mysqlIt); !same {
t.Error(diff)
}
im.Remove("mysql", 1)
t.Check(test.FileExists(s.configDir+"/mysql-1.conf"), Equals, false)
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:40,代码来源:instance_test.go
示例12: Test500Error
func (s *SenderTestSuite) Test500Error(t *C) {
spool := mock.NewSpooler(nil)
spool.FilesOut = []string{"file1", "file2", "file3"}
spool.DataOut = map[string][]byte{
"file1": []byte("file1"),
"file2": []byte("file2"),
"file3": []byte("file3"),
}
sender := data.NewSender(s.logger, s.client)
err := sender.Start(spool, s.tickerChan, 5, false)
t.Assert(err, IsNil)
s.tickerChan <- time.Now()
got := test.WaitBytes(s.dataChan)
if same, diff := test.IsDeeply(got[0], []byte("file1")); !same {
t.Error(diff)
}
// 3 files before API error.
t.Check(len(spool.DataOut), Equals, 3)
// Simulate API error.
select {
case s.respChan <- &proto.Response{Code: 503}:
case <-time.After(500 * time.Millisecond):
t.Error("Sender receives prot.Response after sending data")
}
// Wait for it to finsih and return.
if !test.WaitStatusPrefix(data.MAX_SEND_ERRORS*data.CONNECT_ERROR_WAIT, sender, "data-sender", "Idle") {
t.Fatal("Timeout waiting for data-sender status=Idle")
}
// Still 3 files after API error.
t.Check(len(spool.DataOut), Equals, 3)
t.Check(len(spool.RejectedFiles), Equals, 0)
// There's only 1 call to SendBytes because after an API error
// the send stops immediately.
trace := test.DrainTraceChan(s.client.TraceChan)
t.Check(trace, DeepEquals, []string{
"ConnectOnce",
"SendBytes",
"Recv",
"DisconnectOnce",
})
err = sender.Stop()
t.Assert(err, IsNil)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:52,代码来源:data_test.go
示例13: TestSendData
func (s *SenderTestSuite) TestSendData(t *C) {
spool := mock.NewSpooler(nil)
slow001, err := ioutil.ReadFile(sample + "slow001.json")
if err != nil {
t.Fatal(err)
}
spool.FilesOut = []string{"slow001.json"}
spool.DataOut = map[string][]byte{"slow001.json": slow001}
sender := data.NewSender(s.logger, s.client)
err = sender.Start(spool, s.tickerChan, 5, false)
if err != nil {
t.Fatal(err)
}
data := test.WaitBytes(s.dataChan)
if len(data) != 0 {
t.Errorf("No data sent before tick; got %+v", data)
}
s.tickerChan <- time.Now()
data = test.WaitBytes(s.dataChan)
if same, diff := test.IsDeeply(data[0], slow001); !same {
t.Error(diff)
}
t.Check(len(spool.DataOut), Equals, 1)
select {
case s.respChan <- &proto.Response{Code: 200}:
case <-time.After(500 * time.Millisecond):
t.Error("Sender receives prot.Response after sending data")
}
// Sender should include its websocket client status. We're using a mock ws client
// which reports itself as "data-client: ok".
status := sender.Status()
t.Check(status["data-client"], Equals, "ok")
err = sender.Stop()
t.Assert(err, IsNil)
t.Check(len(spool.DataOut), Equals, 0)
t.Check(len(spool.RejectedFiles), Equals, 0)
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:49,代码来源:data_test.go
示例14: TestC003
// COUNTER
func (s *AggregatorTestSuite) TestC003(t *C) {
interval := int64(5)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c003 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
for i := 1; i <= 5; i++ {
file := fmt.Sprintf("%s/c003-%d.json", sample, i)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
}
// Next interval causes 1st to be reported.
file := fmt.Sprintf("%s/c003-n.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
/**
* Pretend we're monitoring Bytes_sents every second:
* first val = 100
* prev this diff val/s
* next val 100 200 100 100
* next val 200 400 200 200
* next val 400 800 400 400
* next val 800 1600 800 800
*
* So min bytes/s = 100, max = 800, avg = 375. These are
* the values in c003r.json.
*/
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c003r.json", expect); err != nil {
t.Fatal("c003r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
t.Fatal(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:46,代码来源:mm_test.go
示例15: TestGetAllConfigs
func (s *AgentTestSuite) TestGetAllConfigs(t *C) {
cmd := &proto.Cmd{
Ts: time.Now(),
User: "daniel",
Cmd: "GetAllConfigs",
Service: "agent",
}
s.sendChan <- cmd
got := test.WaitReply(s.recvChan)
t.Assert(len(got), Equals, 1)
reply := got[0]
t.Check(reply.Error, Equals, "")
t.Assert(reply.Data, Not(HasLen), 0)
gotConfigs := []proto.AgentConfig{}
err := json.Unmarshal(reply.Data, &gotConfigs)
t.Assert(err, IsNil)
bytes, _ := json.Marshal(s.config)
sort.Sort(test.ByInternalService(gotConfigs))
expectConfigs := []proto.AgentConfig{
{
InternalService: "agent",
Config: string(bytes),
Running: true,
},
{
InternalService: "mm",
Config: `{"Foo":"bar"}`,
Running: false,
},
{
InternalService: "qan",
Config: `{"Foo":"bar"}`,
Running: false,
},
}
if ok, diff := test.IsDeeply(gotConfigs, expectConfigs); !ok {
test.Dump(gotConfigs)
t.Error(diff)
}
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:44,代码来源:agent_test.go
示例16: TestC003Lost
func (s *AggregatorTestSuite) TestC003Lost(t *C) {
interval := int64(5)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Ts in c003 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
// The full sequence is files 1-5, but we send only 1 and 5,
// simulating monitor failure during 2-4. More below...
file := fmt.Sprintf("%s/c003-1.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
file = fmt.Sprintf("%s/c003-5.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
// Next interval causes 1st to be reported.
file = fmt.Sprintf("%s/c003-n.json", sample)
if err := sendCollection(file, s.collectionChan); err != nil {
t.Fatal(file, err)
}
/**
* Values we did get are 100 and 1600 and ts 00 to 04. So that looks like
* 1500 bytes / 4s = 375. And since there was only 1 interval, we expect
* 375 for all stat values.
*/
got := test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c003rlost.json", expect); err != nil {
t.Fatal("c003r.json ", err)
}
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
test.Dump(got.Stats)
test.Dump(expect.Stats)
t.Fatal(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:44,代码来源:mm_test.go
示例17: TestStartStopManager
func (s *ManagerTestSuite) TestStartStopManager(t *C) {
m := sysconfig.NewManager(s.logger, s.factory, s.clock, s.spool, s.im)
t.Assert(m, NotNil)
// It shouldn't have added a tickChan yet.
if len(s.clock.Added) != 0 {
t.Error("tickChan not added yet")
}
// Write a sysconfig monitor config to disk.
config := &sysconfig.Config{
ServiceInstance: proto.ServiceInstance{Service: "mysql", InstanceId: 1},
Report: 3600,
// No monitor-specific config
}
pct.Basedir.WriteConfig("sysconfig-mysql-1", config)
// The agent calls sysconfig.Start() to start manager which starts all monitors.
err := m.Start()
t.Assert(err, IsNil)
// It should not add a tickChan to the clock (this is done in Handle()).
if ok, diff := test.IsDeeply(s.clock.Added, []uint{3600}); !ok {
t.Errorf("Adds tickChan, got %#v", diff)
}
// Its status should be "Running".
status := m.Status()
t.Check(status["sysconfig"], Equals, "Running")
// Can't start manager twice.
err = m.Start()
t.Check(err, NotNil)
// Stopping is idempotent.
err = m.Stop()
t.Check(err, IsNil)
err = m.Stop()
t.Check(err, IsNil)
status = m.Status()
t.Check(status["sysconfig"], Equals, "Stopped")
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:43,代码来源:sysconfig_test.go
示例18: TestC001
func (s *AggregatorTestSuite) TestC001(t *C) {
interval := int64(300)
a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool)
go a.Start()
defer a.Stop()
// Load collection from file and send to aggregator.
if err := sendCollection(sample+"/c001-1.json", s.collectionChan); err != nil {
t.Fatal(err)
}
// Ts in c001 is 2009-11-10 23:00:00.
t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
got := test.WaitMmReport(s.dataChan)
if got != nil {
t.Error("No report before 2nd interval, got: %+v", got)
}
// Ts in c001 is 2009-11-10 23:05:01, 1s into the next interval.
if err := sendCollection(sample+"/c001-2.json", s.collectionChan); err != nil {
t.Fatal(err)
}
got = test.WaitMmReport(s.dataChan)
t.Assert(got, NotNil)
t.Check(got.Ts, Equals, t1)
t.Check(uint64(got.Duration), Equals, uint64(interval))
expect := &mm.Report{}
if err := test.LoadMmReport(sample+"/c001r.json", expect); err != nil {
t.Fatal(err)
}
t.Check(got.Ts, Equals, t1)
if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok {
test.Dump(got.Stats)
test.Dump(expect.Stats)
t.Fatal(diff)
}
}
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:41,代码来源:mm_test.go
示例19: TestProcLoadavg001
func (s *ProcLoadavgTestSuite) TestProcLoadavg001(t *C) {
m := system.NewMonitor("", &system.Config{}, s.logger)
content, err := ioutil.ReadFile(sample + "/proc/loadavg001.txt")
if err != nil {
t.Fatal(err)
}
got, err := m.ProcLoadavg(content)
if err != nil {
t.Fatal(err)
}
// Remember: the order of this array must match order in which each
// stat appears in the input file:
expect := []mm.Metric{
{Name: "loadavg/1min", Type: "gauge", Number: 0.45}, // ok
{Name: "loadavg/5min", Type: "gauge", Number: 0.56}, // ok
{Name: "loadavg/15min", Type: "gauge", Number: 0.58}, // ok
{Name: "loadavg/running", Type: "gauge", Number: 1}, // ok
{Name: "loadavg/processes", Type: "gauge", Number: 598}, // ok
}
if same, diff := test.IsDeeply(got, expect); !same {
test.Dump(got)
t.Error(diff)
}
}
开发者ID:hg3rdrock,项目名称:percona-agent,代码行数:24,代码来源:system_test.go
示例20: TestRestartMonitor
/**
* Tests:
* - starting monitor
* - stopping monitor
* - starting monitor again (restarting monitor)
* - sneaked in:) unknown cmd test
*/
func (s *ManagerTestSuite) TestRestartMonitor(t *C) {
// Create and start mm, no monitors yet.
m := mm.NewManager(s.logger, s.factory, s.clock, s.spool, s.im)
t.Assert(m, NotNil)
err := m.Start()
t.Assert(err, IsNil)
// Start a monitor by sending StartService + monitor config.
// This is the config in test/mm/config/mm-mysql-1.conf.
mmConfig := &mysql.Config{
Config: mm.Config{
ServiceInstance: proto.ServiceInstance{
Service: "mysql",
InstanceId: 1,
},
Collect: 1,
Report: 60,
},
Status: map[string]string{
"threads_connected": "gauge",
"threads_running": "gauge",
},
}
mmConfigData, err := json.Marshal(mmConfig)
t.Assert(err, IsNil)
// If this were a real monitor, it would decode and set its own config.
// The mock monitor doesn't have any real config type, so we set it manually.
s.mysqlMonitor.SetConfig(mmConfig)
// The agent calls mm.Handle() with the cmd (for logging and status) and the config data.
cmd := &proto.Cmd{
User: "daniel",
Service: "mm",
Cmd: "StartService",
Data: mmConfigData,
}
reply := m.Handle(cmd)
t.Assert(reply, NotNil)
t.Check(reply.Error, Equals, "")
// The monitor should be running. The mock monitor returns "Running" if
// Start() has been called; else it returns "Stopped".
status := m.Status()
t.Check(status["monitor"], Equals, "Running")
// There should be a 1s collect ticker for the monitor.
if ok, diff := test.IsDeeply(s.clock.Added, []uint{1}); !ok {
t.Errorf("Make 1s ticker for collect interval\n%s", diff)
}
// After starting a monitor, mm should write its config to the dir
// it learned when mm.LoadConfig() was called. Next time agent starts,
// it will have mm start the monitor with this config.
data, err := ioutil.ReadFile(s.configDir + "/mm-mysql-1.conf")
t.Check(err, IsNil)
gotConfig := &mysql.Config{}
err = json.Unmarshal(data, gotConfig)
t.Check(err, IsNil)
if same, diff := test.IsDeeply(gotConfig, mmConfig); !same {
test.Dump(gotConfig)
t.Error(diff)
}
/**
* Stop the monitor.
*/
cmd = &proto.Cmd{
User: "daniel",
Service: "mm",
Cmd: "StopService",
Data: mmConfigData,
}
// Handles StopService without error.
reply = m.Handle(cmd)
t.Assert(reply, NotNil)
t.Check(reply.Error, Equals, "")
// Stop a monitor removes it from the managers list of monitors.
// So it's no longer present in a status request.
status = m.Status()
t.Check(status["monitor"], Equals, "")
// After stopping the monitor, the manager should remove its tickChan.
if len(s.clock.Removed) != 1 {
t.Error("Remove's monitor's tickChan from clock")
}
// After stopping a monitor, mm should remove its config file so agent
// doesn't start it on restart.
file := s.configDir + "/mm-mysql-1.conf"
//.........这里部分代码省略.........
开发者ID:huangzhiyong,项目名称:percona-agent,代码行数:101,代码来源:mm_test.go
注:本文中的github.com/percona/percona-agent/test.IsDeeply函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论