Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Aug 10, 2024
1 parent 8d61e50 commit c05b2fb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,6 +17,14 @@
import static org.junit.jupiter.api.Assertions.*;


/**
* {@link CompletableFutureApiCompatibilityTest} and {@link CffuApiCompatibilityTest}
* are used to check the Cffu <strong>API compatibility</strong> to CompletableFuture.
* <p>
* {@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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,6 +15,14 @@
import static org.junit.jupiter.api.Assertions.*;


/**
* {@link CompletableFutureApiCompatibilityTest} and {@link CffuApiCompatibilityTest}
* are used to check the Cffu <strong>API compatibility</strong> to CompletableFuture.
* <p>
* {@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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.foldright.showcases
package io.foldright.study

import io.foldright.test_utils.*
import io.kotest.core.spec.style.FunSpec
Expand All @@ -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
Expand Down
47 changes: 25 additions & 22 deletions scripts/gen_CffuApiCompatibilityTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit c05b2fb

Please sign in to comment.