diff options
author | Olivier Lamy <olamy@apache.org> | 2013-12-12 22:37:34 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-12-12 22:37:34 +0000 |
commit | 79329d262e0df3eae6e1cb7d92bdb47a2cf5ab21 (patch) | |
tree | afe6889c112438ec1eab539fa0f1e9eb348c3bf2 /archiva-modules | |
parent | 7fc6fb2158429c575bb8bd59c718c6c28694654e (diff) | |
download | archiva-79329d262e0df3eae6e1cb7d92bdb47a2cf5ab21.tar.gz archiva-79329d262e0df3eae6e1cb7d92bdb47a2cf5ab21.zip |
fix timeout
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1550562 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
4 files changed, 88 insertions, 3 deletions
diff --git a/archiva-modules/archiva-base/archiva-filelock/pom.xml b/archiva-modules/archiva-base/archiva-filelock/pom.xml index f37abecc5..6881ef0ec 100644 --- a/archiva-modules/archiva-base/archiva-filelock/pom.xml +++ b/archiva-modules/archiva-base/archiva-filelock/pom.xml @@ -42,6 +42,11 @@ </dependency> <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + + <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> </dependency> diff --git a/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java b/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java index e55a56ad2..08f01488a 100644 --- a/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java +++ b/archiva-modules/archiva-base/archiva-filelock/src/main/java/org/apache/archiva/common/filelock/DefaultFileLockManager.java @@ -19,10 +19,10 @@ package org.apache.archiva.common.filelock; * under the License. */ +import org.apache.commons.lang.time.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import org.springframework.util.StopWatch; import java.io.File; import java.io.FileNotFoundException; @@ -67,7 +67,8 @@ public class DefaultFileLockManager { if ( timeout > 0 ) { - long delta = stopWatch.getTotalTimeMillis(); + long delta = stopWatch.getTime(); + log.debug( "delta {}, timeout {}", delta, timeout ); if ( delta > timeout ) { log.warn( "Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file ); @@ -120,7 +121,8 @@ public class DefaultFileLockManager { if ( timeout > 0 ) { - long delta = stopWatch.getTotalTimeMillis(); + long delta = stopWatch.getTime(); + log.debug( "delta {}, timeout {}", delta, timeout ); if ( delta > timeout ) { log.warn( "Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file ); diff --git a/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java b/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java index 6aa437248..bf756afdf 100644 --- a/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java +++ b/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java @@ -274,4 +274,5 @@ public class DefaultFileLockManagerTest Assert.assertEquals( 10, concurrentFileWrite.success.intValue() ); } + } diff --git a/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTimeoutTest.java b/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTimeoutTest.java new file mode 100644 index 000000000..0b6fafa5b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTimeoutTest.java @@ -0,0 +1,77 @@ +package org.apache.archiva.common.filelock; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import edu.umd.cs.mtc.MultithreadedTestCase; +import edu.umd.cs.mtc.TestFramework; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import javax.inject.Named; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author Olivier Lamy + */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml" } ) +public class DefaultFileLockManagerTimeoutTest +{ + + final Logger logger = LoggerFactory.getLogger( getClass() ); + + @Inject + @Named( value = "fileLockManager#default" ) + FileLockManager fileLockManager; + + + + @Test( expected = FileLockTimeoutException.class ) + public void testTimeout() + throws Throwable + { + + File file = new File( System.getProperty( "buildDirectory" ), "foo.txt" ); + + File largeJar = new File( System.getProperty( "basedir" ), "src/test/cassandra-all-2.0.3.jar" ); + + fileLockManager.setTimeout( 5000 ); + + Lock lock = fileLockManager.writeFileLock( file ); + + FileUtils.copyFile( largeJar, lock.getFile() ); + + lock = fileLockManager.writeFileLock( file ); + + } + +} |