Package plugins.Freetalk.MessageList

Examples of plugins.Freetalk.MessageList.MessageListFetchFailedMarker


  public void testOnMessageListFetchFailed() {
    WoTOwnIdentity author = mOwnIdentities[0];
    Query q;
    ObjectSet<FetchFailedMarker> markers;
    ObjectSet<MessageList> messageLists;
    MessageListFetchFailedMarker marker;
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    assertEquals(0, q.execute().size());
   
    q = db.query();
    q.constrain(MessageList.class);
    assertEquals(0, q.execute().size());
   
    mMessageManager.onMessageListFetchFailed(author, WoTMessageList.assembleURI(author.getRequestURI(), 1), FetchFailedMarker.Reason.DataNotFound);
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    assertEquals(1, q.execute().size());
   
    mMessageManager.clearExpiredFetchFailedMarkers();
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
   
    marker = (MessageListFetchFailedMarker)markers.next();
   
    assertTrue((CurrentTimeUTC.getInMillis() - marker.getDate().getTime()) < 10 * 1000);
    assertEquals(marker.getDate().getTime() + MessageManager.MINIMAL_MESSAGELIST_FETCH_RETRY_DELAY, marker.getDateOfNextRetry().getTime());
    assertEquals(false, marker.isRetryAllowedNow());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(1, messageLists.size());
    assertEquals(messageLists.next().getID(), marker.getMessageListID());
   
    // Now we simulate a retry of the message list fetch
   
    marker.setDateOfNextRetry(marker.getDate());
    marker.setAllowRetryNow(false); // Needed for clearExpiredFetchFailedMarkers to process the marker
    marker.storeWithoutCommit();
    Persistent.checkedCommit(db, this);
       
    mMessageManager.clearExpiredFetchFailedMarkers();
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
    assertEquals(marker, markers.next());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(0, messageLists.size());
   
    mMessageManager.onMessageListFetchFailed(author, WoTMessageList.assembleURI(author.getRequestURI(), 1), FetchFailedMarker.Reason.DataNotFound);
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
    assertEquals(marker, markers.next());
    assertTrue((CurrentTimeUTC.getInMillis() - marker.getDate().getTime()) < 10 * 1000);
    assertEquals(marker.getDate().getTime() + Math.min(MessageManager.MINIMAL_MESSAGELIST_FETCH_RETRY_DELAY*2, MessageManager.MAXIMAL_MESSAGELIST_FETCH_RETRY_DELAY),
          marker.getDateOfNextRetry().getTime());
    assertEquals(1, marker.getNumberOfRetries());
    assertEquals(false, marker.isRetryAllowedNow());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(1, messageLists.size());
    assertEquals(messageLists.next().getID(), marker.getMessageListID());
   
    // Simulate failure with existing marker and existing ghost message list, i.e. the message list fetcher tried to fetch even though it shouldn't.
   
    mMessageManager.onMessageListFetchFailed(author, WoTMessageList.assembleURI(author.getRequestURI(), 1), FetchFailedMarker.Reason.DataNotFound);
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
    assertEquals(marker, markers.next());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(1, messageLists.size());
    assertEquals(messageLists.next().getID(), marker.getMessageListID());
  }
View Full Code Here


    // It's not possible to keep the synchronization order of message lists to synchronize BEFORE synchronizing on Persistent.transactionLock(db) some places so we
    // do not synchronize here.
    // And in this function we don't need to synchronize on it anyway because it is not known to anything which might modify it anyway.
    // In general, due to those issues the functions which modify message lists just use the message manager as synchronization object.
    //synchronized(list) {
    MessageListFetchFailedMarker marker;
    MessageList ghostList;

    try {
      marker = getMessageListFetchFailedMarker(list.getID());
    }
    catch(NoSuchFetchFailedMarkerException e) {
      marker = null;
    }
   
    try {
      ghostList = getMessageList(list.getID());
     
      if(marker == null) {
        if(logDEBUG) Logger.debug(this, "Downloaded a MessageList which we already have: " + list);
        return;
      }

    } catch(NoSuchMessageListException e) {
      ghostList = null;
    }

    synchronized(Persistent.transactionLock(db)) {
        try {
          if(marker != null) {
            // TODO: This is usually an error, but it is no error if the fetched list is the only list which there was a ghost list for (i.e. edition 0)
            // Re-think about the conditions when this is an error and log an error then, not only a warning.
            Logger.warning(this, "MessageList was fetched even though a FetchFailedMarker existed for it! Deleting the marker: " + marker);
            marker.deleteWithoutCommit();
            marker = null;
          }
           
          if(ghostList != null) { // We do not nest it with the above if() for readability / robustness.
            Logger.warning(this, "MessageList was fetched even though a ghost list existed for it! Deleting the ghost list: " + ghostList);
View Full Code Here

    @SuppressWarnings("unchecked")
    final ObjectSet<MessageListFetchFailedMarker> markers = q.execute();
   
    switch(markers.size()) {
      case 1:
        final MessageListFetchFailedMarker result = markers.next();
        result.initializeTransient(mFreetalk);
        return result;
      case 0:
        throw new NoSuchFetchFailedMarkerException(messageListID);
      default:
        throw new DuplicateFetchFailedMarkerException(messageListID);
View Full Code Here

            MessageFetchFailedMarker m = (MessageFetchFailedMarker)marker;
            MessageReference ref = m.getMessageReference();
            ref.clearMessageWasDownloadedFlag();
            ref.storeWithoutCommit();
          } else if(marker instanceof MessageListFetchFailedMarker) {
            MessageListFetchFailedMarker m = (MessageListFetchFailedMarker)marker;
            try {
              MessageList list = getMessageList(m.getMessageListID());
              list.deleteWithoutCommit();
             
              final IdentityStatistics stats = getOrCreateIdentityStatistics(list.getAuthor());
              stats.onMessageListDeleted(list);
              stats.storeWithoutCommit();
             
              m.storeWithoutCommit(); // MessageList.deleteWithoutCommit deletes it.
            }
            catch(NoSuchMessageListException e) {
              // The marker was already processed.
            }
          } else
View Full Code Here

TOP

Related Classes of plugins.Freetalk.MessageList.MessageListFetchFailedMarker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.