use of com.mysql.cj.jdbc.ha.ReplicationConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testReplicationConnectWithNoSource.
@Test
public void testReplicationConnectWithNoSource() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.retriesAllDown.getKeyName(), "3");
props.setProperty(PropertyKey.allowSourceDownConnections.getKeyName(), "true");
Set<String> downedHosts = new HashSet<>();
downedHosts.add("first");
ReplicationConnection conn2 = this.getUnreliableReplicationConnection(new String[] { "first", "second", "third" }, props, downedHosts);
assertTrue(conn2.isReadOnly());
assertFalse(conn2.isSourceConnection());
try {
conn2.createStatement().execute("SELECT 1");
} catch (SQLException e) {
fail("Should not fail to execute SELECT statements!");
}
UnreliableSocketFactory.flushAllStaticData();
conn2.setReadOnly(false);
assertFalse(conn2.isReadOnly());
assertTrue(conn2.isSourceConnection());
try {
conn2.createStatement().execute("DROP TABLE IF EXISTS testRepTable");
conn2.createStatement().execute("CREATE TABLE testRepTable (a INT)");
conn2.createStatement().execute("INSERT INTO testRepTable VALUES (1)");
conn2.createStatement().execute("DROP TABLE IF EXISTS testRepTable");
} catch (SQLException e) {
fail("Should not fail to execute CREATE/INSERT/DROP statements.");
}
}
use of com.mysql.cj.jdbc.ha.ReplicationConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug22643.
/**
* Test of a new feature to fix BUG 22643, specifying a "validation query" in your connection pool that starts with "slash-star ping slash-star" _exactly_
* will cause the driver to " + instead send a ping to the server (much lighter weight), and when using a ReplicationConnection or a LoadBalancedConnection,
* will send the ping across all active connections.
*
* @throws Exception
*/
@Test
public void testBug22643() throws Exception {
checkPingQuery(this.conn);
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
Connection replConnection = getSourceReplicaReplicationConnection(props);
try {
checkPingQuery(replConnection);
} finally {
if (replConnection != null) {
replConnection.close();
}
}
Connection lbConn = getLoadBalancedConnection(props);
try {
checkPingQuery(lbConn);
} finally {
if (lbConn != null) {
lbConn.close();
}
}
}
use of com.mysql.cj.jdbc.ha.ReplicationConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug68763.
/**
* Tests fix for BUG#68763, ReplicationConnection.isSourceConnection() returns false always
*
* @throws Exception
* if the test fails.
*/
@Test
public void testBug68763() throws Exception {
ReplicationConnection replConn = null;
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
replConn = (ReplicationConnection) getSourceReplicaReplicationConnection(props);
replConn.setReadOnly(true);
assertFalse(replConn.isSourceConnection(), "isSourceConnection() should be false for replica connection");
replConn.setReadOnly(false);
assertTrue(replConn.isSourceConnection(), "isSourceConnection() should be true for source connection");
}
use of com.mysql.cj.jdbc.ha.ReplicationConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testReplicationConnectionNoReplicasRemainOnSource.
/**
* Test that we remain on the source when:
* - the connection is not in read-only mode
* - no replicas are configured
* - a new replica is added
*
* @throws Exception
*/
@Test
public void testReplicationConnectionNoReplicasRemainOnSource() throws Exception {
Properties props = getPropertiesFromTestsuiteUrl();
props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
String sourceHost = props.getProperty(PropertyKey.HOST.getKeyName()) + ":" + props.getProperty(PropertyKey.PORT.getKeyName());
Properties props2 = getHostFreePropertiesFromTestsuiteUrl();
props2.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props2.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
ReplicationConnection replConn = getTestReplicationConnectionNoReplicas(sourceHost, props2);
Statement s = replConn.createStatement();
ResultSet rs1 = s.executeQuery("select CONNECTION_ID()");
assertTrue(rs1.next());
int sourceConnectionId = rs1.getInt(1);
rs1.close();
s.close();
// add a replica and make sure we are NOT on a new connection
replConn.addReplicaHost(sourceHost);
s = replConn.createStatement();
rs1 = s.executeQuery("select CONNECTION_ID()");
assertTrue(rs1.next());
assertEquals(sourceConnectionId, rs1.getInt(1));
assertFalse(replConn.isReadOnly());
rs1.close();
s.close();
}
use of com.mysql.cj.jdbc.ha.ReplicationConnection in project JavaSegundasQuintas by ecteruel.
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;
}
Aggregations