Пример #1
0
func (s *NodeSuite) TestProperties(c *C) {
	root := newNode()
	rootProps := NewProperties().SetRetry(1)
	root.setProperties([]string{}, rootProps)
	props := root.properties([]string{})
	c.Assert(props, DeepEquals, rootProps)

	root.setProperties([]string{"a", "b"}, NewProperties().SetTimeout(types.Duration(time.Second)))
	props = root.properties([]string{})
	c.Assert(props, DeepEquals, rootProps)
	props = root.properties([]string{"a"})
	c.Assert(props, DeepEquals, rootProps)
	props = root.properties([]string{"a", "b"})
	c.Assert(props, DeepEquals, NewProperties().SetRetry(1).SetTimeout(types.Duration(time.Second)))

	root.setProperties([]string{"a"}, NewProperties().SetRetry(2))
	props = root.properties([]string{"a", "b"})
	c.Assert(props, DeepEquals, NewProperties().SetRetry(2).SetTimeout(types.Duration(time.Second)))
	props = root.properties([]string{"a", "b", "c"})
	c.Assert(props, DeepEquals, NewProperties().SetRetry(2).SetTimeout(types.Duration(time.Second)))
	props = root.properties([]string{"a", "c"})
	c.Assert(props, DeepEquals, NewProperties().SetRetry(2))
}
Пример #2
0
package storage

import (
	"time"

	"github.com/yosisa/pluq/types"
	"github.com/yosisa/pluq/uid"
)

var (
	DefaultRetry   = types.Retry(10)
	DefaultTimeout = types.Duration(30 * time.Second)
)

type Envelope struct {
	ID       uid.ID
	Queue    string
	Retry    types.Retry
	Timeout  types.Duration
	Messages []*Message
}

func NewEnvelope() *Envelope {
	return &Envelope{
		Retry:   DefaultRetry,
		Timeout: DefaultTimeout,
	}
}

func (e *Envelope) AddMessage(m *Message) {
	e.Messages = append(e.Messages, m)