This PR adds support for configuring the connection pool to proactively create connections to specified hosts. This is useful for "prewarming" the connection pool before it starts being used.
The main public API change is adding `ConnectionPool.setPolicy(Address, AddressPolicy)`. A policy specifies how many _concurrent streams_ should be supported by the pool (which might be satisfied by a single http/2 connection or by N http/1.1 connections).
The main internal change is adding a new task queue to `RealConnectionPool` which checks to see if it needs to create new connections to satisfy existing policies. This task is enqueued any time a policy changes, a connection is closed, or an http/2 connection's settings decrease the number of concurrent streams supported.
This is working towards supporting pre-warmed connections
in ConnectionPool. We want to create connections without a
Call object.
Co-authored-by: Evan Nelson <enelson@squareup.com>
* Prepare to enable Spotless
I'm not super keen on any of these changes, but I am very
keen on having automatic formatting.
* Don't actually enable Spotless yet
* Switch to assertk.fail
* Use assertFailsWith
* More assertFailsWith
* Use more assertFailsWith
* More assertFailsWith
* More assertFailsWith
* Native image dependencies
* Move JUnit dependency
* Don't lock in a specific implementation class
* Missing finally
* Even more assertk
When we split tests into multiplatform we switched them
from AssertJ to assertk. I'm migrating everything over to
assertk so that I can merge tests back together without
changing assertion APIs.
* Fixup some type conversion problems
* Switch back to the kotlin JVM plugin
This does a ton of file moves from jvmMain to main, and jvmTest to test.
* Don't use AnimalSniffer on okcurl
* Use assertk more (#8150)
Just hard-coding 'localhost' is simpler and avoids problems where
the host machine's IP address has additional DNS registrations.
Closes: https://github.com/square/okhttp/issues/7603
* Attempt at a ConnectionListener
* Fixes
* Test for locks
* Fix for locking
* Add events in RouteFailureTest
* Fixes
* Fixes
* Fixes
* Fast path when None
* Don't defer connectionClosed events
* Don't enqueue connection events
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
* Add a proper Kotlin constructor for Request
This turns out to be very useful throughout our test suite.
* Dump updated API
* Fix multipleTags Kotlin conversion
In a race this could cause us to prefer a new connection over
a pooled connection, which violates our invariant that pooled
connections are always used if they're found.
Closes: https://github.com/square/okhttp/issues/7152
* Move code from RealConnection to RealConnectPlan
Also promote RealConnectPlan to a top-level type, ConnectPlan.
Each RealConnection is now created only once its ready to be used
to carry exchanges. We do the actual connect work in ConnectPlan.
* Move startHttp2() back to RealConnection
* Update FastFallbackExchangeFinder for split RealConnection
* Tests for FastFallbackExchangeFinder
This needed more test facets in TaskFaker.
I'm pretty happy with how the tests read.
* More tests for FastFallbackExchangeFinder.
In order to deterministically test FastFallbackExchangeFinder I need
a test facet that supports several test coordinating:
- the call thread is waiting for either a connection to connect
or for the next-connection timeout (250 ms) to elapse
- the in-flight connection needs to connect
TaskFaker wasn't up to the task for this because it assumed at most
two threads, the test thread and the task thread.
With this change TaskFaker can coordinate multiple task threads
that each run sequentially, as directed by a test thread.
This doesn't yet introduce any mechanism to enable or disable
happy eyeballs.
It also doesn't sort IP addresses to alternate IPv6, IPv4
for best success.
It also doesn't limit how many connections are attempted
simultaneously.
It also lacks an appropriate number of tests.
This is bad because it moves test logic out of tests. But it's also
good because it lowers the cost of writing unit tests with common
types like RealConnection and Route.
I attempted to do a literal translation as much as possible.
Subprojects now need plugins to be configured directly so they
can use the appropriate syntax.