qmp_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package monitor
  15. import (
  16. "testing"
  17. "time"
  18. "yunion.io/x/log"
  19. )
  20. func TestQmpMonitor_Connect(t *testing.T) {
  21. onConnected := func() { log.Infof("Monitor Connected") }
  22. onDisConnect := func(error) { log.Infof("Monitor DisConnect") }
  23. onTimeout := func(error) { log.Infof("Monitor Timeout") }
  24. m := NewQmpMonitor("", "", onDisConnect, onTimeout, onConnected, nil)
  25. var host = "127.0.0.1"
  26. var port = 56101
  27. m.Connect(host, port)
  28. rawCallBack := func(res *Response) { log.Infof("OnCallback %s", res) }
  29. // cmd0 := &Command{Execute: "qmp_capabilities"}
  30. // m.Query(cmd0, rawCallBack)
  31. cmd1 := &Command{
  32. Execute: "human-monitor-command",
  33. Args: map[string]string{"command-line": "info block"},
  34. }
  35. m.Query(cmd1, rawCallBack)
  36. statusCallBack := func(res string) { log.Infof("OnStatusCallback %s", res) }
  37. m.QueryStatus(statusCallBack)
  38. m.Disconnect()
  39. time.Sleep(3 * time.Second)
  40. }