Skip to content
Permalink
Browse files
CURATOR-606: ModeledFrameworkImpl.update(T model, int version): Use v…
…ersion in all cases. (#393)
  • Loading branch information
pavlov112 committed Oct 4, 2021
1 parent ddadeea commit ed3cc848f51b309db69f4e453d0509a48e9212d6
Showing 2 changed files with 13 additions and 4 deletions.
@@ -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;
@@ -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 )
@@ -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

0 comments on commit ed3cc84

Please sign in to comment.