Skip to content

Commit

Permalink
Test cases stubs for failover
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Johansson committed May 7, 2015
1 parent edef9c0 commit a077f2d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/mariadb/jdbc/MySQLResultSetMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public int getScale(final int column) throws SQLException {
* @throws java.sql.SQLException if a database access error occurs
*/
public String getTableName(final int column) throws SQLException {
return getColumnInformation(column).getTable();
return getColumnInformation(column).getTable();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private String getString(int idx) {
buffer.getByteBuffer().mark();
Reader reader = new Reader(buffer);
for(int i = 0; i < idx ; i++) {
reader.skipLengthEncodedBytes();
reader.skipLengthEncodedBytes();
}
return new String(reader.getLengthEncodedBytes(),"UTF-8");
} catch (Exception e) {
Expand Down
90 changes: 90 additions & 0 deletions src/test/java/org/mariadb/jdbc/Failover.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.mariadb.jdbc;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class Failover {
//the active connection
protected Connection connection;
//default multi-host URL
protected static final String defaultUrl = "jdbc:mysql://host1,host2,host3:3306/test?user=root";
//hosts
protected String[] hosts;

@BeforeClass
public static void beforeClassFailover() {
//get the multi-host connection string
String url = System.getProperty("dbUrl", defaultUrl);
//parse the url
//TODO JDBCUrl cannot parse the multi-hosts
JDBCUrl jdbcUrl = JDBCUrl.parse(url);
//TODO store hosts in list

//TODO add support for the following url properties
//autoReconnect, maxReconnects, queriesBeforeRetryMaster, secondsBeforeRetryMaster
}

@Before
public void before() throws SQLException{
//get the new multi-host connection
//TODO use DataSource
//TODO MySQLConnection need to support multi-host
}

@Test
public void simulateConnectingToFirstHost()
{
fail("Not implemented");
}

@Test
public void simulateFailingFirstHost()
{
fail("Not implemented");
}

@Test
public void simulateTwoFirstHostsDown()
{
fail("Not implemented");
}

@Test
public void simulateAllHostsDown()
{
fail("Not implemented");
}

@Test
public void loadBalance()
{
fail("Not implemented");
}

@After
public void after() throws SQLException {
try
{
connection.close();
}
catch(Exception e)
{
logInfo(e.toString());
}
}

// common function for logging information
static void logInfo(String message)
{
System.out.println(message);
}
}

0 comments on commit a077f2d

Please sign in to comment.