chaokunyang commented on code in PR #2852:
URL: https://github.com/apache/fory/pull/2852#discussion_r2483106542
##########
java/fory-core/src/test/java/org/apache/fory/ThreadSafeForyTest.java:
##########
@@ -373,4 +374,63 @@ public void testSerializerRegister() {
return null;
});
}
+
+ @Test
+ public void testGetDepth() {
+ Fory fory = Fory.builder().requireClassRegistration(false).build();
+ Assert.assertEquals(fory.getDepth(), -1);
+ BeanA beanA = BeanA.createBeanA(2);
+ byte[] bytes = fory.serialize(beanA);
+ Assert.assertEquals(fory.getDepth(), -1);
+ fory.deserialize(bytes);
+ Assert.assertEquals(fory.getDepth(), -1);
+ }
+
+ @Test
+ public void testRegisterAfterSerializeThrowsException() throws Exception {
+
+ ThreadSafeFory fory =
Fory.builder().requireClassRegistration(true).buildThreadLocalFory();
+
+ java.util.concurrent.CountDownLatch writeStarted = new
java.util.concurrent.CountDownLatch(1);
+ java.util.concurrent.CountDownLatch allowFinish = new
java.util.concurrent.CountDownLatch(1);
+
+ fory.registerSerializer(
+ Foo.class,
+ (Fory f) ->
+ new Serializer<Foo>(f, Foo.class) {
+ @Override
+ public void write(MemoryBuffer buffer, Foo value) {
+ writeStarted.countDown();
+ try {
+ allowFinish.await(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ buffer.writeInt32(value.f1);
+ }
+
+ @Override
+ public Foo read(MemoryBuffer buffer) {
+ Foo foo = new Foo();
+ foo.f1 = buffer.readInt32();
+ return foo;
+ }
+ });
+
+ fory.register(BeanA.class);
+
+ Thread t =
+ new Thread(
+ () -> {
+ fory.serialize(new Foo());
+ });
+ t.start();
+
+ Assert.assertTrue(writeStarted.await(5, TimeUnit.SECONDS));
+
+ Assert.assertThrows(ForyException.class, () -> fory.register(BeanA.class));
+
+ allowFinish.countDown();
Review Comment:
why we need such code? What does it test exactly?
Please keep things simple. You can just use Fory and
TheadSafeFory(ThreadLocalFory/ThradPoolFory) to serialize an object, then
invoke register, adn assert it raise exception. I think this will be enough
##########
java/fory-core/src/test/java/org/apache/fory/ThreadSafeForyTest.java:
##########
@@ -373,4 +374,63 @@ public void testSerializerRegister() {
return null;
});
}
+
+ @Test
+ public void testGetDepth() {
+ Fory fory = Fory.builder().requireClassRegistration(false).build();
+ Assert.assertEquals(fory.getDepth(), -1);
+ BeanA beanA = BeanA.createBeanA(2);
+ byte[] bytes = fory.serialize(beanA);
+ Assert.assertEquals(fory.getDepth(), -1);
+ fory.deserialize(bytes);
+ Assert.assertEquals(fory.getDepth(), -1);
+ }
+
+ @Test
+ public void testRegisterAfterSerializeThrowsException() throws Exception {
+
+ ThreadSafeFory fory =
Fory.builder().requireClassRegistration(true).buildThreadLocalFory();
+
+ java.util.concurrent.CountDownLatch writeStarted = new
java.util.concurrent.CountDownLatch(1);
+ java.util.concurrent.CountDownLatch allowFinish = new
java.util.concurrent.CountDownLatch(1);
+
+ fory.registerSerializer(
+ Foo.class,
+ (Fory f) ->
+ new Serializer<Foo>(f, Foo.class) {
+ @Override
+ public void write(MemoryBuffer buffer, Foo value) {
+ writeStarted.countDown();
+ try {
+ allowFinish.await(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ buffer.writeInt32(value.f1);
+ }
+
+ @Override
+ public Foo read(MemoryBuffer buffer) {
+ Foo foo = new Foo();
+ foo.f1 = buffer.readInt32();
+ return foo;
+ }
+ });
+
+ fory.register(BeanA.class);
+
+ Thread t =
+ new Thread(
+ () -> {
+ fory.serialize(new Foo());
+ });
+ t.start();
+
+ Assert.assertTrue(writeStarted.await(5, TimeUnit.SECONDS));
+
+ Assert.assertThrows(ForyException.class, () -> fory.register(BeanA.class));
+
+ allowFinish.countDown();
Review Comment:
why we need such code? What does it test exactly?
Please keep things simple. You can just use Fory and
TheadSafeFory(ThreadLocalFory/ThradPoolFory) to serialize an object, then
invoke register, adn assert it raise exception. I think this will be enough
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]