Skip to content

Commit

Permalink
add two new server error codes
Browse files Browse the repository at this point in the history
ELEMENT_NOT_FOUND	23
ELEMENT_EXISTS		24

So far,
ELEMENT_NOT_FOUND is returned by map_put (and map_put_items) when policy is REPLACE but key was not found.
ELEMENT_EXISTS is returned by map_put (map_put_items) when policy is CREATE_ONLY but key already exist.
  • Loading branch information
jhecking committed Aug 16, 2016
1 parent bac2c2a commit 8c205d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
14 changes: 12 additions & 2 deletions lib/aerospike/result_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ module ResultCode
# Operation not allowed at this time.
FAIL_FORBIDDEN = 22

# Returned by Map put and put_items operations when policy is REPLACE but key was not found
ELEMENT_NOT_FOUND = 23

# Returned by Map put and put_items operations when policy is CREATE_ONLY but key already exists
ELEMENT_EXISTS = 24

# There are no more records left for query.
QUERY_END = 50

Expand All @@ -129,11 +135,9 @@ module ResultCode

ILLEGAL_STATE = 56


# User name is invalid.
INVALID_USER = 60


# User was previously created.
USER_ALREADY_EXISTS = 61

Expand Down Expand Up @@ -292,6 +296,12 @@ def self.message(code)
when FAIL_FORBIDDEN
"Operation not allowed at this time"

when ELEMENT_NOT_FOUND
"Element not found"

when ELEMENT_EXISTS
"Element already exists"

when QUERY_END
"Query end"

Expand Down
24 changes: 14 additions & 10 deletions spec/aerospike/cdt_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ def verifyOperation(record, operations, expectedResult, expectedRecordPostOp = r
put_items = MapOperation.put_items("map", record["map"], policy: policy)
client.operate(key, [put_items])
end
result = client.operate(key, Array(operations))
expect(result.bins).to eql(expectedResult)
record = client.get(key)
expect(record.bins).to eql(expectedRecordPostOp)
if Exception === expectedResult
expect {
client.operate(key, Array(operations))
}.to raise_error(expectedResult.class, expectedResult.message)
else
result = client.operate(key, Array(operations))
expect(result.bins).to eql(expectedResult)
record = client.get(key)
expect(record.bins).to eql(expectedRecordPostOp)
end
end

describe "MapOperation.set_policy" do
Expand Down Expand Up @@ -75,9 +81,8 @@ def verifyOperation(record, operations, expectedResult, expectedRecordPostOp = r
record = { "map" => { "a" => 1, "c" => 3 } }
policy = MapPolicy.new(write_mode: MapWriteMode::UPDATE_ONLY)
operation = MapOperation.put("map", "b", 99, policy: policy)
expectedResult = { "map" => 2 }
expectedRecord = { "map" => { "a" => 1, "c" => 3 } }
verifyOperation(record, operation, expectedResult, expectedRecord)
expectedResult = Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::ELEMENT_NOT_FOUND, "Element not found")
verifyOperation(record, operation, expectedResult)
end
end

Expand All @@ -86,9 +91,8 @@ def verifyOperation(record, operations, expectedResult, expectedRecordPostOp = r
record = { "map" => { "a" => 1, "b" => 2, "c" => 3 } }
policy = MapPolicy.new(write_mode: MapWriteMode::CREATE_ONLY)
operation = MapOperation.put("map", "b", 99, policy: policy)
expectedResult = { "map" => 3 }
expectedRecord = { "map" => { "a" => 1, "b" => 2, "c" => 3 } }
verifyOperation(record, operation, expectedResult, expectedRecord)
expectedResult = Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::ELEMENT_EXISTS, "Element already exists")
verifyOperation(record, operation, expectedResult)
end

it "creates a new key if it does not exist" do
Expand Down

0 comments on commit 8c205d4

Please sign in to comment.