Skip to content

Commit 6aaa1b8

Browse files
committed
fix test case
1 parent 29c125e commit 6aaa1b8

9 files changed

+258
-122
lines changed

test/com/xxdb/DBConnectionTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,4 +5031,67 @@ public void test_allDateTyp_array_combine() throws IOException {
50315031
System.out.println(data.rows());
50325032
assertEquals(10000, data.rows());
50335033
}
5034+
// @Test
5035+
// public void test_node_disConnect() throws IOException, InterruptedException {
5036+
// DBConnection contr = new DBConnection();
5037+
// contr.connect("192.168.0.69",28920,"admin","123456");
5038+
// List<DBTask> tasks = new ArrayList<>();
5039+
// ExclusiveDBConnectionPool pool = new ExclusiveDBConnectionPool(HOST,18921, "admin", "123456", 20, false, true);
5040+
// class MyThread extends Thread {
5041+
// @Override
5042+
// public void run() {
5043+
// while (true) {
5044+
// try {
5045+
// // 创建任务
5046+
// BasicDBTask task = new BasicDBTask("1..10");
5047+
// // 执行任务
5048+
// pool.execute(task);
5049+
// BasicIntVector data = null;
5050+
// if (task.isSuccessful()) {
5051+
// data = (BasicIntVector)task.getResult();
5052+
// } else {
5053+
// throw new Exception(task.getErrorMsg());
5054+
// }
5055+
// System.out.print(data.getString()+"\n");
5056+
//
5057+
// // 等待1秒
5058+
// Thread.sleep(1000);
5059+
// } catch (Exception e) {
5060+
// // 捕获异常并打印错误信息
5061+
// System.err.println("Error executing task: " + e.getMessage());
5062+
// }
5063+
// }
5064+
// }
5065+
// }
5066+
// class MyThread1 extends Thread {
5067+
// @Override
5068+
// public void run() {
5069+
// while (true) {
5070+
// try {
5071+
// contr.run("try{stopDataNode('"+HOST+":18921')}catch(ex){}");
5072+
// contr.run("try{stopDataNode('"+HOST+":18922')}catch(ex){}");
5073+
// contr.run("try{stopDataNode('"+HOST+":18923')}catch(ex){}");
5074+
// Thread.sleep(1000);
5075+
// contr.run("try{stopDataNode('"+HOST+":18924')}catch(ex){}");
5076+
// Thread.sleep(5000);
5077+
// contr.run("try{startDataNode('"+HOST+":18921')}catch(ex){}");
5078+
// contr.run("try{startDataNode('"+HOST+":18922')}catch(ex){}");
5079+
// contr.run("try{startDataNode('"+HOST+":18923')}catch(ex){}");
5080+
// contr.run("try{startDataNode('"+HOST+":18924')}catch(ex){}");
5081+
// Thread.sleep(5000);
5082+
// } catch (Exception e) {
5083+
// // 捕获异常并打印错误信息
5084+
// System.err.println(e.getMessage());
5085+
// }
5086+
// }
5087+
// }
5088+
// }
5089+
//
5090+
// MyThread thread = new MyThread();
5091+
// MyThread1 thread1 = new MyThread1();
5092+
// thread.start();
5093+
// Thread.sleep(5000);
5094+
// thread1.start();
5095+
// thread.join();
5096+
// }
50345097
}

test/com/xxdb/SimpleDBConnectionPoolTest.java

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,11 @@ public void tearDown() throws Exception {
5959
}
6060
}
6161
@Test
62-
public void test_SimpleDBConnectionPool_config_oldversion(){
63-
config.setInitialPoolSize(5);
64-
SimpleDBConnectionPool pool=new SimpleDBConnectionPool(config);
65-
assertEquals(5,config.getMinimumPoolSize());
66-
assertEquals(5,config.getMaximumPoolSize());
67-
}
68-
@Test
69-
public void test_SimpleDBConnectionPool_config_newversion(){
62+
public void test_SimpleDBConnectionPool_config_setInitialPoolSize(){
63+
config.setInitialPoolSize(10);
7064
SimpleDBConnectionPool pool=new SimpleDBConnectionPool(config);
71-
assertEquals(5,config.getMinimumPoolSize());
72-
assertEquals(5,config.getMaximumPoolSize());
65+
assertEquals(10,config.getMinimumPoolSize());
66+
assertEquals(10,config.getMaximumPoolSize());
7367
}
7468
@Test
7569
public void test_SimpleDBConnectionPool_config_MinimumandPoolSize_and_MaximumPoolSize_null() {
@@ -120,7 +114,6 @@ public void test_SimpleDBConnectionPool_config_InvalididleTimeout_error() {
120114
config.setIdleTimeout(0);
121115
pool = new SimpleDBConnectionPool(config);
122116
assertEquals(600000, config.getIdleTimeout());
123-
124117
}
125118
@Test
126119
public void test_SimpleDBConnectionPool_config_InvalididleTimeout_null() {
@@ -800,6 +793,64 @@ public void test_SimpleDBConnectionPool_closeIdleConnections_Auto() throws Inter
800793
assertEquals(6,pool.getIdleConnectionsCount());
801794
}
802795
@Test
796+
public void test_SimpleDBConnectionPool_closeIdleConnections_Auto_1() throws InterruptedException {
797+
config.setMaximumPoolSize(10);
798+
config.setMinimumPoolSize(6);
799+
config.setIdleTimeout(10000);
800+
pool=new SimpleDBConnectionPool(config);
801+
DBConnection [] A=new DBConnection[10];
802+
for(int i=0;i<10;i++){
803+
A[i]=pool.getConnection();
804+
}
805+
assertEquals(10,pool.getTotalConnectionsCount());
806+
assertEquals(10,pool.getActiveConnectionsCount());
807+
assertEquals(0,pool.getIdleConnectionsCount());
808+
for(int i=0;i<2;i++){
809+
A[i].close();
810+
}
811+
Thread.sleep(9000);
812+
assertEquals(10,pool.getTotalConnectionsCount());
813+
assertEquals(8,pool.getActiveConnectionsCount());
814+
assertEquals(2,pool.getIdleConnectionsCount());
815+
Thread.sleep(1000);
816+
assertEquals(10,pool.getTotalConnectionsCount());
817+
assertEquals(8,pool.getActiveConnectionsCount());
818+
assertEquals(2,pool.getIdleConnectionsCount());
819+
Thread.sleep(972);
820+
assertEquals(8,pool.getTotalConnectionsCount());
821+
assertEquals(8,pool.getActiveConnectionsCount());
822+
assertEquals(0,pool.getIdleConnectionsCount());
823+
}
824+
@Test
825+
public void test_SimpleDBConnectionPool_closeIdleConnections_Auto_2() throws InterruptedException {
826+
config.setMaximumPoolSize(10);
827+
config.setMinimumPoolSize(6);
828+
config.setIdleTimeout(10000);
829+
pool=new SimpleDBConnectionPool(config);
830+
DBConnection [] A=new DBConnection[10];
831+
for(int i=0;i<10;i++){
832+
A[i]=pool.getConnection();
833+
}
834+
assertEquals(10,pool.getTotalConnectionsCount());
835+
assertEquals(10,pool.getActiveConnectionsCount());
836+
assertEquals(0,pool.getIdleConnectionsCount());
837+
// for(int i=0;i<2;i++){
838+
// A[i].close();
839+
// }
840+
Thread.sleep(9000);
841+
assertEquals(10,pool.getTotalConnectionsCount());
842+
assertEquals(10,pool.getActiveConnectionsCount());
843+
assertEquals(0,pool.getIdleConnectionsCount());
844+
Thread.sleep(1000);
845+
assertEquals(10,pool.getTotalConnectionsCount());
846+
assertEquals(10,pool.getActiveConnectionsCount());
847+
assertEquals(0,pool.getIdleConnectionsCount());
848+
Thread.sleep(972);
849+
assertEquals(10,pool.getTotalConnectionsCount());
850+
assertEquals(10,pool.getActiveConnectionsCount());
851+
assertEquals(0,pool.getIdleConnectionsCount());
852+
}
853+
@Test
803854
public void test_SimpleDBConnectionPool_closeIdleConnections_Auto_MultiThread() throws InterruptedException {
804855
config.setMaximumPoolSize(10);
805856
config.setMinimumPoolSize(6);
@@ -809,6 +860,9 @@ public void test_SimpleDBConnectionPool_closeIdleConnections_Auto_MultiThread()
809860
for(int i=0;i<10;i++){
810861
A[i]=pool.getConnection();
811862
}
863+
assertEquals(10,pool.getTotalConnectionsCount());
864+
assertEquals(10,pool.getActiveConnectionsCount());
865+
assertEquals(0,pool.getIdleConnectionsCount());
812866
Thread[] threads = new Thread[10];
813867
for(int i=0;i<10;i++){
814868
int finalI = i;
@@ -867,6 +921,32 @@ public void test_SimpleDBConnectionPool_closeIdleConnectionsManual() throws Inte
867921
assertEquals(6,pool.getIdleConnectionsCount());
868922
}
869923
@Test
924+
public void test_SimpleDBConnectionPool_closeIdleConnectionsManual_1() throws InterruptedException{
925+
config.setMaximumPoolSize(10);
926+
config.setMinimumPoolSize(6);
927+
config.setIdleTimeout(10000);
928+
pool=new SimpleDBConnectionPool(config);
929+
DBConnection [] A=new DBConnection[10];
930+
for(int i=0;i<10;i++){
931+
A[i]=pool.getConnection();
932+
}
933+
assertEquals(10,pool.getTotalConnectionsCount());
934+
assertEquals(10,pool.getActiveConnectionsCount());
935+
assertEquals(0,pool.getIdleConnectionsCount());
936+
for(int i=0;i<2;i++){
937+
A[i].close();
938+
}
939+
Thread.sleep(7000);
940+
assertEquals(10,pool.getTotalConnectionsCount());
941+
assertEquals(8,pool.getActiveConnectionsCount());
942+
assertEquals(2,pool.getIdleConnectionsCount());
943+
944+
pool.manualCleanupIdleConnections();
945+
assertEquals(8,pool.getTotalConnectionsCount());
946+
assertEquals(8,pool.getActiveConnectionsCount());
947+
assertEquals(0,pool.getIdleConnectionsCount());
948+
}
949+
@Test
870950
public void test_SimpleDBConnectionPool_closeIdleConnectionsManual_MultiThread() throws InterruptedException{
871951
config.setMaximumPoolSize(10);
872952
config.setMinimumPoolSize(6);

test/com/xxdb/data/BasicDecimal128VectorTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,6 @@ public void test_BasicDecimal128_isNull() throws Exception{
181181
assertEquals("Value's scale is not the same as the vector's!", e.getMessage());
182182
}
183183
}
184-
@Test
185-
public void test_BasicDecimal128_combine() throws Exception{
186-
DBConnection connection = new DBConnection(false, false, false);
187-
connection.connect(HOST, PORT, "admin", "123456");
188-
BasicDecimal128Vector b128v1 = (BasicDecimal128Vector) connection.run("decimal128(1..10, 4)");
189-
BasicDecimal128Vector b128v2 = (BasicDecimal128Vector) connection.run("decimal128(1..5, 4)");
190-
String re = null;
191-
try {
192-
b128v1.combine(b128v2);
193-
}catch (Exception e){
194-
re=e.getMessage();
195-
}
196-
assertEquals("BasicDecimal128Vector not support combine yet!",re);
197-
198-
199-
}
200184

201185
@Test
202186
public void test_BasicDecimal128Vector_create_Decimal128Vector() throws Exception {

test/com/xxdb/data/TimeTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.xxdb.data;
22

3+
import org.junit.Assert;
34
import org.junit.Test;
45
import java.time.*;
56
import static com.xxdb.data.Utils.countMilliseconds;
@@ -167,6 +168,13 @@ public void testTime(){
167168
throw new RuntimeException(dt + " != " + dt2);
168169
}
169170
}
171+
{
172+
LocalDateTime dt = LocalDateTime.of(2039,1,1,1,1);
173+
long ret = Utils.countMilliseconds(dt);
174+
System.out.println(ret);
175+
Assert.assertEquals(2177456460000l, ret);
176+
}
177+
170178
}
171179
}
172180

test/com/xxdb/streaming/client/cep/EventClientTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void test_EventClient_AttrKeys_null() throws IOException, InterruptedExc
181181
}
182182

183183
@Test
184-
public void test_EventClient_AttrKeys_repetition() throws IOException, InterruptedException {
184+
public void test_EventClient_fieldNames_repetition() throws IOException, InterruptedException {
185185
conn.run("share streamTable(1000000:0, `time`eventType`event, [TIME,STRING,BLOB]) as inputTable;");
186186
EventSchema scheme = new EventSchema();
187187
scheme.setEventType("market");
@@ -198,7 +198,7 @@ public void test_EventClient_AttrKeys_repetition() throws IOException, Interrup
198198
}catch(Exception ex){
199199
re = ex.getMessage();
200200
}
201-
Assert.assertEquals("EventSchema cannot has duplicated attrKey in attrKeys.",re);
201+
Assert.assertEquals("EventSchema cannot has duplicated fieldName in fieldNames.",re);
202202
}
203203

204204
@Test
@@ -242,7 +242,7 @@ public void test_EventClient_AttrKeys_one_colume() throws IOException, Interrup
242242
}
243243

244244
@Test
245-
public void test_EventClient_AttrTypes_null() throws IOException, InterruptedException {
245+
public void test_EventClient_fieldTypes_null() throws IOException, InterruptedException {
246246
EventSchema scheme = new EventSchema();
247247
scheme.setEventType("market");
248248
scheme.setFieldNames(Arrays.asList("market", "code", "price", "qty", "eventTime"));
@@ -262,7 +262,7 @@ public void test_EventClient_AttrTypes_null() throws IOException, InterruptedEx
262262
}
263263

264264
@Test
265-
public void test_EventClient_AttrForms_null() throws IOException, InterruptedException {
265+
public void test_EventClient_fieldForms_null() throws IOException, InterruptedException {
266266
EventSchema scheme = new EventSchema();
267267
scheme.setEventType("market");
268268
scheme.setFieldNames(Arrays.asList("market", "code", "price", "qty", "eventTime"));

0 commit comments

Comments
 (0)