Return-Path: X-Original-To: apmail-archiva-commits-archive@www.apache.org Delivered-To: apmail-archiva-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E825FD4CE for ; Wed, 29 Aug 2012 15:38:51 +0000 (UTC) Received: (qmail 8230 invoked by uid 500); 29 Aug 2012 15:38:51 -0000 Delivered-To: apmail-archiva-commits-archive@archiva.apache.org Received: (qmail 8189 invoked by uid 500); 29 Aug 2012 15:38:51 -0000 Mailing-List: contact commits-help@archiva.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@archiva.apache.org Delivered-To: mailing list commits@archiva.apache.org Received: (qmail 8180 invoked by uid 99); 29 Aug 2012 15:38:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2012 15:38:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2012 15:38:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 635A32388ABA for ; Wed, 29 Aug 2012 15:37:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1378611 [8/25] - in /archiva/site-content/redback/components: ./ expression-evaluator/ redback-components/ spring-apacheds/ spring-cache/ spring-jdo2/ spring-quartz/ spring-registry/ spring-taskqueue/ spring-utils/ xref-test/ xref-test/org... Date: Wed, 29 Aug 2012 15:37:11 -0000 To: commits@archiva.apache.org From: olamy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120829153721.635A32388ABA@eris.apache.org> Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BTaskExitEvaluator.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BTaskExitEvaluator.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BTaskExitEvaluator.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BTaskExitEvaluator.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,50 @@ + + + + +BTaskExitEvaluator xref + + + +
+
+1   package org.apache.archiva.redback.components.taskqueue;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import org.springframework.stereotype.Service;
+23  
+24  /**
+25   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+26   *
+27   */
+28  @Service("taskExitEvaluator#b")
+29  public class BTaskExitEvaluator
+30      implements TaskExitEvaluator
+31  {
+32      public boolean evaluate( Task task )
+33          throws TaskQueueException
+34      {
+35          return ( (BuildProjectTask) task ).isPassBExitEvaluator();
+36      }
+37  }
+
+
+ Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTask.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTask.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTask.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTask.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,170 @@ + + + + +BuildProjectTask xref + + + +
+
+1   package org.apache.archiva.redback.components.taskqueue;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import org.apache.archiva.redback.components.taskqueue.Task;
+23  
+24  /**
+25   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+26   *
+27   */
+28  public class BuildProjectTask
+29      implements Task
+30  {
+31      private boolean passAEntryEvaluator;
+32  
+33      private boolean passBEntryEvaluator;
+34  
+35      private boolean passAExitEvaluator;
+36  
+37      private boolean passBExitEvaluator;
+38  
+39      private long timestamp;
+40  
+41      private long maxExecutionTime;
+42  
+43      private long executionTime;
+44  
+45      private boolean cancelled;
+46  
+47      private boolean done;
+48  
+49      private boolean started;
+50  
+51      private boolean ignoreInterrupts;
+52  
+53      public BuildProjectTask( boolean passAEntryEvaluator, boolean passBEntryEvaluator, boolean passAExitEvaluator,
+54                               boolean passBExitEvaluator )
+55      {
+56          this.passAEntryEvaluator = passAEntryEvaluator;
+57  
+58          this.passBEntryEvaluator = passBEntryEvaluator;
+59  
+60          this.passAExitEvaluator = passAExitEvaluator;
+61  
+62          this.passBExitEvaluator = passBExitEvaluator;
+63      }
+64  
+65      public BuildProjectTask( long timestamp )
+66      {
+67          this( true, true, true, true );
+68  
+69          this.timestamp = timestamp;
+70      }
+71  
+72      public boolean isPassAEntryEvaluator()
+73      {
+74          return passAEntryEvaluator;
+75      }
+76  
+77      public boolean isPassBEntryEvaluator()
+78      {
+79          return passBEntryEvaluator;
+80      }
+81  
+82      public boolean isPassAExitEvaluator()
+83      {
+84          return passAExitEvaluator;
+85      }
+86  
+87      public boolean isPassBExitEvaluator()
+88      {
+89          return passBExitEvaluator;
+90      }
+91  
+92      public long getTimestamp()
+93      {
+94          return timestamp;
+95      }
+96  
+97      public long getMaxExecutionTime()
+98      {
+99          return maxExecutionTime;
+100     }
+101 
+102     public void setMaxExecutionTime( long timeout )
+103     {
+104         maxExecutionTime = timeout;
+105     }
+106 
+107     public void setExecutionTime( long l )
+108     {
+109         this.executionTime = l;
+110     }
+111 
+112     public long getExecutionTime()
+113     {
+114         return executionTime;
+115     }
+116 
+117     public boolean isCancelled()
+118     {
+119         return cancelled;
+120     }
+121 
+122     public void cancel()
+123     {
+124         cancelled = true;
+125     }
+126 
+127     public void done()
+128     {
+129         this.done = true;
+130     }
+131 
+132     public boolean isDone()
+133     {
+134         return done;
+135     }
+136 
+137     public boolean isStarted()
+138     {
+139         return started;
+140     }
+141 
+142     public void start()
+143     {
+144         this.started = true;
+145     }
+146 
+147     public void setIgnoreInterrupts( boolean ignore )
+148     {
+149         this.ignoreInterrupts = ignore;
+150     }
+151 
+152     public boolean ignoreInterrupts()
+153     {
+154         return ignoreInterrupts;
+155     }
+156 
+157 }
+
+
+ Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTaskViabilityEvaluator.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTaskViabilityEvaluator.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTaskViabilityEvaluator.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/BuildProjectTaskViabilityEvaluator.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,76 @@ + + + + +BuildProjectTaskViabilityEvaluator xref + + + +
+
+1   package org.apache.archiva.redback.components.taskqueue;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import org.springframework.stereotype.Service;
+23  
+24  import java.util.ArrayList;
+25  import java.util.Collection;
+26  import java.util.Iterator;
+27  import java.util.List;
+28  
+29  /**
+30   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+31   *
+32   */
+33  @Service( "taskViabilityEvaluator#build-project" )
+34  public class BuildProjectTaskViabilityEvaluator
+35      implements TaskViabilityEvaluator
+36  {
+37      public Collection evaluate( Collection tasks )
+38          throws TaskQueueException
+39      {
+40          BuildProjectTask okTask = null;
+41  
+42          List toBeRemoved = new ArrayList( tasks.size() );
+43  
+44          for ( Iterator it = tasks.iterator(); it.hasNext(); )
+45          {
+46              BuildProjectTask buildProjectTask = (BuildProjectTask) it.next();
+47  
+48              if ( okTask == null )
+49              {
+50                  okTask = buildProjectTask;
+51  
+52                  continue;
+53              }
+54  
+55              if ( buildProjectTask.getTimestamp() - okTask.getTimestamp() < 100 )
+56              {
+57                  toBeRemoved.add( buildProjectTask );
+58              }
+59          }
+60  
+61          return toBeRemoved;
+62      }
+63  }
+
+
+ Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/TaskQueueTest.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/TaskQueueTest.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/TaskQueueTest.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/TaskQueueTest.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,197 @@ + + + + +TaskQueueTest xref + + + +
+
+1   package org.apache.archiva.redback.components.taskqueue;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import junit.framework.TestCase;
+23  import org.junit.Test;
+24  import org.junit.runner.RunWith;
+25  import org.springframework.test.context.ContextConfiguration;
+26  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+27  
+28  import javax.inject.Inject;
+29  import javax.inject.Named;
+30  import java.util.ArrayList;
+31  import java.util.List;
+32  import java.util.concurrent.BlockingQueue;
+33  import java.util.concurrent.LinkedBlockingQueue;
+34  
+35  /**
+36   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+37   *
+38   */
+39  @RunWith( SpringJUnit4ClassRunner.class )
+40  @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+41  public class TaskQueueTest
+42      extends TestCase
+43  {
+44      @Inject
+45      @Named( value = "taskQueue#taskQueueTest" )
+46      private TaskQueue taskQueue;
+47  
+48  
+49      // NOTE: If we were using a blocking queue, the sleep/continue in the ThreadedTaskQueueExecutor wouldn't
+50      // be necessary; the queue would block until an element was available.
+51      @Test
+52      public void testEmptyQueue()
+53          throws Exception
+54      {
+55          assertNull( taskQueue.take() );
+56      }
+57  
+58      @Test
+59      public void testTaskEntryAndExitEvaluators()
+60          throws Exception
+61      {
+62          assertTaskIsAccepted( new BuildProjectTask( true, true, true, true ) );
+63  
+64          assertTaskIsRejected( new BuildProjectTask( false, true, true, true ) );
+65  
+66          assertTaskIsRejected( new BuildProjectTask( true, false, true, true ) );
+67  
+68          assertTaskIsRejected( new BuildProjectTask( true, true, false, true ) );
+69  
+70          assertTaskIsRejected( new BuildProjectTask( true, true, true, false ) );
+71      }
+72  
+73      @Test
+74      public void testTaskViabilityEvaluators()
+75          throws Exception
+76      {
+77          // The first and last task should be accepted
+78  
+79          Task task1 = new BuildProjectTask( 0 );
+80  
+81          Task task2 = new BuildProjectTask( 10 );
+82  
+83          Task task3 = new BuildProjectTask( 20 );
+84  
+85          Task task4 = new BuildProjectTask( 30 );
+86  
+87          Task task5 = new BuildProjectTask( 40 );
+88  
+89          Task task6 = new BuildProjectTask( 100 );
+90  
+91          assertTrue( taskQueue.put( task1 ) );
+92  
+93          assertTrue( taskQueue.put( task2 ) );
+94  
+95          assertTrue( taskQueue.put( task3 ) );
+96  
+97          assertTrue( taskQueue.put( task4 ) );
+98  
+99          assertTrue( taskQueue.put( task5 ) );
+100 
+101         assertTrue( taskQueue.put( task6 ) );
+102 
+103         Task actualTask1 = taskQueue.take();
+104 
+105         assertNotNull( actualTask1 );
+106 
+107         assertEquals( task1, actualTask1 );
+108 
+109         Task actualTask6 = taskQueue.take();
+110 
+111         assertNotNull( actualTask6 );
+112 
+113         assertEquals( task6, actualTask6 );
+114 
+115         assertNull( taskQueue.take() );
+116     }
+117 
+118     @Test
+119     public void testRemoveTask()
+120         throws Exception
+121     {
+122         Task task = new BuildProjectTask( 0 );
+123 
+124         taskQueue.put( task );
+125 
+126         taskQueue.remove( task );
+127 
+128         assertNull( taskQueue.take() );
+129     }
+130 
+131     @Test
+132     public void testRemoveAll()
+133         throws Exception
+134     {
+135 
+136         BlockingQueue<String> foo = new LinkedBlockingQueue<String>();
+137         foo.offer("1");
+138         foo.offer("2");
+139 
+140         Task firstTask = new BuildProjectTask( 110 );
+141 
+142         taskQueue.put( firstTask );
+143 
+144         Task secondTask = new BuildProjectTask( 11120 );
+145 
+146         taskQueue.put( secondTask );
+147 
+148         assertEquals( 2, taskQueue.getQueueSnapshot().size() );
+149 
+150         List tasks = new ArrayList();
+151 
+152         tasks.add( firstTask );
+153 
+154         tasks.add( secondTask );
+155 
+156         taskQueue.removeAll( tasks );
+157 
+158         assertTrue( taskQueue.getQueueSnapshot().isEmpty() );
+159     }
+160 
+161     // ----------------------------------------------------------------------
+162     //
+163     // ----------------------------------------------------------------------
+164 
+165     private void assertTaskIsAccepted( Task expectedTask )
+166         throws Exception
+167     {
+168         taskQueue.put( expectedTask );
+169 
+170         Task actualTask = taskQueue.take();
+171 
+172         assertEquals( expectedTask, actualTask );
+173     }
+174 
+175     private void assertTaskIsRejected( Task expectedTask )
+176         throws Exception
+177     {
+178         taskQueue.put( expectedTask );
+179 
+180         Task actualTask = taskQueue.take();
+181 
+182         assertNull( actualTask );
+183     }
+184 }
+
+
+ Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/BuildProjectTaskExecutor.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/BuildProjectTaskExecutor.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/BuildProjectTaskExecutor.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/BuildProjectTaskExecutor.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,96 @@ + + + + +BuildProjectTaskExecutor xref + + + +
+
+1   package org.apache.archiva.redback.components.taskqueue.execution;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  import org.apache.archiva.redback.components.taskqueue.BuildProjectTask;
+22  import org.apache.archiva.redback.components.taskqueue.Task;
+23  import org.slf4j.Logger;
+24  import org.slf4j.LoggerFactory;
+25  import org.springframework.stereotype.Service;
+26  
+27  /**
+28   *
+29   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
+30   *
+31   */
+32  @Service("taskExecutor#build-project")
+33  public class BuildProjectTaskExecutor
+34      implements TaskExecutor
+35  {
+36  
+37      private Logger logger = LoggerFactory.getLogger( getClass() );
+38  
+39      public void executeTask( Task task0 )
+40          throws TaskExecutionException
+41      {
+42          BuildProjectTask task = (BuildProjectTask) task0;
+43  
+44          task.start();
+45  
+46          logger.info( "Task: " + task + " cancelled: " + task.isCancelled() + "; done: " + task.isDone() );
+47  
+48          long time = System.currentTimeMillis();
+49  
+50          long endTime = task.getExecutionTime() + time;
+51  
+52          for ( long timeToSleep = endTime - time; timeToSleep > 0; timeToSleep = endTime - System.currentTimeMillis() )
+53          {
+54              try
+55              {
+56                  logger.info( "Sleeping " + timeToSleep + "ms (interrupts ignored: " + task.ignoreInterrupts() + ")" );
+57                  Thread.sleep( timeToSleep );
+58  
+59                  task.done();
+60  
+61                  logger.info( "Task completed normally: " + task + " cancelled: " + task.isCancelled() + "; done: "
+62                                   + task.isDone() );
+63              }
+64              catch ( InterruptedException e )
+65              {
+66                  if ( !task.ignoreInterrupts() )
+67                  {
+68                      task.cancel();
+69  
+70                      logger.info(
+71                          "Task cancelled: " + task + " cancelled: " + task.isCancelled() + "; done: " + task.isDone() );
+72  
+73                      throw new TaskExecutionException( "Never interrupt sleeping threads! :)", e );
+74                  }
+75                  else
+76                  {
+77                      logger.info( "Ignoring interrupt" );
+78                  }
+79              }
+80          }
+81  
+82      }
+83  }
+
+
+ Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/TaskQueueExecutorTest.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/TaskQueueExecutorTest.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/TaskQueueExecutorTest.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/TaskQueueExecutorTest.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,120 @@ + + + + +TaskQueueExecutorTest xref + + + +
+
+1   package org.apache.archiva.redback.components.taskqueue.execution;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import junit.framework.TestCase;
+23  import org.apache.archiva.redback.components.taskqueue.BuildProjectTask;
+24  import org.apache.archiva.redback.components.taskqueue.TaskQueue;
+25  import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
+26  import org.junit.Test;
+27  import org.junit.runner.RunWith;
+28  import org.springframework.test.context.ContextConfiguration;
+29  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+30  
+31  import javax.inject.Inject;
+32  import javax.inject.Named;
+33  
+34  /**
+35   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
+36   */
+37  @RunWith( SpringJUnit4ClassRunner.class )
+38  @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+39  public class TaskQueueExecutorTest
+40      extends TestCase
+41  {
+42      @Inject
+43      @Named( value = "taskQueue#default" )
+44      private TaskQueue taskQueue;
+45  
+46      // inject this to start the executor see @PostConstruct in {@link ThreadedTaskQueueExecutor
+47      @Inject
+48      @Named( value = "queueExecutor#default" )
+49      private TaskQueueExecutor taskQueueExecutor;
+50  
+51  
+52      @Test
+53      public void testTimeoutWithInterrupts()
+54          throws TaskQueueException, InterruptedException
+55      {
+56          BuildProjectTask task = putTask( 2 * 1000, false );
+57  
+58          waitForExpectedTaskEnd( task );
+59  
+60          assertTrue( task.isCancelled() );
+61          assertFalse( task.isDone() );
+62      }
+63  
+64      @Test
+65      public void testTimeoutWithoutInterrupts()
+66          throws TaskQueueException, InterruptedException
+67      {
+68          BuildProjectTask task = putTask( 2 * 1000, true );
+69  
+70          waitForExpectedTaskEnd( task );
+71  
+72          // the thread is killed so the task is neither done nor cancelled
+73          assertFalse( task.isCancelled() );
+74          assertFalse( task.isDone() );
+75      }
+76  
+77      private BuildProjectTask putTask( int executionTime, boolean ignoreInterrupts )
+78          throws TaskQueueException
+79      {
+80          BuildProjectTask task = new BuildProjectTask( 100 );
+81          task.setMaxExecutionTime( executionTime );
+82          task.setExecutionTime( 10 * executionTime );
+83          task.setIgnoreInterrupts( ignoreInterrupts );
+84  
+85          taskQueue.put( task );
+86          return task;
+87      }
+88  
+89      private static void waitForExpectedTaskEnd( BuildProjectTask task )
+90          throws InterruptedException
+91      {
+92          // thread scheduling may take some time, so we want to wait until the task
+93          // is actually running before starting to count the timeout.
+94          for ( int i = 0; i < 500; i++ )
+95          {
+96              if ( task.isStarted() )
+97              {
+98                  break;
+99              }
+100             Thread.sleep( 10 );
+101         }
+102 
+103         assertTrue( "Task not started in 5 seconds - heavy load?", task.isStarted() );
+104 
+105         Thread.sleep( task.getMaxExecutionTime() );
+106     }
+107 }
+
+
+ Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-frame.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-frame.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-frame.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-frame.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,27 @@ + + + + + + Apache Archiva Redback Components 2.0-SNAPSHOT Reference Package org.apache.archiva.redback.components.taskqueue.execution + + + + +

+ org.apache.archiva.redback.components.taskqueue.execution +

+ +

Classes

+ + + + + \ No newline at end of file Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-summary.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-summary.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-summary.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/execution/package-summary.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,72 @@ + + + + + + Apache Archiva Redback Components 2.0-SNAPSHOT Reference Package org.apache.archiva.redback.components.taskqueue.execution + + + +
+ +
+
+ +
+ +

Package org.apache.archiva.redback.components.taskqueue.execution

+ + + + + + + + + + + + + + + +
Class Summary
+ BuildProjectTaskExecutor +
+ TaskQueueExecutorTest +
+ +
+ +
+
+ +
+
+ Copyright © 2006-2012 The Apache Software Foundation. All Rights Reserved. + + \ No newline at end of file Added: archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/package-frame.html URL: http://svn.apache.org/viewvc/archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/package-frame.html?rev=1378611&view=auto ============================================================================== --- archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/package-frame.html (added) +++ archiva/site-content/redback/components/xref-test/org/apache/archiva/redback/components/taskqueue/package-frame.html Wed Aug 29 15:37:03 2012 @@ -0,0 +1,42 @@ + + + + + + Apache Archiva Redback Components 2.0-SNAPSHOT Reference Package org.apache.archiva.redback.components.taskqueue + + + + +

+ org.apache.archiva.redback.components.taskqueue +

+ +

Classes

+ + + + + \ No newline at end of file