2020package org .apache .iotdb .pipe .it .dual .tablemodel .manual .basic ;
2121
2222import org .apache .iotdb .commons .client .sync .SyncConfigNodeIServiceClient ;
23+ import org .apache .iotdb .commons .pipe .config .constant .SystemConstant ;
2324import org .apache .iotdb .confignode .rpc .thrift .TAlterPipeReq ;
25+ import org .apache .iotdb .confignode .rpc .thrift .TCreatePipeReq ;
2426import org .apache .iotdb .confignode .rpc .thrift .TDropPipeReq ;
27+ import org .apache .iotdb .confignode .rpc .thrift .TShowPipeInfo ;
28+ import org .apache .iotdb .confignode .rpc .thrift .TShowPipeReq ;
2529import org .apache .iotdb .confignode .rpc .thrift .TStartPipeReq ;
2630import org .apache .iotdb .confignode .rpc .thrift .TStopPipeReq ;
31+ import org .apache .iotdb .isession .SessionConfig ;
2732import org .apache .iotdb .it .env .cluster .node .DataNodeWrapper ;
2833import org .apache .iotdb .it .framework .IoTDBTestRunner ;
2934import org .apache .iotdb .itbase .category .MultiClusterIT2DualTableManualBasic ;
4247import java .sql .SQLException ;
4348import java .sql .Statement ;
4449import java .util .Collections ;
50+ import java .util .HashMap ;
51+ import java .util .List ;
52+ import java .util .Map ;
4553
4654import static org .junit .Assert .fail ;
4755
@@ -245,7 +253,7 @@ public void testReadPipeIsolation() {
245253 }
246254
247255 @ Test
248- public void testCaptureTreeAndTableIsolation () throws Exception {
256+ public void testCaptureTreeAndTableIgnoredByDialectIsolation () throws Exception {
249257 final String treePipeName = "tree_a2b" ;
250258 final String tablePipeName = "table_a2b" ;
251259
@@ -272,7 +280,7 @@ public void testCaptureTreeAndTableIsolation() throws Exception {
272280 Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
273281
274282 // Show table pipe by table session
275- Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
283+ Assert .assertEquals (0 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
276284
277285 // 2. Create table pipe by table session
278286 try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
@@ -292,30 +300,105 @@ public void testCaptureTreeAndTableIsolation() throws Exception {
292300 }
293301
294302 // Show tree pipe by tree session
295- Assert .assertEquals (2 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
303+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
296304
297305 // Show table pipe by table session
298- Assert .assertEquals (2 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
306+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
299307
300308 // 3. Drop pipe
301309 try (final SyncConfigNodeIServiceClient client =
302310 (SyncConfigNodeIServiceClient ) senderEnv .getLeaderConfigNodeConnection ()) {
303311 Assert .assertEquals (
304312 TSStatusCode .SUCCESS_STATUS .getStatusCode (),
305- client .dropPipeExtended (new TDropPipeReq (treePipeName ).setIsTableModel (true )).getCode ());
313+ client .dropPipeExtended (new TDropPipeReq (treePipeName ).setIsTableModel (false )).getCode ());
306314 Assert .assertEquals (
307315 TSStatusCode .SUCCESS_STATUS .getStatusCode (),
308- client
309- .dropPipeExtended (new TDropPipeReq (tablePipeName ).setIsTableModel (false ))
310- .getCode ());
316+ client .dropPipeExtended (new TDropPipeReq (tablePipeName ).setIsTableModel (true )).getCode ());
317+ }
318+ }
319+
320+ @ Test
321+ public void testSameNameTreeOnlyAndTableOnlyPipeIsolation () throws Exception {
322+ final String pipeName = "same_name_pipe" ;
323+ final DataNodeWrapper receiverDataNode = receiverEnv .getDataNodeWrapper (0 );
324+
325+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TREE_SQL_DIALECT );
326+ final Statement statement = connection .createStatement ()) {
327+ statement .execute (
328+ String .format (
329+ "create pipe %s with sink ('node-urls'='%s')" ,
330+ pipeName , receiverDataNode .getIpAndPortString ()));
331+ }
332+
333+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
334+ final Statement statement = connection .createStatement ()) {
335+ statement .execute (
336+ String .format (
337+ "create pipe %s with sink ('node-urls'='%s')" ,
338+ pipeName , receiverDataNode .getIpAndPortString ()));
339+ }
340+
341+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
342+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
343+
344+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
345+ final Statement statement = connection .createStatement ()) {
346+ statement .execute ("stop pipe " + pipeName );
347+ }
348+
349+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
350+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
351+
352+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TREE_SQL_DIALECT );
353+ final Statement statement = connection .createStatement ()) {
354+ statement .execute ("drop pipe " + pipeName );
355+ }
356+
357+ Assert .assertEquals (0 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
358+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
359+
360+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
361+ final Statement statement = connection .createStatement ()) {
362+ statement .execute ("start pipe " + pipeName );
363+ statement .execute ("drop pipe " + pipeName );
311364 }
365+
366+ Assert .assertEquals (0 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
367+ Assert .assertEquals (0 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
312368 }
313369
314370 @ Test
315- public void testCaptureCornerCases () {
371+ public void testSameNamePipeWithCaptureAttributesStillIsolated () throws Exception {
372+ final String pipeName = "same_name_conflict_pipe" ;
316373 final DataNodeWrapper receiverDataNode = receiverEnv .getDataNodeWrapper (0 );
317374
318- // 1. Create tree pipe but capture table data
375+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TREE_SQL_DIALECT );
376+ final Statement statement = connection .createStatement ()) {
377+ statement .execute (
378+ String .format (
379+ "create pipe %s with sink ('node-urls'='%s')" ,
380+ pipeName , receiverDataNode .getIpAndPortString ()));
381+ }
382+
383+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
384+ final Statement statement = connection .createStatement ()) {
385+ statement .execute (
386+ String .format (
387+ "create pipe %s"
388+ + " with source ('capture.tree'='true','capture.table'='true')"
389+ + " with sink ('node-urls'='%s')" ,
390+ pipeName , receiverDataNode .getIpAndPortString ()));
391+ }
392+
393+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
394+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
395+ }
396+
397+ @ Test
398+ public void testCaptureAttributesAreIgnoredByDialect () {
399+ final DataNodeWrapper receiverDataNode = receiverEnv .getDataNodeWrapper (0 );
400+
401+ // 1. Create tree pipe with capture attributes pointing to table data
319402 try (final Connection connection = senderEnv .getConnection (BaseEnv .TREE_SQL_DIALECT );
320403 final Statement statement = connection .createStatement ()) {
321404 statement .execute (
@@ -333,12 +416,12 @@ public void testCaptureCornerCases() {
333416 }
334417
335418 // Show tree pipe by tree session
336- Assert .assertEquals (0 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
419+ Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
337420
338421 // Show table pipe by table session
339- Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
422+ Assert .assertEquals (0 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
340423
341- // 2. Create table pipe but capture tree data
424+ // 2. Create table pipe with capture attributes pointing to tree data
342425 try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
343426 final Statement statement = connection .createStatement ()) {
344427 statement .execute (
@@ -373,14 +456,114 @@ public void testCaptureCornerCases() {
373456 + " with sink ("
374457 + "'node-urls'='%s')" ,
375458 "p3" , receiverDataNode .getIpAndPortString ()));
376- fail ();
377- } catch (final SQLException ignored ) {
459+ } catch (final SQLException e ) {
460+ e .printStackTrace ();
461+ fail (e .getMessage ());
378462 }
379463
380464 // Show tree pipe by tree session
381- Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
465+ Assert .assertEquals (2 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TREE_SQL_DIALECT ));
382466
383467 // Show table pipe by table session
384468 Assert .assertEquals (1 , TableModelUtils .showPipesCount (senderEnv , BaseEnv .TABLE_SQL_DIALECT ));
385469 }
470+
471+ @ Test
472+ public void testDirectRpcCreationDialectCompatibility () throws Exception {
473+ final String pipeName = "rpc_same_name_pipe" ;
474+ final DataNodeWrapper receiverDataNode = receiverEnv .getDataNodeWrapper (0 );
475+ final Map <String , String > sinkAttributes = new HashMap <>();
476+ sinkAttributes .put ("sink" , "iotdb-thrift-sink" );
477+ sinkAttributes .put ("sink.ip" , receiverDataNode .getIp ());
478+ sinkAttributes .put ("sink.port" , String .valueOf (receiverDataNode .getPort ()));
479+
480+ try (final SyncConfigNodeIServiceClient client =
481+ (SyncConfigNodeIServiceClient ) senderEnv .getLeaderConfigNodeConnection ()) {
482+ Assert .assertEquals (
483+ TSStatusCode .SUCCESS_STATUS .getStatusCode (),
484+ client .createPipe (new TCreatePipeReq (pipeName , sinkAttributes )).getCode ());
485+
486+ Assert .assertEquals (1 , showPipes (client , false ).size ());
487+ Assert .assertEquals (0 , showPipes (client , true ).size ());
488+ Assert .assertTrue (
489+ showPipes (client , false )
490+ .get (0 )
491+ .pipeExtractor
492+ .contains (
493+ SystemConstant .SQL_DIALECT_KEY + "=" + SystemConstant .SQL_DIALECT_TREE_VALUE ));
494+
495+ final Map <String , String > tableSourceAttributes = new HashMap <>();
496+ tableSourceAttributes .put (
497+ SystemConstant .SQL_DIALECT_KEY , SystemConstant .SQL_DIALECT_TABLE_VALUE );
498+ Assert .assertEquals (
499+ TSStatusCode .SUCCESS_STATUS .getStatusCode (),
500+ client
501+ .createPipe (
502+ new TCreatePipeReq (pipeName , sinkAttributes )
503+ .setExtractorAttributes (tableSourceAttributes ))
504+ .getCode ());
505+
506+ Assert .assertEquals (1 , showPipes (client , false ).size ());
507+ Assert .assertEquals (1 , showPipes (client , true ).size ());
508+ Assert .assertTrue (
509+ showPipes (client , true )
510+ .get (0 )
511+ .pipeExtractor
512+ .contains (
513+ SystemConstant .SQL_DIALECT_KEY + "=" + SystemConstant .SQL_DIALECT_TABLE_VALUE ));
514+
515+ Assert .assertNotEquals (
516+ TSStatusCode .SUCCESS_STATUS .getStatusCode (),
517+ client .createPipe (new TCreatePipeReq (pipeName , sinkAttributes )).getCode ());
518+ }
519+ }
520+
521+ @ Test
522+ public void testLegacyLifecycleRpcPrefersTreePipeThenTablePipe () throws Exception {
523+ final String pipeName = "legacy_same_name_pipe" ;
524+ final DataNodeWrapper receiverDataNode = receiverEnv .getDataNodeWrapper (0 );
525+
526+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TREE_SQL_DIALECT );
527+ final Statement statement = connection .createStatement ()) {
528+ statement .execute (
529+ String .format (
530+ "create pipe %s with sink ('node-urls'='%s')" ,
531+ pipeName , receiverDataNode .getIpAndPortString ()));
532+ }
533+ try (final Connection connection = senderEnv .getConnection (BaseEnv .TABLE_SQL_DIALECT );
534+ final Statement statement = connection .createStatement ()) {
535+ statement .execute (
536+ String .format (
537+ "create pipe %s with sink ('node-urls'='%s')" ,
538+ pipeName , receiverDataNode .getIpAndPortString ()));
539+ }
540+
541+ try (final SyncConfigNodeIServiceClient client =
542+ (SyncConfigNodeIServiceClient ) senderEnv .getLeaderConfigNodeConnection ()) {
543+ Assert .assertEquals (1 , showPipes (client , false ).size ());
544+ Assert .assertEquals (1 , showPipes (client , true ).size ());
545+
546+ Assert .assertEquals (
547+ TSStatusCode .SUCCESS_STATUS .getStatusCode (), client .dropPipe (pipeName ).getCode ());
548+ Assert .assertEquals (0 , showPipes (client , false ).size ());
549+ Assert .assertEquals (1 , showPipes (client , true ).size ());
550+
551+ Assert .assertEquals (
552+ TSStatusCode .SUCCESS_STATUS .getStatusCode (), client .dropPipe (pipeName ).getCode ());
553+ Assert .assertEquals (0 , showPipes (client , false ).size ());
554+ Assert .assertEquals (0 , showPipes (client , true ).size ());
555+ }
556+ }
557+
558+ private List <TShowPipeInfo > showPipes (
559+ final SyncConfigNodeIServiceClient client , final boolean isTableModel ) throws Exception {
560+ final List <TShowPipeInfo > showPipeResult =
561+ client .showPipe (
562+ new TShowPipeReq ()
563+ .setIsTableModel (isTableModel )
564+ .setUserName (SessionConfig .DEFAULT_USER ))
565+ .pipeInfoList ;
566+ showPipeResult .removeIf (i -> i .getId ().startsWith ("__consensus" ));
567+ return showPipeResult ;
568+ }
386569}
0 commit comments