Search in sources :

Example 11 with ApnsNotification

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

the class BatchApnsServiceTest method simpleBatchWait_maxDelay.

@Test
public void simpleBatchWait_maxDelay() throws IOException, InterruptedException {
    // send message
    ApnsNotification message1 = service.push("1234", "{}");
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    ApnsNotification message2 = service.push("4321", "{}");
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    ApnsNotification message3 = service.push("4321", "{}");
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    ApnsNotification message4 = service.push("4321", "{}");
    // make sure no message was send yet
    verify(prototype, times(0)).copy();
    verify(prototype, times(0)).sendMessage(message1);
    verify(prototype, times(0)).sendMessage(message2);
    verify(prototype, times(0)).sendMessage(message3);
    verify(prototype, times(0)).sendMessage(message4);
    verify(prototype, times(0)).close();
    Thread.sleep(delayTimeInSec1_4_millis + /* for sure */
    250);
    // verify batch sends and close the connection
    verify(prototype, times(1)).copy();
    verify(prototype, times(1)).sendMessage(message1);
    verify(prototype, times(1)).sendMessage(message2);
    verify(prototype, times(1)).sendMessage(message3);
    verify(prototype, times(1)).sendMessage(message4);
    verify(prototype, times(1)).close();
}
Also used : ApnsNotification(com.notnoop.apns.ApnsNotification) Test(org.junit.Test)

Example 12 with ApnsNotification

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

the class BatchApnsServiceTest method simpleBatchWait_multiple.

@Test
public void simpleBatchWait_multiple() throws IOException, InterruptedException {
    // send message
    ApnsNotification message1 = service.push("1234", "{}");
    Thread.sleep(delayTimeInSec1_2_millis);
    ApnsNotification message2 = service.push("4321", "{}");
    // make sure no message was send yet
    verify(prototype, times(0)).copy();
    verify(prototype, times(0)).sendMessage(message1);
    verify(prototype, times(0)).sendMessage(message2);
    verify(prototype, times(0)).close();
    Thread.sleep(delayTimeInSec1_4_millis * 3);
    // still no send
    verify(prototype, times(0)).copy();
    verify(prototype, times(0)).sendMessage(message1);
    verify(prototype, times(0)).sendMessage(message2);
    verify(prototype, times(0)).close();
    Thread.sleep(delayTimeInSec1_4_millis + /* for sure */
    250);
    // verify batch sends and close the connection
    verify(prototype, times(1)).copy();
    verify(prototype, times(1)).sendMessage(message1);
    verify(prototype, times(1)).sendMessage(message2);
    verify(prototype, times(1)).close();
}
Also used : ApnsNotification(com.notnoop.apns.ApnsNotification) Test(org.junit.Test)

Aggregations

ApnsNotification (com.notnoop.apns.ApnsNotification)12 EnhancedApnsNotification (com.notnoop.apns.EnhancedApnsNotification)7 DeliveryError (com.notnoop.apns.DeliveryError)6 ApnsService (com.notnoop.apns.ApnsService)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 Test (org.junit.Test)3 ApnsDelegate (com.notnoop.apns.ApnsDelegate)2 NetworkIOException (com.notnoop.exceptions.NetworkIOException)2 ApnsDeliveryErrorException (com.notnoop.exceptions.ApnsDeliveryErrorException)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Queue (java.util.Queue)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 MessageType (org.apache.camel.component.apns.model.MessageType)1