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.FileSystemException;
34 import java.nio.file.Files;
35 import java.nio.file.StandardCopyOption;
38 * @author Olivier Lamy
40 @RunWith(SpringJUnit4ClassRunner.class)
41 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml" })
42 public class DefaultFileLockManagerTimeoutTest
45 final Logger logger = LoggerFactory.getLogger( getClass() );
48 @Named(value = "fileLockManager#default")
49 FileLockManager fileLockManager;
52 public void initialize()
54 fileLockManager.setSkipLocking( false );
56 fileLockManager.setTimeout( 5000 );
58 fileLockManager.clearLockFiles();
61 @Test(expected = FileLockTimeoutException.class)
62 public void testTimeout()
67 File file = new File(System.getProperty("buildDirectory"), "foo.txt");
69 Files.deleteIfExists(file.toPath());
71 File largeJar = new File(System.getProperty("basedir"), "src/test/cassandra-all-2.0.3.jar");
73 Lock lock = fileLockManager.writeFileLock(file);
75 Files.copy(largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
77 lock = fileLockManager.writeFileLock(file);
78 } catch (FileSystemException ex) {
79 logger.error("Exception from filesystem "+ex.getMessage());