From c05b2fbcf5c5f944f4a29ef9b2a9e5a5309d99d3 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 10 Aug 2024 22:53:20 +0800 Subject: [PATCH] WIP --- .../CffuApiCompatibilityTest.java | 17 ++++--- ...CompletableFutureApiCompatibilityTest.java | 17 ++++--- .../CompletableFutureUsageStudyCaseTest.kt} | 7 ++- scripts/gen_CffuApiCompatibilityTest.sh | 47 ++++++++++--------- 4 files changed, 46 insertions(+), 42 deletions(-) rename cffu-core/src/test/java/io/foldright/{showcases/CompletableFutureUsageShowcaseTest.kt => study/CompletableFutureUsageStudyCaseTest.kt} (99%) diff --git a/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java b/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java index 97c37646..ab92ca15 100644 --- a/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java +++ b/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java @@ -1,14 +1,5 @@ package io.foldright.compatibility_test; -//////////////////////////////////////////////////////////////////////////////// -// CompletableFutureApiCompatibilityTest and CffuApiCompatibilityTest are used to test -// the Cffu API compatibility to CompletableFuture. -// -// CffuApiCompatibilityTest.java file is auto generated -// from CompletableFutureApiCompatibilityTest.java -// by script gen_CffuApiCompatibilityTest.sh -//////////////////////////////////////////////////////////////////////////////// - import io.foldright.test_utils.TestUtils; import io.foldright.cffu.Cffu; import io.foldright.cffu.CffuFactory; @@ -26,6 +17,14 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * {@link CompletableFutureApiCompatibilityTest} and {@link CffuApiCompatibilityTest} + * are used to check the Cffu API compatibility to CompletableFuture. + *

+ * {@code CffuApiCompatibilityTest.java} file is auto generated + * from {@code CompletableFutureApiCompatibilityTest.java} file + * by script {@code scripts/gen_CffuApiCompatibilityTest.sh}. + */ @SuppressWarnings("RedundantThrows") class CffuApiCompatibilityTest { private static final String hello = "Cffu API Compatibility Test - Hello"; diff --git a/cffu-core/src/test/java/io/foldright/compatibility_test/CompletableFutureApiCompatibilityTest.java b/cffu-core/src/test/java/io/foldright/compatibility_test/CompletableFutureApiCompatibilityTest.java index 8d505927..44a470c6 100644 --- a/cffu-core/src/test/java/io/foldright/compatibility_test/CompletableFutureApiCompatibilityTest.java +++ b/cffu-core/src/test/java/io/foldright/compatibility_test/CompletableFutureApiCompatibilityTest.java @@ -1,14 +1,5 @@ package io.foldright.compatibility_test; -//////////////////////////////////////////////////////////////////////////////// -// CompletableFutureApiCompatibilityTest and CffuApiCompatibilityTest are used to test -// the Cffu API compatibility to CompletableFuture. -// -// CffuApiCompatibilityTest.java file is auto generated -// from CompletableFutureApiCompatibilityTest.java -// by script gen_CffuApiCompatibilityTest.sh -//////////////////////////////////////////////////////////////////////////////// - import io.foldright.test_utils.TestUtils; import io.foldright.test_utils.TestingExecutorUtils; import org.junit.jupiter.api.AfterAll; @@ -24,6 +15,14 @@ import static org.junit.jupiter.api.Assertions.*; +/** + * {@link CompletableFutureApiCompatibilityTest} and {@link CffuApiCompatibilityTest} + * are used to check the Cffu API compatibility to CompletableFuture. + *

+ * {@code CffuApiCompatibilityTest.java} file is auto generated + * from {@code CompletableFutureApiCompatibilityTest.java} file + * by script {@code scripts/gen_CffuApiCompatibilityTest.sh}. + */ @SuppressWarnings("RedundantThrows") class CompletableFutureApiCompatibilityTest { private static final String hello = "CompletableFuture API Compatibility Test - Hello"; diff --git a/cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt b/cffu-core/src/test/java/io/foldright/study/CompletableFutureUsageStudyCaseTest.kt similarity index 99% rename from cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt rename to cffu-core/src/test/java/io/foldright/study/CompletableFutureUsageStudyCaseTest.kt index 04827f05..5f8510a3 100644 --- a/cffu-core/src/test/java/io/foldright/showcases/CompletableFutureUsageShowcaseTest.kt +++ b/cffu-core/src/test/java/io/foldright/study/CompletableFutureUsageStudyCaseTest.kt @@ -1,4 +1,4 @@ -package io.foldright.showcases +package io.foldright.study import io.foldright.test_utils.* import io.kotest.core.spec.style.FunSpec @@ -17,7 +17,10 @@ import java.lang.Thread.currentThread import java.util.concurrent.* import java.util.concurrent.atomic.AtomicBoolean -class CompletableFutureUsageShowcaseTest : FunSpec({ +/** + * Study CompletableFuture usage. + */ +class CompletableFutureUsageStudyCaseTest : FunSpec({ test("execution thread/executor behavior: then*(non-Async) operations chained after COMPLETED CF(completed by immediate value), trigger by then* invocation and run in place SEQUENTIALLY").config( invocations = 100 diff --git a/scripts/gen_CffuApiCompatibilityTest.sh b/scripts/gen_CffuApiCompatibilityTest.sh index 166e4c05..c7b7ee3b 100755 --- a/scripts/gen_CffuApiCompatibilityTest.sh +++ b/scripts/gen_CffuApiCompatibilityTest.sh @@ -9,33 +9,36 @@ readonly target_file="$TEST_FILE_DIR/CffuApiCompatibilityTest.java" trap 'chmod -w "$target_file"' EXIT chmod +w "$target_file" -sed -r '/^import /,${ - # skip if GEN_MARK_KEEP - /\bGEN_MARK_KEEP\b/b +sed -r ' + /^import /,/^import static/ { + # adjust imports + s/import io\.foldright\.test_utils\.TestingExecutorUtils;/import io.foldright.cffu.Cffu;\nimport io.foldright.cffu.CffuFactory;\nimport io.foldright.test_utils.TestingExecutorUtils;/ + /import java.util.concurrent.CompletableFuture;/d + } - # adjust imports - s/import io\.foldright\.test_utils\.TestingExecutorUtils;/import io.foldright.cffu.Cffu;\nimport io.foldright.cffu.CffuFactory;\nimport io.foldright.test_utils.TestingExecutorUtils;/ - /import java.util.concurrent.CompletableFuture;/d + /^class /,$ { + # skip if GEN_MARK_KEEP + /\bGEN_MARK_KEEP\b/b - # replace JUnit test class name - s/\bclass\s+CompletableFutureApiCompatibilityTest\b/class CffuApiCompatibilityTest/ + # replace JUnit test class name + s/\bclass\s+CompletableFutureApiCompatibilityTest\b/class CffuApiCompatibilityTest/ - /@EnabledForJreRange\(.*\)$/d + /@EnabledForJreRange\(.*\)$/d - # replace CompatibilityTestHelper methods - s/\b(TestUtils)\.(\w*)CompletableFuture(\w*)/\1\.\2Cffu\3/g + # replace CompatibilityTestHelper methods + s/\b(TestUtils)\.(\w*)CompletableFuture(\w*)/\1\.\2Cffu\3/g - # replace CompletableFuture constructor to cffuFactory.newIncompleteCffu() methods - s/\bnew\s+CompletableFuture<>/cffuFactory.newIncompleteCffu/g + # replace CompletableFuture constructor to cffuFactory.newIncompleteCffu() methods + s/\bnew\s+CompletableFuture<>/cffuFactory.newIncompleteCffu/g - # replace static methods of CompletableFuture - s/\bCompletableFuture\./cffuFactory\./g + # replace static methods of CompletableFuture + s/\bCompletableFuture\./cffuFactory\./g - # replace CompletableFuture class name - s/\bCompletableFuture\b/Cffu/g + # replace CompletableFuture class name + s/\bCompletableFuture\b/Cffu/g - # generate new contents - s/^(\s*).*\bGEN_MARK_FACTORY_FIELD\b.*$/\1private static CffuFactory cffuFactory;/ - s/^(\s*).*\bGEN_MARK_FACTORY_INIT\b.*$/\1cffuFactory = CffuFactory.builder\(executorService\).build\(\);/ - -}' "$source_file" >"$target_file" + # generate new contents + s/^(\s*).*\bGEN_MARK_FACTORY_FIELD\b.*$/\1private static CffuFactory cffuFactory;/ + s/^(\s*).*\bGEN_MARK_FACTORY_INIT\b.*$/\1cffuFactory = CffuFactory.builder\(executorService\).build\(\);/ + } + ' "$source_file" >"$target_file"