Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ private[http2] object PriorityTree {
private class PriorityTreeImpl(nodes: TreeMap[Int, PriorityInfo]) extends PriorityTree {
def rootNode: PriorityNode = node(0)

def insertOrUpdate(streamId: Int, streamDependency: Int, weight: Int, exclusive: Boolean): PriorityTree =
def insertOrUpdate(streamId: Int, streamDependency: Int, weight: Int, exclusive: Boolean): PriorityTree = {
require(streamId != 0, "Cannot update root node")
if (nodes.isDefinedAt(streamId)) update(streamId, streamDependency, weight, exclusive)
else insert(streamId, streamDependency, weight, exclusive)
}

private def insert(streamId: Int, streamDependency: Int, weight: Int, exclusive: Boolean): PriorityTreeImpl = {
require(!nodes.isDefinedAt(streamId), s"Cannot insert node twice: $streamId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,25 @@ class PriorityTreeSpec extends AnyWordSpec with Matchers {

"prune nodes" in pending

"fail when updating the root node" in pending
"fail when introducing a dependency on itself" in pending
"fail when updating the root node" in {
val tree = PriorityTree().insertOrUpdate(1, 0, 16, exclusive = false)

intercept[IllegalArgumentException] {
tree.insertOrUpdate(0, 1, 16, exclusive = true)
}
}

"fail when introducing a dependency on itself" in {
val empty = PriorityTree()
intercept[IllegalArgumentException] {
empty.insertOrUpdate(1, 1, 16, exclusive = false)
}

val tree = empty.insertOrUpdate(1, 0, 16, exclusive = false)
intercept[IllegalArgumentException] {
tree.insertOrUpdate(1, 1, 16, exclusive = false)
}
}
}

def printLike(resultingTree: String): Matcher[PriorityTree] =
Expand Down