Skip to content

Commit

Permalink
Merge pull request #423 from Danielle9897/RDBC-832-fixDeleteCmpXchg
Browse files Browse the repository at this point in the history
RDBC-832 Fix DeleteCompareExchangeValueOperation behavior when key doesn't exist
  • Loading branch information
ml054 authored Apr 25, 2024
2 parents 36790be + 66dc85e commit 0747884
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CompareExchangeResult<T> {
throwError("InvalidOperationException", "Response is invalid. Index is missing");
}

const val = response.Value.Object || null;
const val = response.Value?.Object || null;
return CompareExchangeResult._create(val, response.Index, response.Successful, conventions, clazz);
}

Expand Down
29 changes: 29 additions & 0 deletions test/Ported/UniqueValuesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,35 @@ describe("UniqueValuesTest", function () {
assert.strictEqual(readValue.value, "Karmel");
});

it("tryingToDeleteNonExistingKeyShouldNotThrow", async () => {
const res1= await store.operations.send(
new PutCompareExchangeValueOperation<string>("key/1", "Name", 0));

assert.strictEqual(res1.value, "Name");
assert.ok(res1.successful);

const res2 = await store.operations.send(
new DeleteCompareExchangeValueOperation<string>("key/2", res1.index));

assert.ok(res2.successful);
assert.equal(res2.value, null);
assert.equal(res2.index, res1.index + 1);

const res3 = await store.operations.send(
new DeleteCompareExchangeValueOperation<string>("key/2", 0));

assert.ok(res3.successful);
assert.equal(res3.value, null);
assert.equal(res3.index, res2.index + 1);

const res4 = await store.operations.send(
new DeleteCompareExchangeValueOperation<string>("key/2", 999));

assert.ok(res4.successful);
assert.equal(res4.value, null);
assert.equal(res4.index, res3.index + 1);
});

it("returnCurrentValueWhenPuttingConcurrently", async () => {
const user = new User();
user.name = "Karmel";
Expand Down

0 comments on commit 0747884

Please sign in to comment.