PlusAnonymousConcurrentUserDataModel extends PlusAnonymousUserDataModel { public Long takeAvailableUser() { Long takenUserID = usersPool.poll(); if (takenUserID != null) { tempPrefs.put(takenUserID, new GenericUserPreferenceArray(0)); return takenUserID; } return null; } PlusAnonymousConcurrentUserDataModel(DataModel delegate, int maxConcurrentUsers); Long takeAvailableUser(); boolean releaseUser(Long userID); void setTempPrefs(PreferenceArray prefs, long anonymousUserID); void clearTempPrefs(long anonymousUserID); @Override LongPrimitiveIterator getUserIDs(); @Override PreferenceArray getPreferencesFromUser(long userID); @Override FastIDSet getItemIDsFromUser(long userID); @Override PreferenceArray getPreferencesForItem(long itemID); @Override Float getPreferenceValue(long userID, long itemID); @Override Long getPreferenceTime(long userID, long itemID); @Override int getNumUsers(); @Override int getNumUsersWithPreferenceFor(long itemID); @Override int getNumUsersWithPreferenceFor(long itemID1, long itemID2); @Override void setPreference(long userID, long itemID, float value); @Override void removePreference(long userID, long itemID);  }
@Test public void testTakeFirstAvailableUser() { PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10); Long expResult = PlusAnonymousUserDataModel.TEMP_USER_ID; Long result = instance.takeAvailableUser(); assertEquals(expResult, result); }
@Test public void testTakeNextAvailableUser() { PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10); instance.takeAvailableUser(); Long result = instance.takeAvailableUser(); Long expResult = PlusAnonymousUserDataModel.TEMP_USER_ID + 1; assertEquals(expResult, result); }
@Test public void testTakeUnavailableUser() { PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(1); instance.takeAvailableUser(); assertNull(instance.takeAvailableUser()); }