Skip to content

Commit

Permalink
Merge pull request #253 from tschottdorf/master
Browse files Browse the repository at this point in the history
add ConditionFailedError to {Set,}GoError()+test
  • Loading branch information
tbg committed Jan 15, 2015
2 parents 96c1221 + 7d582e1 commit d7efcaa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 0 additions & 2 deletions proto/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ message ConditionFailedError {
}

// Error is a union type containing all available errors.
// NOTE: new error types must be added here, and potentially in
// the two locations (*ResponseHeader).{,Set}GoError().
message Error {
option (gogoproto.onlyone) = true;
optional GenericError generic = 1;
Expand Down
35 changes: 35 additions & 0 deletions storage/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,3 +1600,38 @@ func TestInternalMerge(t *testing.T) {
t.Errorf("Get did not return expected value: %s != %s", string(a), e)
}
}

// TestConditionFailedError tests that a ConditionFailedError correctly
// bubbles up from MVCC to Range.
func TestConditionFailedError(t *testing.T) {
s, r, _, _ := createTestRange(t)
key := []byte("k")
value := []byte("quack")
pArgs, pReply := putArgs(key, value, 1, s.StoreID())
if err := r.executeCmd(proto.Put, pArgs, pReply); err != nil {
t.Fatal(err)
}
args := &proto.ConditionalPutRequest{
RequestHeader: proto.RequestHeader{
Key: key,
Timestamp: proto.MinTimestamp,
RaftID: 1,
Replica: proto.Replica{StoreID: s.StoreID()},
},
Value: proto.Value{
Bytes: value,
},
ExpValue: &proto.Value{
Bytes: []byte("moo"),
},
}
reply := &proto.ConditionalPutResponse{}
err := r.executeCmd(proto.ConditionalPut, args, reply)
if cErr, ok := err.(*proto.ConditionFailedError); err == nil || !ok {
t.Fatalf("expected ConditionFailedError, got %T with content %+v",
err, err)
} else if v := cErr.ActualValue; v == nil || !bytes.Equal(v.Bytes, value) {
t.Errorf("ConditionFailedError with bytes %q expected, but got %+v",
value, v)
}
}
1 change: 1 addition & 0 deletions storage/response_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func TestResponseCacheShouldCache(t *testing.T) {
{&proto.RangeNotFoundError{}, true},
{&proto.RangeKeyMismatchError{}, true},
{&proto.TransactionStatusError{}, true},
{&proto.ConditionFailedError{}, true},
{&proto.WriteIntentError{}, false},
{&proto.WriteTooOldError{}, false},
}
Expand Down

0 comments on commit d7efcaa

Please sign in to comment.