FinalStateSetterManager { public void set(K k, S s){ S previous = map.put(k, s); if(!ObjectUtils.equals(previous, s)){ logger.debug("[set]{},{}->{}", k, previous, s); keyedOneThreadTaskExecutor.execute(k, new CheckAndSetTask(k, s)); } } FinalStateSetterManager(Executor executors, Function<K, S> getter, BiConsumer<K, S> setter); void set(K k, S s);  }
@Test public void testSet() throws TimeoutException { String testKey = randomString(10); finalStateSetterManager = new FinalStateSetterManager<>(executors, (String key) -> randomString(10), (key, value) -> count.incrementAndGet()); finalStateSetterManager.set(testKey, randomString(10)); sleep(100); finalStateSetterManager.set(testKey, randomString(10)); waitConditionUntilTimeOut(() -> count.get() == 2); }
@Test public void testMultiExecuteFinal() throws TimeoutException { String testKey = randomString(10); finalStateSetterManager = new FinalStateSetterManager<>(executors, (String key) -> randomString(10), (key, value) -> { int current = count.incrementAndGet(); if( current == 1){ sleep(500); } }); finalStateSetterManager.set(testKey, randomString(10)); sleep(100); for(int i=0;i<10;i++){ finalStateSetterManager.set(testKey, randomString(10)); } sleep(1000); waitConditionUntilTimeOut(() -> count.get() == 2); }