Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare to enable Spotless #8179

Merged
merged 2 commits into from
Jan 7, 2024
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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ class ExtensionLifecycleTest {
@RegisterExtension
val clientTestRule: OkHttpClientTestRule = OkHttpClientTestRule()

lateinit var _server: MockWebServer
lateinit var setUpServer: MockWebServer

@BeforeEach
fun setup(server: MockWebServer) {
_server = server
this.setUpServer = server
assertThat(server.started).isTrue()
server.enqueue(MockResponse())
}

@AfterEach
fun tearDown(server: MockWebServer) {
assertThat(_server).isSameAs(server)
assertThat(setUpServer).isSameAs(server)
assertThat(server.started).isTrue()
server.enqueue(MockResponse())
}

@Test
fun testClient(server: MockWebServer) {
assertThat(_server).isSameAs(server)
assertThat(setUpServer).isSameAs(server)
assertThat(server.started).isTrue()
clientTestRule.newClient().newCall(Request(server.url("/"))).execute().use {
assertThat(it.code).isEqualTo(200)
Expand Down
43 changes: 22 additions & 21 deletions mockwebserver/src/main/kotlin/mockwebserver3/MockResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,30 @@ class MockResponse {
internal var trailers: Headers.Builder

// At most one of (body,webSocketListener,streamHandler) is non-null.
private var body_: MockResponseBody? = null
private var streamHandler_: StreamHandler? = null
private var webSocketListener_: WebSocketListener? = null
private var bodyVar: MockResponseBody? = null
private var streamHandlerVar: StreamHandler? = null
private var webSocketListenerVar: WebSocketListener? = null

var body: MockResponseBody?
get() = body_
get() = bodyVar
set(value) {
body_ = value
streamHandler_ = null
webSocketListener_ = null
bodyVar = value
streamHandlerVar = null
webSocketListenerVar = null
}
var streamHandler: StreamHandler?
get() = streamHandler_
get() = streamHandlerVar
set(value) {
streamHandler_ = value
body_ = null
webSocketListener_ = null
streamHandlerVar = value
bodyVar = null
webSocketListenerVar = null
}
var webSocketListener: WebSocketListener?
get() = webSocketListener_
get() = webSocketListenerVar
set(value) {
webSocketListener_ = value
body_ = null
streamHandler_ = null
webSocketListenerVar = value
bodyVar = null
streamHandlerVar = null
}

var throttleBytesPerPeriod: Long
Expand All @@ -185,9 +186,9 @@ class MockResponse {
this.inTunnel = false
this.informationalResponses = mutableListOf()
this.status = "HTTP/1.1 200 OK"
this.body_ = null
this.streamHandler_ = null
this.webSocketListener_ = null
this.bodyVar = null
this.streamHandlerVar = null
this.webSocketListenerVar = null
this.headers = Headers.Builder()
.add("Content-Length", "0")
this.trailers = Headers.Builder()
Expand All @@ -206,9 +207,9 @@ class MockResponse {
this.status = mockResponse.status
this.headers = mockResponse.headers.newBuilder()
this.trailers = mockResponse.trailers.newBuilder()
this.body_ = mockResponse.body
this.streamHandler_ = mockResponse.streamHandler
this.webSocketListener_ = mockResponse.webSocketListener
this.bodyVar = mockResponse.body
this.streamHandlerVar = mockResponse.streamHandler
this.webSocketListenerVar = mockResponse.webSocketListener
this.throttleBytesPerPeriod = mockResponse.throttleBytesPerPeriod
this.throttlePeriodNanos = mockResponse.throttlePeriodNanos
this.socketPolicy = mockResponse.socketPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ class MockWebServer : Closeable {
random = SecureRandom(),
pingIntervalMillis = 0,
extensions = WebSocketExtensions.parse(webSocketResponse.headers),
minimumDeflateSize = 0L // Compress all messages if compression is enabled.
// Compress all messages if compression is enabled.
minimumDeflateSize = 0L,
)
val name = "MockWebServer WebSocket ${request.path!!}"
webSocket.initReaderAndWriter(name, streams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ val avoidedTests = setOf(
"okhttp3.internal.platform.PlatformTest",
"okhttp3.internal.platform.android.AndroidSocketAdapterTest",
"okhttp3.osgi.OsgiTest",
"okhttp3.CookiesTest", // hanging
"okhttp3.WholeOperationTimeoutTest", // hanging
// Hanging.
"okhttp3.CookiesTest",
// Hanging.
"okhttp3.WholeOperationTimeoutTest",
)

/**
Expand All @@ -49,4 +51,4 @@ fun main() {
.sorted()
.distinct()
knownTestFile.writeText(testClasses.joinToString("\n"))
}
}
2 changes: 1 addition & 1 deletion okcurl/src/main/kotlin/okhttp3/curl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.github.ajalt.clikt.parameters.options.multiple
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.int
import java.security.cert.X509Certificate
import java.util.*
import java.util.Properties
import java.util.concurrent.TimeUnit.SECONDS
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.SSLSocketFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("ktlint:standard:filename")
package okhttp3.curl.internal

import java.io.IOException
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import org.junit.jupiter.params.provider.ArgumentsSource

/**
* Tests for round-tripping headers through hpack.
*
* TODO: update hpack-test-case with the output of our encoder.
* This test will hide complementary bugs in the encoder and decoder,
* We should test that the encoder is producing responses that are
*/
// TODO: update hpack-test-case with the output of our encoder.
// This test will hide complementary bugs in the encoder and decoder,
// We should test that the encoder is producing responses that are
class HpackRoundTripTest : HpackDecodeTestBase() {
internal class StoriesTestProvider : SimpleProvider() {
override fun arguments(): List<Any> = createStories(RAW_DATA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,21 @@ class SimpleIdnaMappingTable internal constructor(


private val optionsDelimiter = Options.of(
".".encodeUtf8(), // 0.
" ".encodeUtf8(), // 1.
";".encodeUtf8(), // 2.
"#".encodeUtf8(), // 3.
"\n".encodeUtf8(), // 4.
// 0.
".".encodeUtf8(),
// 1.
" ".encodeUtf8(),
// 2.
";".encodeUtf8(),
// 3.
"#".encodeUtf8(),
// 4.
"\n".encodeUtf8(),
)

private val optionsDot = Options.of(
".".encodeUtf8(), // 0.
// 0.
".".encodeUtf8(),
)

private const val DELIMITER_DOT = 0
Expand All @@ -97,13 +103,20 @@ private const val DELIMITER_HASH = 3
private const val DELIMITER_NEWLINE = 4

private val optionsType = Options.of(
"deviation ".encodeUtf8(), // 0.
"disallowed ".encodeUtf8(), // 1.
"disallowed_STD3_mapped ".encodeUtf8(), // 2.
"disallowed_STD3_valid ".encodeUtf8(), // 3.
"ignored ".encodeUtf8(), // 4.
"mapped ".encodeUtf8(), // 5.
"valid ".encodeUtf8(), // 6.
// 0.
"deviation ".encodeUtf8(),
// 1.
"disallowed ".encodeUtf8(),
// 2.
"disallowed_STD3_mapped ".encodeUtf8(),
// 3.
"disallowed_STD3_valid ".encodeUtf8(),
// 4.
"ignored ".encodeUtf8(),
// 5.
"mapped ".encodeUtf8(),
// 6.
"valid ".encodeUtf8(),
)

internal const val TYPE_DEVIATION = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,14 @@ class HttpLoggingInterceptor @JvmOverloads constructor(
val contentLength = responseBody.contentLength()
val bodySize = if (contentLength != -1L) "$contentLength-byte" else "unknown-length"
logger.log(
"<-- ${response.code}${if (response.message.isEmpty()) "" else ' ' + response.message} ${response.request.url} (${tookMs}ms${if (!logHeaders) ", $bodySize body" else ""})")
buildString {
append("<-- ${response.code}")
if (response.message.isNotEmpty()) append(" ${response.message}")
append(" ${response.request.url} (${tookMs}ms")
if (!logHeaders) append(", $bodySize body")
append(")")
}
)

if (logHeaders) {
val headers = response.headers
Expand Down Expand Up @@ -287,11 +294,13 @@ class HttpLoggingInterceptor @JvmOverloads constructor(
logger.log(buffer.clone().readString(charset))
}

if (gzippedLength != null) {
logger.log("<-- END HTTP (${totalMs}ms, ${buffer.size}-byte, $gzippedLength-gzipped-byte body)")
} else {
logger.log("<-- END HTTP (${totalMs}ms, ${buffer.size}-byte body)")
}
logger.log(
buildString {
append("<-- END HTTP (${totalMs}ms, ${buffer.size}-byte")
if (gzippedLength != null) append(", $gzippedLength-gzipped-byte")
append(" body)")
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.RegisterExtension

@ExtendWith(MockWebServerExtension::class)
@Suppress("ktlint:standard:max-line-length")
class LoggingEventListenerTest {
@RegisterExtension
val platform = PlatformRule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package okhttp3
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.lang.AssertionError
import java.lang.reflect.InvocationTargetException
import java.net.*
import java.net.InetAddress
import java.net.SocketAddress
import java.net.SocketException
import java.nio.channels.SocketChannel
import java.util.function.BiFunction
import javax.net.ssl.HandshakeCompletedListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,24 @@ class OkHttpClientTestRule : BeforeEachCallback, AfterEachCallback {
var recordFrames = false
var recordSslDebug = false

private val sslExcludeFilter = "^(?:Inaccessible trust store|trustStore is|Reload the trust store|Reload trust certs|Reloaded|adding as trusted certificates|Ignore disabled cipher suite|Ignore unsupported cipher suite).*".toRegex()
private val sslExcludeFilter = Regex(
buildString {
append("^(?:")
append(
listOf(
"Inaccessible trust store",
"trustStore is",
"Reload the trust store",
"Reload trust certs",
"Reloaded",
"adding as trusted certificates",
"Ignore disabled cipher suite",
"Ignore unsupported cipher suite",
).joinToString(separator = "|")
)
append(").*")
}
)

private val testLogHandler = object : Handler() {
override fun publish(record: LogRecord) {
Expand Down Expand Up @@ -139,7 +156,12 @@ class OkHttpClientTestRule : BeforeEachCallback, AfterEachCallback {
val taskRunner = TaskRunner(backend)

OkHttpClient.Builder()
.connectionPool(buildConnectionPool(connectionListener = connectionListener, taskRunner = taskRunner))
.connectionPool(
buildConnectionPool(
connectionListener = connectionListener,
taskRunner = taskRunner,
)
)
.dispatcher(Dispatcher(backend.executor))
.taskRunnerInternal(taskRunner)
} else {
Expand All @@ -150,7 +172,9 @@ class OkHttpClientTestRule : BeforeEachCallback, AfterEachCallback {
private fun loomThreadFactory(): ThreadFactory {
val ofVirtual = Thread::class.java.getMethod("ofVirtual").invoke(null)

return Class.forName("java.lang.Thread\$Builder").getMethod("factory").invoke(ofVirtual) as ThreadFactory
return Class.forName("java.lang.Thread\$Builder")
.getMethod("factory")
.invoke(ofVirtual) as ThreadFactory
}

private fun isLoom(): Boolean {
Expand Down
Loading