@Test
  @ClientCompatibleTest
  public void alterAndGet() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref = hazelcastInstance.getAtomicReference("alterAndGet");

    assertNull(ref.alterAndGet(new NullFunction()));
    assertEquals(null, ref.get());

    ref.set("foo");
    assertEquals("foobar", ref.alterAndGet(new AppendFunction("bar")));
    assertEquals("foobar", ref.get());

    assertEquals(null, ref.alterAndGet(new NullFunction()));
    assertEquals(null, ref.get());
  }
  @Test(expected = IllegalArgumentException.class)
  @ClientCompatibleTest
  public void alterAndGet_whenCalledWithNullFunction() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref =
        hazelcastInstance.getAtomicReference("alterAndGet_whenCalledWithNullFunction");

    ref.alterAndGet(null);
  }
  @Test
  @ClientCompatibleTest
  public void getAndAlter_when_same_reference() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();

    BitSet bitSet = new BitSet();
    IAtomicReference<BitSet> ref2 = hazelcastInstance.getAtomicReference(randomString());
    ref2.set(bitSet);
    bitSet.set(100);
    assertEquals(bitSet, ref2.alterAndGet(new FailingFunctionAlter()));
    assertEquals(bitSet, ref2.get());
  }
  @Test
  @ClientCompatibleTest
  public void alterAndGet_whenException() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref =
        hazelcastInstance.getAtomicReference("alterAndGet_whenException");
    ref.set("foo");

    try {
      ref.alterAndGet(new FailingFunction());
      fail();
    } catch (WoohaaException expected) {
    }

    assertEquals("foo", ref.get());
  }