RefocusForwarder extends DefaultService implements RefocusService, NotificationForwarder { public void setStubSender( Supplier<RefocusResponse> stub) { this.stub_sender = stub; } @Inject  RefocusForwarder(SystemConfiguration config, Provider<EntityManager> emf); @Override Properties getServiceProperties(); @Override boolean sendRefocusNotification(String subject_aspect, String value, String user_id, String token_id, History history); @Override boolean sendRefocusNotification(String subject_aspect, String value, String user_id, String token_id, History history, long nextFireTime); @Override int forwardNotifications(); @Override int getNotificationsEnqueued(); @Override int getNotificationsDelivered(); @Override int getNotificationsDiscarded(); @Override int getNotificationsProcessed(); @Override int getMaxQueueLength(); void setStubSender( Supplier<RefocusResponse> stub); CloseableHttpClient getHttpClient(); RefocusResponse makeResponse(int resp, JsonObject result); static String stackTraceToString(Throwable e);  }
@Test public void testRefocusForwarderSendSamples() { ResultListSupplier responseSupplier = new ResultListSupplier(new ArrayList<StubResult>(), make200(10, 1), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 100; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(num_notifications, 0, num_notifications); }
@Test public void testRefocusForwarderThrottled() { ResultListSupplier responseSupplier = new ResultListSupplier( new ArrayList<StubResult>(), makeTooManyRequests(120), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(0, num_notifications, num_notifications); }
@Test public void testRefocusForwarderTimedOut() { ResultListSupplier responseSupplier = new ResultListSupplier( new ArrayList<StubResult>(), makeTimedOut(10), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(0, num_notifications, num_notifications); }
@Test public void testRefocusForwarderInterruptedIOException() { RefocusForwarder.Duration d = new RefocusForwarder.Duration(); ResultListSupplier responseSupplier = new ResultListSupplier( new ArrayList<StubResult>(), makeWithInterruptedIOException(10, -1), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(0, num_notifications, num_notifications); }
@Test public void testRefocusForwarderIOException() { ResultListSupplier responseSupplier = new ResultListSupplier( new ArrayList<StubResult>(), makeWithIOException(10, -1), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(0, num_notifications, num_notifications); }
@Test public void testRefocusNoAuth() { ResultListSupplier responseSupplier = new ResultListSupplier( new ArrayList<StubResult>(), makeWithResponseCode(10, HttpStatus.SC_UNAUTHORIZED), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(0, num_notifications, num_notifications); }
@Test public void testRefocusServiceUnavail() { ResultListSupplier responseSupplier = new ResultListSupplier( new ArrayList<StubResult>(), makeWithResponseCode(10, HttpStatus.SC_SERVICE_UNAVAILABLE), refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(0, num_notifications, num_notifications); }
@Test public void testIntermittentThrottle() { StubResult [] cycle = { makeTooManyRequests(10), makeTooManyRequests(10), make200(10, 1) }; ResultCycleStubSupplier responseSupplier = new ResultCycleStubSupplier( cycle, refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(num_notifications, 0, num_notifications); }
@Test public void testIntermittentInterruptedIOException() { StubResult [] cycle = { makeWithInterruptedIOException(10, -1), makeWithInterruptedIOException(10, -1), make200(10, 1) }; ResultCycleStubSupplier responseSupplier = new ResultCycleStubSupplier( cycle, refocusForwarder); refocusForwarder.setStubSender(responseSupplier); int num_notifications = 5; History history = mock(History.class); enqueueSamples(num_notifications, history); waitUntilQueuedNotificationsAreProcessed(refocusForwarder); logForwarderStats(); verifyProcessed(num_notifications, 0, num_notifications); }