Skip to content

Commit b911045

Browse files
committed
AJ-854:add test case about pta
1 parent c5f2c9a commit b911045

File tree

2 files changed

+853
-0
lines changed

2 files changed

+853
-0
lines changed

test/com/xxdb/ConnectionPoolTest.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.xxdb.multithreadedtablewriter.MultithreadedTableWriter;
88
import com.xxdb.route.AutoFitTableUpsert;
99
import com.xxdb.route.PartitionedTableAppender;
10+
import junit.framework.Assert;
1011
import org.junit.After;
1112
import org.junit.Before;
1213
import org.junit.Test;
@@ -21,6 +22,7 @@
2122

2223
import static com.xxdb.Prepare.PrepareUser_authMode;
2324
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertTrue;
2426

2527
public class ConnectionPoolTest {
2628
private static String dburl="dfs://demohash";
@@ -2618,5 +2620,72 @@ public void Test_PartitionedTableAppender_iotAnyVector_1() throws Exception {
26182620
assertEquals("10", bt10.getColumn(0).getString(0));
26192621
pool.shutdown();
26202622
}
2623+
2624+
@Test(timeout = 120000)
2625+
public void test_ChunkInTransaction_insert() throws Exception {
2626+
DBConnection conn = new DBConnection();
2627+
conn.connect(HOST,PORT,"admin","123456");
2628+
StringBuilder sb = new StringBuilder();
2629+
sb.append("\n" +
2630+
"dbName = \"dfs://test_ChunkInTransaction\"\n" +
2631+
"if(exists(dbName)){\n" +
2632+
"\tdropDatabase(dbName)\t\n" +
2633+
"}\n" +
2634+
"db=database(dbName, VALUE,1..6)\n" +
2635+
"t=table(1:0, `volume`valueTrade, [INT, DOUBLE])\n" +
2636+
" ;share t as t1;\tcreatePartitionedTable(dbHandle=db, table=t, tableName=`pt, partitionColumns=[\"volume\"])\n");
2637+
conn.run(sb.toString());
2638+
2639+
ExclusiveDBConnectionPool pool = new ExclusiveDBConnectionPool(HOST,8802,"admin","123456",3,false,false);
2640+
PartitionedTableAppender appender = new PartitionedTableAppender("dfs://test_ChunkInTransaction","pt","volume", pool);
2641+
PartitionedTableAppender appender1 = new PartitionedTableAppender("dfs://test_ChunkInTransaction","pt","volume", pool);
2642+
2643+
List<String> colNames = Arrays.asList("volume", "valueTrade");
2644+
BasicIntVector volume = new BasicIntVector(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
2645+
BasicDoubleVector valueTrade = new BasicDoubleVector(Arrays.asList(1.0, 2.9, 3.9, 4.9, 5.9, 6.7, 7.7, 8.7, 9.7, 10.7));
2646+
List<Vector> cols = Arrays.asList(volume, valueTrade);
2647+
BasicTable table = new BasicTable(colNames, cols);
2648+
2649+
class MyThread1 extends Thread {
2650+
@Override
2651+
public void run() {
2652+
try {
2653+
int rows = appender.append(table);
2654+
System.out.println("rows:" + rows);
2655+
} catch (Exception e) {
2656+
// 捕获异常并打印错误信息
2657+
System.err.println( e.getMessage());
2658+
}
2659+
}
2660+
}
2661+
final String[] re = {null};
2662+
2663+
class MyThread2 extends Thread {
2664+
@Override
2665+
public void run() {
2666+
try {
2667+
int rows1 = appender1.append(table);
2668+
System.out.println("rows1:" + rows1);
2669+
} catch (Exception e) {
2670+
// 捕获异常并打印错误信息
2671+
System.err.println(e.getMessage());
2672+
re[0] = e.getMessage();
2673+
2674+
}
2675+
}
2676+
}
2677+
2678+
MyThread1 thread1 = new MyThread1();
2679+
MyThread2 thread2 = new MyThread2();
2680+
thread1.start();
2681+
Thread.sleep(5);
2682+
thread2.start();
2683+
thread1.join();
2684+
thread2.join();
2685+
System.out.println(re[0].toString());
2686+
assertEquals(true, re[0].toString().contains("is currently locked and in use"));
2687+
pool.shutdown();
2688+
}
2689+
26212690
}
26222691

0 commit comments

Comments
 (0)