Skip to content

Commit

Permalink
Test fix for producer idempotence
Browse files Browse the repository at this point in the history
Signed-off-by: Nithin <nithin.pankaj@walmart.com>
  • Loading branch information
nithin-pankaj committed May 30, 2024
1 parent 486138b commit 2c557f1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hlf.java.rest.client.exception.FabricTransactionException;
import hlf.java.rest.client.exception.ServiceException;
import hlf.java.rest.client.model.ClientResponseModel;
import hlf.java.rest.client.service.RecencyTransactionContext;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class TransactionFulfillmentImplTest {
@Mock Network network;
@Mock Contract contract;
@Mock Transaction transaction;
@Mock RecencyTransactionContext recencyTransactionContext;

private String testNetworkString = "some string";
private String testContractString = "some string";
Expand Down Expand Up @@ -69,7 +71,9 @@ public void writeTransactionToLedgerTest()
Mockito.when(gatewayConnetion.getNetwork(Mockito.anyString())).thenReturn(network);
Mockito.when(network.getContract(Mockito.anyString())).thenReturn(contract);
Mockito.when(contract.createTransaction(Mockito.anyString())).thenReturn(transaction);
Mockito.when(transaction.getTransactionId()).thenReturn("TX-1234");
Mockito.when(transaction.submit(Mockito.<String>any())).thenReturn(byteArrayResponse);
Mockito.doNothing().when(recencyTransactionContext).setTransactionContext(Mockito.anyString());
/*
* Mockito.when(contract.submitTransaction(Mockito.anyString(),
* Mockito.<String>any())) .thenReturn(byteArrayResponse);
Expand All @@ -92,7 +96,9 @@ public void writeTransactionToLedgerContractExceptionTest()
Mockito.when(gatewayConnetion.getNetwork(Mockito.anyString())).thenReturn(network);
Mockito.when(network.getContract(Mockito.anyString())).thenReturn(contract);
Mockito.when(contract.createTransaction(Mockito.anyString())).thenReturn(transaction);
Mockito.when(transaction.getTransactionId()).thenReturn("TX-1234");
Mockito.when(transaction.submit(Mockito.<String>any())).thenThrow(new ContractException(""));
Mockito.doNothing().when(recencyTransactionContext).setTransactionContext(Mockito.anyString());
/*
* Mockito.when(contract.submitTransaction(Mockito.anyString(),
* Mockito.<String>any())) .thenThrow(new ContractException(""));
Expand All @@ -115,7 +121,9 @@ public void writeTransactionToLedgerTimeoutExceptionTest()
Mockito.when(gatewayConnetion.getNetwork(Mockito.anyString())).thenReturn(network);
Mockito.when(network.getContract(Mockito.anyString())).thenReturn(contract);
Mockito.when(contract.createTransaction(Mockito.anyString())).thenReturn(transaction);
Mockito.when(transaction.getTransactionId()).thenReturn("TX-1234");
Mockito.when(transaction.submit(Mockito.<String>any())).thenThrow(new TimeoutException());
Mockito.doNothing().when(recencyTransactionContext).setTransactionContext(Mockito.anyString());
/*
* Mockito.when(contract.submitTransaction(Mockito.anyString(),
* Mockito.<String>any())) .thenThrow(new TimeoutException());
Expand All @@ -138,7 +146,9 @@ public void writeTransactionToLedgerInterruptExceptionTest()
Mockito.when(gatewayConnetion.getNetwork(Mockito.anyString())).thenReturn(network);
Mockito.when(network.getContract(Mockito.anyString())).thenReturn(contract);
Mockito.when(contract.createTransaction(Mockito.anyString())).thenReturn(transaction);
Mockito.when(transaction.getTransactionId()).thenReturn("TX-1234");
Mockito.when(transaction.submit(Mockito.<String>any())).thenThrow(new InterruptedException());
Mockito.doNothing().when(recencyTransactionContext).setTransactionContext(Mockito.anyString());
/*
* Mockito.when(contract.submitTransaction(Mockito.anyString(),
* Mockito.<String>any())) .thenThrow(new InterruptedException());
Expand Down
7 changes: 5 additions & 2 deletions src/test/resources/application-default-consumer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ kafka:
event-listener:
ssl-enabled: false
brokerHost: localhost:9092
topic: test-publisher-event-topic
topic: test-publisher-event-topice
enable-idempotence: true
management:
endpoints:
web:
Expand Down Expand Up @@ -57,10 +58,12 @@ management:
http.server.requests: 1s
custom:
kafka:
enabled: true
enabled: false
server:
config:
location: /Users/n0p0328/work/hlf-connector/src/main/resources/config/
servlet:
context-path: /hlf-rest-client
port: 8282
dedupe:
enable: true
6 changes: 5 additions & 1 deletion src/test/resources/application-per-partition-consumer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ kafka:
ssl-enabled: false
brokerHost: localhost:9092
topic: test-publisher-event-topic
enable-idempotence: true
failed-message-listener:
brokerHost: localhost:9092
topic: test-consumer-dlt
ssl-enabled: false
enable-idempotence: true
management:
endpoints:
web:
Expand Down Expand Up @@ -62,10 +64,12 @@ management:
http.server.requests: 1s
custom:
kafka:
enabled: true
enabled: false
server:
config:
location: /Users/n0p0328/work/hlf-connector/src/main/resources/config/
servlet:
context-path: /hlf-rest-client
port: 8282
dedupe:
enable: true
5 changes: 3 additions & 2 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ kafka:
event-listener:
brokerHost: localhost:9093
topic: hlf-offchain-topic


enable-idempotence: true
dedupe:
enable: false
---
spring:
profiles: intg
Expand Down

0 comments on commit 2c557f1

Please sign in to comment.