@Test public void correctNumberOfValuesInCache() throws InterruptedException { ReadExpressionTester exp = new ReadExpressionTester(timedCacheOf(vDouble("x"), Duration.ofMillis(100))); Instant reference = Instant.now(); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(0))))); assertThat(((List) exp.getValue()).size(), equalTo(1)); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(10))))); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(20))))); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(30))))); assertThat(((List) exp.getValue()).size(), equalTo(4)); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(40))))); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(50))))); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(60))))); assertThat(((List) exp.getValue()).size(), equalTo(7)); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(115))))); assertThat(((List) exp.getValue()).size(), equalTo(6)); exp.writeValue("x", newVDouble(0.0, newTime(reference.plus(Duration.ofMillis(155))))); assertThat(((List) exp.getValue()).size(), equalTo(3)); }
@Override public void writeValue(T newValue) { Runnable task; if (newValue != null) { synchronized(buffer) { buffer.add(newValue); prune(); task = notification; } if (task != null) { task.run(); } } }
TimedCacheCollector implements Collector<T, List<T>> { @Override public void writeValue(T newValue) { Runnable task; if (newValue != null) { synchronized(buffer) { buffer.add(newValue); prune(); task = notification; } if (task != null) { task.run(); } } } }
TimedCacheCollector implements Collector<T, List<T>> { @Override public void writeValue(T newValue) { Runnable task; if (newValue != null) { synchronized(buffer) { buffer.add(newValue); prune(); task = notification; } if (task != null) { task.run(); } } } TimedCacheCollector(ReadFunction<T> function, Duration cachedPeriod); }
TimedCacheCollector implements Collector<T, List<T>> { @Override public void writeValue(T newValue) { Runnable task; if (newValue != null) { synchronized(buffer) { buffer.add(newValue); prune(); task = notification; } if (task != null) { task.run(); } } } TimedCacheCollector(ReadFunction<T> function, Duration cachedPeriod); @Override void setChangeNotification(Runnable notification); @Override void writeValue(T newValue); @Override List<T> readValue(); }
TimedCacheCollector implements Collector<T, List<T>> { @Override public void writeValue(T newValue) { Runnable task; if (newValue != null) { synchronized(buffer) { buffer.add(newValue); prune(); task = notification; } if (task != null) { task.run(); } } } TimedCacheCollector(ReadFunction<T> function, Duration cachedPeriod); @Override void setChangeNotification(Runnable notification); @Override void writeValue(T newValue); @Override List<T> readValue();  }