1 package org.apache.archiva.common.filelock;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.test.context.ContextConfiguration;
28 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30 import javax.inject.Inject;
31 import javax.inject.Named;
33 import java.nio.file.Files;
34 import java.nio.file.StandardCopyOption;
37 * @author Olivier Lamy
39 @RunWith(SpringJUnit4ClassRunner.class)
40 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml" })
41 public class DefaultFileLockManagerTimeoutTest
44 final Logger logger = LoggerFactory.getLogger( getClass() );
47 @Named(value = "fileLockManager#default")
48 FileLockManager fileLockManager;
51 public void initialize()
53 fileLockManager.setSkipLocking( false );
55 fileLockManager.setTimeout( 5000 );
57 fileLockManager.clearLockFiles();
60 @Test(expected = FileLockTimeoutException.class)
61 public void testTimeout()
65 File file = new File( System.getProperty( "buildDirectory" ), "foo.txt" );
67 Files.deleteIfExists( file.toPath() );
69 File largeJar = new File( System.getProperty( "basedir" ), "src/test/cassandra-all-2.0.3.jar" );
71 Lock lock = fileLockManager.writeFileLock( file );
73 Files.copy( largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING );
75 lock = fileLockManager.writeFileLock( file );