@@ -32,6 +32,7 @@ public class ThreadedClientsubscribeReverseTest {
32
32
static int controller_port = Integer .parseInt (bundle .getString ("CONTROLLER_PORT" ));
33
33
//static int PORT = 9002;
34
34
private static ThreadedClient client ;
35
+ static long total = 0 ;
35
36
36
37
@ BeforeClass
37
38
public static void setUp () throws IOException {
@@ -114,7 +115,7 @@ public void doEvent(IMessage msg) {
114
115
}
115
116
};
116
117
117
- public void wait_data (String table_name ,int data_row ) throws IOException , InterruptedException {
118
+ public static void wait_data (String table_name , int data_row ) throws IOException , InterruptedException {
118
119
BasicInt row_num ;
119
120
while (true ){
120
121
row_num = (BasicInt )conn .run ("(exec count(*) from " +table_name +")[0]" );
@@ -243,7 +244,7 @@ public void test_ThreadedClient_null() throws IOException {
243
244
}
244
245
245
246
@ Test
246
- public void test_ThreadedClient_only_subscribePort () throws IOException {
247
+ public void test_ThreadedClient_only_subscribePort () throws IOException , InterruptedException {
247
248
ThreadedClient client2 = new ThreadedClient (0 );
248
249
String script1 = "st1 = streamTable(1000000:0,`tag`ts`data,[INT,TIMESTAMP,DOUBLE])\n " +
249
250
"share(st1,`Trades)\t \n "
@@ -3639,4 +3640,42 @@ public void test_ThreadClient_subscribe_backupSites_server_disconnect_1() throws
3639
3640
System .out .println ("这里可以手工断掉这个集群下所有可用节点http://192.168.0.69:18920/?view=overview-old" );
3640
3641
Thread .sleep (1000000 );
3641
3642
}
3642
- }
3643
+ public static MessageHandler MessageHandler_handler_getOffset = new MessageHandler () {
3644
+ @ Override
3645
+ public void doEvent (IMessage msg ) {
3646
+ System .out .println (msg .getOffset ());
3647
+ try {
3648
+ String script = String .format ("insert into Receive values(%d,%s,%f)" , Integer .parseInt (msg .getEntity (0 ).getString ()), msg .getEntity (1 ).getString (), Double .valueOf (msg .getEntity (2 ).toString ()));
3649
+ conn .run (script );
3650
+ assertEquals (total , msg .getOffset ());
3651
+ total ++;
3652
+ System .out .println ("msg.getOffset is :" + msg .getOffset ());
3653
+ } catch (IOException e ) {
3654
+ e .printStackTrace ();
3655
+ }
3656
+ total =total ++;
3657
+ }
3658
+ };
3659
+ @ Test (timeout = 180000 )
3660
+ public void test_subscribe_getOffset () throws Exception {
3661
+ String script1 = "st1 = streamTable(1000000:0,`tag`ts`data,[INT,TIMESTAMP,DOUBLE])\n " +
3662
+ "share(st1,`Trades)\t \n "
3663
+ + "setStreamTableFilterColumn(objByName(`Trades),`tag)" ;
3664
+ conn .run (script1 );
3665
+ String script2 = "st2 = streamTable(1000000:0,`tag`ts`data,[INT,TIMESTAMP,DOUBLE])\n " +
3666
+ "share(st2, `Receive)\t \n " ;
3667
+ conn .run (script2 );
3668
+ client .subscribe (HOST , PORT , "Trades" , MessageHandler_handler_getOffset , true );
3669
+ conn .run ("n=5000;t=table(1..n as tag,now()+1..n as ts,rand(100.0,n) as data);" + "Trades.append!(t)" );
3670
+ wait_data ("Receive" ,5000 );
3671
+ BasicTable re = (BasicTable ) conn .run ("Receive" );
3672
+ BasicTable tra = (BasicTable ) conn .run ("Trades" );
3673
+ assertEquals (5000 , re .rows ());
3674
+ for (int i = 0 ; i < re .rows (); i ++) {
3675
+ assertEquals (re .getColumn (0 ).get (i ), tra .getColumn (0 ).get (i ));
3676
+ assertEquals (re .getColumn (1 ).get (i ), tra .getColumn (1 ).get (i ));
3677
+ assertEquals (((Scalar )re .getColumn (2 ).get (i )).getNumber ().doubleValue (), ((Scalar )tra .getColumn (2 ).get (i )).getNumber ().doubleValue (), 4 );
3678
+ }
3679
+ client .unsubscribe (HOST , PORT , "Trades" );
3680
+ }
3681
+ }
0 commit comments