|
8 | 8 | import com.xxdb.io.LittleEndianDataOutputStream; |
9 | 9 | import com.xxdb.io.Long2; |
10 | 10 | import com.xxdb.io.ProgressListener; |
| 11 | +import com.xxdb.streaming.client.IMessage; |
| 12 | +import com.xxdb.streaming.client.MessageHandler; |
| 13 | +import com.xxdb.streaming.client.ThreadedClient; |
11 | 14 | import org.junit.*; |
12 | 15 |
|
13 | 16 | import java.io.*; |
|
18 | 21 | import java.time.*; |
19 | 22 | import java.util.*; |
20 | 23 | import java.util.Date; |
| 24 | +import java.util.concurrent.CountDownLatch; |
21 | 25 | import java.util.stream.DoubleStream; |
22 | 26 | import java.util.stream.IntStream; |
23 | 27 |
|
@@ -1750,24 +1754,24 @@ public void testDecimal128Matrix() throws IOException { |
1750 | 1754 | assertEquals("1", matrix3.getRowLabel(0).getString()); |
1751 | 1755 | assertEquals("4.00", matrix3.get(0,0).getString()); |
1752 | 1756 | } |
1753 | | - @Test |
1754 | | - public void testBasicTableSerialize() throws IOException { |
1755 | | - StringBuilder sb = new StringBuilder(); |
1756 | | - sb.append("n=20000\n"); |
1757 | | - sb.append("syms=`IBM`C`MS`MSFT`JPM`ORCL`BIDU`SOHU`GE`EBAY`GOOG`FORD`GS`PEP`USO`GLD`GDX`EEM`FXI`SLV`SINA`BAC`AAPL`PALL`YHOO`KOH`TSLA`CS`CISO`SUN\n"); |
1758 | | - sb.append("mytrades=table(09:30:00+rand(18000,n) as timestamp,rand(syms,n) as sym, 10*(1+rand(100,n)) as qty,5.0+rand(100.0,n) as price);\n"); |
1759 | | - sb.append("select qty,price from mytrades where sym==`IBM;"); |
1760 | | - BasicTable table = (BasicTable) conn.run(sb.toString()); |
1761 | | - |
1762 | | - File f = new File("F:\\tmp\\test.dat"); |
1763 | | - FileOutputStream fos = new FileOutputStream(f); |
1764 | | - BufferedOutputStream bos = new BufferedOutputStream(fos); |
1765 | | - LittleEndianDataOutputStream dataStream = new LittleEndianDataOutputStream(bos); |
1766 | | - table.write(dataStream); |
1767 | | - bos.flush(); |
1768 | | - dataStream.close(); |
1769 | | - fos.close(); |
1770 | | - } |
| 1757 | + //@Test |
| 1758 | +// public void testBasicTableSerialize() throws IOException { |
| 1759 | +// StringBuilder sb = new StringBuilder(); |
| 1760 | +// sb.append("n=20000\n"); |
| 1761 | +// sb.append("syms=`IBM`C`MS`MSFT`JPM`ORCL`BIDU`SOHU`GE`EBAY`GOOG`FORD`GS`PEP`USO`GLD`GDX`EEM`FXI`SLV`SINA`BAC`AAPL`PALL`YHOO`KOH`TSLA`CS`CISO`SUN\n"); |
| 1762 | +// sb.append("mytrades=table(09:30:00+rand(18000,n) as timestamp,rand(syms,n) as sym, 10*(1+rand(100,n)) as qty,5.0+rand(100.0,n) as price);\n"); |
| 1763 | +// sb.append("select qty,price from mytrades where sym==`IBM;"); |
| 1764 | +// BasicTable table = (BasicTable) conn.run(sb.toString()); |
| 1765 | +// |
| 1766 | +// File f = new File("F:\\tmp\\test.dat"); |
| 1767 | +// FileOutputStream fos = new FileOutputStream(f); |
| 1768 | +// BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 1769 | +// LittleEndianDataOutputStream dataStream = new LittleEndianDataOutputStream(bos); |
| 1770 | +// table.write(dataStream); |
| 1771 | +// bos.flush(); |
| 1772 | +// dataStream.close(); |
| 1773 | +// fos.close(); |
| 1774 | +// } |
1771 | 1775 |
|
1772 | 1776 | /* @Test |
1773 | 1777 | public void testBasicTableDeserialize() throws IOException { |
@@ -2813,7 +2817,8 @@ public void Test_DBConnection_upload_any() throws Exception { |
2813 | 2817 | public void Test_DBConnection_table_any_upload() throws Exception { |
2814 | 2818 | DBConnection conn = new DBConnection(); |
2815 | 2819 | conn.connect(HOST, PORT,"admin","123456"); |
2816 | | - BasicTable re1 = (BasicTable) conn.run("re = table(100:0, `sex`name`eye, [STRING,ANY,ANY]);\n" + |
| 2820 | + BasicTable re1 = (BasicTable) conn.run("try{undef(\"re\",SHARED)}catch(except){};\n" + |
| 2821 | + "re = table(100:0, `sex`name`eye, [STRING,ANY,ANY]);\n" + |
2817 | 2822 | "re.tableInsert(`f`m,([`jill],['tom' 'dick' 'harry' 'jack']), ([`gray],['blue' 'green' 'blue' 'blue']));\n" + |
2818 | 2823 | "select * from re;"); |
2819 | 2824 | assertEquals("sex name eye \n" + |
@@ -2908,41 +2913,37 @@ public void test_DBConnection_not_login() throws IOException, InterruptedExcepti |
2908 | 2913 | @Test |
2909 | 2914 | public void TestPartitionTable() throws IOException, InterruptedException { |
2910 | 2915 | //createPartitionTable |
2911 | | - StringBuilder sb = new StringBuilder(); |
2912 | | - sb.append("n=10000;"); |
2913 | | - sb.append("t = table(rand(1 2 3,n)as id,rand(1..10,n)as val);"); |
2914 | | - sb.append("if(existsDatabase('dfs://db1')){ dropDatabase('dfs://db1')}"); |
2915 | | - sb.append("db = database('dfs://db1',VALUE ,1 2);"); |
2916 | | - sb.append("pt = db.createPartitionedTable(t,`pt,`id).append!(t);"); |
2917 | | - conn.run(sb.toString()); |
| 2916 | + String script = "n=10000;\n" + |
| 2917 | + "t = table(rand(1 2 3,n)as id,rand(1..10,n)as val);\n" + |
| 2918 | + "if(existsDatabase('dfs://db1')){ dropDatabase('dfs://db1')}\n" + |
| 2919 | + "db = database('dfs://db1',VALUE ,1 2);\n" + |
| 2920 | + "pt = db.createPartitionedTable(t,`pt,`id).append!(t);"; |
| 2921 | + conn.run(script); |
2918 | 2922 | BasicLong res = (BasicLong) conn.run("exec count(*) from pt"); |
2919 | 2923 | assertEquals(true, res.getLong() > 0); |
2920 | 2924 | //addValuePartitions |
2921 | | - sb.append("addValuePartitions(db,3);"); |
2922 | | - sb.append("pt.append!(t);"); |
2923 | | - conn.run(sb.toString()); |
| 2925 | + conn.run("addValuePartitions(db,3);\n " + |
| 2926 | + "pt.append!(t);"); |
2924 | 2927 | BasicInt res3 = (BasicInt) conn.run("size(exec count(dfsPath) from pnodeRun(getAllChunks) where dfsPath like \"/db1/3%\" group by chunkId);"); |
2925 | 2928 | assertEquals(1, res3.getInt()); |
2926 | 2929 | //dropPartition |
2927 | | - conn.run("dropPartition(db,"+"\"/"+"3"+"/\""+",`pt);"); |
| 2930 | + conn.run("dropPartition(db,\"/3/\",`pt);"); |
2928 | 2931 | BasicBoolean res4 = (BasicBoolean) conn.run("existsPartition('dfs://db1/3');"); |
2929 | 2932 | assertFalse(res4.getBoolean()); |
2930 | 2933 | //addColumn |
2931 | | - sb.append("addColumn(pt,[\"x\", \"y\"],[INT, INT]);"); |
2932 | | - sb.append("t1 = table(rand(1 2 3 4,n) as id,rand(1..10,n) as val,rand(1..5,n) as x,rand(1..10,n) as y );"); |
2933 | | - sb.append("pt.append!(t1);"); |
2934 | | - conn.run(sb.toString()); |
2935 | | - conn.run("pnodeRun(purgeCacheEngine)"); |
2936 | | - sleep(5000); |
| 2934 | + conn.run("addColumn(pt,[\"x\", \"y\"],[INT, INT]);\n" + |
| 2935 | + "t1 = table(rand(1 2 3 4,n) as id,rand(1..10,n) as val,rand(1..5,n) as x,rand(1..10,n) as y );\n" + |
| 2936 | + "pt.append!(t1);\n" + |
| 2937 | + "pnodeRun(purgeCacheEngine);"); |
| 2938 | + sleep(1000); |
2937 | 2939 | BasicLong res_x = (BasicLong) conn.run("exec count(*) from pt where x=1"); |
2938 | 2940 | assertEquals(true, res_x.getLong() > 0); |
2939 | 2941 | //PartitionTableJoin |
2940 | | - sb.append("t2 = table(1 as id,2 as val);"); |
2941 | | - sb.append("pt2 = db.createPartitionedTable(t2,`pt2,`id).append!(t2);"); |
2942 | | - conn.run(sb.toString()); |
2943 | | - BasicLong resej = (BasicLong) conn.run("exec count(*) from ej(pt,pt2,`id);"); |
2944 | | - BasicLong respt = (BasicLong) conn.run("exec count(*) from pt;"); |
2945 | | - assertEquals(true, resej.getLong() < respt.getLong()); |
| 2942 | + conn.run("t2 = table(1 as id,2 as val);\n" + |
| 2943 | + "pt2 = db.createPartitionedTable(t2,`pt2,`id).append!(t2);"); |
| 2944 | + BasicTable resej = (BasicTable) conn.run("select count(*) from ej(pt,pt2,`id);"); |
| 2945 | + BasicTable respt = (BasicTable) conn.run("select count(*) from pt;"); |
| 2946 | + assertEquals(true, Integer.parseInt(resej.getColumn(0).getString(0)) < Integer.parseInt(respt.getColumn(0).getString(0))); |
2946 | 2947 | } |
2947 | 2948 |
|
2948 | 2949 | @Test |
@@ -6091,4 +6092,14 @@ public void Test_DBConnection_run_function_exception() throws IOException, Inter |
6091 | 6092 | assertEquals(true, re.contains("The user name or password is incorrect. function: login")); |
6092 | 6093 | } |
6093 | 6094 |
|
| 6095 | + //@Test //AJ-820 |
| 6096 | + public void test_run() throws IOException, InterruptedException { |
| 6097 | + DBConnection conn = new DBConnection(); |
| 6098 | + Boolean isuccessful = conn.connect("192.168.0.69", 8848, "admin", "123456", "", false, null, true); |
| 6099 | + while (true) |
| 6100 | + { |
| 6101 | + System.out.println(conn.run("1+1")); |
| 6102 | + conn.run("sleep(100)"); |
| 6103 | + } |
| 6104 | + } |
6094 | 6105 | } |
0 commit comments