88import com .xxdb .io .LittleEndianDataOutputStream ;
99import com .xxdb .io .Long2 ;
1010import com .xxdb .io .ProgressListener ;
11- import com .xxdb .route .AutoFitTableUpsert ;
12- import com .xxdb .streaming .client .Site ;
1311import org .junit .*;
14- import org .slf4j .Logger ;
15- import org .slf4j .LoggerFactory ;
1612
1713import java .io .*;
1814import java .lang .reflect .*;
1915import java .math .BigDecimal ;
2016import java .net .*;
21- import java .sql .*;
22- import java .sql .Array ;
2317import java .text .SimpleDateFormat ;
2418import java .time .*;
2519import java .util .*;
3428
3529public class DBConnectionTest {
3630
37-
3831 private DBConnection conn ;
3932 static ResourceBundle bundle = ResourceBundle .getBundle ("com/xxdb/setup/settings" );
4033 static String HOST = bundle .getString ("HOST" );
@@ -77,7 +70,6 @@ static void compareBasicTable(BasicTable table, BasicTable newTable)
7770
7871 }
7972 }
80-
8173 }
8274 @ Before
8375 public void setUp () throws IOException {
@@ -4590,169 +4582,8 @@ public void TestConnectWithoutUserid() throws IOException, InterruptedException
45904582 sleep (500 );
45914583 assertEquals (true , conn .isConnected ());
45924584 }
4593- @ Test
4594- public void Test_connect_EnableHighAvailability_false () throws IOException , InterruptedException {
4595- DBConnection conn = new DBConnection ();
4596- conn .connect (HOST ,CONTROLLER_PORT ,"admin" ,"123456" ,null ,false );
4597- DBConnection conn1 = new DBConnection ();
4598- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
4599- BasicString nodeAliasTmp = (BasicString )conn1 .run ("getNodeAlias()" );
4600- String nodeAlias = nodeAliasTmp .getString ();
4601- try {
4602- conn .run ("stopDataNode(\" " +nodeAlias +"\" )" );
4603- }catch (Exception ex )
4604- {
4605- System .out .println (ex );
4606- }
4607- sleep (5000 );
4608- //DBConnection conn1 = new DBConnection();
4609- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
4610- sleep (500 );
4611- String e = null ;
4612- try {
4613- conn1 .run ("a=1;\n a" );
4614- }catch (Exception ex )
4615- {
4616- e = ex .getMessage ();
4617- System .out .println (ex );
4618- }
4619- assertNotNull (e );
4620- sleep (1000 );
4621- try {
4622- conn .run ("startDataNode(\" " +nodeAlias +"\" )" );
4623- }catch (Exception ex )
4624- {
4625- System .out .println (ex );
4626- }
4627- sleep (5000 );
4628- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
4629- conn1 .run ("a=1;\n a" );
4630- assertEquals (true , conn1 .isConnected ());
4631- conn1 .close ();
4632- }
4633- @ Test
4634- public void Test_connect_EnableHighAvailability_true () throws IOException , InterruptedException {
4635- DBConnection conn = new DBConnection ();
4636- conn .connect (HOST ,CONTROLLER_PORT ,"admin" ,"123456" ,null ,false );
4637- DBConnection conn1 = new DBConnection ();
4638- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,true );
4639- BasicString nodeAliasTmp = (BasicString )conn1 .run ("getNodeAlias()" );
4640- String nodeAlias = nodeAliasTmp .getString ();
4641- try {
4642- conn .run ("stopDataNode(\" " +nodeAlias +"\" )" );
4643- }catch (Exception ex )
4644- {
4645- System .out .println (ex );
4646- }
4647- sleep (5000 );
4648- conn1 .run ("a=1;\n a" );
4649- //The connection switches to a different node to execute the code
4650- try {
4651- conn .run ("startDataNode(\" " +nodeAlias +"\" )" );
4652- }catch (Exception ex )
4653- {
4654- System .out .println (ex );
4655- }
4656- sleep (5000 );
4657- assertEquals (true , conn1 .isConnected ());
4658- }
4659- //@Test //AJ-287
4660- public void Test_getConnection_highAvailability_false () throws SQLException , ClassNotFoundException , IOException {
4661- String script = "def restart(n)\n " +
4662- "{\n " +
4663- "try{\n " +
4664- "stopDataNode(\" " +HOST +":" +PORT +"\" );\n " +
4665- "}catch(ex)\n " +
4666- "{print(ex)}\n " +
4667- "sleep(n);\n " +
4668- "try{\n " +
4669- "stopDataNode(\" " +HOST +":" +PORT +"\" );\n " +
4670- "}catch(ex)\n " +
4671- "{print(ex)}\n " +
4672- "}\n " +
4673- "submitJob(\" restart\" ,\" restart\" ,restart,1000);" ;
4674- conn = new DBConnection (false , false , false );
4675- conn .connect (HOST , CONTROLLER_PORT , "admin" , "123456" ,null ,false ,null ,true );
4676- conn .run (script );
4677- DBConnection conn1 = new DBConnection (false , false , false );
4678- conn1 .connect (HOST , PORT , "admin" , "123456" ,null ,false ,null ,true );
4679- conn1 .close ();
4680- conn .close ();
4681- }
46824585
46834586 @ Test
4684- public void Test_connect_EnableHighAvailability_true_1 () throws IOException , InterruptedException {
4685- DBConnection conn1 = new DBConnection ();
4686- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,true );
4687- BasicString nodeAliasTmp = (BasicString )conn1 .run ("getNodeAlias()" );
4688- String nodeAlias = nodeAliasTmp .getString ();
4689- try {
4690- conn .run ("stopDataNode(\" " +nodeAlias +"\" )" );
4691- }catch (Exception ex )
4692- {
4693- System .out .println (ex );
4694- }
4695- sleep (1000 );
4696- conn1 .run ("a=1;\n a" );
4697- //The connection switches to a different node to execute the code
4698- try {
4699- conn .run ("startDataNode(\" " +nodeAlias +"\" )" );
4700- }catch (Exception ex )
4701- {
4702- System .out .println (ex );
4703- }
4704- sleep (1000 );
4705- assertEquals (true , conn1 .isConnected ());
4706- }
4707- @ Test
4708- public void Test_reConnect__true () throws IOException , InterruptedException {
4709- DBConnection conn1 = new DBConnection ();
4710- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false ,null ,true );
4711- BasicString nodeAliasTmp = (BasicString )conn1 .run ("getNodeAlias()" );
4712- String nodeAlias = nodeAliasTmp .getString ();
4713- try {
4714- conn .run ("stopDataNode(\" " +nodeAlias +"\" )" );
4715- }catch (Exception ex )
4716- {
4717- System .out .println (ex );
4718- }
4719- sleep (1000 );
4720- conn1 .run ("a=1;\n a" );
4721- //The connection switches to a different node to execute the code
4722- try {
4723- conn .run ("startDataNode(\" " +nodeAlias +"\" )" );
4724- }catch (Exception ex )
4725- {
4726- System .out .println (ex );
4727- }
4728- sleep (1000 );
4729- assertEquals (true , conn1 .isConnected ());
4730- }
4731- @ Test //reConnect is not valid
4732- public void Test_reConnect__false () throws IOException , InterruptedException {
4733- DBConnection conn1 = new DBConnection ();
4734- conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false ,null ,false );
4735- BasicString nodeAliasTmp = (BasicString )conn1 .run ("getNodeAlias()" );
4736- String nodeAlias = nodeAliasTmp .getString ();
4737- try {
4738- conn .run ("stopDataNode(\" " +nodeAlias +"\" )" );
4739- }catch (Exception ex )
4740- {
4741- System .out .println (ex );
4742- }
4743- sleep (1000 );
4744- conn1 .run ("a=1;\n a" );
4745- //The connection switches to a different node to execute the code
4746- try {
4747- conn .run ("startDataNode(\" " +nodeAlias +"\" )" );
4748- }catch (Exception ex )
4749- {
4750- System .out .println (ex );
4751- }
4752- sleep (1000 );
4753- assertEquals (true , conn1 .isConnected ());
4754- }
4755- //@Test
47564587 public void test_string_length ()throws Exception {
47574588 conn = new DBConnection (false , false , false );
47584589 conn .connect (HOST , PORT , "admin" , "123456" );
@@ -4762,7 +4593,7 @@ public void test_string_length()throws Exception{
47624593 data1 .put ("da" ,data );
47634594 conn .upload (data1 );
47644595 }
4765- // @Test
4596+ @ Test
47664597 public void test_string_length2 ()throws Exception {
47674598 DBConnection conn = new DBConnection (false , false , false );
47684599 conn .connect (HOST , PORT , "admin" , "123456" );
@@ -4777,7 +4608,7 @@ public void test_string_length2()throws Exception{
47774608 data1 .put ("da" ,data );
47784609 conn .upload (data1 );
47794610 }
4780- // @Test
4611+ @ Test
47814612 public void test_BasicDBTask1223 ()throws Exception {
47824613 conn = new DBConnection (false , false , false );
47834614 conn .connect (HOST , PORT , "admin" , "123456" );
@@ -5313,69 +5144,6 @@ public void test_allDateType_array_combine() throws IOException {
53135144 System .out .println (data .rows ());
53145145 assertEquals (10000 , data .rows ());
53155146 }
5316- // @Test
5317- // public void test_node_disConnect() throws IOException, InterruptedException {
5318- // DBConnection contr = new DBConnection();
5319- // contr.connect("192.168.0.69",28920,"admin","123456");
5320- // List<DBTask> tasks = new ArrayList<>();
5321- // ExclusiveDBConnectionPool pool = new ExclusiveDBConnectionPool(HOST,18921, "admin", "123456", 20, false, true);
5322- // class MyThread extends Thread {
5323- // @Override
5324- // public void run() {
5325- // while (true) {
5326- // try {
5327- // // 创建任务
5328- // BasicDBTask task = new BasicDBTask("1..10");
5329- // // 执行任务
5330- // pool.execute(task);
5331- // BasicIntVector data = null;
5332- // if (task.isSuccessful()) {
5333- // data = (BasicIntVector)task.getResult();
5334- // } else {
5335- // throw new Exception(task.getErrorMsg());
5336- // }
5337- // System.out.print(data.getString()+"\n");
5338- //
5339- // // 等待1秒
5340- // Thread.sleep(1000);
5341- // } catch (Exception e) {
5342- // // 捕获异常并打印错误信息
5343- // System.err.println("Error executing task: " + e.getMessage());
5344- // }
5345- // }
5346- // }
5347- // }
5348- // class MyThread1 extends Thread {
5349- // @Override
5350- // public void run() {
5351- // while (true) {
5352- // try {
5353- // contr.run("try{stopDataNode('"+HOST+":18921')}catch(ex){}");
5354- // contr.run("try{stopDataNode('"+HOST+":18922')}catch(ex){}");
5355- // contr.run("try{stopDataNode('"+HOST+":18923')}catch(ex){}");
5356- // Thread.sleep(1000);
5357- // contr.run("try{stopDataNode('"+HOST+":18924')}catch(ex){}");
5358- // Thread.sleep(5000);
5359- // contr.run("try{startDataNode('"+HOST+":18921')}catch(ex){}");
5360- // contr.run("try{startDataNode('"+HOST+":18922')}catch(ex){}");
5361- // contr.run("try{startDataNode('"+HOST+":18923')}catch(ex){}");
5362- // contr.run("try{startDataNode('"+HOST+":18924')}catch(ex){}");
5363- // Thread.sleep(5000);
5364- // } catch (Exception e) {
5365- // // 捕获异常并打印错误信息
5366- // System.err.println(e.getMessage());
5367- // }
5368- // }
5369- // }
5370- // }
5371- //
5372- // MyThread thread = new MyThread();
5373- // MyThread1 thread1 = new MyThread1();
5374- // thread.start();
5375- // Thread.sleep(5000);
5376- // thread1.start();
5377- // thread.join();
5378- // }
53795147
53805148 @ Test //api设置的parallelism小于server的setMaxJobParallelism
53815149 public void test_DBConnection_run_parallelism_1 () throws IOException {
0 commit comments