-
Notifications
You must be signed in to change notification settings - Fork 37
Fix TCP client seeing "already connected" error when resend message after having exception in the first send #94
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5a75f8f
TCP Client issue fix
caowei-amazon 26fa45b
Merge branch 'emf_java_1.0' into caowei
caowei-amazon 1807393
Add session token in README.md
caowei-amazon ed829dc
Merge branch 'caowei' of github.com:awslabs/aws-embedded-metrics-java…
caowei-amazon 93d156f
Removed the slf4j-simple dependency
caowei-amazon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,50 @@ protected Socket createSocket() { | |
|
||
assertEquals(bos.toString(), message); | ||
} | ||
|
||
@Test | ||
public void testSendMessageWithGetOSException_THEN_createSocketTwice() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once this PR is merged can we also add these tests to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I believe this also apply to that |
||
Socket socket = mock(Socket.class); | ||
doNothing().when(socket).connect(any()); | ||
when(socket.getOutputStream()).thenThrow(IOException.class); | ||
|
||
Endpoint endpoint = Endpoint.DEFAULT_TCP_ENDPOINT; | ||
TCPClient client = | ||
new TCPClient(endpoint) { | ||
@Override | ||
protected Socket createSocket() { | ||
return socket; | ||
} | ||
}; | ||
|
||
TCPClient spyClient = spy(client); | ||
|
||
String message = "Test message"; | ||
spyClient.sendMessage(message); | ||
verify(spyClient, atLeast(2)).createSocket(); | ||
} | ||
|
||
@Test | ||
public void testSendMessageWithWriteOSException_THEN_createSocketTwice() throws IOException { | ||
Socket socket = mock(Socket.class); | ||
doNothing().when(socket).connect(any()); | ||
ByteArrayOutputStream bos = mock(ByteArrayOutputStream.class); | ||
when(socket.getOutputStream()).thenReturn(bos); | ||
doThrow(IOException.class).when(bos).write(any()); | ||
|
||
Endpoint endpoint = Endpoint.DEFAULT_TCP_ENDPOINT; | ||
TCPClient client = | ||
new TCPClient(endpoint) { | ||
@Override | ||
protected Socket createSocket() { | ||
return socket; | ||
} | ||
}; | ||
|
||
TCPClient spyClient = spy(client); | ||
|
||
String message = "Test message"; | ||
spyClient.sendMessage(message); | ||
verify(spyClient, atLeast(2)).createSocket(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try running integration tests with an IAM user with no session token variable set, and see if this still works?
Also, we'll want this on master later as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool. We still want to be using temporary credentials with a session token when possible, I just want to make sure it will still continue to work with long-lived credentials (if someone running the tests chooses to do that).