From 7062b1946124ba7abcf68d7f43e41b01d773dcb7 Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Fri, 5 Jul 2019 22:17:37 +0300 Subject: [PATCH] alternator-test: expand tests of duplicate items in BatchWriteItem The tests we had for BatchWriteItem's refusal to accept duplicate keys only used test_table_s, with just a hash key. This patch adds tests for test_table, i.e., a table with both hash and sort keys - to check that we check duplicates in that case correctly as well. Moreover, the expanded tests also verify that although identical keys are not allowed, keys with just one component (hash or sort key) the same but the other not the same - are fine. Signed-off-by: Nadav Har'El Message-Id: <20190705191737.22235-1-nyh@scylladb.com> --- alternator-test/test_batch.py | 39 ++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/alternator-test/test_batch.py b/alternator-test/test_batch.py index 3178294e04..8f459cc803 100644 --- a/alternator-test/test_batch.py +++ b/alternator-test/test_batch.py @@ -67,26 +67,59 @@ def test_batch_write_and_delete(test_table_s): # It is forbidden to update the same key twice in the same batch. # DynamoDB says "Provided list of item keys contains duplicates". -def test_batch_write_duplicate_write(test_table_s): +def test_batch_write_duplicate_write(test_table_s, test_table): p = random_string() with pytest.raises(ClientError, match='ValidationException.*duplicates'): with test_table_s.batch_writer() as batch: batch.put_item({'p': p}) batch.put_item({'p': p}) + c = random_string() + with pytest.raises(ClientError, match='ValidationException.*duplicates'): + with test_table.batch_writer() as batch: + batch.put_item({'p': p, 'c': c}) + batch.put_item({'p': p, 'c': c}) + # But it is fine to touch items with one component the same, but the other not. + other = random_string() + with test_table.batch_writer() as batch: + batch.put_item({'p': p, 'c': c}) + batch.put_item({'p': p, 'c': other}) + batch.put_item({'p': other, 'c': c}) -def test_batch_write_duplicate_delete(test_table_s): +def test_batch_write_duplicate_delete(test_table_s, test_table): p = random_string() with pytest.raises(ClientError, match='ValidationException.*duplicates'): with test_table_s.batch_writer() as batch: batch.delete_item(Key={'p': p}) batch.delete_item(Key={'p': p}) + c = random_string() + with pytest.raises(ClientError, match='ValidationException.*duplicates'): + with test_table.batch_writer() as batch: + batch.delete_item(Key={'p': p, 'c': c}) + batch.delete_item(Key={'p': p, 'c': c}) + # But it is fine to touch items with one component the same, but the other not. + other = random_string() + with test_table.batch_writer() as batch: + batch.delete_item(Key={'p': p, 'c': c}) + batch.delete_item(Key={'p': p, 'c': other}) + batch.delete_item(Key={'p': other, 'c': c}) -def test_batch_write_duplicate_write_and_delete(test_table_s): +def test_batch_write_duplicate_write_and_delete(test_table_s, test_table): p = random_string() with pytest.raises(ClientError, match='ValidationException.*duplicates'): with test_table_s.batch_writer() as batch: batch.delete_item(Key={'p': p}) batch.put_item({'p': p}) + c = random_string() + with pytest.raises(ClientError, match='ValidationException.*duplicates'): + with test_table.batch_writer() as batch: + batch.delete_item(Key={'p': p, 'c': c}) + batch.put_item({'p': p, 'c': c}) + # But it is fine to touch items with one component the same, but the other not. + other = random_string() + with test_table.batch_writer() as batch: + batch.delete_item(Key={'p': p, 'c': c}) + batch.put_item({'p': p, 'c': other}) + batch.put_item({'p': other, 'c': c}) # Test that BatchWriteItem's PutRequest completely replaces an existing item. # It shouldn't merge it with a previously existing value. See also the same