Skip to content

Commit

Permalink
Swap order of new member in AddressPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
peckb1 committed Apr 24, 2024
1 parent a4befc3 commit 96345cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions okhttp/api/okhttp.api
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ public final class okhttp3/ConnectionPool$AddressPolicy {
public final field maximumConcurrentCallsPerConnection I
public final field minimumConcurrentCalls I
public fun <init> ()V
public fun <init> (IIJI)V
public synthetic fun <init> (IIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (IJII)V
public synthetic fun <init> (IJIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
}

public final class okhttp3/ConnectionSpec {
Expand Down
9 changes: 4 additions & 5 deletions okhttp/src/main/kotlin/okhttp3/ConnectionPool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ class ConnectionPool internal constructor(
* Connections will still be closed if they idle beyond the keep-alive but will be replaced.
*/
@JvmField val minimumConcurrentCalls: Int = 0,
/** How long to wait to retry pre-emptive connection attempts that fail. */
@JvmField val backoffDelayMillis: Long = 60 * 1000,
/** How much jitter to introduce in connection retry backoff delays */
@JvmField val backoffJitterMillis: Int = 100,
/**
* The maximum number of concurrent calls per connection.
*
* Set this value to 1 to disable HTTP/2 connection coalescing
*/
@JvmField val maximumConcurrentCallsPerConnection: Int = Int.MAX_VALUE,
/** How long to wait to retry pre-emptive connection attempts that fail. */
@JvmField val backoffDelayMillis: Long = 60 * 1000,
/** How much jitter to introduce in connection retry backoff delays */
@JvmField val backoffJitterMillis: Int = 100,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class RealConnection(
connection: Http2Connection,
settings: Settings,
) {
this.withLock {
this.withLock {
this.lastMaxConcurrentStreamsFromSettings = settings.getMaxConcurrentStreams()
recalculateAllocationLimit()
}
Expand All @@ -369,7 +369,7 @@ class RealConnection(
* made during settings changes
*/
internal fun recalculateAllocationLimit() {
this.withLock {
this.withLock {
val oldLimit = allocationLimit
allocationLimit = getMaximumAllocationLimit()

Expand Down Expand Up @@ -425,7 +425,7 @@ class RealConnection(
e: IOException?,
) {
var noNewExchangesEvent = false
this.withLock {
this.withLock {
if (e is StreamResetException) {
when {
e.errorCode == ErrorCode.REFUSED_STREAM -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class ConnectionPoolTest {

// Add a connection to the pool that won't expire for a while
routePlanner.defaultConnectionIdleAtNanos = expireLater
setPolicy(pool, address, ConnectionPool.AddressPolicy(1))
setPolicy(pool, address, ConnectionPool.AddressPolicy(minimumConcurrentCalls = 1))
assertThat(pool.connectionCount()).isEqualTo(1)

// All other connections created will expire sooner
Expand All @@ -287,31 +287,31 @@ class ConnectionPoolTest {
// which can satisfy a larger policy
val connection = routePlanner.plans.first().connection
val http2Connection = connectHttp2(peer, connection, 5)
setPolicy(pool, address, ConnectionPool.AddressPolicy(5))
setPolicy(pool, address, ConnectionPool.AddressPolicy(minimumConcurrentCalls = 5))
assertThat(pool.connectionCount()).isEqualTo(1)

// Decrease the policy max connections, and check that new connections are created
setPolicy(pool, address, ConnectionPool.AddressPolicy(5, 1))
setPolicy(pool, address, ConnectionPool.AddressPolicy(minimumConcurrentCalls = 5, maximumConcurrentCallsPerConnection = 1))
// fills up the first connect and then adds single connections
// 5 = 1 + 1 + 1 + 1 + 1 (five unique connections)
assertThat(pool.connectionCount()).isEqualTo(5)

// increase the policy max connections, and check that new connections are created
setPolicy(pool, address, ConnectionPool.AddressPolicy(5, 2))
setPolicy(pool, address, ConnectionPool.AddressPolicy(minimumConcurrentCalls = 5, maximumConcurrentCallsPerConnection = 2))
forceConnectionsToExpire(pool, expireSooner)
// fills up the first connect and then adds single connections
// 5 = 2 + 1 + 1 + 1 (four unique connections)
assertThat(pool.connectionCount()).isEqualTo(4)

// increase the policy max connections, and check that new connections are created
setPolicy(pool, address, ConnectionPool.AddressPolicy(5, 4))
setPolicy(pool, address, ConnectionPool.AddressPolicy(minimumConcurrentCalls = 5, maximumConcurrentCallsPerConnection = 4))
forceConnectionsToExpire(pool, expireSooner)
// fills up the first connect and then adds single connections
// 5 = 4 + 1 (two unique connections)
assertThat(pool.connectionCount()).isEqualTo(2)

// Decrease the policy max connections, and check that new connections are created
setPolicy(pool, address, ConnectionPool.AddressPolicy(5, 3))
setPolicy(pool, address, ConnectionPool.AddressPolicy(minimumConcurrentCalls = 5, maximumConcurrentCallsPerConnection = 3))
// fills up the first connect and then removes an unused after
// 5 = 3 + 1 + 1 (three unique connections)
assertThat(pool.connectionCount()).isEqualTo(3)
Expand Down

0 comments on commit 96345cf

Please sign in to comment.