hmp_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. )
  19. func TestHmpMonitor_Connect(t *testing.T) {
  20. onConnected := func() { t.Logf("Monitor Connected") }
  21. onDisConnect := func(error) { t.Logf("Monitor DisConnect") }
  22. onTimeout := func(error) { t.Logf("Monitor Timeout") }
  23. m := NewHmpMonitor("fake_server", "", onDisConnect, onTimeout, onConnected)
  24. var host = "127.0.0.1"
  25. var port = 55901
  26. m.Connect(host, port)
  27. rawCallBack := func(res string) { t.Logf("OnCallback: %s", res) }
  28. m.Query("info block", rawCallBack)
  29. m.Query("unknown cmd", rawCallBack)
  30. statusCallBack := func(res string) { t.Logf("OnStatusCallback %s", res) }
  31. m.QueryStatus(statusCallBack)
  32. m.GetBlockJobCounts(func(res int) { t.Logf("GetBlockJobCounts %d", res) })
  33. m.GetCpuCount(func(res int) { t.Logf("GetCpuCount %d", res) })
  34. time.Sleep(3 * time.Second)
  35. m.Disconnect()
  36. }