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.io.IOException;
34 import java.nio.file.FileSystemException;
35 import java.nio.file.Files;
36 import java.nio.file.StandardCopyOption;
39 * @author Olivier Lamy
41 @RunWith(SpringJUnit4ClassRunner.class)
42 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml" })
43 public class DefaultFileLockManagerTimeoutTest
46 final Logger logger = LoggerFactory.getLogger( getClass() );
49 @Named(value = "fileLockManager#default")
50 FileLockManager fileLockManager;
53 public void initialize()
55 fileLockManager.setSkipLocking( false );
57 fileLockManager.setTimeout( 5000 );
59 fileLockManager.clearLockFiles();
62 @Test(expected = FileLockTimeoutException.class)
63 public void testTimeout()
68 File file = new File(System.getProperty("buildDirectory"), "foo.txt");
70 Files.deleteIfExists(file.toPath());
72 File largeJar = new File(System.getProperty("basedir"), "src/test/cassandra-all-2.0.3.jar");
74 Lock lock = fileLockManager.writeFileLock(file);
77 Files.copy(largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
78 } catch (IOException e) {
79 logger.warn("Copy failed "+e.getMessage());
80 // On windows a FileSystemException is thrown
84 lock = fileLockManager.writeFileLock(file);
85 } catch (FileSystemException ex) {
86 logger.error("Exception from filesystem "+ex.getMessage());