Merge "Don't cache ImapFolders"

This commit is contained in:
Marc Blank 2011-06-29 13:34:44 -07:00 committed by Android (Google) Code Review
commit 77160c8c08
7 changed files with 19 additions and 33 deletions

View File

@ -76,7 +76,7 @@ public abstract class Folder {
* @return True if further commands are not expected to have to open the
* connection.
*/
public abstract boolean isOpenForTest();
public abstract boolean isOpen();
/**
* Returns the mode the folder was opened with. This may be different than the mode the open

View File

@ -49,6 +49,7 @@ import com.android.emailcommon.mail.Part;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.service.SearchParams;
import com.android.emailcommon.utility.Utility;
import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
@ -90,7 +91,7 @@ class ImapFolder extends Folder {
public void open(OpenMode mode, PersistentDataCallbacks callbacks)
throws MessagingException {
try {
if (isOpenForTest()) {
if (isOpen()) {
if (mMode == mode) {
// Make sure the connection is valid.
// If it's not we'll close it down and continue on to get a new one.
@ -140,7 +141,8 @@ class ImapFolder extends Folder {
}
@Override
public boolean isOpenForTest() {
@VisibleForTesting
public boolean isOpen() {
return mExists && mConnection != null;
}
@ -1059,7 +1061,7 @@ class ImapFolder extends Folder {
}
private void checkOpen() throws MessagingException {
if (!isOpenForTest()) {
if (!isOpen()) {
throw new MessagingException("Folder " + mName + " is not open.");
}
}

View File

@ -90,14 +90,6 @@ public class ImapStore extends Store {
private final ConcurrentLinkedQueue<ImapConnection> mConnectionPool =
new ConcurrentLinkedQueue<ImapConnection>();
/**
* Cache of ImapFolder objects. ImapFolders are attached to a given folder on the server
* and as long as their associated connection remains open they are reusable between
* requests. This cache lets us make sure we always reuse, if possible, for a given
* folder name.
*/
private final HashMap<String, ImapFolder> mFolderCache = new HashMap<String, ImapFolder>();
/**
* Static named constructor.
*/
@ -320,15 +312,7 @@ public class ImapStore extends Store {
@Override
public Folder getFolder(String name) {
ImapFolder folder;
synchronized (mFolderCache) {
folder = mFolderCache.get(name);
if (folder == null) {
folder = new ImapFolder(this, name);
mFolderCache.put(name, folder);
}
}
return folder;
return new ImapFolder(this, name);
}
/**

View File

@ -933,7 +933,7 @@ public class Pop3Store extends Store {
}
@Override
public boolean isOpenForTest() {
public boolean isOpen() {
return mTransport.isOpen();
}

View File

@ -1479,9 +1479,9 @@ public class ImapStoreUnitTests extends InstrumentationTestCase {
assertEquals(1, folder.getMessageCount());
assertEquals(OpenMode.READ_WRITE, folder.getMode());
assertTrue(folder.isOpenForTest());
assertTrue(folder.isOpen());
folder.close(false);
assertFalse(folder.isOpenForTest());
assertFalse(folder.isOpen());
// READ-ONLY
expectNoop(mock, true); // Need it because we reuse the connection.

View File

@ -402,7 +402,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -444,7 +444,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -487,7 +487,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -539,7 +539,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -586,7 +586,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -645,7 +645,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -692,7 +692,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// NOTE: everything from here down is copied from testOneUnread() and should be consolidated
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);
@ -741,7 +741,7 @@ public class Pop3StoreUnitTests extends InstrumentationTestCase {
// test is, can we recover? So I'll try a new connection, without the failure.
// confirm that we're closed at this point
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpenForTest());
assertFalse("folder should be 'closed' after an IOError", mFolder.isOpen());
// and confirm that the next connection will be OK
checkOneUnread(mockTransport);

View File

@ -103,7 +103,7 @@ public class MockFolder extends Folder {
}
@Override
public boolean isOpenForTest() {
public boolean isOpen() {
return false;
}