eolivelli commented on code in PR #510:
URL: https://github.com/apache/curator/pull/510#discussion_r1881896545
##########
curator-framework/src/test/java/org/apache/curator/framework/imps/TestCreate.java:
##########
@@ -540,6 +564,65 @@ public void testIdempotentCreateConnectionLoss() throws
Exception {
}
}
+ /**
+ * Tests all cases of create().orSetData()
+ */
+ @Test
+ public void testOrSetData() throws Exception {
+ CuratorFramework client = createClient(new DefaultACLProvider());
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 5,
TimeUnit.SECONDS, new LinkedBlockingQueue<>());
+ try {
+ client.start();
+
+ Stat stat = new Stat();
+
+ String path = "/idpcreate";
+ String pathWithParents1 = "/idpcreate/1/a/b/c/d";
+ String pathWithParents2 = "/idpcreate/2/a/b/c/d";
+ byte[] data1 = new byte[] {1, 2, 3};
+ byte[] data2 = new byte[] {4, 5, 6};
+
+ // first and second create should succeed with the same path and
different data
+ check(client, client.create().orSetData(), path, data1, 0,
KeeperException.Code.OK);
+ check(client, client.create().orSetData(), path, data2, 1,
KeeperException.Code.OK);
+ check(client, client.create(), path, data2, false);
+
+ // without creatingParentsIfNeeded, it should fail
+ check(client, client.create().orSetData(), pathWithParents1,
data1, 0, KeeperException.Code.NONODE);
+
+ // with creatingParentsIfNeeded, it should succeed and succeed a
second time as well
+ check(
+ client,
+ client.create().orSetData().creatingParentsIfNeeded(),
+ pathWithParents1,
+ data1,
+ 0,
+ KeeperException.Code.OK);
+ check(client, client.create().orSetData(), pathWithParents1,
data2, 1, KeeperException.Code.OK);
+
+ // Check that calling the same create().orSetData() in parallel is
ok
+ Callable<Exception> setData = () -> {
+ try {
+
client.create().orSetData().creatingParentsIfNeeded().forPath(pathWithParents2,
data2);
+ } catch (Exception e) {
+ return e;
+ }
+ return null;
+ };
+ Future<Exception> f1 = executor.submit(setData);
Review Comment:
with Mockito I mean that we can use a spy or override some method to ensure
that we are hitting the expected code path.
> I tested this after reverting the fix, it failed in the first runs without
resorting to "run x times" on my 2015 macbook pro
let me try
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]