You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/04/01 14:19:54 UTC

[isis] branch 2033-IoC_spring updated: ISIS-2033: testing very basic spring async action idioms

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch 2033-IoC_spring
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/2033-IoC_spring by this push:
     new 7456141  ISIS-2033: testing very basic spring async action idioms
7456141 is described below

commit 7456141e4d87db877e45567d76853ab909109c3e
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Apr 1 16:19:44 2019 +0200

    ISIS-2033: testing very basic spring async action idioms
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-2033
---
 .../incubator/command/CommandExecutionService.java |  5 +++
 .../springapp/tests/async/AsyncDemoService.java    | 31 ++++++++++++++
 .../async/AsyncExecutionTest_NativeSpring.java     | 50 ++++++++++++++++++++++
 .../CustomerTest.java                              |  2 +-
 .../ProductTest_NativeJdo.java                     |  2 +-
 5 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/example/application/springapp/src/main/java/isis/incubator/command/CommandExecutionService.java b/example/application/springapp/src/main/java/isis/incubator/command/CommandExecutionService.java
new file mode 100644
index 0000000..a4ce019
--- /dev/null
+++ b/example/application/springapp/src/main/java/isis/incubator/command/CommandExecutionService.java
@@ -0,0 +1,5 @@
+package isis.incubator.command;
+
+public interface CommandExecutionService {
+
+}
diff --git a/example/application/springapp/src/test/java/springapp/tests/async/AsyncDemoService.java b/example/application/springapp/src/test/java/springapp/tests/async/AsyncDemoService.java
new file mode 100644
index 0000000..ad3774d
--- /dev/null
+++ b/example/application/springapp/src/test/java/springapp/tests/async/AsyncDemoService.java
@@ -0,0 +1,31 @@
+package springapp.tests.async;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class AsyncDemoService {
+
+	@Async
+	public CompletableFuture<String> asyncMethodWithReturnType() {
+		
+	    System.out.println("Execute method asynchronously - " + Thread.currentThread().getName());
+	    
+	    try {
+	        Thread.sleep(250);
+	        return new AsyncResult<String>("hello world !!!!")
+	        		.completable();
+	    } catch (InterruptedException e) {
+	        //
+	    }
+	 
+	    return null;
+	}
+	
+	
+}
diff --git a/example/application/springapp/src/test/java/springapp/tests/async/AsyncExecutionTest_NativeSpring.java b/example/application/springapp/src/test/java/springapp/tests/async/AsyncExecutionTest_NativeSpring.java
new file mode 100644
index 0000000..b5cccce
--- /dev/null
+++ b/example/application/springapp/src/test/java/springapp/tests/async/AsyncExecutionTest_NativeSpring.java
@@ -0,0 +1,50 @@
+package springapp.tests.async;
+
+import static java.time.Duration.ofMillis;
+import static org.junit.jupiter.api.Assertions.assertTimeout;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import javax.inject.Inject;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import lombok.val;
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(classes = {AsyncDemoService.class})
+@EnableAsync
+class AsyncExecutionTest_NativeSpring {
+	
+	@Inject AsyncDemoService asyncDemoService;
+
+	@Test
+	void shouldRunAsync() {
+		
+		// we expect this to take no longer than ~250ms. (Each demo task sleeps 250ms.)
+		assertTimeout(ofMillis(300), () -> {
+
+			List<CompletableFuture<String>> futures = new ArrayList<>();
+			
+			for(int i = 0; i < 25; i++) {
+				val completable = asyncDemoService.asyncMethodWithReturnType();
+				
+				futures.add(completable);
+			}
+			
+			val combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
+			
+			combinedFuture.join();
+			
+	    });
+		
+	}
+	
+
+}
diff --git a/example/application/springapp/src/test/java/springapp/tests/bootstrapping/CustomerTest.java b/example/application/springapp/src/test/java/springapp/tests/persistence/CustomerTest.java
similarity index 98%
rename from example/application/springapp/src/test/java/springapp/tests/bootstrapping/CustomerTest.java
rename to example/application/springapp/src/test/java/springapp/tests/persistence/CustomerTest.java
index 7d60329..87b6fc7 100644
--- a/example/application/springapp/src/test/java/springapp/tests/bootstrapping/CustomerTest.java
+++ b/example/application/springapp/src/test/java/springapp/tests/persistence/CustomerTest.java
@@ -1,4 +1,4 @@
-package springapp.tests.bootstrapping;
+package springapp.tests.persistence;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/example/application/springapp/src/test/java/springapp/tests/bootstrapping/ProductTest_NativeJdo.java b/example/application/springapp/src/test/java/springapp/tests/persistence/ProductTest_NativeJdo.java
similarity index 99%
rename from example/application/springapp/src/test/java/springapp/tests/bootstrapping/ProductTest_NativeJdo.java
rename to example/application/springapp/src/test/java/springapp/tests/persistence/ProductTest_NativeJdo.java
index 50cff56..97d005a 100644
--- a/example/application/springapp/src/test/java/springapp/tests/bootstrapping/ProductTest_NativeJdo.java
+++ b/example/application/springapp/src/test/java/springapp/tests/persistence/ProductTest_NativeJdo.java
@@ -1,4 +1,4 @@
-package springapp.tests.bootstrapping;
+package springapp.tests.persistence;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;