From 8add13c7967735f2fbe45ad879f4e071db0faa55 Mon Sep 17 00:00:00 2001 From: Shuchang Li Date: Wed, 20 Nov 2024 11:35:20 +0800 Subject: [PATCH] fix(java): ClassLoaderFuryPooled#setFactoryCallback cannot effect old Fury (#1946) ## What does this PR do? ClassLoaderFuryPooled#setFactoryCallback cannot effect old fury. so if `org.apache.fury.pool.FuryPooledObjectFactory#classLoaderFuryPooledCache` expired, new classLoaderFuryPooled can not effected by custom factoryCallback ## Related issues ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark Co-authored-by: shuchang.li --- .../apache/fury/pool/ClassLoaderFuryPooled.java | 3 ++- .../fury/pool/ClassLoaderFuryPooledTest.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java b/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java index c1ad2adaf9..ececce993f 100644 --- a/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java +++ b/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java @@ -123,6 +123,7 @@ private void addFury() { } void setFactoryCallback(Consumer factoryCallback) { - this.factoryCallback = factoryCallback; + this.factoryCallback = this.factoryCallback.andThen(factoryCallback); + allFury.keySet().forEach(factoryCallback); } } diff --git a/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java b/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java index 9e148e78e2..c039342fc3 100644 --- a/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/pool/ClassLoaderFuryPooledTest.java @@ -83,6 +83,23 @@ public void testGetFuryWithIncreaseCapacity() { } } + @Test + public void testFuryAfterSetFactoryCallback() { + int minPoolSize = 4; + ClassLoaderFuryPooled pooled = getPooled(minPoolSize, 6); + + try { + pooled.setFactoryCallback( + fury -> { + throw new RuntimeException(); + }); + pooled.getFury(); + Assert.fail(); + } catch (RuntimeException e) { + // Success + } + } + @Test public void testGetFuryAwait() throws InterruptedException { int minPoolSize = 3;