Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #31 from apache/awaitility
Browse files Browse the repository at this point in the history
use awaitility library when possible
  • Loading branch information
olamy committed Aug 6, 2022
2 parents 6fde270 + 296e1d5 commit 469cb71
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
30 changes: 20 additions & 10 deletions pom.xml
Expand Up @@ -271,7 +271,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${io.swagger.version}</version>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand All @@ -282,6 +286,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

<!-- JUNIT 5 -->
<dependency>
<groupId>org.junit.platform</groupId>
Expand Down Expand Up @@ -447,15 +457,15 @@
<outputEncoding>UTF-8</outputEncoding>
<skipDeploy>true</skipDeploy>
<stagingDirectory>${site.staging.base}/target/staging${scmPublishPath}</stagingDirectory>
<asciidoc>
<!-- optional site-wide AsciiDoc attributes -->
<attributes>
<icons>font</icons>
<source-highlighter>coderay</source-highlighter>
<coderay-css>style</coderay-css>
<toclevels>2</toclevels>
</attributes>
</asciidoc>
<!-- <asciidoc>-->
<!-- &lt;!&ndash; optional site-wide AsciiDoc attributes &ndash;&gt;-->
<!-- <attributes>-->
<!-- <icons>font</icons>-->
<!-- <source-highlighter>coderay</source-highlighter>-->
<!-- <coderay-css>style</coderay-css>-->
<!-- <toclevels>2</toclevels>-->
<!-- </attributes>-->
<!-- </asciidoc>-->
</configuration>
<dependencies>
<dependency>
Expand Down
Expand Up @@ -47,14 +47,6 @@
public abstract class AbstractCacheTestCase
extends TestCase
{
// static
// {
// Logger logger = Logger.getLogger( "org.codehaus.plexus.cache" );
// logger.setLevel( Level.ALL );
// ConsoleHandler handler = new ConsoleHandler( );
// handler.setLevel( Level.ALL );
// logger.addHandler( handler );
// }

private static final Logger log = LoggerFactory.getLogger( AbstractCacheTestCase.class );

Expand Down
Expand Up @@ -20,6 +20,7 @@
*/

import junit.framework.TestCase;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -37,6 +38,7 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.inject.Inject;
import java.util.concurrent.TimeUnit;

@RunWith ( SpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
Expand Down Expand Up @@ -81,10 +83,8 @@ public void testCreation()

scheduler.scheduleJob( jobDetail, trigger );

while ( !triggerFired )
{
Thread.sleep( 10 );
}
Awaitility.await().atLeast( 100, TimeUnit.MILLISECONDS ).until( () -> triggerFired );

logger.info( "ok triggerFired" );
}

Expand Down
Expand Up @@ -23,13 +23,15 @@
import org.apache.archiva.components.taskqueue.BuildProjectTask;
import org.apache.archiva.components.taskqueue.TaskQueue;
import org.apache.archiva.components.taskqueue.TaskQueueException;
import org.awaitility.Awaitility;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.concurrent.TimeUnit;

/**
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
Expand Down Expand Up @@ -90,16 +92,7 @@ private static void waitForExpectedTaskEnd( BuildProjectTask task )
{
// thread scheduling may take some time, so we want to wait until the task
// is actually running before starting to count the timeout.
for ( int i = 0; i < 500; i++ )
{
if ( task.wasStarted( ) )
{
break;
}
Thread.sleep( 10 );
}

assertTrue( "Task not started in 5 seconds - heavy load?", task.isStarted( ) );
Awaitility.await().atMost( 5, TimeUnit.SECONDS ).until( () -> task.isStarted() );

Thread.sleep( task.getMaxExecutionTime( ) );
}
Expand Down

0 comments on commit 469cb71

Please sign in to comment.