Пример #1
0
// TestBlockingNotifierUpdate tests the BlockingNotifier with a NotifyUpdate call. A ClusterChangeEvent should be generated and contain a Member representing the memberlist.Node that has been updated.
func TestBlockingNotifierUpdate(t *testing.T) {

	// Create node
	metadata := []byte("metadata")
	node := memberlist.Node{
		Name: "Node 1",
		Meta: metadata,
	}

	// Setup notifier
	out := make(chan raftor.ClusterChangeEvent)
	defer close(out)

	// Create blocking notifier
	blocker := Notifier(out)

	// Create event delegate
	delegate := NewEventDelegate(blocker)

	// NotifyUpdate
	go func() {
		delegate.NotifyUpdate(&node)
	}()

	// Wait for event
	evt := <-out

	// Test correctness
	hash := uint64(murmur.Murmur3([]byte(node.Name), murmur.M3Seed))
	assert.Equal(t, raftor.UpdateMember, evt.Type)
	assert.Equal(t, hash, evt.Member.ID())
	assert.Equal(t, metadata, evt.Member.Meta())
}
Пример #2
0
// TestBufferedNotifierJoin tests the BufferedNotifier with multiple messages.
func TestBufferedNotifier(t *testing.T) {
	node := memberlist.Node{
		Name: "Node 1",
	}

	// Hash node
	hash := uint64(murmur.Murmur3([]byte(node.Name), murmur.M3Seed))

	// Setup notifier
	out := make(chan raftor.ClusterChangeEvent, 3)
	defer close(out)

	// Create blocking notifier
	notifier := Notifier(out)

	// Create event delegate
	delegate := NewEventDelegate(notifier)

	// Perform notifications
	go func() {
		node.Meta = []byte("join")
		delegate.NotifyJoin(&node)

		node.Meta = []byte("update")
		delegate.NotifyUpdate(&node)

		node.Meta = []byte("leave")
		delegate.NotifyLeave(&node)
	}()

	// Test join
	evt := <-out
	assert.Equal(t, raftor.AddMember, evt.Type)
	assert.Equal(t, hash, evt.Member.ID())
	assert.True(t, bytes.Equal([]byte("join"), evt.Member.Meta()))

	// Test update
	evt = <-out
	assert.Equal(t, raftor.UpdateMember, evt.Type)
	assert.Equal(t, hash, evt.Member.ID())
	assert.True(t, bytes.Equal([]byte("update"), evt.Member.Meta()))

	// Test leave
	evt = <-out
	assert.Equal(t, raftor.RemoveMember, evt.Type)
	assert.Equal(t, hash, evt.Member.ID())
	assert.True(t, bytes.Equal([]byte("leave"), evt.Member.Meta()))
}
Пример #3
0
// hash performs a Murmur3 hash on the memberlist.Node name
func (n *notifier) hash(other *memberlist.Node) uint64 {
	return uint64(murmur.Murmur3([]byte(other.Name), murmur.M3Seed))
}