示例#1
0
func TestHandoffPut(t *testing.T) {
	config := Config{HandoffInterval: time.Millisecond * 10}
	client := &FakeTransferrer{map[string][]*data.Data{}, false}
	h := NewHintedHandoff(config, client)

	h.Put(data.New("foo", "bar"), "n1")
	h.Put(data.New("food", "bar"), "n1")
	h.Put(data.New("foo", "baz"), "n1")
	h.Put(data.New("food", "bar"), "n2")
	h.Put(data.New("foo", "baz"), "n2")

	// Client initially fails. Wait for it to recover and check hints are
	// still sent.
	time.Sleep(config.HandoffInterval * 2)
	client.status = true
	time.Sleep(config.HandoffInterval * 2)

	if len(client.sent["n1"]) != 3 {
		t.Errorf("Should have sent one item, but sent %d", len(client.sent["n1"]))
	}

	if len(client.sent["n2"]) != 2 {
		t.Errorf("Should have sent one item, but sent %d", len(client.sent["n1"]))
	}
}
示例#2
0
// Put finds the key on the correct node in the cluster, sets
// the value and returns a status bool.
// If the key is owned by current node then it coordinates the operation.
// Otherwise it sends the coordination request to the correct node.
func (t *Toystore) Put(key string, value interface{}) (ok bool) {
	address := t.Ring.Find(key)

	if t.isCoordinator(address) {
		ok = t.CoordinatePut(data.New(key, value))
	} else {
		t.log.Printf("Forwarding PUT request to coordinator %s for %s", address, value)
		ok = t.client.CoordinatePut(address, data.New(key, value))
	}
	return
}
示例#3
0
func TestMemoryStore(t *testing.T) {
	res := New()
	res.Put(data.New("foo", "bar"))
	str, success := res.Get("foo")
	if !success {
		t.Error("Test Memory Store unsuccessful.")
	}
	Equal(t, str.Value.(string), "bar")
}