kezhuw commented on code in PR #396:
URL: https://github.com/apache/curator/pull/396#discussion_r1161280354
##########
curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestCachedModeledFramework.java:
##########
@@ -181,6 +184,72 @@ public void testAccessCacheDirectly()
}
}
+ // Verify the CachedModeledFramework does not attempt to deserialize empty
ZNodes on deletion.
+ // See: CURATOR-609
+ @Test
+ public void testEmptyNodeDeserialization()
+ {
+ // The sub-path is the ZNode that will be removed that does not
contain a model. This model with no data
+ // should not result in attempt to deserialize.
+ final String subPath = modelSpec.path().toString() + "/sub";
+
+ final String firstModelPath = subPath + "/first";
+ final String secondModelPath = subPath + "/second";
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ final AtomicBoolean caughtException = new AtomicBoolean(false);
+
+ // Create a custom listener to signal the end of the test and ensure
no exceptions are thrown.
+ final ModeledCacheListener<TestModel> listener = new
ModeledCacheListener<TestModel>() {
+ @Override
+ public void accept(Type t, ZPath p, Stat s, TestModel m)
+ {
+ if (t == ModeledCacheListener.Type.NODE_ADDED &&
p.toString().equals(secondModelPath)) {
+ latch.countDown();
+ }
+ }
+
+ public void handleException(Exception e) {
+ System.err.printf("Caught unexpected exception %s%n", e);
+ caughtException.set(true);
+ }
+ };
+
+ // Create a cache client which watches the parent path.
+ try (CachedModeledFramework<TestModel> cacheClient =
ModeledFramework.wrap(async, modelSpec).cached())
+ {
+ cacheClient.listenable().addListener(listener);
+
+ final JacksonModelSerializer<TestModel> serializer =
JacksonModelSerializer.build(TestModel.class);
+
+ ModelSpec<TestModel> firstModelSpec =
ModelSpec.builder(ZPath.parse(firstModelPath), serializer).build();
+ ModeledFramework<TestModel> firstModelClient =
ModeledFramework.wrap(async, firstModelSpec);
+
+ ModelSpec<TestModel> secondModelSpec =
ModelSpec.builder(ZPath.parse(secondModelPath), serializer).build();
+ ModeledFramework<TestModel> secondModelClient =
ModeledFramework.wrap(async, secondModelSpec);
+
+ final TestModel model = new TestModel("a", "b", "c", 20,
BigInteger.ONE);
+
+ cacheClient.start();
+
+ // Creating the first model creates the parent path structure.
+ complete(firstModelClient.set(model));
+
+ // Delete the first model, then delete the sub-path. As the
sub-path is an empty ZNode, this should not
+ // throw an exception.
+ complete(firstModelClient.delete());
+ complete(firstModelClient.unwrap().delete().forPath(subPath));
+
+ // Finally, create a second model purely to signal the end of the
test.
+ complete(secondModelClient.set(model));
Review Comment:
How about name these `signalModel...` ? So we known their usages at first
place.
--
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]