Search in sources :

Example 1 with ApnsService

use of com.notnoop.apns.ApnsService in project camel by apache.

the class ApnsConsumerIdleMessageTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
    ApnsService apnsService = apnsServiceFactory.getApnsService();
    ApnsComponent apnsComponent = new ApnsComponent(apnsService);
    camelContext.addComponent("apns", apnsComponent);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ApnsServiceFactory(org.apache.camel.component.apns.factory.ApnsServiceFactory) ApnsService(com.notnoop.apns.ApnsService)

Example 2 with ApnsService

use of com.notnoop.apns.ApnsService in project camel by apache.

the class ApnsConsumerTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
    ApnsService apnsService = apnsServiceFactory.getApnsService();
    ApnsComponent apnsComponent = new ApnsComponent(apnsService);
    camelContext.addComponent("apns", apnsComponent);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ApnsServiceFactory(org.apache.camel.component.apns.factory.ApnsServiceFactory) ApnsService(com.notnoop.apns.ApnsService)

Example 3 with ApnsService

use of com.notnoop.apns.ApnsService in project camel by apache.

the class ApnsProducerWithoutTokensHeaderTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
    ApnsService apnsService = apnsServiceFactory.getApnsService();
    ApnsComponent apnsComponent = new ApnsComponent(apnsService);
    camelContext.addComponent("apns", apnsComponent);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ApnsServiceFactory(org.apache.camel.component.apns.factory.ApnsServiceFactory) ApnsService(com.notnoop.apns.ApnsService)

Example 4 with ApnsService

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

the class ApnsConnectionCacheTest method cacheLengthNotification.

/**
     * Test to make sure that if the cache length is violated we get
     * a notification
     *
     * @throws InterruptedException
     */
@Test(timeout = 5000)
public void cacheLengthNotification() throws InterruptedException {
    server = new ApnsServerStub(FixedCertificates.serverContext().getServerSocketFactory());
    final CountDownLatch sync = new CountDownLatch(1);
    int ORIGINAL_CACHE_LENGTH = 100;
    final AtomicInteger modifiedCacheLength = new AtomicInteger();
    server.getWaitForError().acquire();
    server.start();
    ApnsService service = APNS.newService().withSSLContext(clientContext()).withGatewayDestination(LOCALHOST, server.getEffectiveGatewayPort()).withDelegate(new ApnsDelegate() {

        public void messageSent(ApnsNotification message, boolean resent) {
        }

        public void messageSendFailed(ApnsNotification message, Throwable e) {
        }

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

        public void cacheLengthExceeded(int newCacheLength) {
            modifiedCacheLength.set(newCacheLength);
            sync.countDown();
        }

        public void notificationsResent(int 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 < 101; ++i) {
        service.push(eMsg3);
    }
    server.sendError(8, eMsg2.getIdentifier());
    server.getWaitForError().release();
    server.getMessages().acquire();
    sync.await();
    Assert.assertTrue(ORIGINAL_CACHE_LENGTH < modifiedCacheLength.get());
}
Also used : 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) StartSendingApnsDelegate(com.notnoop.apns.StartSendingApnsDelegate) ApnsDelegate(com.notnoop.apns.ApnsDelegate) ApnsService(com.notnoop.apns.ApnsService)

Example 5 with ApnsService

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

the class ApnsConnectionCacheTest method handleReTransmissionError1Good1Bad2Good.

/**
     * Test2 to make sure that after rejected notification
     * in-flight notifications are re-transmitted
     *
     * @throws InterruptedException
     */
@Test(timeout = 5000)
public void handleReTransmissionError1Good1Bad2Good() throws InterruptedException {
    server = new ApnsServerStub(FixedCertificates.serverContext().getServerSocketFactory());
    final CountDownLatch sync = new CountDownLatch(6);
    final AtomicInteger numResent = new AtomicInteger();
    final AtomicInteger numSent = new AtomicInteger();
    final AtomicInteger numStartSend = new AtomicInteger();
    int EXPECTED_RESEND_COUNT = 2;
    int EXPECTED_SEND_COUNT = 3;
    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(msg1.length() * 3 + eMsg2.length() * 2);
    service.push(msg1);
    service.push(eMsg2);
    service.push(eMsg1);
    service.push(msg2);
    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)

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