use of com.octo.android.robospice.persistence.exception.SpiceException in project robospice by stephanenicolas.
the class RequestProcessorTest method testDefaultRetryPolicy_implements_retry_countdown_and_exponential_backoff.
public void testDefaultRetryPolicy_implements_retry_countdown_and_exponential_backoff() throws Exception {
// define local values since class constant values didn't reveal
// incremental backoff
final long localDelayBeforeRetry = 200;
final float localRetryBackoffMultiplier = 5.0f;
final int localRetryCount = 3;
// given
DefaultRetryPolicy retryPolicy = new DefaultRetryPolicy(localRetryCount, localDelayBeforeRetry, localRetryBackoffMultiplier);
assertEquals(localRetryCount, retryPolicy.getRetryCount());
assertEquals(localDelayBeforeRetry, retryPolicy.getDelayBeforeRetry());
// when
SpiceException e = null;
retryPolicy.retry(e);
// then
assertEquals(localRetryCount - 1, retryPolicy.getRetryCount());
assertEquals((long) (localDelayBeforeRetry * localRetryBackoffMultiplier), retryPolicy.getDelayBeforeRetry());
}
use of com.octo.android.robospice.persistence.exception.SpiceException in project ETSMobile-Android2 by ApplETS.
the class Utility method loadNotifications.
/**
* Gets MonÉTS notifications and update DB
* @param context
* @param requestListener
*/
public static void loadNotifications(Context context, final RequestListener<Object> requestListener) {
final SecurePreferences securePreferences = new SecurePreferences(context);
final boolean allNotifsLoaded = securePreferences.getBoolean(Constants.ALL_NOTIFS_LOADED, false);
MonETSNotificationsRequest monETSNotificationsRequest;
if (!allNotifsLoaded) {
monETSNotificationsRequest = new MonETSNotificationsRequest(context, false);
} else {
monETSNotificationsRequest = new MonETSNotificationsRequest(context, true);
}
final DataManager dataManager = DataManager.getInstance(context);
dataManager.start();
final DatabaseHelper databaseHelper = new DatabaseHelper(context);
dataManager.sendRequest(monETSNotificationsRequest, new RequestListener<Object>() {
@Override
public void onRequestFailure(SpiceException spiceException) {
requestListener.onRequestFailure(spiceException);
dataManager.stop();
}
@Override
public void onRequestSuccess(Object o) {
if (o instanceof MonETSNotificationList) {
try {
Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
MonETSNotificationList list = (MonETSNotificationList) o;
for (MonETSNotification monETSNotification : list) {
dao.createOrUpdate(monETSNotification);
}
if (!allNotifsLoaded) {
securePreferences.edit().putBoolean(Constants.ALL_NOTIFS_LOADED, true).commit();
}
requestListener.onRequestSuccess(list);
} catch (SQLException e) {
e.printStackTrace();
}
}
dataManager.stop();
}
});
}
Aggregations