### Question:
DistributedAtomicLong implements DistributedAtomicNumber<Long> { @Override public AtomicValue<Long> compareAndSet(Long expectedValue, Long newValue) throws Exception { return new AtomicLong(value.compareAndSet(valueToBytes(expectedValue), valueToBytes(newValue))); } DistributedAtomicLong(CuratorFramework client, String counterPath, RetryPolicy retryPolicy);  DistributedAtomicLong(CuratorFramework client, String counterPath, RetryPolicy retryPolicy, PromotedToLock promotedToLock); @Override AtomicValue<Long> get(); @Override void forceSet(Long newValue); @Override AtomicValue<Long> compareAndSet(Long expectedValue, Long newValue); @Override AtomicValue<Long> trySet(Long newValue); @Override boolean initialize(Long initialize); @Override AtomicValue<Long> increment(); @Override AtomicValue<Long> decrement(); @Override AtomicValue<Long> add(Long delta); @Override AtomicValue<Long> subtract(Long delta);  }### Answer:
@Test public void testCompareAndSet() throws Exception { final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); try { final AtomicBoolean doIncrement = new AtomicBoolean(false); DistributedAtomicLong dal = new DistributedAtomicLong(client, "/counter", new RetryOneTime(1)) { @Override public byte[] valueToBytes(Long newValue) { if ( doIncrement.get() ) { DistributedAtomicLong inc = new DistributedAtomicLong(client, "/counter", new RetryOneTime(1)); try { inc.increment(); } catch ( Exception e ) { throw new Error(e); } } return super.valueToBytes(newValue); } }; dal.forceSet(1L); Assert.assertTrue(dal.compareAndSet(1L, 5L).succeeded()); Assert.assertFalse(dal.compareAndSet(1L, 5L).succeeded()); doIncrement.set(true); Assert.assertFalse(dal.compareAndSet(5L, 10L).succeeded()); } finally { client.close(); } }