Skip to content

Commit

Permalink
SCB-1121 Fix the test error of SagaDubboProviderFilterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
WillemJiang committed Jan 22, 2019
1 parent b98bedd commit 29c34c3
Showing 1 changed file with 19 additions and 4 deletions.
Expand Up @@ -21,12 +21,16 @@
import org.apache.servicecomb.pack.omega.context.OmegaContext;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -41,6 +45,7 @@ public String nextId() {
}
});
private final Invocation invocation = mock(Invocation.class);
private final Invoker invoker = mock(Invoker.class);

private final SagaDubboProviderFilter filter = new SagaDubboProviderFilter();

Expand All @@ -55,18 +60,28 @@ public void setUpOmegaContextInTransactionRequest() {
when(invocation.getAttachment(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(globalTxId);
when(invocation.getAttachment(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(localTxId);

filter.invoke(null, invocation);
doAnswer(new Answer<Void>() {
// Just verify the context setting
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
assertThat(omegaContext.globalTxId(), is(globalTxId));
assertThat(omegaContext.localTxId(), is(localTxId));
return null;
}
}).when(invoker).invoke(invocation);

assertThat(omegaContext.globalTxId(), is(globalTxId));
assertThat(omegaContext.localTxId(), is(localTxId));
filter.invoke(invoker, invocation);

assertThat(omegaContext.globalTxId(), is(nullValue()));
assertThat(omegaContext.localTxId(), is(nullValue()));
}

@Test
public void doNothingInNonTransactionRequest() {
when(invocation.getAttachment(OmegaContext.GLOBAL_TX_ID_KEY)).thenReturn(null);
when(invocation.getAttachment(OmegaContext.LOCAL_TX_ID_KEY)).thenReturn(null);

filter.invoke(null, invocation);
filter.invoke(invoker, invocation);

assertThat(omegaContext.globalTxId(), is(nullValue()));
assertThat(omegaContext.localTxId(), is(nullValue()));
Expand Down

0 comments on commit 29c34c3

Please sign in to comment.