use of com.mysql.cj.jdbc.ha.ReplicationConnection in project aws-mysql-jdbc by awslabs.
the class ConnectionRegressionTest method getTestReplicationConnectionNoReplicas.
/**
* Internal method for tests to get a replication connection with a
* single source host to the test URL.
*
* @param sourceHost
* @param props
* @return a replication connection
* @throws Exception
*/
private ReplicationConnection getTestReplicationConnectionNoReplicas(String sourceHost, Properties props) throws Exception {
List<HostInfo> sourceHosts = new ArrayList<>();
sourceHosts.add(mainConnectionUrl.getHostOrSpawnIsolated(sourceHost));
// empty
List<HostInfo> replicaHosts = new ArrayList<>();
Map<String, String> properties = new HashMap<>();
props.stringPropertyNames().stream().forEach(k -> properties.put(k, props.getProperty(k)));
ReplicationConnection replConn = ReplicationConnectionProxy.createProxyInstance(new ReplicationConnectionUrl(sourceHosts, replicaHosts, properties));
return replConn;
}
use of com.mysql.cj.jdbc.ha.ReplicationConnection in project aws-mysql-jdbc by awslabs.
the class StatementRegressionTest method testBug78961.
/**
* Tests fix for Bug#78961 - Can't call MySQL procedure with InOut parameters in Fabric environment.
*
* Although this is a Fabric related bug we are able reproduce it using a couple of multi-host connections.
*
* @throws Exception
*/
@Test
public void testBug78961() throws Exception {
createProcedure("testBug78961", "(IN c1 FLOAT, IN c2 FLOAT, OUT h FLOAT, INOUT t FLOAT) BEGIN SET h = SQRT(c1 * c1 + c2 * c2); SET t = t + h; END;");
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
Connection highLevelConn = getLoadBalancedConnection(props);
assertTrue(highLevelConn.getClass().getName().startsWith("com.sun.proxy") || highLevelConn.getClass().getName().startsWith("$Proxy"));
Connection lowLevelConn = getSourceReplicaReplicationConnection(props);
// This simulates the behavior from Fabric connections that are causing the problem.
((ReplicationConnection) lowLevelConn).setProxy((JdbcConnection) highLevelConn);
CallableStatement cstmt = lowLevelConn.prepareCall("{CALL testBug78961 (?, ?, ?, ?)}");
cstmt.setFloat(1, 3.0f);
cstmt.setFloat(2, 4.0f);
cstmt.setFloat(4, 5.0f);
cstmt.registerOutParameter(3, Types.FLOAT);
cstmt.registerOutParameter(4, Types.FLOAT);
cstmt.execute();
assertEquals(5.0f, cstmt.getFloat(3));
assertEquals(10.0f, cstmt.getFloat(4));
}
use of com.mysql.cj.jdbc.ha.ReplicationConnection in project aws-mysql-jdbc by awslabs.
the class NonRegisteringDriverTest method testReplicationProtocolReturnsReplicationConnectionProxy.
@Test
public void testReplicationProtocolReturnsReplicationConnectionProxy() throws SQLException {
String url = "jdbc:mysql:replication://host-1:1234,host-2:1234/test";
ReplicationConnection mockReplicationProtocolConn = Mockito.mock(ReplicationConnection.class);
ConnectionUrl connUrl = ConnectionUrl.getConnectionUrlInstance(url, new Properties());
NonRegisteringDriver driver = new NonRegisteringDriver();
try (MockedStatic<ReplicationConnectionProxy> mockStaticReplicationConnectionProxy = mockStatic(ReplicationConnectionProxy.class)) {
mockStaticReplicationConnectionProxy.when(() -> ReplicationConnectionProxy.createProxyInstance(eq(connUrl))).thenReturn(mockReplicationProtocolConn);
Connection replicationConn = driver.connect(url, new Properties());
assertEquals(mockReplicationProtocolConn, replicationConn);
}
}
Aggregations