コード例 #1
0
  @Test
  @ClientCompatibleTest
  public void getAndAlter() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref = hazelcastInstance.getAtomicReference("getAndAlter");

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

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

    assertEquals("foobar", ref.getAndAlter(new NullFunction()));
    assertEquals(null, ref.get());
  }
コード例 #2
0
  @Test(expected = IllegalArgumentException.class)
  @ClientCompatibleTest
  public void getAndAlter_whenCalledWithNullFunction() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref =
        hazelcastInstance.getAtomicReference("getAndAlter_whenCalledWithNullFunction");

    ref.getAndAlter(null);
  }
コード例 #3
0
  @Test
  @ClientCompatibleTest
  public void getAndAlter_whenException() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref =
        hazelcastInstance.getAtomicReference("getAndAlter_whenException");
    ref.set("foo");

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

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