polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [04/50] [abbrv] zest-qi4j git commit: CircuitBreaker: use Awaitility in test instead of Thread.sleep
Date Fri, 24 Apr 2015 06:36:17 GMT
CircuitBreaker: use Awaitility in test instead of Thread.sleep


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/5968ab9d
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/5968ab9d
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/5968ab9d

Branch: refs/heads/master
Commit: 5968ab9d9ee44ed02cfb2368975a1c7d7bf4c820
Parents: 1acd403
Author: Paul Merlin <paul@nosphere.org>
Authored: Thu Feb 20 22:17:42 2014 +0100
Committer: Paul Merlin <paul@nosphere.org>
Committed: Thu Feb 20 22:17:42 2014 +0100

----------------------------------------------------------------------
 libraries/circuitbreaker/build.gradle           | 14 ++++++------
 .../circuitbreaker/CircuitBreakerTest.java      | 24 +++++++++++++++-----
 2 files changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/5968ab9d/libraries/circuitbreaker/build.gradle
----------------------------------------------------------------------
diff --git a/libraries/circuitbreaker/build.gradle b/libraries/circuitbreaker/build.gradle
index 597eaf6..8070a77 100644
--- a/libraries/circuitbreaker/build.gradle
+++ b/libraries/circuitbreaker/build.gradle
@@ -3,17 +3,17 @@ description = "Qi4j Circuit Breaker Library provides a framework for connecting
 jar { manifest {name = "Qi4j Library - Circuit Breaker"}}
 
 dependencies {
-  compile(project(":org.qi4j.core:org.qi4j.core.api"))
-  compile( project(':org.qi4j.libraries:org.qi4j.library.jmx' ) )
+    compile project( ':org.qi4j.core:org.qi4j.core.api' )
+    compile project( ':org.qi4j.libraries:org.qi4j.library.jmx' )
 
-  testCompile(project(":org.qi4j.core:org.qi4j.core.testsupport"))
+    testCompile project( ':org.qi4j.core:org.qi4j.core.testsupport' )
+    testCompile libraries.awaitility
 
-  testRuntime(project(":org.qi4j.core:org.qi4j.core.runtime"))
-  testRuntime(libraries.logback)
+    testRuntime project( ':org.qi4j.core:org.qi4j.core.runtime' )
+    testRuntime libraries.logback
 }
 
-task(runSample, dependsOn: 'testClasses', type: JavaExec) {
+task( runSample, dependsOn: 'testClasses', type: JavaExec ) {
     main = 'org.qi4j.library.circuitbreaker.jmx.CircuitBreakerManagementTest'
     classpath = sourceSets.test.runtimeClasspath
 }
-

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/5968ab9d/libraries/circuitbreaker/src/test/java/org/qi4j/library/circuitbreaker/CircuitBreakerTest.java
----------------------------------------------------------------------
diff --git a/libraries/circuitbreaker/src/test/java/org/qi4j/library/circuitbreaker/CircuitBreakerTest.java
b/libraries/circuitbreaker/src/test/java/org/qi4j/library/circuitbreaker/CircuitBreakerTest.java
index 6977451..783237f 100644
--- a/libraries/circuitbreaker/src/test/java/org/qi4j/library/circuitbreaker/CircuitBreakerTest.java
+++ b/libraries/circuitbreaker/src/test/java/org/qi4j/library/circuitbreaker/CircuitBreakerTest.java
@@ -20,10 +20,14 @@ import java.beans.PropertyChangeListener;
 import java.beans.PropertyVetoException;
 import java.beans.VetoableChangeListener;
 import java.io.IOException;
+import java.util.concurrent.Callable;
 import org.hamcrest.CoreMatchers;
 import org.junit.Before;
 import org.junit.Test;
 
+import static com.jayway.awaitility.Awaitility.await;
+import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
+import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
 /**
@@ -126,12 +130,8 @@ public class CircuitBreakerTest
 
         // END SNIPPET: direct
         assertThat( cb.status(), CoreMatchers.equalTo( CircuitBreaker.Status.off ) );
-        try {
-            System.out.println( "Wait..." );
-            Thread.sleep( 300 );
-        } catch ( InterruptedException e ) {
-            // Ignore
-        }
+        System.out.println( "Wait..." );
+        await().atMost( FIVE_HUNDRED_MILLISECONDS ).until( circuitBreakerStatus(), is( CircuitBreaker.Status.on
) );
 
         // START SNIPPET: direct
         // CircuitBreaker is back on
@@ -139,6 +139,18 @@ public class CircuitBreakerTest
         // END SNIPPET: direct
         assertThat( cb.status(), CoreMatchers.equalTo( CircuitBreaker.Status.on ) );
     }
+    
+    private Callable<CircuitBreaker.Status> circuitBreakerStatus()
+    {
+        return new Callable<CircuitBreaker.Status>()
+        {
+            @Override
+            public CircuitBreaker.Status call() throws Exception
+            {
+                return cb.status();
+            }
+        };
+    }
 
     @Test
     public void GivenCBWhenExceptionsAndSuccessesThenStatusIsOn()


Mime
View raw message