@Test public void failException() { TransmissionPolicyManager tpm = new TransmissionPolicyManager(true); TransmissionDispatcher mockedDispatcher = Mockito.mock(TransmissionDispatcher.class); TransmissionHandlerArgs args = new TransmissionHandlerArgs(); args.setResponseCode(0); args.setTransmission(null); args.setTransmissionDispatcher(mockedDispatcher); args.setException(new Exception("Mocked")); ThrottlingHandler eh = new ThrottlingHandler(tpm); boolean result = eh.validateTransmissionAndSend(args); Assert.assertFalse(result); }
boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getRetryHeader() != null && args.getTransmission() != null && args.getTransmissionDispatcher() != null) { args.getTransmission().incrementNumberOfSends(); switch (args.getResponseCode()) { case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: suspendTransmissions(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, args.getRetryHeader()); args.getTransmissionDispatcher().dispatch(args.getTransmission()); return true; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } logger.trace("Http response code {} not handled by {}.", args.getResponseCode(), this.getClass().getName()); return false; }
ThrottlingHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getRetryHeader() != null && args.getTransmission() != null && args.getTransmissionDispatcher() != null) { args.getTransmission().incrementNumberOfSends(); switch (args.getResponseCode()) { case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: suspendTransmissions(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, args.getRetryHeader()); args.getTransmissionDispatcher().dispatch(args.getTransmission()); return true; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } logger.trace("Http response code {} not handled by {}.", args.getResponseCode(), this.getClass().getName()); return false; } }
ThrottlingHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getRetryHeader() != null && args.getTransmission() != null && args.getTransmissionDispatcher() != null) { args.getTransmission().incrementNumberOfSends(); switch (args.getResponseCode()) { case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: suspendTransmissions(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, args.getRetryHeader()); args.getTransmissionDispatcher().dispatch(args.getTransmission()); return true; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } logger.trace("Http response code {} not handled by {}.", args.getResponseCode(), this.getClass().getName()); return false; } ThrottlingHandler(TransmissionPolicyManager policy); }
ThrottlingHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getRetryHeader() != null && args.getTransmission() != null && args.getTransmissionDispatcher() != null) { args.getTransmission().incrementNumberOfSends(); switch (args.getResponseCode()) { case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: suspendTransmissions(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, args.getRetryHeader()); args.getTransmissionDispatcher().dispatch(args.getTransmission()); return true; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } logger.trace("Http response code {} not handled by {}.", args.getResponseCode(), this.getClass().getName()); return false; } ThrottlingHandler(TransmissionPolicyManager policy); @Override void onTransmissionSent(TransmissionHandlerArgs args); }
ThrottlingHandler implements TransmissionHandler { boolean validateTransmissionAndSend(TransmissionHandlerArgs args) { if (args.getRetryHeader() != null && args.getTransmission() != null && args.getTransmissionDispatcher() != null) { args.getTransmission().incrementNumberOfSends(); switch (args.getResponseCode()) { case TransmissionSendResult.THROTTLED: case TransmissionSendResult.THROTTLED_OVER_EXTENDED_TIME: suspendTransmissions(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, args.getRetryHeader()); args.getTransmissionDispatcher().dispatch(args.getTransmission()); return true; default: logger.trace("Http response code {} not handled by {}", args.getResponseCode(), this.getClass().getName()); return false; } } logger.trace("Http response code {} not handled by {}.", args.getResponseCode(), this.getClass().getName()); return false; } ThrottlingHandler(TransmissionPolicyManager policy); @Override void onTransmissionSent(TransmissionHandlerArgs args);  }