milamberspace commented on code in PR #6859:
URL: https://github.com/apache/jmeter/pull/6859#discussion_r4653436871


##########
src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/AccessLogSamplerTest.kt:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.http.sampler
+
+import com.github.tomakehurst.wiremock.client.WireMock.aResponse
+import com.github.tomakehurst.wiremock.client.WireMock.equalTo
+import com.github.tomakehurst.wiremock.client.WireMock.get
+import com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor
+import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
+import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
+import com.github.tomakehurst.wiremock.junit5.WireMockTest
+import org.apache.jmeter.junit.JMeterTestCase
+import org.junit.jupiter.api.Assertions.assertNotNull
+import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.CsvSource
+import java.beans.Introspector
+import java.nio.file.Path
+import kotlin.io.path.writeText
+
+@WireMockTest
+class AccessLogSamplerTest : JMeterTestCase() {
+    @TempDir
+    lateinit var dir: Path
+
+    @Test
+    fun `implementation is exposed as a test bean property`() {
+        val property = Introspector.getBeanInfo(AccessLogSampler::class.java)
+            .propertyDescriptors
+            .singleOrNull { it.name == "implementation" }
+
+        assertNotNull(property?.readMethod)
+        assertNotNull(property?.writeMethod)
+    }
+
+    @ParameterizedTest
+    @CsvSource(
+        "Java,true,keep-alive",
+        "Java,false,close",
+        "HttpClient4,true,keep-alive",
+        "HttpClient4,false,close",
+        "HttpClient5,true,keep-alive",
+        "HttpClient5,false,close",
+    )
+    fun `selected implementation honors keep alive`(
+        implementation: String,
+        keepAlive: Boolean,
+        expectedConnection: String,
+        server: WireMockRuntimeInfo,
+    ) {
+        val sampler = createSampler(server).apply {
+            setImplementation(implementation)
+            setUseKeepAlive(keepAlive)
+        }
+
+        try {
+            assertSamplesAndConnectionHeaders(sampler, server, 
expectedConnection)
+        } finally {
+            sampler.testEnded()
+        }
+    }
+
+    @Test
+    fun `missing implementation and keep alive settings keep legacy 
defaults`(server: WireMockRuntimeInfo) {
+        val sampler = createSampler(server)
+
+        try {
+            assertSamplesAndConnectionHeaders(sampler, server, "close")
+        } finally {
+            sampler.testEnded()
+        }
+    }
+
+    private fun createSampler(server: WireMockRuntimeInfo): AccessLogSampler {
+        
server.wireMock.register(get("/one").willReturn(aResponse().withStatus(200)))
+        
server.wireMock.register(get("/two").willReturn(aResponse().withStatus(200)))
+
+        val logFile = dir.resolve("access.log")
+        logFile.writeText(
+            """
+            127.0.0.1 - - [21/Oct/2003:05:37:21 -0500] "GET /one HTTP/1.1" 200 
10
+            127.0.0.1 - - [21/Oct/2003:05:37:22 -0500] "GET /two HTTP/1.1" 200 
10
+            """.trimIndent(),
+        )
+        return AccessLogSampler().apply {
+            setLogFile(logFile.toString())
+            setParserClassName(AccessLogSampler.DEFAULT_CLASS)
+            setDomain("localhost")
+            setPortString(server.httpPort.toString())
+        }
+    }
+
+    private fun assertSamplesAndConnectionHeaders(
+        sampler: AccessLogSampler,
+        server: WireMockRuntimeInfo,
+        expectedConnection: String,
+    ) {
+        assertTrue(sampler.sampleWithParser().isSuccessful)
+        assertTrue(sampler.sampleWithParser().isSuccessful)
+
+        server.wireMock.verifyThat(
+            getRequestedFor(urlEqualTo("/one")).withHeader("Connection", 
equalTo(expectedConnection)),

Review Comment:
   The `Java` implementation also sends `Connection: keep-alive`/`close` 
depending on `useKeepAlive`, so these assertions would pass even if the sampler 
never delegated to HC4/HC5. Please add something implementation-specific, for 
instance on the default `User-Agent`:
   
   ```kotlin
   // expectedUserAgent: "Java/.*", "Apache-HttpClient/4.*" or 
"Apache-HttpClient/5.*"
   server.wireMock.verifyThat(
       getRequestedFor(urlEqualTo("/one")).withHeader("User-Agent", 
matching(expectedUserAgent)),
   )
   ```



##########
src/core/src/main/java/org/apache/jmeter/util/PropertiesBasedPrefixResolver.java:
##########
@@ -36,7 +36,9 @@
 
 /**
  * {@link PrefixResolver} implementation that loads prefix configuration from 
jmeter property xpath.namespace.config
+ * @deprecated This Xalan-based class is scheduled for removal.
  */
+@Deprecated(since = "6.0", forRemoval = true)

Review Comment:
   This change (and those in `PropertiesBasedPrefixResolverForXpath2`, 
`XPathUtil`, plus the Xalan entry and contributor line in `changes.xml`) 
belongs to #6856, not to this PR. Could you rebase on `master` and drop the 
`#6591` commits?



##########
xdocs/changes.xml:
##########
@@ -95,6 +95,7 @@ Summary
     <li><issue>6250</issue>Avoid adding "; charset=" automatically to 
<code>multipart/form-data</code> requests to align behavior with modern HTTP 
clients.</li>
     <li><issue>6080</issue>Preserve the original HTTP method when following 
307 and 308 redirects according to the HTTP specification. Contributed by 
LeeJiWon (github.com/dlwldnjs1009)</li>
     <li><issue>6267</issue><pr>6268</pr>Add a space between key and value 
after <code>:</code> in View Results Tree &gt; Sampler result tab for better 
readability.</li>
+    <li><issue>6461</issue>Allow the Access Log Sampler to select the 
<code>Java</code>, <code>HttpClient4</code>, or <code>HttpClient5</code> 
implementation. The default remains <code>Java</code> with keep-alive disabled 
for backward compatibility.</li>

Review Comment:
   Please add `<pr>6859</pr>` and mention the new *Use Keep-Alive* option, e.g.:
   
   ```suggestion
       <li><issue>6461</issue><pr>6859</pr>Allow the Access Log Sampler to 
select the <code>Java</code>, <code>HttpClient4</code>, or 
<code>HttpClient5</code> implementation and to use keep-alive connections. The 
defaults remain <code>Java</code> with keep-alive disabled for backward 
compatibility.</li>
   ```



##########
src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/AccessLogSamplerTest.kt:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.http.sampler
+
+import com.github.tomakehurst.wiremock.client.WireMock.aResponse
+import com.github.tomakehurst.wiremock.client.WireMock.equalTo
+import com.github.tomakehurst.wiremock.client.WireMock.get
+import com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor
+import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
+import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
+import com.github.tomakehurst.wiremock.junit5.WireMockTest
+import org.apache.jmeter.junit.JMeterTestCase
+import org.junit.jupiter.api.Assertions.assertNotNull
+import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.CsvSource
+import java.beans.Introspector
+import java.nio.file.Path
+import kotlin.io.path.writeText
+
+@WireMockTest
+class AccessLogSamplerTest : JMeterTestCase() {
+    @TempDir
+    lateinit var dir: Path
+
+    @Test
+    fun `implementation is exposed as a test bean property`() {
+        val property = Introspector.getBeanInfo(AccessLogSampler::class.java)
+            .propertyDescriptors
+            .singleOrNull { it.name == "implementation" }
+
+        assertNotNull(property?.readMethod)
+        assertNotNull(property?.writeMethod)
+    }
+
+    @ParameterizedTest
+    @CsvSource(
+        "Java,true,keep-alive",
+        "Java,false,close",
+        "HttpClient4,true,keep-alive",
+        "HttpClient4,false,close",
+        "HttpClient5,true,keep-alive",
+        "HttpClient5,false,close",
+    )
+    fun `selected implementation honors keep alive`(
+        implementation: String,
+        keepAlive: Boolean,
+        expectedConnection: String,
+        server: WireMockRuntimeInfo,
+    ) {
+        val sampler = createSampler(server).apply {
+            setImplementation(implementation)
+            setUseKeepAlive(keepAlive)
+        }
+
+        try {
+            assertSamplesAndConnectionHeaders(sampler, server, 
expectedConnection)
+        } finally {
+            sampler.testEnded()

Review Comment:
   Nit: `threadFinished()` should also be called here (and below), otherwise 
the HC4/HC5 clients created for this thread are not closed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to