michael-o commented on a change in pull request #49: [MNG-2802] Concurrent-safe 
access to local Maven repository
URL: https://github.com/apache/maven-wagon/pull/49#discussion_r301250444
 
 

 ##########
 File path: 
wagon-providers/wagon-file-test/src/test/java/org/apache/maven/wagon/providers/file/LazyLockableFileOutputStreamIntegrationTest.java
 ##########
 @@ -0,0 +1,127 @@
+package org.apache.maven.wagon.providers.file;
+
+/*
+ * 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 org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class LazyLockableFileOutputStreamIntegrationTest
+{
+
+    //This timeout is just to ensure a failing test doesn't hang indefinitely
+    private static final long processTimeoutInMilliseconds = 30000;
+    //This timeout is "real" and says how long to wait for a file lock
+    private static final String lockTimeoutInSeconds = "5";
+
+    @Test
+    public void testLockDontWait() throws Exception
+    {
+        String jarFile = System.getProperty( "jarFile" );
+        String testOutputDir = System.getProperty( "testOutputDir" );
+        String lockFile = testOutputDir + "lockfile1";
+        Process firstProcess = startProcess( jarFile, testOutputDir, lockFile, 
false );
+        waitForReady( firstProcess );
+        ensureNotExited( firstProcess, testOutputDir );
+
+        Process secondProcess = startProcess( jarFile, testOutputDir, 
lockFile, false );
+        waitForReady( secondProcess );
+
+        // CHECKSTYLE_OFF: MagicNumber
+        assertEquals( 126, secondProcess.waitFor() );
+        // CHECKSTYLE_ON: MagicNumber
+        firstProcess.getOutputStream().close();
+        assertEquals( 0, firstProcess.waitFor() );
+    }
+
+    @Test
+    public void testLockWait() throws Exception
+    {
+        String jarFile = System.getProperty( "jarFile" );
+        String testOutputDir = System.getProperty( "testOutputDir" );
+        String lockFile = testOutputDir + "lockfile2";
+        Process firstProcess = startProcess( jarFile, testOutputDir, lockFile, 
false );
+        waitForReady( firstProcess );
+        ensureNotExited( firstProcess, testOutputDir );
+
+        Process secondProcess = startProcess( jarFile, testOutputDir, 
lockFile, true );
+        waitForReady( secondProcess );
+        
+        // CHECKSTYLE_OFF: MagicNumber
+        assertEquals( 127, secondProcess.waitFor() );
+        // CHECKSTYLE_ON: MagicNumber
+        firstProcess.getOutputStream().close();
+        assertEquals( 0, firstProcess.waitFor() );
+    }
+
+    private void ensureNotExited(Process process, String testOutputDir) {
+        try
+        {
+            int exitValue = process.exitValue();
+            fail( "Lock process exited unexpectedly with status " + exitValue 
+ ".\nSee " + testOutputDir
 
 Review comment:
   Don't use hardcoded `\n`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to