You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

  1. package mock
  2. import (
  3. stdlog "log"
  4. "reflect"
  5. "github.com/tendermint/tmlibs/log"
  6. em "github.com/tendermint/tools/tm-monitor/eventmeter"
  7. )
  8. type EventMeter struct {
  9. latencyCallback em.LatencyCallbackFunc
  10. disconnectCallback em.DisconnectCallbackFunc
  11. eventCallback em.EventCallbackFunc
  12. }
  13. func (e *EventMeter) Start() error { return nil }
  14. func (e *EventMeter) Stop() {}
  15. func (e *EventMeter) SetLogger(l log.Logger) {}
  16. func (e *EventMeter) RegisterLatencyCallback(cb em.LatencyCallbackFunc) { e.latencyCallback = cb }
  17. func (e *EventMeter) RegisterDisconnectCallback(cb em.DisconnectCallbackFunc) {
  18. e.disconnectCallback = cb
  19. }
  20. func (e *EventMeter) Subscribe(eventID string, cb em.EventCallbackFunc) error {
  21. e.eventCallback = cb
  22. return nil
  23. }
  24. func (e *EventMeter) Unsubscribe(eventID string) error {
  25. e.eventCallback = nil
  26. return nil
  27. }
  28. func (e *EventMeter) Call(callback string, args ...interface{}) {
  29. switch callback {
  30. case "latencyCallback":
  31. e.latencyCallback(args[0].(float64))
  32. case "disconnectCallback":
  33. e.disconnectCallback()
  34. case "eventCallback":
  35. e.eventCallback(args[0].(*em.EventMetric), args[1])
  36. }
  37. }
  38. type RpcClient struct {
  39. Stubs map[string]interface{}
  40. }
  41. func (c *RpcClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
  42. s, ok := c.Stubs[method]
  43. if !ok {
  44. stdlog.Fatalf("Call to %s, but no stub is defined for it", method)
  45. }
  46. rv, rt := reflect.ValueOf(result), reflect.TypeOf(result)
  47. rv, rt = rv.Elem(), rt.Elem()
  48. rv.Set(reflect.ValueOf(s))
  49. return s, nil
  50. }