-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: Setup concurrent tests #85
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,11 @@ import java.io.IOException | |
import java.io.RandomAccessFile | ||
import java.net.MalformedURLException | ||
import java.net.URL | ||
import java.nio.channels.FileLock | ||
import java.nio.channels.OverlappingFileLockException | ||
import java.util.concurrent.ExecutorService | ||
|
||
|
||
internal class JUnit5MavenDependencyResolver private constructor( | ||
repositoryUrl: String, | ||
repositoryId: String, | ||
|
@@ -20,6 +23,7 @@ internal class JUnit5MavenDependencyResolver private constructor( | |
proxyHost: String?, | ||
proxyPort: Int, | ||
) : MavenDependencyResolver(repositoryUrl, repositoryId, repositoryUserName, repositoryPassword, proxyHost, proxyPort) { | ||
@Suppress("unused") | ||
constructor() : this( | ||
MavenRoboSettings.getMavenRepositoryUrl(), | ||
MavenRoboSettings.getMavenRepositoryId(), | ||
|
@@ -44,9 +48,12 @@ internal class JUnit5MavenDependencyResolver private constructor( | |
val artifacts: List<Pair<DependencyJar, MavenJarArtifact>> = dependencies.map { it to MavenJarArtifact(it) } | ||
|
||
for ((dependencyJar, artifact) in artifacts) { | ||
if (!File(localRepositoryDir, artifact.jarPath()).exists()) { | ||
val artifactJarFile = File(localRepositoryDir, artifact.jarPath()) | ||
if (!artifactJarFile.exists()) { | ||
whileLocked(dependencyJar) { | ||
mavenArtifactFetcher.fetchArtifact(artifact) | ||
if (!artifactJarFile.exists()) { | ||
mavenArtifactFetcher.fetchArtifact(artifact) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -73,9 +80,17 @@ internal class JUnit5MavenDependencyResolver private constructor( | |
try { | ||
RandomAccessFile(lockFile, "rw").use { raf -> | ||
raf.channel.use { channel -> | ||
channel.lock().use { | ||
runnable.run() | ||
var lock: FileLock? = null | ||
while (lock == null) { | ||
try { | ||
lock = channel.tryLock() | ||
} catch (e: OverlappingFileLockException) { | ||
// Sleep for a while before retrying | ||
Thread.sleep(100) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log the swallowed exception. The caught catch (e: OverlappingFileLockException) {
// Log the exception for diagnostic purposes
logger.warn("OverlappingFileLockException encountered: ${e.message}")
Thread.sleep(100)
} Toolsdetekt
|
||
} | ||
runnable.run() | ||
lock.release() | ||
} | ||
} | ||
} catch (e: IOException) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log the swallowed exception.
The caught
OverlappingFileLockException
is swallowed without logging. Consider logging this exception to aid in diagnosing potential issues.Tools
detekt