mengnankkkk commented on code in PR #2852:
URL: https://github.com/apache/fory/pull/2852#discussion_r2476980166


##########
java/fory-core/src/test/java/org/apache/fory/ThreadSafeForyTest.java:
##########
@@ -373,4 +373,137 @@ public void testSerializerRegister() {
           return null;
         });
   }
+
+  @Test
+  public void testRegisterClassAfterInitialization() throws 
InterruptedException {
+    ExecutorService executor = Executors.newSingleThreadExecutor();
+    AtomicReference<Throwable> ex = new AtomicReference<>();
+
+    try {
+      ThreadSafeFory fory = 
Fory.builder().requireClassRegistration(true).buildThreadLocalFory();
+
+      fory.register(BeanB.class);
+
+      BeanB bean = BeanB.createBeanB(2);
+      byte[] bytes = fory.serialize(bean);
+
+      executor.execute(
+          () -> {
+            try {
+              Object deserialized = fory.deserialize(bytes);
+              Assert.assertEquals(deserialized, bean);
+            } catch (Throwable t) {
+              ex.set(t);
+            }
+          });
+
+      executor.shutdown();
+      assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
+
+      if (ex.get() != null) {
+        throw new AssertionError("error", ex.get());
+      }
+    } finally {
+      if (!executor.isTerminated()) {
+        executor.shutdownNow();
+      }
+    }
+  }
+
+  @Test
+  public void testConcurrentRegisterAndDeserialize() throws 
InterruptedException {
+    ExecutorService executor = Executors.newFixedThreadPool(4);
+    ConcurrentHashMap<String, Throwable> errors = new ConcurrentHashMap<>();
+
+    try {
+      ThreadSafeFory fory = 
Fory.builder().requireClassRegistration(true).buildThreadLocalFory();
+
+      fory.register(BeanA.class);
+      fory.register(BeanB.class);
+      BeanA beanA = BeanA.createBeanA(2);
+      byte[] bytesA = fory.serialize(beanA);

Review Comment:
   Okay, I understand the problem and will make changes. Thank you for your 
code review.



-- 
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]

Reply via email to