/** * Returns the instance of this class associated with this user and community. * * @param account User account. * @param communityId Community ID. * @return Instance of this class. */ public static synchronized CacheManager getInstance(UserAccount account, String communityId) { if (account == null) { account = SmartStoreSDKManager.getInstance().getUserAccountManager().getCurrentUser(); } if (account == null) { return null; } String uniqueId = account.getUserId(); if (UserAccount.INTERNAL_COMMUNITY_ID.equals(communityId)) { communityId = null; } if (!TextUtils.isEmpty(communityId)) { uniqueId = uniqueId + communityId; } CacheManager instance = null; if (INSTANCES == null) { INSTANCES = new HashMap<String, CacheManager>(); instance = new CacheManager(account, communityId); INSTANCES.put(uniqueId, instance); } else { instance = INSTANCES.get(uniqueId); } if (instance == null) { instance = new CacheManager(account, communityId); INSTANCES.put(uniqueId, instance); } instance.resetInMemoryCache(); return instance; }
@Override public void setUp() throws Exception { super.setUp(); targetContext = getInstrumentation().getTargetContext(); final Application app = Instrumentation.newApplication(TestForceApp.class, targetContext); getInstrumentation().callApplicationOnCreate(app); TestCredentials.init(getInstrumentation().getContext()); eq = new EventsListenerQueue(); if (SmartSyncSDKManager.getInstance() == null) { eq.waitForEvent(EventType.AppCreateComplete, 5000); } final LoginOptions loginOptions = new LoginOptions( TestCredentials.LOGIN_URL, null, TEST_CALLBACK_URL, TestCredentials.CLIENT_ID, TEST_SCOPES); final ClientManager clientManager = new ClientManager(targetContext, TestCredentials.ACCOUNT_TYPE, loginOptions, true); clientManager.createNewAccount( TestCredentials.ACCOUNT_NAME, TestCredentials.USERNAME, TestCredentials.REFRESH_TOKEN, TEST_AUTH_TOKEN, TestCredentials.INSTANCE_URL, TestCredentials.LOGIN_URL, TestCredentials.IDENTITY_URL, TestCredentials.CLIENT_ID, TestCredentials.ORG_ID, TestCredentials.USER_ID, null); MetadataManager.reset(null); CacheManager.hardReset(null); SyncManager.reset(); metadataManager = MetadataManager.getInstance(null); cacheManager = CacheManager.getInstance(null); syncManager = SyncManager.getInstance(); restClient = initRestClient(); metadataManager.setRestClient(restClient); syncManager.setRestClient(restClient); smartStore = cacheManager.getSmartStore(); }
@Override public void tearDown() throws Exception { if (eq != null) { eq.tearDown(); eq = null; } MetadataManager.reset(null); CacheManager.hardReset(null); super.tearDown(); }