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

Add UDS read/write error handling and tests with glide core mock. #76

Conversation

Yury-Fridlyand
Copy link

@Yury-Fridlyand Yury-Fridlyand commented Feb 6, 2024

Features:

  1. Error handling on UDS write
  2. Error handling on UDS read
  3. Glide core mock
  4. Test superclass with glide core mock
  5. Tests for error handling

Missing:

  1. Error handling on channel creation. Left TODO there. Requires significant rework of ChannelHandler.
  2. IT. Can't be reproduced in IT unfortunately.

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>

@Override
public void operationComplete(@NonNull ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {

Choose a reason for hiding this comment

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

According to https://netty.io/4.0/api/io/netty/channel/ChannelFuture.html, !isSuccess just means that the future did not complete successfully.
We should check for cause != null to determine if it failed.
In the case of isCancelled, do we feel it is necessary to terminate the client?

Copy link
Author

Choose a reason for hiding this comment

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

I added extra checks, but I have no idea how to test them. Any clue?

Signed-off-by: Yury-Fridlyand <[email protected]>
import redis_request.RedisRequestOuterClass.RedisRequest;
import response.ResponseOuterClass.Response;

public class ConnectionWithGlideMockTests extends RustCoreLibMockTestBase {

Choose a reason for hiding this comment

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

Can we add tests for InterruptedExceptions on the thread?

Copy link
Author

Choose a reason for hiding this comment

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

What should I do to get one? Kill a thread?

Choose a reason for hiding this comment

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

yes?

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>

private static ConnectionRequest createConnectionRequest() {
return ConnectionRequest.newBuilder()
.addAddresses(NodeAddress.newBuilder().setHost("dummyhost").setPort(42).build())
Copy link

Choose a reason for hiding this comment

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

Let's add a comment about why fake values are used.


// Not a public class, can't import
assertEquals(
"io.netty.channel.StacklessClosedChannelException",
Copy link

Choose a reason for hiding this comment

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

This seems brittle if Netty's version changes.

Choose a reason for hiding this comment

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

hopefully they make it public when they update?

Copy link
Author

Choose a reason for hiding this comment

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

I hope it won't happen without CI verification to catch failures.


public class RustCoreMock {

public abstract static class GlideMock {
Copy link

Choose a reason for hiding this comment

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

This could be an interface with a default isRaw() function (as well as be made into a @FunctionalInterface) to make this a bit more flexible.

Copy link
Author

Choose a reason for hiding this comment

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

Added in f4699ad

buf.release();
if (messageProcessor.isRaw()) {
ch.writeAndFlush(
Unpooled.copiedBuffer(messageProcessor.handle(bytes)));
Copy link

Choose a reason for hiding this comment

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

This has alot of nesting. Anyway it can be reduced? It's deep enough that it's pretty unreadable in GitHub's diff view.

Copy link
Author

Choose a reason for hiding this comment

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

The linter adds 4/8 spaces for each next identation.
In client side the same code is split over 5 classes, but here we have a testing tool. I decided to keep all together to avoid resolving dependencies in those classes.

Choose a reason for hiding this comment

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

@Yury-Fridlyand at least create a separate class for ChannelInboundHandlerAdapter?

Signed-off-by: Yury-Fridlyand <[email protected]>
Copy link

@acarbonetto acarbonetto left a comment

Choose a reason for hiding this comment

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

lgtm

buf.release();
if (messageProcessor.isRaw()) {
ch.writeAndFlush(
Unpooled.copiedBuffer(messageProcessor.handle(bytes)));

Choose a reason for hiding this comment

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

@Yury-Fridlyand at least create a separate class for ChannelInboundHandlerAdapter?

@Yury-Fridlyand Yury-Fridlyand merged commit 7ade9d6 into java/integ_yuryf_handle_uds_errors Feb 13, 2024
10 checks passed
@Yury-Fridlyand Yury-Fridlyand deleted the java/dev_yuryf_handle_uds_errors branch February 13, 2024 01:03
SanHalacogluImproving pushed a commit that referenced this pull request Feb 27, 2024
valkey-io#949)

Add UDS read/write error handling and tests with glide core mock. (#76)

* Add UDS read/write error handling and tests with glide core mock.

Signed-off-by: Yury-Fridlyand <[email protected]>
cyip10 pushed a commit that referenced this pull request Jun 24, 2024
valkey-io#949)

Add UDS read/write error handling and tests with glide core mock. (#76)

* Add UDS read/write error handling and tests with glide core mock.

Signed-off-by: Yury-Fridlyand <[email protected]>
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.

3 participants