Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ else if ( event.getResultCode() == KeeperException.Code.OK.intValue() )

if(nodeExists)
{
client.setData().inBackground(setDataCallback).forPath(getActualPath(), data);
client.setData().inBackground(setDataCallback).forPath(getActualPath(), getData());
}
else
{
Expand Down Expand Up @@ -338,10 +338,14 @@ public void setData(byte[] data) throws Exception
this.data.set(Arrays.copyOf(data, data.length));
if ( isActive() )
{
client.setData().inBackground().forPath(getActualPath(), this.data.get());
client.setData().inBackground().forPath(getActualPath(), getData());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this change isn't required as the data is being accessed directly from within this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it so it was the same both places actually getting the data, but can revert this change. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough. Leave it as is, it's probably nicer to have the data accessed in the same way.

}
}

private byte[] getData() {
return this.data.get();
}

private void deleteNode() throws Exception
{
String localNodePath = nodePath.getAndSet(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.framework.state.ConnectionState;
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.RetryOneTime;
Expand Down Expand Up @@ -536,6 +538,45 @@ public void process(WatchedEvent event)
node.close();
}
}

@Test
public void testSetUpdatedDataWhenReconnected() throws Exception
{
CuratorFramework curator = newCurator();

byte[] initialData = "Hello World".getBytes();
byte[] updatedData = "Updated".getBytes();

PersistentEphemeralNode node = new PersistentEphemeralNode(curator, PersistentEphemeralNode.Mode.EPHEMERAL, PATH, initialData);
node.start();
try
{
node.waitForInitialCreate(timing.forWaiting().seconds(), TimeUnit.SECONDS);
assertTrue(Arrays.equals(curator.getData().forPath(node.getActualPath()), initialData));

node.setData(updatedData);
assertTrue(Arrays.equals(curator.getData().forPath(node.getActualPath()), updatedData));

server.restart();

final CountDownLatch dataUpdateLatch = new CountDownLatch(1);
curator.getData().inBackground(new BackgroundCallback() {

@Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
dataUpdateLatch.countDown();
}
}).forPath(node.getActualPath());

assertTrue(timing.awaitLatch(dataUpdateLatch));

assertTrue(Arrays.equals(curator.getData().forPath(node.getActualPath()), updatedData));
}
finally
{
node.close();
}
}

/**
* See CURATOR-190
Expand Down