4747import java .security .KeyStore ;
4848import java .util .ArrayList ;
4949import java .util .HashMap ;
50+ import java .util .List ;
5051import java .util .Random ;
5152import java .util .concurrent .CountDownLatch ;
5253
@@ -955,38 +956,32 @@ public void onMessageArrived(String topic, byte[] data) {
955956 * Now, Client-1 comes back, connects and subscribes to the topic and
956957 * checks if it can receive the message that Client-2 published.
957958 *
958- * This test is currently ignored because persistent session
959- * (cleanSession = false) is not yet implemented by AWS IoT.
960- *
961- * Please remove the @Ignore annotation when the feature is
962- * released by AWS IoT.
963959 */
964- @ Ignore
965960 @ Test
966961 public void mqttPersistentSession () throws Exception {
967- final ArrayList <AWSIotMqttClientStatusCallback .AWSIotMqttClientStatus > statuses = new ArrayList <AWSIotMqttClientStatusCallback .AWSIotMqttClientStatus >();
968- final ArrayList <String > messages = new ArrayList <String >();
962+ final List <AWSIotMqttClientStatusCallback .AWSIotMqttClientStatus > statuses = new ArrayList <AWSIotMqttClientStatusCallback .AWSIotMqttClientStatus >();
963+ final List <String > messages = new ArrayList <String >();
969964
970965 String largeMessageString = new String ("largeMessageBytes" );
971966 final String topic = "sdk/test/integration/ws/reconnect" ;
972967
973- AWSIotMqttManager mqttManager = new AWSIotMqttManager ("client-id-1" ,
974- Region .getRegion (Regions .US_EAST_1 ),
968+ AWSIotMqttManager mqttManager = new AWSIotMqttManager ("persistent- client-id-1" ,
969+ Region .getRegion (Regions .US_EAST_1 ),
975970 endpointPrefix );
976971
977972 mqttManager .setCleanSession (false );
978- mqttManager .setAutoReconnect (false );
973+ mqttManager .setAutoReconnect (true );
979974
980- // connect to AWS IoT using keystore
975+ // connect to AWS IoT using credentials provider
981976 final CountDownLatch countDownLatch = new CountDownLatch (1 );
982977 mqttManager .connect (credentialsProvider , new AWSIotMqttClientStatusCallback () {
983978 @ Override
984979 public void onStatusChanged (AWSIotMqttClientStatus status , Throwable throwable ) {
985980 statuses .add (status );
986981 if (status == AWSIotMqttClientStatus .Connecting ) {
987- System .out .println ("Client client-id-1 connecton status: " + status );
982+ System .out .println ("Client persistent- client-id-1 connecton status: " + status );
988983 } else if (status == AWSIotMqttClientStatus .Connected ) {
989- System .out .println ("Client client-id-1 connecton status: " + status );
984+ System .out .println ("Client persistent- client-id-1 connecton status: " + status );
990985 countDownLatch .countDown ();
991986 }
992987 }
@@ -999,12 +994,12 @@ public void onStatusChanged(AWSIotMqttClientStatus status, Throwable throwable)
999994 }
1000995
1001996 // subscribe to MQTT topic
1002- mqttManager .subscribeToTopic (topic ,
1003- AWSIotMqttQos .QOS0 ,
997+ mqttManager .subscribeToTopic (topic ,
998+ AWSIotMqttQos .QOS1 ,
1004999 new AWSIotMqttNewMessageCallback () {
10051000 @ Override
10061001 public void onMessageArrived (String topic , byte [] data ) {
1007- System .out .println ("Client client-id-1 received a message on topic:" + topic );
1002+ System .out .println ("Client persistent- client-id-1 received a message on topic:" + topic );
10081003 messages .add (new String (data ));
10091004 }
10101005 });
@@ -1020,23 +1015,20 @@ public void onMessageArrived(String topic, byte[] data) {
10201015 assertEquals (AWSIotMqttClientStatusCallback .AWSIotMqttClientStatus .Connecting , statuses .get (0 ));
10211016 assertEquals (AWSIotMqttClientStatusCallback .AWSIotMqttClientStatus .Connected , statuses .get (1 ));
10221017
1023- AWSIotMqttManager mqttManager2 = new AWSIotMqttManager ("client-id-2" ,
1024- Region .getRegion (Regions .US_EAST_1 ),
1018+ AWSIotMqttManager mqttManager2 = new AWSIotMqttManager ("persistent- client-id-2" ,
1019+ Region .getRegion (Regions .US_EAST_1 ),
10251020 endpointPrefix );
10261021
1027- mqttManager2 .setCleanSession (false );
1028- mqttManager2 .setAutoReconnect (false );
1029-
10301022 // connect to AWS IoT using keystore
10311023 final CountDownLatch countDownLatch2 = new CountDownLatch (1 );
10321024 mqttManager2 .connect (credentialsProvider , new AWSIotMqttClientStatusCallback () {
10331025 @ Override
10341026 public void onStatusChanged (AWSIotMqttClientStatus status , Throwable throwable ) {
10351027 statuses .add (status );
10361028 if (status == AWSIotMqttClientStatus .Connecting ) {
1037- System .out .println ("Client client-id-2 connecton status: " + status );
1029+ System .out .println ("Client persistent- client-id-2 connecton status: " + status );
10381030 } else if (status == AWSIotMqttClientStatus .Connected ) {
1039- System .out .println ("Client client-id-2 connecton status: " + status );
1031+ System .out .println ("Client persistent- client-id-2 connecton status: " + status );
10401032 countDownLatch2 .countDown ();
10411033 }
10421034 }
@@ -1051,11 +1043,11 @@ public void onStatusChanged(AWSIotMqttClientStatus status, Throwable throwable)
10511043 // publish large message
10521044 mqttManager2 .publishString (largeMessageString ,
10531045 topic ,
1054- AWSIotMqttQos .QOS0 ,
1046+ AWSIotMqttQos .QOS1 ,
10551047 new AWSIotMqttMessageDeliveryCallback () {
10561048 @ Override
10571049 public void statusChanged (MessageDeliveryStatus status , Object userData ) {
1058- System .out .println ("Client client-id-2 published a message. Status :" + status );
1050+ System .out .println ("Client persistent- client-id-2 published a message. Status :" + status );
10591051 }
10601052 }, null );
10611053
@@ -1065,23 +1057,16 @@ public void statusChanged(MessageDeliveryStatus status, Object userData) {
10651057 mqttManager2 .disconnect ();
10661058 Thread .sleep (3000 );
10671059
1068- mqttManager = new AWSIotMqttManager ("client-id-1" ,
1069- Region .getRegion (Regions .US_EAST_1 ),
1070- endpointPrefix );
1071-
1072- mqttManager .setCleanSession (false );
1073- mqttManager .setAutoReconnect (true );
1074-
1075- // connect to AWS IoT using keystore
1060+ // connect to AWS IoT using credentials provider
10761061 final CountDownLatch countDownLatch3 = new CountDownLatch (1 );
10771062 mqttManager .connect (credentialsProvider , new AWSIotMqttClientStatusCallback () {
10781063 @ Override
10791064 public void onStatusChanged (AWSIotMqttClientStatus status , Throwable throwable ) {
10801065 statuses .add (status );
10811066 if (status == AWSIotMqttClientStatus .Connecting ) {
1082- System .out .println ("Client client-id-1 connecton status: " + status );
1067+ System .out .println ("Client persistent- client-id-1 connecton status: " + status );
10831068 } else if (status == AWSIotMqttClientStatus .Connected ) {
1084- System .out .println ("Client client-id-1 connecton status: " + status );
1069+ System .out .println ("Client persistent- client-id-1 connecton status: " + status );
10851070 countDownLatch3 .countDown ();
10861071 }
10871072 }
@@ -1095,11 +1080,11 @@ public void onStatusChanged(AWSIotMqttClientStatus status, Throwable throwable)
10951080
10961081 // subscribe to MQTT topic
10971082 mqttManager .subscribeToTopic (topic ,
1098- AWSIotMqttQos .QOS0 ,
1083+ AWSIotMqttQos .QOS1 ,
10991084 new AWSIotMqttNewMessageCallback () {
11001085 @ Override
11011086 public void onMessageArrived (String topic , byte [] data ) {
1102- System .out .println ("Client client-id-1 received a message on topic:" + topic );
1087+ System .out .println ("Client persistent- client-id-1 received a message on topic:" + topic );
11031088 messages .add (new String (data ));
11041089 }
11051090 });
0 commit comments