Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion debug/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion debug/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion ls/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IgContextManager(private val contentService: ContentService) {

fun getContext(uri: URI): NpmProcessor? {
val root = Uris.getHead(uri)
return cachedContext.getOrPut(root) { readContext(root) }.orElse(null)
return cachedContext.computeIfAbsent(root) { readContext(it) }.orElse(null)
}

protected fun clearContext(uri: URI) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import java.io.InputStream
import java.net.URI
import java.nio.file.Path
import java.nio.file.Paths
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicInteger

class IgContextManagerTest {
private lateinit var manager: IgContextManager
Expand Down Expand Up @@ -143,6 +145,55 @@ class IgContextManagerTest {
assertEquals(countAfterFirst, readCount, "Unrelated file change should not clear cache")
}

// -----------------------------------------------------------------------
// getContext — concurrent callers trigger readContext() exactly once
// -----------------------------------------------------------------------

@Test
fun getContext_concurrentCalls_onlyReadsContextOnce() {
val readCount = AtomicInteger(0)
val cs =
object : ContentService {
override fun locate(
root: URI,
identifier: VersionedIdentifier,
) = emptySet<URI>()

override fun read(uri: URI): InputStream? {
readCount.incrementAndGet()
return null
}
}

// Establish baseline: how many content-service reads does one getContext() trigger?
val baselineManager = IgContextManager(cs)
baselineManager.getContext(TEST_URI)
val readsPerContext = readCount.get()

// Reset and run N threads simultaneously against a cold cache.
readCount.set(0)
val localManager = IgContextManager(cs)
val threadCount = 10
val startGate = CountDownLatch(1)
val threads =
(1..threadCount).map {
Thread {
startGate.await()
localManager.getContext(TEST_URI)
}
}
threads.forEach { it.start() }
startGate.countDown()
threads.forEach { it.join() }

assertEquals(
readsPerContext,
readCount.get(),
"Concurrent getContext() calls should invoke readContext() exactly once " +
"(expected $readsPerContext reads, got ${readCount.get()})",
)
}

// -----------------------------------------------------------------------
// findIgContext path conversion — the URI passed to IGContext.initializeFromIni
// must be a valid OS filesystem path, not a URI artefact.
Expand Down
2 changes: 1 addition & 1 deletion ls/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion plugin/debug/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.opencds.cqf.cql.ls</groupId>
<artifactId>cql-ls</artifactId>
<packaging>pom</packaging>
<version>4.4.1</version>
<version>4.5.0-SNAPSHOT</version>

<name>CQL Language Server</name>
<description>A Language Server for CQL implementing the LSP</description>
Expand Down
Loading