From 1c1c70cd5a45b4e1dac3df1b1cebb00629778d06 Mon Sep 17 00:00:00 2001 From: "preeti singh[Microsoft]" <preeti.singh@microsoft.com> Date: Thu, 8 Dec 2022 04:22:46 +0000 Subject: [PATCH] adding logs, upgrading neety version in azure, increasing connecttimeout. --- testing/notification-test-azure/pom.xml | 28 ++++--- .../api/TestStorageIntegration.java | 19 ++++- .../osdu/notification/util/TestUtils.java | 84 +++++++++++-------- 3 files changed, 81 insertions(+), 50 deletions(-) diff --git a/testing/notification-test-azure/pom.xml b/testing/notification-test-azure/pom.xml index 4348c8bfc..6147349d3 100644 --- a/testing/notification-test-azure/pom.xml +++ b/testing/notification-test-azure/pom.xml @@ -48,31 +48,33 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>core-lib-azure</artifactId> - <version>0.0.22</version> + <version>0.12.0-rc10</version> <exclusions> - <exclusion> - <groupId>io.projectreactor</groupId> - <artifactId>reactor-core</artifactId> - </exclusion> + <exclusion> <groupId>com.azure</groupId> <artifactId>azure-storage-blob</artifactId> </exclusion> <exclusion> - <groupId>io.projectreactor.netty</groupId> - <artifactId>reactor-netty</artifactId> + <groupId>com.azure</groupId> + <artifactId>azure-core-http-netty</artifactId> </exclusion> </exclusions> </dependency> <dependency> - <groupId>io.projectreactor</groupId> - <artifactId>reactor-core</artifactId> - <version>3.3.5.RELEASE</version> + <groupId>io.netty</groupId> + <artifactId>netty-all</artifactId> + <version>4.1.50.Final</version> + </dependency> + <dependency> + <groupId>io.netty</groupId> + <artifactId>netty-transport</artifactId> + <version>4.1.15.Final</version> </dependency> <dependency> - <groupId>io.projectreactor.netty</groupId> - <artifactId>reactor-netty</artifactId> - <version>0.9.7.RELEASE</version> + <groupId>com.azure</groupId> + <artifactId>azure-core-http-netty</artifactId> + <version>1.2.0</version> </dependency> <dependency> <groupId>junit</groupId> diff --git a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java index e02bd2b89..d8f68d234 100644 --- a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java +++ b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java @@ -32,12 +32,14 @@ import org.opengroup.osdu.notification.util.*; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public class TestStorageIntegration extends BaseTestTemplate { + Logger logger= Logger.getLogger(""); private String subscriptionId = null; private String notificationId = null; private final String ackSubscriptionId = "AckSubscription"; @@ -86,6 +88,7 @@ public class TestStorageIntegration extends BaseTestTemplate { headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken()); DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers); subscriptionService = factory.create(dpsHeaders); + logger.info("dps headers created."); // Create a new subscription Subscription subscription = new Subscription(); @@ -105,6 +108,7 @@ public class TestStorageIntegration extends BaseTestTemplate { System.out.println("Subscription exception inner response : " + e.getHttpResponse()); throw e; } + logger.info("New subscription created"); } private void deleteAckSubscription() throws SubscriptionException { @@ -141,19 +145,26 @@ public class TestStorageIntegration extends BaseTestTemplate { try { // Creates an actual subscription with a test endpoint i.e REGISTER_CUSTOM_PUSH_URL_HMAC this.createResource(); + logger.info("Actual subscription with a test endpoint created successfully"); + // Delay to get the above subscription registered by Notification Service TimeUnit.SECONDS.sleep(60); - + logger.info("Subscription registered by Notification service successfully"); + // Delete the Test Ack subscription if there exists any as a part of cleanup. // The Test Ack Subscription gets created if the the test endpoint of actual subscription // created above receives notification from Notification Service. this.deleteAckSubscription(); // Delete legal tag + logger.info("Cleaning up previous Legal Tag if any. "); LegalTagUtils.delete(LEGAL_TAG, this.testUtils.getAdminToken()); - + + // Create legal tag used in storage record + logger.info("Creating New legal tag"); LegalTagUtils.create(LEGAL_TAG, this.testUtils.getAdminToken()); + // Insert a storage Record.This will send a notification to the event grid/service bus topic // subscriptions.From there it goes to the Notification Service.Finally from there it goes to the // test endpoint i.e REGISTER_CUSTOM_PUSH_URL_HMAC which creates the Test ack Subscription. @@ -172,21 +183,25 @@ public class TestStorageIntegration extends BaseTestTemplate { while (ackSubscription == null && retryCount > 0) { TimeUnit.SECONDS.sleep(timeOut); ackSubscription = subscriptionService.get(ackSubscriptionId); + logger.info("Retry time: "+retryCount+" to get Test Ack subscription."); retryCount--; } Assertions.assertNotNull(ackSubscription, "Unable to retrieve test ack subscription. Elapsed time in minutes : " + (stopWatch.getTime(TimeUnit.MINUTES))); if (ackSubscription != null) { assertEquals("Unexpected Test Ack Subscription.", ackNotificationId, ackSubscription.getNotificationId()); } + logger.info("IT run successful"); stopWatch.stop(); } catch (Exception e) { fail("An exception occurred :" + e); } finally { + logger.info("Executing finally block"); // Delete Actual Subscription this.deleteResource(); // Deletion of Test Ack Subscription this.deleteAckSubscription(); // Delete legal tag + logger.info("Deleting legal tag"); LegalTagUtils.delete(LEGAL_TAG, this.testUtils.getAdminToken()); } diff --git a/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java b/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java index 17d5d90b5..9e49c7b65 100644 --- a/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java +++ b/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java @@ -22,6 +22,7 @@ import java.net.URL; import java.security.SecureRandom; import java.security.cert.X509Certificate; import java.util.*; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; @@ -35,6 +36,7 @@ import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; public abstract class TestUtils { + static Logger logger = Logger.getLogger(""); protected String serviceAccountFile; protected static String opsToken = null; protected static String adminToken = null; @@ -75,47 +77,58 @@ public abstract class TestUtils { public static ClientResponse send(String path, String httpMethod, String token, String requestBody, String query, Map<String, String> headers, boolean enforceHttp) throws Exception { - - Client client = getClient(); - client.setConnectTimeout(50000); - client.setReadTimeout(50000); - client.setFollowRedirects(false); - String url = getApiPath(path + query, enforceHttp); - System.out.println(url); - System.out.println(httpMethod); - System.out.println(requestBody); - System.out.println(headers); - - WebResource webResource = client.resource(url); - final WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON) - .header("Authorization", token); - headers.forEach((k, v) -> builder.header(k, v)); - ClientResponse response = builder.method(httpMethod, ClientResponse.class, requestBody); - + ClientResponse response; + try { + Client client = getClient(); + client.setConnectTimeout(300000); + client.setReadTimeout(50000); + client.setFollowRedirects(false); + String url = getApiPath(path + query, enforceHttp); + System.out.println(url); + System.out.println(httpMethod); + System.out.println(requestBody); + System.out.println(headers); + + WebResource webResource = client.resource(url); + final WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON) + .header("Authorization", token); + headers.forEach((k, v) -> builder.header(k, v)); + response = builder.method(httpMethod, ClientResponse.class, requestBody); + } catch (Exception e) { + e.printStackTrace(); + throw new AssertionError("Error: Send request error", e); + } + logger.info("waiting on response"); return response; } public static ClientResponse send(String url, String path, String httpMethod, String token, String requestBody, String query, Map<String, String> headers, boolean enforceHttp) throws Exception { - - Client client = getClient(); - client.setConnectTimeout(50000); - client.setReadTimeout(50000); - client.setFollowRedirects(false); - String URL = getApiPath(url, path + query, enforceHttp); - System.out.println(url + path); - System.out.println(httpMethod); - System.out.println(requestBody); - System.out.println(headers); - WebResource webResource = client.resource(URL); - final WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON); - if (!token.isEmpty()) { - builder.header("Authorization", token); + ClientResponse response; + try { + Client client = getClient(); + client.setConnectTimeout(300000); + client.setReadTimeout(50000); + client.setFollowRedirects(false); + String URL = getApiPath(url, path + query, enforceHttp); + System.out.println(url + path); + System.out.println(httpMethod); + System.out.println(requestBody); + System.out.println(headers); + WebResource webResource = client.resource(URL); + final WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON); + if (!token.isEmpty()) { + logger.info("Token is not empty so adding to request header"); + builder.header("Authorization", token); + } + headers.forEach((k, v) -> builder.header(k, v)); + response = builder.method(httpMethod, ClientResponse.class, requestBody); + } catch (Exception e) { + e.printStackTrace(); + throw new AssertionError("Error: Send request error", e); } - headers.forEach((k, v) -> builder.header(k, v)); - ClientResponse response = builder.method(httpMethod, ClientResponse.class, requestBody); - + logger.info("waiting on response"); return response; } @@ -159,8 +172,9 @@ public abstract class TestUtils { sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { + logger.info("Exception occurred"); } - + logger.info("Creating client"); return Client.create(); } } \ No newline at end of file -- GitLab