@Test public void compensateCorrespondingOmegaInstanceOnly() throws Exception { TxEvent event = eventOf(serviceName2, instanceId2One, TxStartedEvent); compositeOmegaCallback.compensate(event); verify(callback1One, never()).compensate(event); verify(callback1Two, never()).compensate(event); verify(callback2One).compensate(event); verify(callback2Two, never()).compensate(event); assertThat(callbacks.get(serviceName1).values(), containsInAnyOrder(callback1One, callback1Two)); assertThat(callbacks.get(serviceName2).values(), containsInAnyOrder(callback2One, callback2Two)); }
@Override public void compensate(TxEvent event) { Map<String, OmegaCallback> serviceCallbacks = callbacks.getOrDefault(event.serviceName(), emptyMap()); if (serviceCallbacks.isEmpty()) { throw new AlphaException("No such omega callback found for service " + event.serviceName()); } OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId()); if (omegaCallback == null) { LOG.info("Cannot find the service with the instanceId {}, call the other instance.", event.instanceId()); omegaCallback = serviceCallbacks.values().iterator().next(); } try { omegaCallback.compensate(event); } catch (Exception e) { serviceCallbacks.values().remove(omegaCallback); throw e; } }
CompositeOmegaCallback implements OmegaCallback { @Override public void compensate(TxEvent event) { Map<String, OmegaCallback> serviceCallbacks = callbacks.getOrDefault(event.serviceName(), emptyMap()); if (serviceCallbacks.isEmpty()) { throw new AlphaException("No such omega callback found for service " + event.serviceName()); } OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId()); if (omegaCallback == null) { LOG.info("Cannot find the service with the instanceId {}, call the other instance.", event.instanceId()); omegaCallback = serviceCallbacks.values().iterator().next(); } try { omegaCallback.compensate(event); } catch (Exception e) { serviceCallbacks.values().remove(omegaCallback); throw e; } } }
CompositeOmegaCallback implements OmegaCallback { @Override public void compensate(TxEvent event) { Map<String, OmegaCallback> serviceCallbacks = callbacks.getOrDefault(event.serviceName(), emptyMap()); if (serviceCallbacks.isEmpty()) { throw new AlphaException("No such omega callback found for service " + event.serviceName()); } OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId()); if (omegaCallback == null) { LOG.info("Cannot find the service with the instanceId {}, call the other instance.", event.instanceId()); omegaCallback = serviceCallbacks.values().iterator().next(); } try { omegaCallback.compensate(event); } catch (Exception e) { serviceCallbacks.values().remove(omegaCallback); throw e; } } CompositeOmegaCallback(Map<String, Map<String, OmegaCallback>> callbacks); }
CompositeOmegaCallback implements OmegaCallback { @Override public void compensate(TxEvent event) { Map<String, OmegaCallback> serviceCallbacks = callbacks.getOrDefault(event.serviceName(), emptyMap()); if (serviceCallbacks.isEmpty()) { throw new AlphaException("No such omega callback found for service " + event.serviceName()); } OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId()); if (omegaCallback == null) { LOG.info("Cannot find the service with the instanceId {}, call the other instance.", event.instanceId()); omegaCallback = serviceCallbacks.values().iterator().next(); } try { omegaCallback.compensate(event); } catch (Exception e) { serviceCallbacks.values().remove(omegaCallback); throw e; } } CompositeOmegaCallback(Map<String, Map<String, OmegaCallback>> callbacks); @Override void compensate(TxEvent event); }
CompositeOmegaCallback implements OmegaCallback { @Override public void compensate(TxEvent event) { Map<String, OmegaCallback> serviceCallbacks = callbacks.getOrDefault(event.serviceName(), emptyMap()); if (serviceCallbacks.isEmpty()) { throw new AlphaException("No such omega callback found for service " + event.serviceName()); } OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId()); if (omegaCallback == null) { LOG.info("Cannot find the service with the instanceId {}, call the other instance.", event.instanceId()); omegaCallback = serviceCallbacks.values().iterator().next(); } try { omegaCallback.compensate(event); } catch (Exception e) { serviceCallbacks.values().remove(omegaCallback); throw e; } } CompositeOmegaCallback(Map<String, Map<String, OmegaCallback>> callbacks); @Override void compensate(TxEvent event);  }