Code example for Random

Methods: nextLong, sleep

0
		String topicArn = null;
		String queueURL = null;
 
		try { 
			 
			String topicName = "T" + rand.nextLong();
			CNSTestingUtils.addTopic(cns, user1, out, topicName);
			String res = out.toString();
			topicArn = CNSTestingUtils.getArnFromString(res);
			out.reset();
			 
			CNSTestingUtils.addPermission(cns, user1, out, topicArn, "*", "*", rand.nextLong()+"");
			out.reset();
 
			String token = "faketoken";
 
			CNSTestingUtils.confirmSubscription(cns, user1, out, topicArn, token, null);
			assertTrue(CNSTestingUtils.verifyErrorResponse(out.toString(), "NotFound", "Resource not found."));				
			out.reset();
 
			CNSTestingUtils.confirmSubscription(cns, user1, out, topicArn, null, null);
			assertTrue(CNSTestingUtils.verifyErrorResponse(out.toString(), "InvalidParameter", "request parameter does not comply with the associated constraints."));				
			out.reset();
			 
			String cqsResponse = CNSTestingUtils.addQueue(cqs, user2, "Q" + rand.nextLong());
			ICQSQueuePersistence queueHandler = PersistenceFactory.getQueuePersistence();	
			queueURL = CNSTestingUtils.getQueueUrl(cqsResponse);					
			queueHandler.getQueue(queueURL);
 
			String endpoint = queueURL;
			String protocol = "cqs";
			CNSTestingUtils.setPermissionForUser(cqs, user2, user1, queueURL);
 
			CNSTestingUtils.subscribe(cns, user2, out, endpoint, protocol, topicArn);
			CNSTestingUtils.getSubscriptionArnFromString(out.toString());
			out.reset();
			Thread.sleep(1000);
 
			String msg = CNSTestingUtils.receiveMessage(cqs, user2, queueURL, "1");
			String receiptHandle = CNSTestingUtils.getReceiptHandle(msg);
			String message = CNSTestingUtils.getMessage(msg);
			assertTrue("Failed to receive message", message != null);