/** * Static initializer, use this to get the active instance. This insures we only ever have one * copy going at once! * * @return a singleton post manager. */ public static CachedPostManager getInstance(Context context) { if (sPostManager == null) { sPostManager = new CachedPostManager(context.getApplicationContext()); sPostManager.mProfileManager = UserProfileManager.getInstance(context); } return sPostManager; }
@Test public void testStress() throws NoSessionException, GetFailedException, PutFailedException, IOException, NoPeerConnectionException, AbortModifyException { UserProfileManager profileManager = new UserProfileManager(client.getDataManager(), userCredentials); for (int i = 0; i < 10; i++) { final boolean isFolder = rnd.nextBoolean(); final File file = new File(root, randomString()); if (!isFolder) { FileUtils.writeStringToFile(file, randomString()); } final byte[] md5Hash = HashUtil.hash(file); final KeyPair fileKeys = generateRSAKeyPair(RSA_KEYLENGTH.BIT_512); while (true) { String pid = UUID.randomUUID().toString(); profileManager.modifyUserProfile( pid, new IUserProfileModification() { @Override public void modifyUserProfile(UserProfile userProfile) { List<FolderIndex> indexes = getIndexList(userProfile.getRoot()); if (isFolder) { new FolderIndex( indexes.get(rnd.nextInt(indexes.size())), fileKeys, randomString()); } else { new FileIndex( indexes.get(rnd.nextInt(indexes.size())), fileKeys, file.getName(), md5Hash); } } }); break; } } }
@Override protected Void doExecute() throws InvalidProcessStateException, ProcessExecutionException { try { if (operation == Operation.PUT) { profileManager.modifyUserProfile( getID(), new IUserProfileModification() { @Override public void modifyUserProfile(UserProfile userProfile) { if (operation == Operation.MODIFY) { new FolderIndex(userProfile.getRoot(), null, randomString()); } } }); } else { profileManager.readUserProfile(); } } catch (GetFailedException | PutFailedException | AbortModifyException e) { throw new ProcessExecutionException(this, e); } return null; }