}
@Test
public void should_refresh_many() throws Exception {
CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").addFriends("bob", "alice").age(35L).buid();
CompleteBean john = CompleteBeanTestBuilder.builder().randomId().name("John").addFriends("bob", "alice").age(35L).buid();
CompleteBean jack = CompleteBeanTestBuilder.builder().randomId().name("Jack").addFriends("bob", "alice").age(35L).buid();
paul = manager.insert(paul).getImmediately();
john = manager.insert(john).getImmediately();
jack = manager.insert(jack).getImmediately();
session.execute("UPDATE completebean SET name='Paul_modified' WHERE id=" + paul.getId());
session.execute("UPDATE completebean SET friends=friends + ['eve'] WHERE id=" + paul.getId());
session.execute("UPDATE completebean SET name='John_modified' WHERE id=" + john.getId());
session.execute("UPDATE completebean SET friends=friends + ['oscar'] WHERE id=" + john.getId());
session.execute("UPDATE completebean SET name='Jack_modified' WHERE id=" + jack.getId());
session.execute("UPDATE completebean SET friends=friends + ['mallory'] WHERE id=" + jack.getId());
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Object> successSpy = new AtomicReference<>();
FutureCallback<Object> successCallBack = new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
successSpy.getAndSet(result);
latch.countDown();
}
@Override
public void onFailure(Throwable t) {
latch.countDown();
}
};
final AchillesFuture<CompleteBean> futurePaul = manager.refresh(paul, withAsyncListeners(successCallBack));
final AchillesFuture<CompleteBean> futureJohn = manager.refresh(john);
final AchillesFuture<CompleteBean> futureJack = manager.refresh(jack);
futurePaul.get();
assertThat(paul.getName()).isEqualTo("Paul_modified");
assertThat(paul.getFriends()).hasSize(3);
assertThat(paul.getFriends().get(2)).isEqualTo("eve");
futureJohn.get();
assertThat(john.getName()).isEqualTo("John_modified");
assertThat(john.getFriends()).hasSize(3);
assertThat(john.getFriends().get(2)).isEqualTo("oscar");
futureJack.get();
assertThat(jack.getName()).isEqualTo("Jack_modified");
assertThat(jack.getFriends()).hasSize(3);
assertThat(jack.getFriends().get(2)).isEqualTo("mallory");
latch.await();
Thread.sleep(100);
assertThat(successSpy.get()).isNotNull().isInstanceOf(CompleteBean.class)
.isNotExactlyInstanceOf(Factory.class);