@Test public void interruptT03Packet() { final Map<String, String> customSettings = Maps.newHashMap(); customSettings.put(SIMULATED_REJECT_ERROR_CODE, InterledgerErrorCode.T03_CONNECTOR_BUSY_CODE); this.link = new LoopbackLink( () -> OPERATOR_ADDRESS, LinkSettings.builder().linkType(LoopbackLink.LINK_TYPE).customSettings(customSettings).build(), packetRejector ); link.setLinkId(LinkId.of("foo")); expectedException.expect(RuntimeException.class); expectedException.expectMessage("java.lang.InterruptedException: sleep interrupted"); Thread.currentThread().interrupt(); link.sendPacket(preparePacket()); }
@Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null"); return Optional.ofNullable(this.getLinkSettings().getCustomSettings().get(SIMULATED_REJECT_ERROR_CODE)) .map((value) -> { if (value.equals("T02")) { return packetRejector.reject(this.getLinkId(), preparePacket, InterledgerErrorCode.T02_PEER_BUSY, "Loopback set to manually reject via simulate_timeout=T02"); } else if (value.equals("T03")) { return sleepAndReject(preparePacket, 60000); } if (value.equals("T99")) { throw new RuntimeException("T99 APPLICATION ERROR"); } else { return InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData()) .build(); } }) .orElseGet(InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData())::build); }
LoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null"); return Optional.ofNullable(this.getLinkSettings().getCustomSettings().get(SIMULATED_REJECT_ERROR_CODE)) .map((value) -> { if (value.equals("T02")) { return packetRejector.reject(this.getLinkId(), preparePacket, InterledgerErrorCode.T02_PEER_BUSY, "Loopback set to manually reject via simulate_timeout=T02"); } else if (value.equals("T03")) { return sleepAndReject(preparePacket, 60000); } if (value.equals("T99")) { throw new RuntimeException("T99 APPLICATION ERROR"); } else { return InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData()) .build(); } }) .orElseGet(InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData())::build); } }
LoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null"); return Optional.ofNullable(this.getLinkSettings().getCustomSettings().get(SIMULATED_REJECT_ERROR_CODE)) .map((value) -> { if (value.equals("T02")) { return packetRejector.reject(this.getLinkId(), preparePacket, InterledgerErrorCode.T02_PEER_BUSY, "Loopback set to manually reject via simulate_timeout=T02"); } else if (value.equals("T03")) { return sleepAndReject(preparePacket, 60000); } if (value.equals("T99")) { throw new RuntimeException("T99 APPLICATION ERROR"); } else { return InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData()) .build(); } }) .orElseGet(InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData())::build); } LoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final LinkSettings linkSettings,
      final PacketRejector packetRejector
  ); }
LoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null"); return Optional.ofNullable(this.getLinkSettings().getCustomSettings().get(SIMULATED_REJECT_ERROR_CODE)) .map((value) -> { if (value.equals("T02")) { return packetRejector.reject(this.getLinkId(), preparePacket, InterledgerErrorCode.T02_PEER_BUSY, "Loopback set to manually reject via simulate_timeout=T02"); } else if (value.equals("T03")) { return sleepAndReject(preparePacket, 60000); } if (value.equals("T99")) { throw new RuntimeException("T99 APPLICATION ERROR"); } else { return InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData()) .build(); } }) .orElseGet(InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData())::build); } LoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final LinkSettings linkSettings,
      final PacketRejector packetRejector
  ); @Override void registerLinkHandler(LinkHandler ilpDataHandler); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); @Override String toString(); }
LoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null"); return Optional.ofNullable(this.getLinkSettings().getCustomSettings().get(SIMULATED_REJECT_ERROR_CODE)) .map((value) -> { if (value.equals("T02")) { return packetRejector.reject(this.getLinkId(), preparePacket, InterledgerErrorCode.T02_PEER_BUSY, "Loopback set to manually reject via simulate_timeout=T02"); } else if (value.equals("T03")) { return sleepAndReject(preparePacket, 60000); } if (value.equals("T99")) { throw new RuntimeException("T99 APPLICATION ERROR"); } else { return InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData()) .build(); } }) .orElseGet(InterledgerFulfillPacket.builder() .fulfillment(LOOPBACK_FULFILLMENT) .data(preparePacket.getData())::build); } LoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final LinkSettings linkSettings,
      final PacketRejector packetRejector
  ); @Override void registerLinkHandler(LinkHandler ilpDataHandler); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); @Override String toString(); static final String LINK_TYPE_STRING; static final LinkType LINK_TYPE; static final InterledgerFulfillment LOOPBACK_FULFILLMENT; static final String SIMULATED_REJECT_ERROR_CODE; }