Search in sources :

Example 6 with DataNodesStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus in project cobar by alibaba.

the class TestDataNodes method testSwitchIndex.

/*
     * test has suspect that there are no dataNodes with duplicated poolName
     * first test switch @@dataSource poolName, then test switch @@dataSource poolName:index
     */
@Test
public void testSwitchIndex() {
    String testDataNode = null;
    boolean resultSwitch = false;
    int indexBeforeSwitch = 0;
    int indexAfterSwitch = 0;
    int dataSourceNumOfTestDataNode = 0;
    dataNodeStatusList = cobarAdapter.listDataNodes();
    //test first dataNode with multi-dataSources or last dataNode with single dataSource
    for (DataNodesStatus dataNodeStatus : dataNodeStatusList) {
        testDataNode = dataNodeStatus.getPoolName();
        indexBeforeSwitch = dataNodeStatus.getIndex();
        String[] dataSources = dataNodeStatus.getDataSource().split(",");
        dataSourceNumOfTestDataNode = dataSources.length;
        if (dataSourceNumOfTestDataNode > 1) {
            resultSwitch = true;
            break;
        }
    }
    Assert.assertNotNull(testDataNode);
    //switch @@dataSource poolName
    try {
        sCobarNode.excuteSQL(managerConnection, "switch @@dataSource " + testDataNode);
    } catch (SQLException e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    }
    DataNodesStatus testDataNodeStatus = this.getDataNodeStatus(testDataNode);
    Assert.assertNotNull(testDataNodeStatus);
    indexAfterSwitch = testDataNodeStatus.getIndex();
    if (resultSwitch) {
        Assert.assertTrue(indexBeforeSwitch != indexAfterSwitch);
    } else {
        Assert.assertTrue(indexBeforeSwitch == indexAfterSwitch);
    }
    //switch @@dataSource poolName:index
    try {
        sCobarNode.excuteSQL(managerConnection, "switch @@dataSource " + testDataNode + " : " + indexBeforeSwitch);
    } catch (SQLException e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    }
    testDataNodeStatus = this.getDataNodeStatus(testDataNode);
    Assert.assertNotNull(testDataNodeStatus);
    indexAfterSwitch = testDataNodeStatus.getIndex();
    Assert.assertTrue(indexBeforeSwitch == indexAfterSwitch);
}
Also used : DataNodesStatus(com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 7 with DataNodesStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus in project cobar by alibaba.

the class TestDataNodes method testExcute.

@Test
public void testExcute() {
    String testDataNode = "ddl_test";
    dataNodeStatusList = cobarAdapter.listDataNodes();
    DataNodesStatus testDNStatusBefore = getDataNodeStatus(testDataNode);
    Assert.assertNotNull(testDNStatusBefore);
    try {
        sCobarNode.excuteSQL(dmlConnection, "show tables");
    } catch (SQLException e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    }
    DataNodesStatus testDNStatusAfter = getDataNodeStatus(testDataNode);
    Assert.assertNotNull(testDNStatusAfter);
    Assert.assertEquals(testDNStatusBefore.getExecuteCount() + 1, testDNStatusAfter.getExecuteCount());
}
Also used : DataNodesStatus(com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)7 SQLException (java.sql.SQLException)4 Test (org.junit.Test)4 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)1 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)1 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)1 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)1 IOException (java.io.IOException)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 JSONObject (net.sf.json.JSONObject)1 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1