Search in sources :

Example 21 with ApnsService

use of com.notnoop.apns.ApnsService in project java-apns by notnoop.

the class FeedbackTest method simpleFeedbackWithTimeout.

@Test()
public void simpleFeedbackWithTimeout() throws IOException {
    server.getToSend().write(simple);
    server.getToWaitBeforeSend().set(5000);
    ApnsService service = APNS.newService().withSSLContext(clientContext).withGatewayDestination(LOCALHOST, server.getEffectiveGatewayPort()).withFeedbackDestination(LOCALHOST, server.getEffectiveFeedbackPort()).withReadTimeout(1000).build();
    try {
        service.getInactiveDevices();
        fail("RuntimeException expected");
    } catch (RuntimeException e) {
        assertEquals("Socket timeout exception expected", SocketTimeoutException.class, e.getCause().getClass());
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) ApnsService(com.notnoop.apns.ApnsService) Test(org.junit.Test)

Example 22 with ApnsService

use of com.notnoop.apns.ApnsService in project java-apns by notnoop.

the class ApnsConnectionCacheTest method handleReTransmissionError5Good1Bad7Good.

/**
     * Test1 to make sure that after rejected notification
     * in-flight notifications are re-transmitted
     *
     * @throws InterruptedException
     */
@Test(timeout = 5000)
public void handleReTransmissionError5Good1Bad7Good() throws InterruptedException {
    server = new ApnsServerStub(FixedCertificates.serverContext().getServerSocketFactory());
    //5 success 1 fail 7 success 7 resent
    final CountDownLatch sync = new CountDownLatch(20);
    final AtomicInteger numResent = new AtomicInteger();
    final AtomicInteger numSent = new AtomicInteger();
    final AtomicInteger numStartSend = new AtomicInteger();
    int EXPECTED_RESEND_COUNT = 7;
    int EXPECTED_SEND_COUNT = 12;
    server.getWaitForError().acquire();
    server.start();
    ApnsService service = APNS.newService().withSSLContext(clientContext()).withGatewayDestination(LOCALHOST, server.getEffectiveGatewayPort()).withDelegate(new StartSendingApnsDelegate() {

        public void startSending(final ApnsNotification message, final boolean resent) {
            if (!resent) {
                numStartSend.incrementAndGet();
            }
        }

        public void messageSent(ApnsNotification message, boolean resent) {
            if (!resent) {
                numSent.incrementAndGet();
            }
            sync.countDown();
        }

        public void messageSendFailed(ApnsNotification message, Throwable e) {
            numSent.decrementAndGet();
        }

        public void connectionClosed(DeliveryError e, int messageIdentifier) {
        }

        public void cacheLengthExceeded(int newCacheLength) {
        }

        public void notificationsResent(int resendCount) {
            numResent.set(resendCount);
        }
    }).build();
    server.stopAt(eMsg1.length() * 5 + eMsg2.length() + eMsg3.length() * 14);
    for (int i = 0; i < 5; ++i) {
        service.push(eMsg1);
    }
    service.push(eMsg2);
    for (int i = 0; i < 7; ++i) {
        service.push(eMsg3);
    }
    server.sendError(8, eMsg2.getIdentifier());
    server.getWaitForError().release();
    server.getMessages().acquire();
    sync.await();
    Assert.assertEquals(EXPECTED_RESEND_COUNT, numResent.get());
    Assert.assertEquals(EXPECTED_SEND_COUNT, numSent.get());
    Assert.assertEquals(EXPECTED_SEND_COUNT + 1, numStartSend.get());
}
Also used : StartSendingApnsDelegate(com.notnoop.apns.StartSendingApnsDelegate) ApnsServerStub(com.notnoop.apns.utils.ApnsServerStub) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeliveryError(com.notnoop.apns.DeliveryError) ApnsNotification(com.notnoop.apns.ApnsNotification) SimpleApnsNotification(com.notnoop.apns.SimpleApnsNotification) EnhancedApnsNotification(com.notnoop.apns.EnhancedApnsNotification) CountDownLatch(java.util.concurrent.CountDownLatch) ApnsService(com.notnoop.apns.ApnsService)

Example 23 with ApnsService

use of com.notnoop.apns.ApnsService in project java-apns by notnoop.

the class QueuedApnsServiceTCTest method newService.

protected ApnsService newService(ApnsConnection connection, ApnsFeedbackConnection feedback) {
    ApnsService service = new ApnsServiceImpl(connection, null);
    ApnsService queued = new QueuedApnsService(service);
    queued.start();
    return queued;
}
Also used : ApnsService(com.notnoop.apns.ApnsService)

Example 24 with ApnsService

use of com.notnoop.apns.ApnsService in project java-apns by notnoop.

the class QueuedApnsServiceTCTest method pushEventually.

@Test
public void pushEventually() {
    ConnectionStub connection = spy(new ConnectionStub(0, 1));
    ApnsService service = newService(connection, null);
    service.push(notification);
    connection.semaphore.acquireUninterruptibly();
    verify(connection, times(1)).sendMessage(notification);
}
Also used : ConnectionStub(com.notnoop.apns.internal.QueuedApnsServiceTest.ConnectionStub) ApnsService(com.notnoop.apns.ApnsService) Test(org.junit.Test)

Example 25 with ApnsService

use of com.notnoop.apns.ApnsService in project java-apns by notnoop.

the class QueuedApnsServiceTest method pushEventuallySample.

@Test
public void pushEventuallySample() {
    ConnectionStub connection = spy(new ConnectionStub(0, 1));
    ApnsService service = newService(connection, null);
    service.push("2342", "{}");
    connection.semaphore.acquireUninterruptibly();
    verify(connection, times(1)).sendMessage(notification);
}
Also used : ApnsService(com.notnoop.apns.ApnsService) Test(org.junit.Test)

Aggregations

ApnsService (com.notnoop.apns.ApnsService)32 Test (org.junit.Test)20 ApnsNotification (com.notnoop.apns.ApnsNotification)5 DeliveryError (com.notnoop.apns.DeliveryError)5 EnhancedApnsNotification (com.notnoop.apns.EnhancedApnsNotification)5 SimpleApnsNotification (com.notnoop.apns.SimpleApnsNotification)5 StartSendingApnsDelegate (com.notnoop.apns.StartSendingApnsDelegate)5 ApnsServerStub (com.notnoop.apns.utils.ApnsServerStub)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 CamelContext (org.apache.camel.CamelContext)4 ApnsServiceFactory (org.apache.camel.component.apns.factory.ApnsServiceFactory)4 ApnsDelegate (com.notnoop.apns.ApnsDelegate)2 Repeat (com.notnoop.apns.utils.junit.Repeat)2 ApnsServiceBuilder (com.notnoop.apns.ApnsServiceBuilder)1 ConnectionStub (com.notnoop.apns.internal.QueuedApnsServiceTest.ConnectionStub)1 NetworkIOException (com.notnoop.exceptions.NetworkIOException)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 GeneralSecurityException (java.security.GeneralSecurityException)1