Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCB-1011 Added a NPE check in TransactionAspect #585

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -55,7 +55,10 @@ Object advise(ProceedingJoinPoint joinPoint, Compensable compensable) throws Thr
if (transactionContext != null) {
populateOmegaContext(context, transactionContext);
}

// SCB-1011 Need to check if the globalTxId transaction is null to avoid the message sending failure
if (context.globalTxId() == null) {
throw new OmegaException("Cannot find the globalTxId from OmegaContext. Please using @SagaStart to start a global transaction.");
}
String localTxId = context.localTxId();
context.newLocalTxId();
LOG.debug("Updated context {} for compensable method {} ", context, method.toString());
Expand Down
Expand Up @@ -22,6 +22,7 @@
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -142,6 +143,17 @@ public void setNewLocalTxIdCompensableWithTransactionContext() throws Throwable
assertThat(omegaContext.localTxId(), is(transactionLocalTxId));
}

@Test
public void globalTxIsNotSet() throws Throwable {
omegaContext.setGlobalTxId(null);
try {
aspect.advise(joinPoint, compensable);
fail("Expect exception here");
} catch (OmegaException ex) {
assertThat(ex.getMessage(), is("Cannot find the globalTxId from OmegaContext. Please using @SagaStart to start a global transaction."));
}
}

@Test
public void newLocalTxIdInCompensable() throws Throwable {
aspect.advise(joinPoint, compensable);
Expand Down