use of org.awaitility.Duration in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method testNotificationWillShowInForegroundHandler_notCallCompleteShowsNotificationAfterTimeout.
@Test
@Config(shadows = { ShadowGenerateNotification.class, ShadowTimeoutHandler.class, ShadowNotificationReceivedEvent.class })
public void testNotificationWillShowInForegroundHandler_notCallCompleteShowsNotificationAfterTimeout() throws Exception {
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// 1. Init OneSignal
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
OneSignal.initWithContext(blankActivity);
OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent -> {
callbackCounter++;
lastForegroundNotificationReceivedEvent = notificationReceivedEvent;
});
threadAndTaskWait();
blankActivityController.resume();
threadAndTaskWait();
// Mock timeout to 1, given that we are not calling complete inside NotificationWillShowInForegroundHandler we depend on the timeout complete
ShadowTimeoutHandler.setMockDelayMillis(1);
// 2. Receive a notification
FCMBroadcastReceiver_processBundle(blankActivity, getBaseNotifBundle());
threadAndTaskWait();
// 3. Make sure the AppNotificationJob is not null
assertNotNull(lastForegroundNotificationReceivedEvent);
// 4. Make sure the callback counter is only fired once for App NotificationWillShowInForegroundHandler
assertEquals(1, callbackCounter);
// Complete being call from Notification Receiver Handler thread
Awaitility.await().atMost(new Duration(5, TimeUnit.SECONDS)).pollInterval(new Duration(500, TimeUnit.MILLISECONDS)).untilAsserted(() -> {
// 5. Make sure 1 notification exists in DB
assertNotificationDbRecords(1);
// 6. Notification not opened then badges should be 1
assertEquals(1, ShadowBadgeCountUpdater.lastCount);
});
}
use of org.awaitility.Duration in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method testNotificationWillShowInForegroundHandler_silentNotificationNotSavedUntilTimerCompleteIsDone.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testNotificationWillShowInForegroundHandler_silentNotificationNotSavedUntilTimerCompleteIsDone() throws Exception {
// 1. Init OneSignal
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
OneSignal.initWithContext(blankActivity);
OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent -> {
callbackCounter++;
lastForegroundNotificationReceivedEvent = notificationReceivedEvent;
new Thread(() -> {
try {
// Simulate long work
Thread.sleep(5000);
// Check notification is still not saved
assertNotificationDbRecords(0);
notificationReceivedEvent.complete(null);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
});
threadAndTaskWait();
blankActivityController.resume();
threadAndTaskWait();
// 2. Receive a notification
FCMBroadcastReceiver_processBundle(blankActivity, getBaseNotifBundle());
threadAndTaskWait();
// 3. Make sure the AppNotificationJob is not null
assertNotNull(lastForegroundNotificationReceivedEvent);
// 4. Make sure the callback counter is only fired once for App NotificationWillShowInForegroundHandler
assertEquals(1, callbackCounter);
// 5. Make sure 0 notification exists in DB because complete was not called yet
assertNotificationDbRecords(0);
// Complete being call from User thread
Awaitility.await().atMost(new Duration(10, TimeUnit.SECONDS)).pollInterval(new Duration(500, TimeUnit.MILLISECONDS)).untilAsserted(() -> {
// Make sure 1 notification exists in DB
assertNotificationDbRecords(1, true);
});
}
use of org.awaitility.Duration in project providence by morimekta.
the class QueuedFileMessageWriterTest method testAFewWrites_serviceCalls.
@Test
@SuppressWarnings("unchecked")
public void testAFewWrites_serviceCalls() throws IOException, InterruptedException {
setDefaultPollDelay(new Duration(10, TimeUnit.MILLISECONDS));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
QueuedMessageWriter writer = new QueuedMessageWriter(target);
ExecutorService executorService = Executors.newFixedThreadPool(11);
for (int i = 0; i < 10; ++i) {
executorService.submit(() -> {
MessageGenerator generator = new MessageGenerator();
for (int j = 0; j < 10; ++j) {
try {
if (j > 0)
sleep(1L);
PServiceCall tmp = new PServiceCall("test", PServiceCallType.CALL, j, generator.generate(CompactFields.kDescriptor));
writer.write(tmp);
} catch (IOException e) {
throw new UncheckedIOException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
sleep(10L);
executorService.shutdown();
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
sleep(1L);
writer.close();
}
use of org.awaitility.Duration in project providence by morimekta.
the class QueuedFileMessageWriterTest method testAFewWrites.
@Test
@SuppressWarnings("unchecked")
public void testAFewWrites() throws IOException, InterruptedException {
setDefaultPollDelay(new Duration(10, TimeUnit.MILLISECONDS));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
QueuedMessageWriter writer = new QueuedMessageWriter(target);
ExecutorService executorService = Executors.newFixedThreadPool(11);
for (int i = 0; i < 10; ++i) {
executorService.submit(() -> {
MessageGenerator generator = new MessageGenerator();
for (int j = 0; j < 10; ++j) {
try {
if (j > 0)
sleep(1L);
writer.write(generator.generate(CompactFields.kDescriptor));
} catch (IOException e) {
throw new UncheckedIOException(e.getMessage(), e);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
});
}
sleep(10L);
executorService.shutdown();
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
sleep(1L);
writer.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
List<CompactFields> result = MessageStreams.stream(bais, new BinarySerializer(), CompactFields.kDescriptor).collect(Collectors.toList());
assertThat(result, hasSize(100));
}
Aggregations