Skip to content

Commit

Permalink
CURATOR-606: ModeledFrameworkImpl.update(T model, int version): Use v…
Browse files Browse the repository at this point in the history
…ersion in all cases. (#393)
  • Loading branch information
pavlov112 authored Oct 4, 2021
1 parent ddadeea commit ed3cc84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.curator.x.async.api.AsyncCuratorFrameworkDsl;
import org.apache.curator.x.async.api.AsyncPathAndBytesable;
import org.apache.curator.x.async.api.AsyncPathable;
import org.apache.curator.x.async.api.AsyncSetDataBuilder;
import org.apache.curator.x.async.api.AsyncTransactionSetDataBuilder;
import org.apache.curator.x.async.api.CreateOption;
import org.apache.curator.x.async.api.WatchableAsyncCuratorFramework;
Expand Down Expand Up @@ -205,7 +206,8 @@ public AsyncStage<Stat> update(T item, int version)
try
{
byte[] bytes = modelSpec.serializer().serialize(item);
AsyncPathAndBytesable<AsyncStage<Stat>> next = isCompressed() ? dslClient.setData().compressedWithVersion(version) : dslClient.setData();
AsyncSetDataBuilder dataBuilder = dslClient.setData();
AsyncPathAndBytesable<AsyncStage<Stat>> next = isCompressed() ? dataBuilder.compressedWithVersion(version) : dataBuilder.withVersion(version);
return next.forPath(resolveForSet(item), bytes);
}
catch ( Exception e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,18 @@ public void testVersioned()
complete(versioned.read().whenComplete((v, e) -> {
assertNull(e);
assertTrue(v.version() > 0);
}).thenCompose(versioned::set), (s, e) -> assertNull(e)); // version is correct should succeed
}).thenCompose(versioned::set), (s, e) -> assertNull(e)); // read version is correct; set moves version to 2

Versioned<TestModel> badVersion = Versioned.from(model, 100000);
complete(versioned.set(badVersion), (v, e) -> assertTrue(e instanceof KeeperException.BadVersionException));

complete(versioned.update(badVersion), (v, e) -> assertTrue(e instanceof KeeperException.BadVersionException));

final Versioned<TestModel> goodVersion = Versioned.from(model, 2);
complete(versioned.update(goodVersion).whenComplete((v, e) -> {
assertNull(e);
assertEquals(3, v.getVersion());
}));

final Stat stat = new Stat();
complete(client.read(stat));
// wrong version, needs to fail
Expand Down

0 comments on commit ed3cc84

Please sign in to comment.