コード例 #1
0
  @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());
  }
コード例 #2
0
  @Test(expected = IllegalArgumentException.class)
  @ClientCompatibleTest
  public void alterAndGet_whenCalledWithNullFunction() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    IAtomicReference<String> ref =
        hazelcastInstance.getAtomicReference("alterAndGet_whenCalledWithNullFunction");

    ref.alterAndGet(null);
  }
コード例 #3
0
  @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());
  }
コード例 #4
0
  @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());
  }