/** * Suspend the transmission thread according to the current back off policy. */ public void backoff() { policyState.setCurrentState(TransmissionPolicy.BACKOFF); long backOffMillis = backoffManager.backOffCurrentSenderThreadValue(); if (backOffMillis > 0) { long backOffSeconds = backOffMillis / 1000; InternalLogger.INSTANCE.info("App is throttled, telemetry will be blocked for %s seconds.", backOffSeconds); this.suspendInSeconds(TransmissionPolicy.BACKOFF, backOffSeconds); } }
this.transmissionPolicyManager.suspendInSeconds(suspensionPolicy, retryAfterAsSeconds); } catch (Throwable e) { InternalLogger.INSTANCE.error("Throttled but failed to block transmission.%nStack Trace:%n%s",
@Test(expected = IllegalArgumentException.class) public void testSuspendInSecondsWithZeroSeconds() { TransmissionPolicyManager tested = new TransmissionPolicyManager(true); tested.suspendInSeconds(TransmissionPolicy.BLOCKED_AND_CANNOT_BE_PERSISTED, 0); }
@Test public void testSuspendInSecondsWithTwoWhereTheFirstOneCounts() throws InterruptedException { TransmissionPolicyManager tested = new TransmissionPolicyManager(true); tested.suspendInSeconds(TransmissionPolicy.BLOCKED_AND_CANNOT_BE_PERSISTED, 2); tested.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, 1); Thread.sleep(1500); assertEquals(TransmissionPolicy.BLOCKED_AND_CANNOT_BE_PERSISTED, tested.getTransmissionPolicyState().getCurrentState()); Thread.sleep(1000); assertEquals(TransmissionPolicy.UNBLOCKED, tested.getTransmissionPolicyState().getCurrentState()); }
@Test public void testSuspendInSecondsWithTwoWhereTheSecondOneCounts() throws InterruptedException { TransmissionPolicyManager tested = new TransmissionPolicyManager(true); tested.suspendInSeconds(TransmissionPolicy.BLOCKED_AND_CANNOT_BE_PERSISTED, 1); tested.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, 2); Thread.sleep(1500); assertEquals(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, tested.getTransmissionPolicyState().getCurrentState()); Thread.sleep(1000); assertEquals(TransmissionPolicy.UNBLOCKED, tested.getTransmissionPolicyState().getCurrentState()); } }
@Test public void testSuspendInSecondsWithUnBlock() { TransmissionPolicyManager tested = new TransmissionPolicyManager(true); tested.suspendInSeconds(TransmissionPolicy.UNBLOCKED, 10); assertEquals(TransmissionPolicy.UNBLOCKED, tested.getTransmissionPolicyState().getCurrentState()); }