@Override
    public AtomicValue<Long> compareAndSet(Long expectedValue, Long newValue) throws Exception {
        return new AtomicLong(value.compareAndSet(valueToBytes(expectedValue), valueToBytes(newValue)));
    }
@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 {
                            // this will force a bad version exception
                            inc.increment();
                        } catch (Exception e) {
                            throw new Error(e);
                        }
                    }

                    return super.valueToBytes(newValue);
                }
            };
            dal.forceSet(1L);

            assertTrue(dal.compareAndSet(1L, 5L).succeeded());
            assertFalse(dal.compareAndSet(1L, 5L).succeeded());

            doIncrement.set(true);
            assertFalse(dal.compareAndSet(5L, 10L).succeeded());
        } finally {
            client.close();
        }
    }