EvictExpirableRecordsPersistence extends Action { Observable<String> startTaskIfNeeded(boolean isEncrypted) { this.isEncrypted = isEncrypted; oEvictingTask.subscribe(); return oEvictingTask; } @Inject  EvictExpirableRecordsPersistence(Memory memory, Persistence persistence,
      Integer maxMgPersistenceCache, String encryptKey);  static final float PERCENTAGE_MEMORY_STORED_TO_STOP; }
@Test public void When_Not_Reached_Memory_Threshold_Not_Emit() { evictExpirableRecordsPersistenceUT = new io.rx_cache2.internal.cache.EvictExpirableRecordsPersistence(memory, disk, 10, null); populate(true); assertThat(disk.allKeys().size(), is(100)); TestObserver testObserver = evictExpirableRecordsPersistenceUT.startTaskIfNeeded(false).test(); testObserver.awaitTerminalEvent(); testObserver .assertNoErrors() .assertNoValues(); }
@Theory @Test public void When_Reached_Memory_Threshold_Perform_Task(int maxMgPersistenceCache) { evictExpirableRecordsPersistenceUT = new io.rx_cache2.internal.cache.EvictExpirableRecordsPersistence(memory, disk, maxMgPersistenceCache, null); populate(true); assertThat(disk.allKeys().size(), is(mocksCount())); TestObserver testObserver = evictExpirableRecordsPersistenceUT.startTaskIfNeeded(false).test(); testObserver.awaitTerminalEvent(); testObserver.assertNoErrors(); int expectedStoredMB = (int) (maxMgPersistenceCache * io.rx_cache2.internal.cache.EvictExpirableRecordsPersistence.PERCENTAGE_MEMORY_STORED_TO_STOP); assertThat(expectedStoredMB, is(disk.storedMB())); }
@Test public void When_Reached_Memory_Threshold_But_Not_Expirable_Records_Do_Not_Evict() { int maxMgPersistenceCache = 5; evictExpirableRecordsPersistenceUT = new io.rx_cache2.internal.cache.EvictExpirableRecordsPersistence(memory, disk, maxMgPersistenceCache, null); populate(false); assertThat(disk.allKeys().size(), is(mocksCount())); TestObserver testObserver = evictExpirableRecordsPersistenceUT.startTaskIfNeeded(false).test(); testObserver.awaitTerminalEvent(); testObserver.assertNoErrors(); assertThat(sizeMbDataPopulated(), is(disk.storedMB())); testObserver = new TestObserver(); evictExpirableRecordsPersistenceUT.startTaskIfNeeded(false).subscribe(testObserver); testObserver.awaitTerminalEvent(); testObserver.assertNoErrors(); testObserver.assertValue(Locale.RECORD_CAN_NOT_BE_EVICTED_BECAUSE_NO_ONE_IS_EXPIRABLE); }