-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat: enable setting ipType connection option for r2dbc drivers #937
Conversation
d4c6581
to
4d4a259
Compare
8a0ffdb
to
735f2cf
Compare
d5263a3
to
0b322d1
Compare
* Returns preferred ip address that can be used to establish Cloud SQL connection. | ||
*/ | ||
public static String getHostIp(String csqlInstanceName, String ipTypes) | ||
throws IOException { |
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.
nit: can we move this up to the signature line?
*/ | ||
public static String getHostIp(String csqlInstanceName) throws IOException { | ||
public static String getHostIp(String csqlInstanceName) | ||
throws IOException { |
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.
nit: move this up a line
r2dbc/core/pom.xml
Outdated
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.1</version> |
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.
4.13.2
pom.xml
Outdated
@@ -273,9 +273,9 @@ | |||
com.google.guava:guava | |||
|
|||
Global test dependencies unused in r2dbc core (no tests currently): |
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 we update this comment since we have tests now?
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.
In fact, the first junit package could probably be deleted.
public class GcpConnectionFactoryProviderTest { | ||
|
||
static final String PUBLIC_IP = "127.0.0.1"; | ||
static final String PRIVATE_IP = "127.0.0.2"; |
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.
Nit: 10.0.0.1
is a more private-like IP address.
</dependency> | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcpkix-jdk15on</artifactId> |
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.
What does this dependency do?
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.
This is necessary to create the fake ephemeral cert that the coreSocketFactoryStub
uses.
pom.xml
Outdated
@@ -273,9 +273,9 @@ | |||
com.google.guava:guava | |||
|
|||
Global test dependencies unused in r2dbc core (no tests currently): | |||
junit:junit,com.google.truth:truth | |||
junit:junit,com.google.truth:truth, org.bouncycastle:bcpkix-jdk15on |
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.
I suppose this plugin can't see that you are using this dep in test, can it?
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.
yeah the plugin throws errors that it's an unused dependency, but we have to include it in the test suites that subclass GcpConnectionFactoryProviderTest
or else we get ClassNotFound errors
|
||
@Test | ||
public void setsCorrectOptionsForDriverHostAndPortPrivate() { | ||
try (MockedStatic<CoreSocketFactory> mockSocketFactory = Mockito.mockStatic( |
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.
We we pull this duplicated setup into a shared function, passing in the assertions maybe?
@shubha-rajan can we split this PR up? It's pretty big. A few ideas:
|
Sure |
c3d240b
to
a325f52
Compare
mockSocketFactory.when(() -> CoreSocketFactory.getSslData(fakeInstanceName)) | ||
.thenReturn(coreSocketFactoryStub.getCloudSqlInstance(fakeInstanceName).getSslData()); | ||
|
||
mockSocketFactory.when(() -> CoreSocketFactory.getHostIp(fakeInstanceName, "PRIVATE")) |
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.
How does this line differ from the line below?
1ed1463
to
16c3265
Compare
Currently there is no way to use the R2DBC connectors and specify IP Type, which is a glaring feature gap. This PR adds support for setting IP type when configuring an R2DBC connection factory and adds tests to make sure the right IP address is being used.
Lots of testing boilerplate here, but the relevant files to look at are:
CoreSocketFactory.java
GcpConnectionFactoryProvider.java
CloudSqlConnectionFactory.java
GcpConnectionFactoryProviderMysqlTest.java
(for the test)Also added
GcpConnectionFactoryProviderTest.java
which is mostly just providing a stub for the CoreSocketFactory which can be used in tests that extend the class