From 4bd2ca68d1b6ccffc43d6385f59c64ca2208fe86 Mon Sep 17 00:00:00 2001 From: Jan Lukavsky Date: Tue, 22 Oct 2024 17:15:08 +0200 Subject: [PATCH] [proxima-direct-core] O2-Czech-Republic#341 fix DUPLICATE response handling --- .../TransactionalOnlineAttributeWriter.java | 5 +++++ ...TransactionalOnlineAttributeWriterTest.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/direct/core/src/main/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriter.java b/direct/core/src/main/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriter.java index 5eceec9b8..661437121 100644 --- a/direct/core/src/main/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriter.java +++ b/direct/core/src/main/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriter.java @@ -199,6 +199,11 @@ public void update(List addedInputs) { case OPEN: future = manager.updateTransaction(transactionId, addedInputs); break; + case COMMITTED: + future = + CompletableFuture.failedFuture( + new TransactionRejectedException(transactionId, Flags.DUPLICATE)); + break; default: future = CompletableFuture.failedFuture( diff --git a/direct/core/src/test/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriterTest.java b/direct/core/src/test/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriterTest.java index 2c557c3dd..5645bf7d9 100644 --- a/direct/core/src/test/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriterTest.java +++ b/direct/core/src/test/java/cz/o2/proxima/direct/core/transaction/TransactionalOnlineAttributeWriterTest.java @@ -407,6 +407,24 @@ public void testTransactionReopen() throws InterruptedException { assertEquals(Flags.DUPLICATE, res.take().getResponseFlags()); } + @Test(timeout = 10000) + public void testTransactionReopenWithUpdate() throws InterruptedException { + TransactionalOnlineAttributeWriter writer = direct.getGlobalTransactionWriter(); + assertTrue(user.isTransactional()); + for (int i = 0; i < 2; i++) { + toReturn.add(Response.forRequest(anyRequest()).duplicate(1L)); + } + String transactionId = UUID.randomUUID().toString(); + BlockingQueue res = new ArrayBlockingQueue<>(1); + try (Transaction t = writer.begin(transactionId)) { + t.beginGlobal(); + t.update(List.of(KeyAttributes.ofMissingAttribute(gateway, "key", device, "dummy"))); + t.commitWrite( + Collections.emptyList(), (succ, exc) -> res.add((TransactionRejectedException) exc)); + } + assertEquals(Flags.DUPLICATE, res.take().getResponseFlags()); + } + @Test(timeout = 10_000) public void testWriteInTransactionWithTransform() throws InterruptedException { List> attrs = Arrays.asList(userGateways, gatewayUsers);