/** * Test of asynchronouslySendNotificationMessage method, of class PushManager. * * @throws Exception If an error occurs */ public void testAsynchronouslySendNotificationMessage_SendMoreThanOneMessage() throws Exception { final int messagesToSend = 100; final int sendingTimeSeconds = 2; final MockHelperNotificationEngine mockNotificationEngine = new MockHelperNotificationEngine() { @Override public void sendNotificationMessage( String username, String deviceId, Alert[] alerts, int uimode) throws NotificationNotSentException, NotificationException { idleFor(sendingTimeSeconds); incrementMessagesSent(); } public void validate() { assertEquals("All messages have to be sent", messagesToSend, totalMessageSent); } }; PushManager instance = new PushManager() { @Override protected NotificationEngine createNotificationEngine() { return mockNotificationEngine; } }; Future<?>[] futures = new Future<?>[messagesToSend]; for (int i = 0; i < messagesToSend; ++i) { String username = "******"; String deviceId = "IMEI-1234567890"; Alert[] alerts = new Alert[] {new Alert()}; int uimode = 0; futures[i] = instance.asynchronouslySendNotificationMessage(username, deviceId, alerts, uimode); } Thread.sleep(100); // the notification messages deliveries are just started so they are all in progress assertEquals( Math.min(instance.getCoreThreadPoolSize(), messagesToSend), instance.getCurrentPushInProgressCount()); assertEquals( Math.max(0, messagesToSend - instance.getCoreThreadPoolSize()), instance.getQueuedPushCount()); waitingDeliveryTermination(futures, sendingTimeSeconds); assertEquals(0, instance.getCurrentPushInProgressCount()); mockNotificationEngine.validate(); }