Skip to content

MINOR: Cleanup redundancies in BaseRequestTest#7735

Merged
hachikuji merged 7 commits into
apache:trunkfrom
hachikuji:cleanup-base-request-test
Dec 5, 2019
Merged

MINOR: Cleanup redundancies in BaseRequestTest#7735
hachikuji merged 7 commits into
apache:trunkfrom
hachikuji:cleanup-base-request-test

Conversation

@hachikuji

Copy link
Copy Markdown
Contributor

This patch eliminates a lot of redundancy and general messiness around the usage of BaseRequestTest and specifically response deserialization.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Comment thread core/src/test/scala/unit/kafka/server/BaseRequestTest.scala Outdated
@hachikuji hachikuji force-pushed the cleanup-base-request-test branch 2 times, most recently from 902502c to 5063081 Compare November 22, 2019 19:54
@hachikuji hachikuji force-pushed the cleanup-base-request-test branch from 04e6304 to 275d34b Compare November 23, 2019 06:09
@ijuma ijuma self-assigned this Nov 24, 2019

@ijuma ijuma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Nice clean-up. A few minor comments.

socket.setSoTimeout(1000)
try {
val response = sendAndReceive(produceRequest, ApiKeys.PRODUCE, socket)
assertEquals(0, response.remaining)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need this assertion anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion was actually never getting executed. The call to sendAndReceive raises a timeout exception, which is what verifyMaxConnections is looking for.

import org.apache.kafka.common.protocol.ApiKeys
import org.apache.kafka.common.requests.{ApiVersionsRequest, ApiVersionsResponse}

abstract class AbstractApiVersionsRequestTest extends BaseRequestTest {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this abstract base class worth it? We could either add this single method to BaseRequestTest or TestUtils.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit more justifiable if we take the validateApiVersionsResponse method out of the ApiVersionsRequestTest companion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move this method to the companion? Nice to avoid long inheritance hierarchies.

@hachikuji hachikuji Nov 26, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could but it's a little more awkward since it requires an instance of BaseRequestTest. We could also add it to BaseRequestTest, but I was hoping to keep that class generic and to avoid leaking a bunch of api-specific noise into it.

protected def error(error: Errors, errorMessage: Option[String] = None): ApiError =
new ApiError(error, errorMessage.orNull)

protected def toStructWithDuplicateFirstTopic(request: CreateTopicsRequest): Struct = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that this is no longer used. Do you know if we are still testing the case where we have a duplicate topic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tracked the removal of the uses of this method back to this: e2e8bdb#diff-217dea05d3ff55c8bf10503c329f7c2b. I don't see a clear reason for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmccabe do you remember why the test was removed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateTopicsRequest was the first RPC converted over to automatic generation, if I remember correctly. I converted it while writing the generator.

I think when the automatic code generation was first developed, it didn't have support for multiple identical elements in the same map. So it wasn't possible to serialize the invalid request at that point. So I had to remove this test. Later on I added support for duplicate entries in the same map.

We should definitely re-add a test for duplicate createTopics elements. There should also be a test like this in KafkaAdminClientTest to test the admin client's handling of it (AC should not allow this to even get to the server)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we file a JIRA please?

@@ -65,21 +65,20 @@ class ApiVersionsRequestTest extends BaseRequestTest {
@Test
def testApiVersionsRequestValidationV0(): Unit = {
val apiVersionsRequest = new ApiVersionsRequest.Builder().build( 0.asInstanceOf[Short])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing issue, but empty space before 0 should be removed.

connectAndReceive[DeleteTopicsResponse](request, destination = socketServer)
}

private def sendMetadataRequest(request: MetadataRequest): MetadataResponse = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it even worth having this method? There are a few other examples like that in other classes.

}
}

private def responseThrottleTime(apiKey: ApiKeys, response: Struct): Int = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see this go. I had done something similar in https://github.com/apache/kafka/pull/7409/files#diff-8259941614685619733d9f458762a0b6L564, but hadn't gotten around to pushing that PR over the line.

apiVersion: Short,
clientId: String = "client-id",
correlationIdOpt: Option[Int] = None
): RequestHeader = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is a bit unusual, any reason for it not to be on the previous line?

@Test
def testApiVersionsRequestBeforeSaslHandshakeRequest(): Unit = {
val plaintextSocket = connect(protocol = securityProtocol)
val plaintextSocket = connect()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename this to socket as the current name is a bit misleading. Same for the other methods.

@zhengb0

zhengb0 commented Dec 4, 2019

Copy link
Copy Markdown

I'm sorry, I'm not careful

@ijuma ijuma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hachikuji

Copy link
Copy Markdown
Contributor Author

retest this please

2 similar comments
@hachikuji

Copy link
Copy Markdown
Contributor Author

retest this please

@hachikuji

Copy link
Copy Markdown
Contributor Author

retest this please

@hachikuji hachikuji merged commit eaccb92 into apache:trunk Dec 5, 2019
gitlw pushed a commit to linkedin/kafka that referenced this pull request Sep 9, 2021
…Test (apache#7735)

This patch eliminates some redundancy and general messiness around the usage of `BaseRequestTest` and specifically response deserialization.

Reviewers: Ismael Juma <ismael@juma.me.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants