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);
}
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());
}
Aggregations