Skip to content

Commit

Permalink
Bug fix in TransactionCountHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
IsuruMaduranga committed Jul 17, 2023
1 parent bd6ecb4 commit 801b881
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public TransactionCountHandler() {
}

Check warning on line 47 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L42-L47

Added lines #L42 - L47 were not covered by tests

// Start the transaction count record scheduler
transactionCountScheduledExecutor.scheduleAtFixedRate(this::handleTransactionCount,
transactionCountScheduledExecutor.scheduleAtFixedRate(this::handleScheduledTransactionCountCommit,

Check warning on line 50 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L50

Added line #L50 was not covered by tests
0, TRANSACTION_COUNT_COMMIT_INTERVAL, TimeUnit.SECONDS);
}

Check warning on line 52 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L52

Added line #L52 was not covered by tests

Expand All @@ -63,7 +63,7 @@ public boolean handleRequestInFlow(MessageContext messageContext) {
// Counting message received via an open WebSocket
String transport = axis2MessageContext.getIncomingTransportName();

Check warning on line 64 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L64

Added line #L64 was not covered by tests
if (transport.equals(APIMgtGatewayConstants.TRANSPORT_WS) || transport.equals(APIMgtGatewayConstants.TRANSPORT_WSS)){
transactionCountExecutor.execute(this::handleScheduledTransactionCountCommit);
transactionCountExecutor.execute(this::handleTransactionCountCommit);

Check warning on line 66 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L66

Added line #L66 was not covered by tests
}
} catch (RejectedExecutionException e) {
LOG.error("Transaction could not be counted.", e);
Expand All @@ -81,7 +81,7 @@ public boolean handleRequestOutFlow(MessageContext messageContext) {

// Counting outgoing messages that are not related to any request-response pair
if (isThereAnAssociatedIncomingRequest == null) {
transactionCountExecutor.execute(this::handleTransactionCount);
transactionCountExecutor.execute(this::handleTransactionCountCommit);

Check warning on line 84 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L84

Added line #L84 was not covered by tests
}
} catch (RejectedExecutionException e) {
LOG.error("Transaction could not be counted.", e);
Expand All @@ -103,12 +103,12 @@ public boolean handleResponseOutFlow(MessageContext messageContext) {

// Counting request-response pairs
if (isThereAnAssociatedIncomingRequest instanceof Boolean) {
transactionCountExecutor.execute(this::handleTransactionCount);
transactionCountExecutor.execute(this::handleTransactionCountCommit);

Check warning on line 106 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L106

Added line #L106 was not covered by tests
}
return true;

Check warning on line 108 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L108

Added line #L108 was not covered by tests
}

private void handleTransactionCount() {
private void handleTransactionCountCommit() {
lock.lock();

Check warning on line 112 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L112

Added line #L112 was not covered by tests
try {
if (transactionCount.incrementAndGet() >= MAX_TRANSACTION_COUNT) {
Expand All @@ -127,9 +127,12 @@ private void handleTransactionCount() {
private void handleScheduledTransactionCountCommit() {
lock.lock();

Check warning on line 128 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L128

Added line #L128 was not covered by tests
try {
TransactionCountRecord transactionCountRecord = new TransactionCountRecord(transactionCount.get());
transactionCountRecordQueue.add(transactionCountRecord);
transactionCount.set(0);
int transactionCountValue = transactionCount.get();

Check warning on line 130 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L130

Added line #L130 was not covered by tests
if (transactionCountValue != 0) {
TransactionCountRecord transactionCountRecord = new TransactionCountRecord(transactionCountValue);
transactionCountRecordQueue.add(transactionCountRecord);
transactionCount.set(0);

Check warning on line 134 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L132-L134

Added lines #L132 - L134 were not covered by tests
}
} catch (Exception e) {
LOG.error("Error while handling transaction count.", e);

Check warning on line 137 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L136-L137

Added lines #L136 - L137 were not covered by tests
} finally {
Expand Down

0 comments on commit 801b881

Please sign in to comment.