206 Commits

Author SHA1 Message Date
Evan Nelson
c9ba5d732b Support minimum connection pool size (#8287)
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.
2024-04-03 13:39:41 -07:00
Jesse Wilson
79aa6fc056 Test webSocketCloseTimeout (#8317)
* Test webSocketCloseTimeout

* Spotless
2024-04-01 10:21:25 -04:00
Jesse Wilson
e18252dd20 Extract an interface for a ConnectionUser (#8276)
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>
2024-03-06 09:33:38 -08:00
Jesse Wilson
a228fd64cc Reformat with Spotless (#8180)
* Enable spotless

* Run spotlessApply

* Fixup trimMargin

* Re-run spotlessApply
2024-01-07 20:13:22 -05:00
Jesse Wilson
0e312d7804 Prepare to enable Spotless (#8179)
* 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
2024-01-07 11:05:34 -05:00
Jesse Wilson
23d67c304f Switch to assertFailsWith (#8177)
* 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
2024-01-06 00:31:00 -05:00
Jesse Wilson
eb6c016f6f Stop using AssertJ (#8174)
* Stop using AssertJ

This completes the migration to assertk.

* Fix a missing import

* Fix some type issues
2024-01-04 00:32:07 -05:00
Yuri Schimke
265cb04e99 Test with release build & update proguard config. (#8156) 2023-12-23 14:46:51 +00:00
Jesse Wilson
1561bbaeae Convert some tests to Kotlin (#8152)
* Rename .java to .kt without conversion

* Convert to Kotlin
2023-12-21 06:25:40 -05:00
Jesse Wilson
e285d4e68b Even more assertk (#8151)
* 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
2023-12-20 20:54:49 -05:00
Jesse Wilson
c056530682 Switch back to the kotlin JVM plugin (#8149)
* 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)
2023-12-20 18:27:07 -05:00
Jesse Wilson
6b7b611308 Remove expect/actuals (#8147)
* Remove expect/actuals from okcurl

* Remove expect/actuals from okhttp-coroutines

* Remove expect/actuals from okhttp

* Remove expect/actuals from okhttp-testing-support

* Fixup build scripts
2023-12-19 07:37:45 -05:00
Benoît Quenaudon
68105a4832 Removing all JS variants (#8145) 2023-12-18 10:49:23 -05:00
Yuri Schimke
e2344c7277 Evict connection pool a second time after tests (#7819) 2023-05-14 09:02:17 +01:00
Yuri Schimke
f62fd47876 Fix websocket reconnect race condition (#7815) 2023-05-13 12:31:00 +01:00
Yuri Schimke
e882b4cdc9 Add flow control observability (#7810) 2023-05-10 09:45:54 +01:00
Jesse Wilson
0d39bc580a Run HttpUrl tests on all platforms (#7802) 2023-05-06 15:30:27 -04:00
Jesse Wilson
cfaefe00c9 Do IDNA mapping on Kotlin/JS (#7800) 2023-05-05 21:22:01 -04:00
Jesse Wilson
6204a3ec51 Make okhttp-testing-support a multiplatform project (#7797) 2023-05-04 07:53:29 -04:00
Yuri Schimke
f408411ff9 Avoid exposing internal methods (#7734) 2023-04-23 08:05:59 +01:00
Yuri Schimke
3db0d8279c Test for proxy location change (#7720) 2023-04-23 07:59:39 +01:00
Yuri Schimke
264d174347 Avoid failing on Loom. (#7716) 2023-02-18 15:26:25 +00:00
renovate[bot]
5ece5e4df7 Update dependency software.amazon.cryptools:AmazonCorrettoCryptoProvider to v2 (#7690)
* Update dependency software.amazon.cryptools:AmazonCorrettoCryptoProvider to v2

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2023-02-18 13:22:01 +00:00
Yuri Schimke
0061139174 Remove RealCall from ConnectionListener (#7681)
* Remove RealCall from ConnectionListener

* API

* API
2023-02-04 16:02:23 -05:00
Jesse Wilson
22fe120548 Delete some dead code (#7666)
Follow-up to https://github.com/square/okhttp/pull/7462/files
2023-01-22 21:46:03 -05:00
Yuri Schimke
33ace75841 Loom Support (#7367) 2023-01-03 10:07:36 +10:00
Yuri Schimke
13ac56ca0a Check for matching ConnectionEvent (#7612)
* Check for matching ConnectionEvent

* Fixes for API file

* Fix tests

* Fix cancel event logic
2023-01-02 11:24:01 -05:00
Jesse Wilson
847b5af240 Avoid InetAddress.getCanonicalHostName(). (#7607)
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
2023-01-02 09:04:37 -05:00
Yuri Schimke
5f7762d9f1 Add CI tests for Loom (#7613) 2023-01-02 16:08:53 +10:00
Yuri Schimke
735ed1a6e5 Add a ConnectionListener (#7456)
* 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>
2023-01-01 09:17:55 -05:00
Jesse Wilson
fe6db78647 Get more TLS stuff passing on BouncyCastle (#7602)
There's something up with ECDSA on BouncyCastle, and rather
than figuring it out I've just switched to RSA signatures
with that provider.
2022-12-31 20:39:55 -05:00
Yuri Schimke
d65406e9f9 Enable fastFallback by default (#7566) 2022-12-24 11:56:20 +10:00
Yuri Schimke
f27a291975 Add tests for multiple routes (#7563) 2022-12-24 10:26:45 +10:00
Yuri Schimke
550fc84605 Rerun flaky tests (#7462) 2022-09-24 11:51:03 +01:00
Yuri Schimke
8050b0fd4a Avoid trivial warning for Optional in test code. (#7293) 2022-06-08 10:42:58 -04:00
Jesse Wilson
79f50e1911 Add a proper Kotlin constructor for Request (#7208)
* 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
2022-04-04 09:44:43 -04:00
Jesse Wilson
b2310de1a8 Never put pooled connections in the result queue (#7154)
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
2022-03-10 21:54:56 -05:00
Goooler
9d0208d43a Cleanup libs.versions.toml (#7082) 2022-02-17 19:03:07 +00:00
Yuri Schimke
362f53546d Adopt Version Catalog and Updates plugin (#7075) 2022-02-15 23:38:32 +00:00
Jesse Wilson
699a2122fc Move code from RealConnection to RealConnectPlan (#7065)
* 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
2022-02-09 20:25:37 -05:00
Goooler
f5758b7f26 Enable Gradle's type-safe project accessors (#7069) 2022-02-08 20:01:28 +00:00
Jesse Wilson
8f9222cd69 Tests for FastFallbackExchangeFinder (#7047)
* Tests for FastFallbackExchangeFinder

This needed more test facets in TaskFaker.

I'm pretty happy with how the tests read.

* More tests for FastFallbackExchangeFinder.
2022-02-01 16:14:44 -05:00
Jesse Wilson
19939f6707 Reorder IP addresses for Fast Fallback (#7048)
* Reorder IP addresses for Fast Fallback

* Shut down TaskFaker after each test

It now owns an ExecutorService that should be shut down.
2022-02-01 11:51:33 -05:00
Jesse Wilson
1a2245a1a6 Rewrite TaskFaker to permit mutiple stalled tasks (#7046)
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.
2022-01-31 15:46:51 -05:00
Jesse Wilson
f15c81b4e9 HappyEyeballs (#7035)
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.
2022-01-28 11:11:05 -05:00
Jesse Wilson
d4b5c9eac8 Create TestValueFactory to reduce test case boilerplate (#7038)
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.
2022-01-28 07:35:27 -05:00
Jesse Wilson
35bb1740a4 Convert the main build.gradle file to KTS (#6925)
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.
2021-11-24 07:19:39 +00:00
Yuri Schimke
c1a6dec505 Allow Custom SSLSocketFactory without ALPN support (#6862)
* Allow Custom SSLSocketFactory without ALPN support

* Allow Custom SSLSocketFactory without ALPN support

* Revert reformatting

* Reuse delegate classes
2021-11-23 20:29:18 -05:00
Jesse Wilson
1ed9863131 Upgrade to Okio 3.0.0 (#6896) 2021-10-29 10:39:56 +03:00
Goooler
e1af67f082 Declare types & Cleanup (#6842)
* Declare types

* Code cleanup

* Declare types
2021-08-30 23:32:43 -04:00