This is an automated email from the ASF dual-hosted git repository. seanyinx pushed a commit to branch SCB-149_service_aware_callback in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
commit 1fe3e9ddb8bbeb53462c69d2ab0c1b83113ac692 Author: seanyinx <[email protected]> AuthorDate: Tue Jan 2 09:11:36 2018 +0800 SCB-149 checked matching of compensation method Signed-off-by: seanyinx <[email protected]> --- .../saga/alpha/core/TxConsistentService.java | 2 +- .../saga/alpha/core/TxConsistentServiceTest.java | 14 +++++++------- .../saga/alpha/server/AlphaIntegrationTest.java | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/alpha/alpha-core/src/main/java/io/servicecomb/saga/alpha/core/TxConsistentService.java b/alpha/alpha-core/src/main/java/io/servicecomb/saga/alpha/core/TxConsistentService.java index 15f5099..34218bf 100644 --- a/alpha/alpha-core/src/main/java/io/servicecomb/saga/alpha/core/TxConsistentService.java +++ b/alpha/alpha-core/src/main/java/io/servicecomb/saga/alpha/core/TxConsistentService.java @@ -49,6 +49,6 @@ public class TxConsistentService { // TODO: 2017/12/27 we must define a way to find which service to compensate, to avoid sending to all private void compensate(TxEvent event) { List<TxEvent> events = eventRepository.findStartedTransactions(event.globalTxId(), TxStartedEvent.name()); - events.forEach(evt -> omegaCallback.compensate(evt.globalTxId(), evt.localTxId(), event.compensationMethod(), evt.payloads())); + events.forEach(evt -> omegaCallback.compensate(evt.globalTxId(), evt.localTxId(), evt.compensationMethod(), evt.payloads())); } } diff --git a/alpha/alpha-core/src/test/java/io/servicecomb/saga/alpha/core/TxConsistentServiceTest.java b/alpha/alpha-core/src/test/java/io/servicecomb/saga/alpha/core/TxConsistentServiceTest.java index 9d9332d..635690b 100644 --- a/alpha/alpha-core/src/test/java/io/servicecomb/saga/alpha/core/TxConsistentServiceTest.java +++ b/alpha/alpha-core/src/test/java/io/servicecomb/saga/alpha/core/TxConsistentServiceTest.java @@ -91,12 +91,12 @@ public class TxConsistentServiceTest { @Test public void compensateGlobalTx_OnAnyLocalTxFailure() throws Exception { String localTxId1 = UUID.randomUUID().toString(); - events.add(eventOf(TxStartedEvent, "service a".getBytes(), localTxId1)); - events.add(eventOf(TxEndedEvent, new byte[0], localTxId1)); + events.add(eventOf(TxStartedEvent, "service a".getBytes(), localTxId1, "method a")); + events.add(eventOf(TxEndedEvent, new byte[0], localTxId1, "method a")); String localTxId2 = UUID.randomUUID().toString(); - events.add(eventOf(TxStartedEvent, "service b".getBytes(), localTxId2)); - events.add(eventOf(TxEndedEvent, new byte[0], localTxId2)); + events.add(eventOf(TxStartedEvent, "service b".getBytes(), localTxId2, "method b")); + events.add(eventOf(TxEndedEvent, new byte[0], localTxId2, "method b")); TxEvent abortEvent = newEvent(TxAbortedEvent); @@ -104,8 +104,8 @@ public class TxConsistentServiceTest { await().atMost(1, SECONDS).until(() -> compensationContexts.size() > 1); assertThat(compensationContexts, containsInAnyOrder( - new CompensationContext(globalTxId, localTxId1, compensationMethod, "service a".getBytes()), - new CompensationContext(globalTxId, localTxId2, compensationMethod, "service b".getBytes()) + new CompensationContext(globalTxId, localTxId1, "method a", "service a".getBytes()), + new CompensationContext(globalTxId, localTxId2, "method b", "service b".getBytes()) )); } @@ -113,7 +113,7 @@ public class TxConsistentServiceTest { return new TxEvent(serviceName, instanceId, new Date(), globalTxId, localTxId, parentTxId, eventType.name(), compensationMethod, "yeah".getBytes()); } - private TxEvent eventOf(EventType eventType, byte[] payloads, String localTxId) { + private TxEvent eventOf(EventType eventType, byte[] payloads, String localTxId, String compensationMethod) { return new TxEvent(serviceName, instanceId, new Date(), globalTxId, localTxId, diff --git a/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java b/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java index 271977e..05ab8d2 100644 --- a/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java +++ b/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java @@ -104,20 +104,20 @@ public class AlphaIntegrationTest { @Test public void doNotCompensateDuplicateTxOnFailure() throws Exception { // duplicate events with same content but different timestamp - eventRepo.save(eventEnvelopeOf(TxStartedEvent, localTxId, parentTxId, "service a".getBytes())); - eventRepo.save(eventEnvelopeOf(TxStartedEvent, localTxId, parentTxId, "service a".getBytes())); - eventRepo.save(eventEnvelopeOf(TxEndedEvent, new byte[0])); + eventRepo.save(eventEnvelopeOf(TxStartedEvent, localTxId, parentTxId, "service a".getBytes(), "method a")); + eventRepo.save(eventEnvelopeOf(TxStartedEvent, localTxId, parentTxId, "service a".getBytes(), "method a")); + eventRepo.save(eventEnvelopeOf(TxEndedEvent, new byte[0], "method a")); String localTxId1 = UUID.randomUUID().toString(); - eventRepo.save(eventEnvelopeOf(TxStartedEvent, localTxId1, UUID.randomUUID().toString(), "service b".getBytes())); - eventRepo.save(eventEnvelopeOf(TxEndedEvent, new byte[0])); + eventRepo.save(eventEnvelopeOf(TxStartedEvent, localTxId1, UUID.randomUUID().toString(), "service b".getBytes(), "method b")); + eventRepo.save(eventEnvelopeOf(TxEndedEvent, new byte[0], "method b")); stub.reportEvent(someGrpcEvent(TxAbortedEvent)); await().atMost(1, SECONDS).until(() -> compensationContexts.size() > 1); assertThat(compensationContexts, containsInAnyOrder( - new CompensationContext(globalTxId, this.localTxId, compensationMethod, "service a".getBytes()), - new CompensationContext(globalTxId, localTxId1, compensationMethod, "service b".getBytes()) + new CompensationContext(globalTxId, this.localTxId, "method a", "service a".getBytes()), + new CompensationContext(globalTxId, localTxId1, "method b", "service b".getBytes()) )); } @@ -135,11 +135,11 @@ public class AlphaIntegrationTest { .build(); } - private TxEventEnvelope eventEnvelopeOf(EventType eventType, byte[] payloads) { - return eventEnvelopeOf(eventType, UUID.randomUUID().toString(), UUID.randomUUID().toString(), payloads); + private TxEventEnvelope eventEnvelopeOf(EventType eventType, byte[] payloads, String compensationMethod) { + return eventEnvelopeOf(eventType, UUID.randomUUID().toString(), UUID.randomUUID().toString(), payloads, compensationMethod); } - private TxEventEnvelope eventEnvelopeOf(EventType eventType, String localTxId, String parentTxId, byte[] payloads) { + private TxEventEnvelope eventEnvelopeOf(EventType eventType, String localTxId, String parentTxId, byte[] payloads, String compensationMethod) { return new TxEventEnvelope(new TxEvent( serviceName, instanceId, -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
