@Test
public void testReplace() throws Exception {

	// Setup
	LongStateStorage stateHandleProvider = new LongStateStorage();
	ZooKeeperStateHandleStore<Long> store = new ZooKeeperStateHandleStore<>(
			ZOOKEEPER.getClient(), stateHandleProvider, Executors.directExecutor());
	// Config
	final String pathInZooKeeper = "/testReplace";
	final Long initialState = 30968470898L;
	final Long replaceState = 88383776661L;
	// Test
	store.addAndLock(pathInZooKeeper, initialState);
	store.replace(pathInZooKeeper, 0, replaceState);
	// Verify
	// State handles created
	assertEquals(2, stateHandleProvider.getStateHandles().size());
	assertEquals(initialState, stateHandleProvider.getStateHandles().get(0).retrieveState());
	assertEquals(replaceState, stateHandleProvider.getStateHandles().get(1).retrieveState());
	// Path created and is persistent
	Stat stat = ZOOKEEPER.getClient().checkExists().forPath(pathInZooKeeper);
	assertNotNull(stat);
	assertEquals(0, stat.getEphemeralOwner());
	// Data is equal
	@SuppressWarnings("unchecked")
	Long actual = ((RetrievableStateHandle<Long>) InstantiationUtil.deserializeObject(
			ZOOKEEPER.getClient().getData().forPath(pathInZooKeeper),
			ClassLoader.getSystemClassLoader())).retrieveState();
	assertEquals(replaceState, actual);
}