package Ġio . lib p 2 p . pubsub Ċ Ċ import Ġio . lib p 2 p . core . pubsub . Message Api Ċ import Ġio . lib p 2 p . core . pubsub . Subscriber Ċ import Ġio . lib p 2 p . core . pubsub . Topic Ċ import Ġio . lib p 2 p . core . pubsub . create Pub sub Api Ċ import Ġio . lib p 2 p . etc . types . toByteArray Ċ import Ġio . lib p 2 p . etc . types . to Byte Buf Ċ import Ġio . lib p 2 p . etc . types . to Long BigEndian Ċ import Ġio . lib p 2 p . pubsub . f lood . F lood Router Ċ import Ġorg . junit . jupiter . api . Assertions Ċ import Ġorg . junit . jupiter . api . Assertions . assertArrayEquals Ċ import Ġorg . junit . jupiter . api . Assertions . assertEquals Ċ import Ġorg . junit . jupiter . api . Assertions . assertFalse Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġjava . nio . charset . StandardCharsets Ċ import Ġjava . time . Duration Ċ import Ġjava . util . concurrent . Linked BlockingQueue Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ class ĠPub sub Api Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest No From Or Seq No Message Field () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf uzz Ġ= ĠDetermin istic F uzz () ĊĠĠĠĠĠĠĠ Ġval Ġrouter 1 Ġ= Ġf uzz . create Test Router ( F lood Router ()) ĊĠĠĠĠĠĠĠ Ġval Ġapi 1 Ġ= Ġcreate Pub sub Api ( router 1 . router ) ĊĠĠĠĠĠĠĠ Ġval Ġrouter 2 Ġ= Ġf uzz . create Test Router ( F lood Router ()) ĊĠĠĠĠĠĠĠ Ġval Ġapi 2 Ġ= Ġcreate Pub sub Api ( router 2 . router ) ĊĊĠĠĠĠĠĠĠ Ġrouter 1 . connect Sem i Dup lex ( router 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġreceived Messages 2 Ġ= ĠLinked BlockingQueue < Message Api >() ĊĠĠĠĠĠĠĠ Ġapi 1 . subscribe ( Subscriber Ġ{ Ġprintln ( it ) Ġ}, ĠTopic (" my Topic ")) ĊĠĠĠĠĠĠĠ Ġapi 2 . subscribe ( Subscriber Ġ{ Ġreceived Messages 2 Ġ+= Ġit Ġ}, ĠTopic (" my Topic ")) ĊĊĠĠĠĠĠĠĠ Ġf uzz . time Controller . add Time ( Duration . of Seconds ( 1 0 )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠNo Ġfrom , Ġsignature Ġor Ġseq No ĊĠĠĠĠĠĠĠ Ġval Ġpublisher 1 Ġ= Ġapi 1 . create Publisher ( null ) Ġ{ Ġnull Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġpublish F ut Ġ= Ġpublisher 1 ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. publish Ext (" Message ". toByteArray (). to Byte Buf (), Ġnull , Ġnull , ĠTopic (" my Topic ")) ĊĊĠĠĠĠĠĠĠ Ġf uzz . time Controller . add Time ( Duration . of Seconds ( 1 )) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( publish F ut . is Done ) ĊĠĠĠĠĠĠĠ Ġval Ġrec Msg Ġ= Ġreceived Messages 2 . poll ( 1 , ĠTimeUnit . SECONDS ) ĊĠĠĠĠĠĠĠ ĠAssertions . assertNotNull ( rec Msg ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġrec Msg . topics . size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Topic (" my Topic "), Ġrec Msg . topics [ 0 ]) ĊĠĠĠĠĠĠĠ ĠAssertions . assertNull ( rec Msg . seq Id ) ĊĠĠĠĠĠĠĠ ĠassertEquals (" Message ", Ġrec Msg . data . toByteArray (). toString ( StandardCharsets . UTF _ 8 )) ĊĠĠĠĠĠĠĠ ĠAssertions . assertNull ( rec Msg . from ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest No Sender PrivateKey () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf uzz Ġ= ĠDetermin istic F uzz () ĊĠĠĠĠĠĠĠ Ġval Ġrouter 1 Ġ= Ġf uzz . create Test Router ( F lood Router ()) ĊĠĠĠĠĠĠĠ Ġval Ġapi 1 Ġ= Ġcreate Pub sub Api ( router 1 . router ) ĊĠĠĠĠĠĠĠ Ġval Ġrouter 2 Ġ= Ġf uzz . create Test Router ( F lood Router ()) ĊĊĠĠĠĠĠĠĠ Ġrouter 1 . connect Sem i Dup lex ( router 2 ) ĊĊĠĠĠĠĠĠĠ Ġapi 1 . subscribe ( Subscriber Ġ{ Ġprintln ( it ) Ġ}, ĠTopic (" my Topic ")) ĊĠĠĠĠĠĠĠ Ġrouter 2 . router . subscribe (" my Topic ") ĊĊĠĠĠĠĠĠĠ Ġf uzz . time Controller . add Time ( Duration . of Seconds ( 1 0 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġpublisher 1 Ġ= Ġapi 1 . create Publisher ( null , Ġ 7 7 7 ) ĊĠĠĠĠĠĠĠ Ġval Ġpublish F ut Ġ= Ġpublisher 1 . publish (" Message ". toByteArray (). to Byte Buf (), ĠTopic (" my Topic ")) ĊĊĠĠĠĠĠĠĠ Ġf uzz . time Controller . add Time ( Duration . of Seconds ( 1 )) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( publish F ut . is Done ) ĊĠĠĠĠĠĠĠ Ġval Ġraw Msg Ġ= Ġrouter 2 . inbound Messages . poll ( 1 , ĠTimeUnit . SECONDS ) !!. protobuf Message ĊĠĠĠĠĠĠĠ Ġprintln ( raw Msg ) ĊĠĠĠĠĠĠĠ ĠassertFalse ( raw Msg . has Signature ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( raw Msg . has From ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" Message ", Ġraw Msg . data . toByteArray (). toString ( StandardCharsets . UTF _ 8 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Publish Ext () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf uzz Ġ= ĠDetermin istic F uzz () ĊĠĠĠĠĠĠĠ Ġval Ġrouter 1 Ġ= Ġf uzz . create Test Router ( F lood Router ()) ĊĠĠĠĠĠĠĠ Ġval Ġapi 1 Ġ= Ġcreate Pub sub Api ( router 1 . router ) ĊĠĠĠĠĠĠĠ Ġval Ġrouter 2 Ġ= Ġf uzz . create Test Router ( F lood Router ()) ĊĊĠĠĠĠĠĠĠ Ġrouter 1 . connect Sem i Dup lex ( router 2 ) ĊĊĠĠĠĠĠĠĠ Ġapi 1 . subscribe ( Subscriber Ġ{ Ġprintln ( it ) Ġ}, ĠTopic (" my Topic ")) ĊĠĠĠĠĠĠĠ Ġrouter 2 . router . subscribe (" my Topic ") ĊĊĠĠĠĠĠĠĠ Ġf uzz . time Controller . add Time ( Duration . of Seconds ( 1 0 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġpublisher 1 Ġ= Ġapi 1 . create Publisher ( null , Ġ 7 7 7 ) ĊĠĠĠĠĠĠĠ Ġval Ġpublish F ut Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpublisher 1 . publish Ext (" Message ". toByteArray (). to Byte Buf (), Ġbyte ArrayOf ( 1 , Ġ 2 , Ġ 3 ), Ġ 3 3 3 , ĠTopic (" my Topic ")) ĊĊĠĠĠĠĠĠĠ Ġf uzz . time Controller . add Time ( Duration . of Seconds ( 1 )) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( publish F ut . is Done ) ĊĠĠĠĠĠĠĠ Ġval Ġraw Msg Ġ= Ġrouter 2 . inbound Messages . poll ( 1 , ĠTimeUnit . SECONDS ) !!. protobuf Message ĊĠĠĠĠĠĠĠ Ġprintln ( raw Msg ) ĊĠĠĠĠĠĠĠ ĠassertFalse ( raw Msg . has Signature ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 3 3 , Ġraw Msg . seq no . toByteArray (). copyOf Range ( 0 , Ġ 8 ). to Long BigEndian ()) ĊĠĠĠĠĠĠĠ Ġassert ArrayEquals ( byte ArrayOf ( 1 , Ġ 2 , Ġ 3 ), Ġraw Msg . from . toByteArray ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" Message ", Ġraw Msg . data . toByteArray (). toString ( StandardCharsets . UTF _ 8 )) ĊĠĠĠ Ġ} Ċ } Ċ