Search in sources :

Example 1 with MessageSentFailedRecord

use of com.notnoop.apns.integration.ApnsDelegateRecorder.MessageSentFailedRecord in project java-apns by notnoop.

the class ApnsConnectionResendTest method testGivenFailedSubmissionDueToErrorThenApnsDownWithNotificationsInBufferEnsureClientNotified.

/*
     * Test when we submit 3 messages to APNS 0, 1, 2.  0 is an error but we don't see the error response back until
     * 1,2 have already been submitted.  Then at this point the network connection to APNS cannot be made, so that
     * when retrying the submissions we have to notify the client that delivery failed for 1 and 2.
     */
@Test
public void testGivenFailedSubmissionDueToErrorThenApnsDownWithNotificationsInBufferEnsureClientNotified() throws Exception {
    final DeliveryError deliveryError = DeliveryError.INVALID_PAYLOAD_SIZE;
    apnsSim.when(NOTIFICATION_0).thenDoNothing();
    apnsSim.when(NOTIFICATION_1).thenDoNothing();
    apnsSim.when(NOTIFICATION_2).thenRespond(ApnsResponse.returnErrorAndShutdown(deliveryError, NOTIFICATION_0));
    testee.push(NOTIFICATION_0);
    testee.push(NOTIFICATION_1);
    testee.push(NOTIFICATION_2);
    // Give some time for connection failure to take place
    Thread.sleep(5000);
    // Verify received expected notifications
    apnsSim.verify();
    // verify delegate calls
    assertEquals(3, delegateRecorder.getSent().size());
    final List<MessageSentFailedRecord> failed = delegateRecorder.getFailed();
    assertEquals(3, failed.size());
    // first is failed delivery due to payload size
    failed.get(0).assertRecord(NOTIFICATION_0, new ApnsDeliveryErrorException(deliveryError));
    // second and third are due to not being able to connect to APNS
    assertNetworkIoExForRedelivery(NOTIFICATION_1, failed.get(1));
    assertNetworkIoExForRedelivery(NOTIFICATION_2, failed.get(2));
}
Also used : MessageSentFailedRecord(com.notnoop.apns.integration.ApnsDelegateRecorder.MessageSentFailedRecord) DeliveryError(com.notnoop.apns.DeliveryError) ApnsDeliveryErrorException(com.notnoop.exceptions.ApnsDeliveryErrorException) Test(org.junit.Test)

Aggregations

DeliveryError (com.notnoop.apns.DeliveryError)1 MessageSentFailedRecord (com.notnoop.apns.integration.ApnsDelegateRecorder.MessageSentFailedRecord)1 ApnsDeliveryErrorException (com.notnoop.exceptions.ApnsDeliveryErrorException)1 Test (org.junit.Test)1