From fdde1007a63617675e30230964babe01ec953dab Mon Sep 17 00:00:00 2001 From: lastpeony Date: Thu, 22 Feb 2024 14:21:11 +0300 Subject: [PATCH 01/10] retry sending webhook with n seconds delay n retry attempts if response is not 200 or IO exception --- .../antmedia/AntMediaApplicationAdapter.java | 105 +++++++++++------- .../AntMediaApplicationAdaptorUnitTest.java | 53 +++++---- 2 files changed, 89 insertions(+), 69 deletions(-) diff --git a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java index cd17837e5..1a3c76fe2 100644 --- a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java +++ b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java @@ -6,32 +6,30 @@ import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.net.SocketTimeoutException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Queue; -import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import javax.validation.constraints.NotNull; +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; @@ -102,6 +100,10 @@ public class AntMediaApplicationAdapter extends MultiThreadedApplicationAdapter public static final String HOOK_ACTION_ENCODER_NOT_OPENED_ERROR = "encoderNotOpenedError"; public static final String HOOK_ACTION_ENDPOINT_FAILED = "endpointFailed"; + public static final int WEBHOOK_RETRY_COUNT = 3; + + public static final int RETRY_SEND_POST_DELAY_SECONDS = 5; + public static final String STREAMS = "streams"; public static final String DEFAULT_LOCALHOST = "127.0.0.1"; @@ -868,56 +870,75 @@ public StringBuilder notifyHook(String url, String id, String action, String str } try { - response = sendPOST(url, variables); + sendPOST(url, variables, WEBHOOK_RETRY_COUNT, result -> {}); } catch (Exception e) { - //Make Exception generi logger.error(ExceptionUtils.getStackTrace(e)); } } - return response; + return null; } - public StringBuilder sendPOST(String url, Map variables) throws IOException { + public void sendPOST(String url, Map variables, int retryAttempts, Handler> resultHandler) { - StringBuilder response = null; - try (CloseableHttpClient httpClient = getHttpClient()) - { - HttpPost httpPost = new HttpPost(url); - RequestConfig requestConfig =RequestConfig.custom() - .setConnectTimeout(2000) - .setConnectionRequestTimeout(2000) - .setSocketTimeout(2000).build(); - httpPost.setConfig(requestConfig); - List urlParameters = new ArrayList<>(); - Set> entrySet = variables.entrySet(); - for (Entry entry : entrySet) { - urlParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); + vertx.executeBlocking(future -> { + if (retryAttempts < 0) { + logger.info("Stopping sending POST because no more retry attempts left. Giving up."); + future.complete(null); + return; } + logger.info("Sending POST request to {}", url); + StringBuilder response; + try (CloseableHttpClient httpClient = getHttpClient()) { + HttpPost httpPost = new HttpPost(url); + RequestConfig requestConfig = RequestConfig.custom() + .setConnectTimeout(2000) + .setConnectionRequestTimeout(2000) + .setSocketTimeout(2000) + .build(); + httpPost.setConfig(requestConfig); + List urlParameters = new ArrayList<>(); + Set> entrySet = variables.entrySet(); + for (Entry entry : entrySet) { + urlParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); + } - HttpEntity postParams = new UrlEncodedFormEntity(urlParameters); - httpPost.setEntity(postParams); + HttpEntity postParams = new UrlEncodedFormEntity(urlParameters); + httpPost.setEntity(postParams); - try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { - logger.info("POST Response Status:: {}" , httpResponse.getStatusLine().getStatusCode()); + try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { + int statusCode = httpResponse.getStatusLine().getStatusCode(); + logger.info("POST Response Status: {}", statusCode); - HttpEntity entity = httpResponse.getEntity(); - if (entity != null) - { - //read entity if it's available - BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); + if (statusCode == HttpStatus.SC_OK) { + // Read entity if it's available + BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); - String inputLine; - response = new StringBuilder(); + String inputLine; + response = new StringBuilder(); - while ((inputLine = reader.readLine()) != null) { - response.append(inputLine); + while ((inputLine = reader.readLine()) != null) { + response.append(inputLine); + } + reader.close(); + } else { + logger.info("Retry attempt for POST in {} seconds due to non-200 response: {}" , RETRY_SEND_POST_DELAY_SECONDS, statusCode); + retrySendPostWithDelay(url, variables, retryAttempts - 1, resultHandler); + return; } - reader.close(); } + } catch (IOException e) { + logger.info("Retry attempt for POST in {} seconds due to IO exception: {}", RETRY_SEND_POST_DELAY_SECONDS, e.getMessage()); + retrySendPostWithDelay(url, variables, retryAttempts - 1, resultHandler); + return; } + future.complete(response); + }, resultHandler); + } - } - return response; + private void retrySendPostWithDelay(String url, Map variables, int retryAttempts, Handler> resultHandler) { + vertx.setTimer(RETRY_SEND_POST_DELAY_SECONDS * 1000, timerId -> { + sendPOST(url, variables, retryAttempts, resultHandler); + }); } public CloseableHttpClient getHttpClient() { diff --git a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java index ead6481d1..4a8c486ec 100644 --- a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java +++ b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java @@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import io.vertx.core.*; import org.apache.commons.lang3.RandomUtils; import org.apache.http.HttpEntity; import org.apache.http.StatusLine; @@ -95,8 +96,6 @@ import io.antmedia.streamsource.StreamFetcher; import io.antmedia.streamsource.StreamFetcherManager; import io.antmedia.track.ISubtrackPoller; -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; import io.vertx.core.impl.VertxImpl; import io.vertx.ext.dropwizard.DropwizardMetricsOptions; @@ -687,7 +686,10 @@ public void testSendPost() { Mockito.when(httpResponse.getStatusLine()).thenReturn(Mockito.mock(StatusLine.class)); Mockito.when(httpResponse.getEntity()).thenReturn(null); - StringBuilder response = spyAdaptor.sendPOST("http://any_url", new HashMap()); + + + + /*StringBuilder response = spyAdaptor.sendPOST("http://any_url", new HashMap() , AntMediaApplicationAdapter.WEBHOOK_RETRY_COUNT, null); assertNull(response); HttpEntity entity = Mockito.mock(HttpEntity.class); @@ -696,9 +698,9 @@ public void testSendPost() { Mockito.when(httpResponse.getEntity()).thenReturn(entity); HashMap map = new HashMap(); map.put("action", "action_any"); - response = spyAdaptor.sendPOST("http://any_url", map); + response = spyAdaptor.sendPOST("http://any_url", map, AntMediaApplicationAdapter.WEBHOOK_RETRY_COUNT, null); assertNotNull(response); - assertEquals(10, response.length()); + assertEquals(10, response.length());*/ } catch (IOException e) { @@ -780,10 +782,11 @@ public void testNotifyHook() { notifyHook = spyAdaptor.notifyHook(url, id, action, streamName, category, vodName, vodId, null); assertNull(notifyHook); - try { ArgumentCaptor captureUrl = ArgumentCaptor.forClass(String.class); ArgumentCaptor variables = ArgumentCaptor.forClass(Map.class); - Mockito.verify(spyAdaptor).sendPOST(captureUrl.capture(), variables.capture()); + ArgumentCaptor retryAttempts = ArgumentCaptor.forClass(Integer.class); + ArgumentCaptor>> handler = ArgumentCaptor.forClass(Handler.class); + Mockito.verify(spyAdaptor).sendPOST(captureUrl.capture(), variables.capture(), retryAttempts.capture(), handler.capture()); assertEquals(url, captureUrl.getValue()); Map variablesMap = variables.getValue(); @@ -794,34 +797,30 @@ public void testNotifyHook() { assertEquals(vodName, variablesMap.get("vodName")); assertEquals(vodId, variablesMap.get("vodId")); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + url = "this is second url"; notifyHook = spyAdaptor.notifyHook(url, id, null, null, null, null, null, null); assertNull(notifyHook); - try { - ArgumentCaptor captureUrl = ArgumentCaptor.forClass(String.class); - ArgumentCaptor variables = ArgumentCaptor.forClass(Map.class); - Mockito.verify(spyAdaptor, Mockito.times(2)).sendPOST(captureUrl.capture(), variables.capture()); - assertEquals(url, captureUrl.getValue()); + ArgumentCaptor captureUrl2 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor variables2 = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor retryAttempts2 = ArgumentCaptor.forClass(Integer.class); + ArgumentCaptor>> handler2 = ArgumentCaptor.forClass(Handler.class); + + Mockito.verify(spyAdaptor, Mockito.times(2)).sendPOST(captureUrl2.capture(), variables2.capture(), retryAttempts2.capture(), handler2.capture()); + assertEquals(url, captureUrl2.getValue()); + + Map variablesMap2 = variables2.getValue(); + assertEquals(id, variablesMap2.get("id")); + assertNull(variablesMap2.get("action")); + assertNull(variablesMap2.get("streamName")); + assertNull(variablesMap2.get("category")); + assertNull(variablesMap2.get("vodName")); + assertNull(variablesMap2.get("vodId")); - Map variablesMap = variables.getValue(); - assertEquals(id, variablesMap.get("id")); - assertNull(variablesMap.get("action")); - assertNull(variablesMap.get("streamName")); - assertNull(variablesMap.get("category")); - assertNull(variablesMap.get("vodName")); - assertNull(variablesMap.get("vodId")); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } } @Test From b4683f169267849deeba8a981a49f48a8a42dd84 Mon Sep 17 00:00:00 2001 From: lastpeony Date: Fri, 23 Feb 2024 15:59:52 +0300 Subject: [PATCH 02/10] unit testing and improvements --- .../antmedia/AntMediaApplicationAdapter.java | 57 +++++++++---------- src/main/java/io/antmedia/AppSettings.java | 34 ++++++++++- .../AntMediaApplicationAdaptorUnitTest.java | 56 ++++++++++++------ .../io/antmedia/test/AppSettingsUnitTest.java | 13 ++++- 4 files changed, 113 insertions(+), 47 deletions(-) diff --git a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java index 1a3c76fe2..50bc59773 100644 --- a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java +++ b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java @@ -100,10 +100,6 @@ public class AntMediaApplicationAdapter extends MultiThreadedApplicationAdapter public static final String HOOK_ACTION_ENCODER_NOT_OPENED_ERROR = "encoderNotOpenedError"; public static final String HOOK_ACTION_ENDPOINT_FAILED = "endpointFailed"; - public static final int WEBHOOK_RETRY_COUNT = 3; - - public static final int RETRY_SEND_POST_DELAY_SECONDS = 5; - public static final String STREAMS = "streams"; public static final String DEFAULT_LOCALHOST = "127.0.0.1"; @@ -870,7 +866,7 @@ public StringBuilder notifyHook(String url, String id, String action, String str } try { - sendPOST(url, variables, WEBHOOK_RETRY_COUNT, result -> {}); + sendPOST(url, variables, appSettings.getWebhookRetryCount()); } catch (Exception e) { logger.error(ExceptionUtils.getStackTrace(e)); } @@ -878,16 +874,9 @@ public StringBuilder notifyHook(String url, String id, String action, String str return null; } - public void sendPOST(String url, Map variables, int retryAttempts, Handler> resultHandler) { - - vertx.executeBlocking(future -> { - if (retryAttempts < 0) { - logger.info("Stopping sending POST because no more retry attempts left. Giving up."); - future.complete(null); - return; - } + public StringBuilder sendPOST(String url, Map variables, int retryAttempts) { logger.info("Sending POST request to {}", url); - StringBuilder response; + StringBuilder response = null; try (CloseableHttpClient httpClient = getHttpClient()) { HttpPost httpPost = new HttpPost(url); RequestConfig requestConfig = RequestConfig.custom() @@ -908,9 +897,8 @@ public void sendPOST(String url, Map variables, int retryAttempt try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { int statusCode = httpResponse.getStatusLine().getStatusCode(); logger.info("POST Response Status: {}", statusCode); - - if (statusCode == HttpStatus.SC_OK) { - // Read entity if it's available + HttpEntity entity = httpResponse.getEntity(); + if(entity != null){ BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); String inputLine; @@ -920,24 +908,35 @@ public void sendPOST(String url, Map variables, int retryAttempt response.append(inputLine); } reader.close(); - } else { - logger.info("Retry attempt for POST in {} seconds due to non-200 response: {}" , RETRY_SEND_POST_DELAY_SECONDS, statusCode); - retrySendPostWithDelay(url, variables, retryAttempts - 1, resultHandler); - return; + } + + if (statusCode != HttpStatus.SC_OK) { + if(!(retryAttempts - 1 < 0)){ + logger.info("Retry attempt for POST in {} milliseconds due to non-200 response: {}" , appSettings.getWebhookRetryDelay(), statusCode); + retrySendPostWithDelay(url, variables, retryAttempts - 1); + }else if(appSettings.getWebhookRetryCount() != 0){ + logger.info("Stopping sending POST because no more retry attempts left. Giving up."); + } + } + return response; + } } catch (IOException e) { - logger.info("Retry attempt for POST in {} seconds due to IO exception: {}", RETRY_SEND_POST_DELAY_SECONDS, e.getMessage()); - retrySendPostWithDelay(url, variables, retryAttempts - 1, resultHandler); - return; + if(!(retryAttempts - 1 < 0)) { + logger.info("Retry attempt for POST in {} milliseconds due to IO exception: {}", appSettings.getWebhookRetryDelay(), e.getMessage()); + retrySendPostWithDelay(url, variables, retryAttempts - 1); + }else if(appSettings.getWebhookRetryCount() != 0){ + logger.info("Stopping sending POST because no more retry attempts left. Giving up."); + } } - future.complete(response); - }, resultHandler); + return null; } - private void retrySendPostWithDelay(String url, Map variables, int retryAttempts, Handler> resultHandler) { - vertx.setTimer(RETRY_SEND_POST_DELAY_SECONDS * 1000, timerId -> { - sendPOST(url, variables, retryAttempts, resultHandler); + public void retrySendPostWithDelay(String url, Map variables, int retryAttempts) { + System.out.println("RETRY SEND POST WITH DELAY!!"); + vertx.setTimer(appSettings.getWebhookRetryDelay(), timerId -> { + sendPOST(url, variables, retryAttempts); }); } diff --git a/src/main/java/io/antmedia/AppSettings.java b/src/main/java/io/antmedia/AppSettings.java index 824f3b939..a30d9fb40 100644 --- a/src/main/java/io/antmedia/AppSettings.java +++ b/src/main/java/io/antmedia/AppSettings.java @@ -732,6 +732,10 @@ public class AppSettings implements Serializable{ */ private static final String SETTINGS_CLUSTER_COMMUNICATION_KEY = "settings.clusterCommunicationKey"; + private static final String SETTINGS_WEBHOOK_RETRY_COUNT = "settings.webHookRetryCount"; + + private static final String SETTINGS_WEBHOOK_RETRY_DELAY = "settings.webHookRetryDelay"; + /** * Comma separated CIDR that rest services are allowed to response @@ -2094,7 +2098,19 @@ public boolean isWriteStatsToDatastore() { */ @Value("${apnKeyId:#{null}}") private String apnKeyId; - + + /** + * Retry count on webhook POST failure + */ + @Value("${webhookRetryCount:${"+SETTINGS_WEBHOOK_RETRY_COUNT+":0}}") + private int webhookRetryCount = 0; + + /** + * Delay in milliseconds between webhook attempts on POST failure. + */ + @Value("${webhookRetryAttemptDelay:${"+SETTINGS_WEBHOOK_RETRY_DELAY+":1000}}") + private long webhookRetryDelay = 1000; + public void setWriteStatsToDatastore(boolean writeStatsToDatastore) { this.writeStatsToDatastore = writeStatsToDatastore; } @@ -3623,4 +3639,20 @@ public void setApnsServer(String apnsServer) { this.apnsServer = apnsServer; } + public int getWebhookRetryCount() { + return webhookRetryCount; + } + + public void setWebhookRetryCount(int webhookRetryCount) { + this.webhookRetryCount = webhookRetryCount; + } + + public long getWebhookRetryDelay() { + return webhookRetryDelay; + } + + public void setWebhookRetryDelay(long webhookRetryDelay) { + this.webhookRetryDelay = webhookRetryDelay; + } + } diff --git a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java index 4a8c486ec..2c9eda9bc 100644 --- a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java +++ b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java @@ -7,13 +7,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.*; import java.io.ByteArrayInputStream; import java.io.File; @@ -51,6 +46,7 @@ import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.red5.server.api.IContext; import org.red5.server.api.scope.IScope; @@ -677,6 +673,8 @@ public void testRunMuxerScript() { public void testSendPost() { try { AntMediaApplicationAdapter spyAdaptor = Mockito.spy(adapter); + AppSettings appSettings = new AppSettings(); + spyAdaptor.setAppSettings(appSettings); CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); Mockito.doReturn(httpClient).when(spyAdaptor).getHttpClient(); @@ -687,9 +685,7 @@ public void testSendPost() { Mockito.when(httpResponse.getEntity()).thenReturn(null); - - - /*StringBuilder response = spyAdaptor.sendPOST("http://any_url", new HashMap() , AntMediaApplicationAdapter.WEBHOOK_RETRY_COUNT, null); + StringBuilder response = spyAdaptor.sendPOST("http://any_url", new HashMap(), appSettings.getWebhookRetryCount() ); assertNull(response); HttpEntity entity = Mockito.mock(HttpEntity.class); @@ -698,10 +694,40 @@ public void testSendPost() { Mockito.when(httpResponse.getEntity()).thenReturn(entity); HashMap map = new HashMap(); map.put("action", "action_any"); - response = spyAdaptor.sendPOST("http://any_url", map, AntMediaApplicationAdapter.WEBHOOK_RETRY_COUNT, null); + response = spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); assertNotNull(response); - assertEquals(10, response.length());*/ + assertEquals(10, response.length()); + + appSettings.setWebhookRetryCount(1); + + HttpEntity entity2 = Mockito.mock(HttpEntity.class); + InputStream is2 = new ByteArrayInputStream(ByteBuffer.allocate(10).array()); + Mockito.when(entity2.getContent()).thenReturn(is2); + Mockito.when(httpResponse.getEntity()).thenReturn(entity2); + + StatusLine statusLine = Mockito.mock(StatusLine.class); + + Mockito.when(httpResponse.getStatusLine()).thenReturn(statusLine); + Mockito.when(statusLine.getStatusCode()).thenReturn(404); + + spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); + + verify(spyAdaptor).retrySendPostWithDelay( + ArgumentMatchers.eq("http://any_url"), + ArgumentMatchers.eq(map), + ArgumentMatchers.eq(appSettings.getWebhookRetryCount() - 1) + ); + + Mockito.when(statusLine.getStatusCode()).thenReturn(200); + spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); + + when(httpClient.execute(any())).thenThrow(new IOException("Simulated IOException")); + spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); + + appSettings.setWebhookRetryCount(0); + spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); + Mockito.verify(spyAdaptor, Mockito.times(2)).retrySendPostWithDelay(any(), any(), anyInt()); } catch (IOException e) { e.printStackTrace(); @@ -785,8 +811,7 @@ public void testNotifyHook() { ArgumentCaptor captureUrl = ArgumentCaptor.forClass(String.class); ArgumentCaptor variables = ArgumentCaptor.forClass(Map.class); ArgumentCaptor retryAttempts = ArgumentCaptor.forClass(Integer.class); - ArgumentCaptor>> handler = ArgumentCaptor.forClass(Handler.class); - Mockito.verify(spyAdaptor).sendPOST(captureUrl.capture(), variables.capture(), retryAttempts.capture(), handler.capture()); + Mockito.verify(spyAdaptor).sendPOST(captureUrl.capture(), variables.capture(), retryAttempts.capture()); assertEquals(url, captureUrl.getValue()); Map variablesMap = variables.getValue(); @@ -807,9 +832,8 @@ public void testNotifyHook() { ArgumentCaptor captureUrl2 = ArgumentCaptor.forClass(String.class); ArgumentCaptor variables2 = ArgumentCaptor.forClass(Map.class); ArgumentCaptor retryAttempts2 = ArgumentCaptor.forClass(Integer.class); - ArgumentCaptor>> handler2 = ArgumentCaptor.forClass(Handler.class); - Mockito.verify(spyAdaptor, Mockito.times(2)).sendPOST(captureUrl2.capture(), variables2.capture(), retryAttempts2.capture(), handler2.capture()); + Mockito.verify(spyAdaptor, Mockito.times(2)).sendPOST(captureUrl2.capture(), variables2.capture(), retryAttempts2.capture()); assertEquals(url, captureUrl2.getValue()); Map variablesMap2 = variables2.getValue(); diff --git a/src/test/java/io/antmedia/test/AppSettingsUnitTest.java b/src/test/java/io/antmedia/test/AppSettingsUnitTest.java index 82357b772..14e09f86e 100644 --- a/src/test/java/io/antmedia/test/AppSettingsUnitTest.java +++ b/src/test/java/io/antmedia/test/AppSettingsUnitTest.java @@ -299,6 +299,15 @@ public void testSettings() { String privateKey = "privateKey"; appSettings.setApnPrivateKey(privateKey); assertEquals(privateKey, appSettings.getApnPrivateKey()); + + int webHookRetryCount = 2; + appSettings.setWebhookRetryCount(webHookRetryCount); + assertEquals(webHookRetryCount, appSettings.getWebhookRetryCount()); + + long webHookRetryDelay = 2000; + appSettings.setWebhookRetryDelay(webHookRetryDelay); + assertEquals(webHookRetryDelay, appSettings.getWebhookRetryDelay()); + } @@ -517,12 +526,14 @@ public void testUnsetAppSettings(AppSettings appSettings) { assertNull(appSettings.getApnTeamId()); assertNull(appSettings.getApnPrivateKey()); assertEquals("api.sandbox.push.apple.com", appSettings.getApnsServer()); + assertEquals(0, appSettings.getWebhookRetryCount()); + assertEquals(1000, appSettings.getWebhookRetryDelay()); //if we add a new field, we just need to check its default value in this test //When a new field is added or removed please update the number of fields and make this test pass //by also checking its default value. assertEquals("New field is added to settings. PAY ATTENTION: Please CHECK ITS DEFAULT VALUE and fix the number of fields.", - 174, numberOfFields); + 176, numberOfFields); } From 821f14dac59173164ddb13b4b2c88b702fd2aaf7 Mon Sep 17 00:00:00 2001 From: lastpeony Date: Mon, 26 Feb 2024 12:00:43 +0300 Subject: [PATCH 03/10] code improvement --- src/main/java/io/antmedia/AntMediaApplicationAdapter.java | 4 ++-- .../io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java index baba8a1e6..581f1da16 100644 --- a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java +++ b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java @@ -913,7 +913,7 @@ public StringBuilder sendPOST(String url, Map variables, int ret } if (statusCode != HttpStatus.SC_OK) { - if (!(retryAttempts - 1 < 0)) { + if (retryAttempts >= 1) { logger.info("Retry attempt for POST in {} milliseconds due to non-200 response: {}", appSettings.getWebhookRetryDelay(), statusCode); retrySendPostWithDelay(url, variables, retryAttempts - 1); } else if (appSettings.getWebhookRetryCount() != 0) { @@ -923,7 +923,7 @@ public StringBuilder sendPOST(String url, Map variables, int ret return response; } } catch (IOException e) { - if (!(retryAttempts - 1 < 0)) { + if (retryAttempts >= 1) { logger.info("Retry attempt for POST in {} milliseconds due to IO exception: {}", appSettings.getWebhookRetryDelay(), e.getMessage()); retrySendPostWithDelay(url, variables, retryAttempts - 1); } else if (appSettings.getWebhookRetryCount() != 0) { diff --git a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java index 2c9eda9bc..fbbe8af2c 100644 --- a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java +++ b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java @@ -788,6 +788,9 @@ public void testHookAfterDefined() public void testNotifyHook() { AntMediaApplicationAdapter spyAdaptor = Mockito.spy(adapter); + AppSettings appSettings = new AppSettings(); + appSettings.setWebhookRetryCount(2); + spyAdaptor.setAppSettings(appSettings); StringBuilder notifyHook = spyAdaptor.notifyHook(null, null, null, null, null, null, null, null); assertNull(notifyHook); From b8b4623b206b2bf6617664cc3f1e456f8a185929 Mon Sep 17 00:00:00 2001 From: lastpeony Date: Mon, 26 Feb 2024 19:20:22 +0300 Subject: [PATCH 04/10] remove static fields from app settings --- src/main/java/io/antmedia/AppSettings.java | 8 +-- .../AntMediaApplicationAdaptorUnitTest.java | 51 +++++++++---------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/main/java/io/antmedia/AppSettings.java b/src/main/java/io/antmedia/AppSettings.java index a30d9fb40..b42c82515 100644 --- a/src/main/java/io/antmedia/AppSettings.java +++ b/src/main/java/io/antmedia/AppSettings.java @@ -732,10 +732,6 @@ public class AppSettings implements Serializable{ */ private static final String SETTINGS_CLUSTER_COMMUNICATION_KEY = "settings.clusterCommunicationKey"; - private static final String SETTINGS_WEBHOOK_RETRY_COUNT = "settings.webHookRetryCount"; - - private static final String SETTINGS_WEBHOOK_RETRY_DELAY = "settings.webHookRetryDelay"; - /** * Comma separated CIDR that rest services are allowed to response @@ -2102,13 +2098,13 @@ public boolean isWriteStatsToDatastore() { /** * Retry count on webhook POST failure */ - @Value("${webhookRetryCount:${"+SETTINGS_WEBHOOK_RETRY_COUNT+":0}}") + @Value("${webhookRetryCount:0}") private int webhookRetryCount = 0; /** * Delay in milliseconds between webhook attempts on POST failure. */ - @Value("${webhookRetryAttemptDelay:${"+SETTINGS_WEBHOOK_RETRY_DELAY+":1000}}") + @Value("${webhookRetryAttemptDelay:1000}") private long webhookRetryDelay = 1000; public void setWriteStatsToDatastore(boolean writeStatsToDatastore) { diff --git a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java index fbbe8af2c..5212e204f 100644 --- a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java +++ b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java @@ -811,42 +811,39 @@ public void testNotifyHook() { notifyHook = spyAdaptor.notifyHook(url, id, action, streamName, category, vodName, vodId, null); assertNull(notifyHook); - ArgumentCaptor captureUrl = ArgumentCaptor.forClass(String.class); - ArgumentCaptor variables = ArgumentCaptor.forClass(Map.class); - ArgumentCaptor retryAttempts = ArgumentCaptor.forClass(Integer.class); - Mockito.verify(spyAdaptor).sendPOST(captureUrl.capture(), variables.capture(), retryAttempts.capture()); - assertEquals(url, captureUrl.getValue()); - - Map variablesMap = variables.getValue(); - assertEquals(id, variablesMap.get("id")); - assertEquals(action, variablesMap.get("action")); - assertEquals(streamName, variablesMap.get("streamName")); - assertEquals(category, variablesMap.get("category")); - assertEquals(vodName, variablesMap.get("vodName")); - assertEquals(vodId, variablesMap.get("vodId")); - + ArgumentCaptor captureUrl = ArgumentCaptor.forClass(String.class); + ArgumentCaptor variables = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor retryAttempts = ArgumentCaptor.forClass(Integer.class); + Mockito.verify(spyAdaptor).sendPOST(captureUrl.capture(), variables.capture(), retryAttempts.capture()); + assertEquals(url, captureUrl.getValue()); + Map variablesMap = variables.getValue(); + assertEquals(id, variablesMap.get("id")); + assertEquals(action, variablesMap.get("action")); + assertEquals(streamName, variablesMap.get("streamName")); + assertEquals(category, variablesMap.get("category")); + assertEquals(vodName, variablesMap.get("vodName")); + assertEquals(vodId, variablesMap.get("vodId")); url = "this is second url"; notifyHook = spyAdaptor.notifyHook(url, id, null, null, null, null, null, null); assertNull(notifyHook); - ArgumentCaptor captureUrl2 = ArgumentCaptor.forClass(String.class); - ArgumentCaptor variables2 = ArgumentCaptor.forClass(Map.class); - ArgumentCaptor retryAttempts2 = ArgumentCaptor.forClass(Integer.class); - - Mockito.verify(spyAdaptor, Mockito.times(2)).sendPOST(captureUrl2.capture(), variables2.capture(), retryAttempts2.capture()); - assertEquals(url, captureUrl2.getValue()); + ArgumentCaptor captureUrl2 = ArgumentCaptor.forClass(String.class); + ArgumentCaptor variables2 = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor retryAttempts2 = ArgumentCaptor.forClass(Integer.class); - Map variablesMap2 = variables2.getValue(); - assertEquals(id, variablesMap2.get("id")); - assertNull(variablesMap2.get("action")); - assertNull(variablesMap2.get("streamName")); - assertNull(variablesMap2.get("category")); - assertNull(variablesMap2.get("vodName")); - assertNull(variablesMap2.get("vodId")); + Mockito.verify(spyAdaptor, Mockito.times(2)).sendPOST(captureUrl2.capture(), variables2.capture(), retryAttempts2.capture()); + assertEquals(url, captureUrl2.getValue()); + Map variablesMap2 = variables2.getValue(); + assertEquals(id, variablesMap2.get("id")); + assertNull(variablesMap2.get("action")); + assertNull(variablesMap2.get("streamName")); + assertNull(variablesMap2.get("category")); + assertNull(variablesMap2.get("vodName")); + assertNull(variablesMap2.get("vodId")); } From 9904afc25a7d9698b2e48e873b754ca0e8001895 Mon Sep 17 00:00:00 2001 From: lastpeony Date: Tue, 27 Feb 2024 17:38:58 +0300 Subject: [PATCH 05/10] sendPOST return type to void --- .../antmedia/AntMediaApplicationAdapter.java | 24 +------------------ .../AntMediaApplicationAdaptorUnitTest.java | 12 ++++++---- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java index a2f6fe540..6738756d3 100644 --- a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java +++ b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java @@ -1,12 +1,9 @@ package io.antmedia; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.net.SocketTimeoutException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -18,8 +15,6 @@ import javax.validation.constraints.NotNull; -import io.vertx.core.AsyncResult; -import io.vertx.core.Handler; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.RandomStringUtils; @@ -31,8 +26,6 @@ import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.conn.ConnectTimeoutException; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; @@ -889,9 +882,8 @@ public StringBuilder notifyHook(String url, String id, String action, String str return null; } - public StringBuilder sendPOST(String url, Map variables, int retryAttempts) { + public void sendPOST(String url, Map variables, int retryAttempts) { logger.info("Sending POST request to {}", url); - StringBuilder response = null; try (CloseableHttpClient httpClient = getHttpClient()) { HttpPost httpPost = new HttpPost(url); RequestConfig requestConfig = RequestConfig.custom() @@ -912,18 +904,6 @@ public StringBuilder sendPOST(String url, Map variables, int ret try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { int statusCode = httpResponse.getStatusLine().getStatusCode(); logger.info("POST Response Status: {}", statusCode); - HttpEntity entity = httpResponse.getEntity(); - if (entity != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); - - String inputLine; - response = new StringBuilder(); - - while ((inputLine = reader.readLine()) != null) { - response.append(inputLine); - } - reader.close(); - } if (statusCode != HttpStatus.SC_OK) { if (retryAttempts >= 1) { @@ -933,7 +913,6 @@ public StringBuilder sendPOST(String url, Map variables, int ret logger.info("Stopping sending POST because no more retry attempts left. Giving up."); } } - return response; } } catch (IOException e) { if (retryAttempts >= 1) { @@ -943,7 +922,6 @@ public StringBuilder sendPOST(String url, Map variables, int ret logger.info("Stopping sending POST because no more retry attempts left. Giving up."); } } - return null; } public void retrySendPostWithDelay(String url, Map variables, int retryAttempts) { diff --git a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java index c869c8f93..16f942d87 100644 --- a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java +++ b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java @@ -683,8 +683,10 @@ public void testSendPost() { Mockito.when(httpResponse.getEntity()).thenReturn(null); - StringBuilder response = spyAdaptor.sendPOST("http://any_url", new HashMap(), appSettings.getWebhookRetryCount() ); - assertNull(response); + spyAdaptor.sendPOST("http://any_url", new HashMap(), appSettings.getWebhookRetryCount() ); + + Mockito.verify(spyAdaptor, Mockito.times(0)).retrySendPostWithDelay(any(), any(), anyInt()); + HttpEntity entity = Mockito.mock(HttpEntity.class); InputStream is = new ByteArrayInputStream(ByteBuffer.allocate(10).array()); @@ -692,9 +694,9 @@ public void testSendPost() { Mockito.when(httpResponse.getEntity()).thenReturn(entity); HashMap map = new HashMap(); map.put("action", "action_any"); - response = spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); - assertNotNull(response); - assertEquals(10, response.length()); + spyAdaptor.sendPOST("http://any_url", map, appSettings.getWebhookRetryCount()); + + Mockito.verify(spyAdaptor, Mockito.times(0)).retrySendPostWithDelay(any(), any(), anyInt()); appSettings.setWebhookRetryCount(1); From 70d7b9bb80e9b723f660252571f8d71a701e0ebf Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 5 Mar 2024 09:04:17 +0300 Subject: [PATCH 06/10] Make notifyHook return void because it always returns null --- .travis.yml | 4 ++-- .../io/antmedia/AntMediaApplicationAdapter.java | 3 +-- .../test/AntMediaApplicationAdaptorUnitTest.java | 16 ++++++++-------- src/test/java/io/antmedia/test/Application.java | 3 +-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51b659306..80aaac507 100644 --- a/.travis.yml +++ b/.travis.yml @@ -143,13 +143,13 @@ before_install: - sudo cat /usr/local/antmedia/log/ant-media-server.log - sudo cp src/test/resources/preset-red5-web.properties /usr/local/antmedia/webapps/LiveApp/WEB-INF/red5-web.properties - sudo cp src/test/resources/preset-red5-web.db /usr/local/antmedia/liveapp.db - - sudo sed -i 's^server.cpu_limit=.*^server.cpu_limit=100^' /usr/local/antmedia/conf/red5.properties + - sudo sed -i 's^server.cpu_limit=.*^server.cpu_limit=95^' /usr/local/antmedia/conf/red5.properties + - sudo sed -i 's^server.memory_limit_percentage=.*^server.memory_limit_percentage=95^' /usr/local/antmedia/conf/red5.properties - sudo service antmedia stop - sudo service antmedia start - sleep 10 - sudo cat /usr/local/antmedia/log/ant-media-server.log - install: - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip=true -B -V --quiet diff --git a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java index 6738756d3..966fcb36f 100644 --- a/src/main/java/io/antmedia/AntMediaApplicationAdapter.java +++ b/src/main/java/io/antmedia/AntMediaApplicationAdapter.java @@ -845,7 +845,7 @@ public static String getRelativePath(String filePath){ * * @return */ - public StringBuilder notifyHook(String url, String id, String action, String streamName, String category, + public void notifyHook(String url, String id, String action, String streamName, String category, String vodName, String vodId, String metadata) { StringBuilder response = null; logger.info("Running notify hook url:{} stream id: {} action:{} vod name:{} vod id:{}", url, id, action, vodName, vodId); @@ -879,7 +879,6 @@ public StringBuilder notifyHook(String url, String id, String action, String str logger.error(ExceptionUtils.getStackTrace(e)); } } - return null; } public void sendPOST(String url, Map variables, int retryAttempts) { diff --git a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java index 16f942d87..da0e77ff9 100644 --- a/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java +++ b/src/test/java/io/antmedia/test/AntMediaApplicationAdaptorUnitTest.java @@ -792,11 +792,11 @@ public void testNotifyHook() { appSettings.setWebhookRetryCount(2); spyAdaptor.setAppSettings(appSettings); - StringBuilder notifyHook = spyAdaptor.notifyHook(null, null, null, null, null, null, null, null); - assertNull(notifyHook); + spyAdaptor.notifyHook(null, null, null, null, null, null, null, null); + Mockito.verify(spyAdaptor, never()).sendPOST(Mockito.any(), Mockito.any(), Mockito.anyInt()); - notifyHook = spyAdaptor.notifyHook("", null, null, null, null, null, null, null); - assertNull(notifyHook); + spyAdaptor.notifyHook("", null, null, null, null, null, null, null); + Mockito.verify(spyAdaptor, never()).sendPOST(Mockito.any(), Mockito.any(), Mockito.anyInt()); String id = String.valueOf((Math.random() * 10000)); @@ -808,8 +808,8 @@ public void testNotifyHook() { String vodId = String.valueOf((Math.random() * 10000)); String url = "this is url"; - notifyHook = spyAdaptor.notifyHook(url, id, action, streamName, category, vodName, vodId, null); - assertNull(notifyHook); + spyAdaptor.notifyHook(url, id, action, streamName, category, vodName, vodId, null); + Mockito.verify(spyAdaptor, times(1)).sendPOST(Mockito.any(), Mockito.any(), Mockito.anyInt()); ArgumentCaptor captureUrl = ArgumentCaptor.forClass(String.class); ArgumentCaptor variables = ArgumentCaptor.forClass(Map.class); @@ -827,8 +827,8 @@ public void testNotifyHook() { url = "this is second url"; - notifyHook = spyAdaptor.notifyHook(url, id, null, null, null, null, null, null); - assertNull(notifyHook); + spyAdaptor.notifyHook(url, id, null, null, null, null, null, null); + ArgumentCaptor captureUrl2 = ArgumentCaptor.forClass(String.class); ArgumentCaptor variables2 = ArgumentCaptor.forClass(Map.class); diff --git a/src/test/java/io/antmedia/test/Application.java b/src/test/java/io/antmedia/test/Application.java index 1ec01055b..1b133c89f 100644 --- a/src/test/java/io/antmedia/test/Application.java +++ b/src/test/java/io/antmedia/test/Application.java @@ -50,7 +50,7 @@ public static void resetFields() { } @Override - public StringBuilder notifyHook(String url, String id, String action, String streamName, String category, + public void notifyHook(String url, String id, String action, String streamName, String category, String vodName, String vodId, String metadata) { logger.info("notify hook action: {}", action); notifyHookAction.add(action); @@ -61,7 +61,6 @@ public StringBuilder notifyHook(String url, String id, String action, String str notifyVodName.add(vodName); notifyVodId.add(vodId); - return null; } @Override From 1161703e10ffcf33a7c17a60c74f1f1a766a4fb3 Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 5 Mar 2024 09:28:14 +0300 Subject: [PATCH 07/10] Make cpu and memory limit to %100 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80aaac507..1be9734ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -143,8 +143,8 @@ before_install: - sudo cat /usr/local/antmedia/log/ant-media-server.log - sudo cp src/test/resources/preset-red5-web.properties /usr/local/antmedia/webapps/LiveApp/WEB-INF/red5-web.properties - sudo cp src/test/resources/preset-red5-web.db /usr/local/antmedia/liveapp.db - - sudo sed -i 's^server.cpu_limit=.*^server.cpu_limit=95^' /usr/local/antmedia/conf/red5.properties - - sudo sed -i 's^server.memory_limit_percentage=.*^server.memory_limit_percentage=95^' /usr/local/antmedia/conf/red5.properties + - sudo sed -i 's^server.cpu_limit=.*^server.cpu_limit=100^' /usr/local/antmedia/conf/red5.properties + - sudo sed -i 's^server.memory_limit_percentage=.*^server.memory_limit_percentage=100^' /usr/local/antmedia/conf/red5.properties - sudo service antmedia stop - sudo service antmedia start - sleep 10 From 1168c54d9398c84e383ef42465c7ecbedb59a10a Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 5 Mar 2024 12:33:36 +0300 Subject: [PATCH 08/10] Fix test case --- src/test/java/io/antmedia/test/MuxerUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/antmedia/test/MuxerUnitTest.java b/src/test/java/io/antmedia/test/MuxerUnitTest.java index c64bac3e4..cee562965 100644 --- a/src/test/java/io/antmedia/test/MuxerUnitTest.java +++ b/src/test/java/io/antmedia/test/MuxerUnitTest.java @@ -1842,7 +1842,7 @@ public void testMp4MuxingAndNotifyCallback() { Application app = (Application) applicationContext.getBean("web.handler"); AntMediaApplicationAdapter appAdaptor = Mockito.spy(app); - doReturn(new StringBuilder("")).when(appAdaptor).notifyHook(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + Mockito.doNothing().when(appAdaptor).notifyHook(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); assertNotNull(appAdaptor); //just check below value that it is not null, this is not related to this case but it should be tested From 0222fd9241cb174568d487b2aa9c0a7410f2ef9f Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 5 Mar 2024 13:26:50 +0300 Subject: [PATCH 09/10] Increase max memory on surefire --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 76c04995f..5d7b4a6f2 100644 --- a/pom.xml +++ b/pom.xml @@ -191,7 +191,7 @@ maven-surefire-plugin false - @{argLine} -Xmx1500M -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -Djava.library.path=${project.basedir}/src/main/server/lib/native-linux-x86_64 + @{argLine} -Xmx3000M -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -Djava.library.path=${project.basedir}/src/main/server/lib/native-linux-x86_64 1 From 52070d43dcaa638b6b26b9b4edf30cf7e7abb111 Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 5 Mar 2024 16:50:09 +0300 Subject: [PATCH 10/10] Increase network limit to adapt increase in update interval --- src/test/java/io/antmedia/test/StreamSchedularUnitTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/antmedia/test/StreamSchedularUnitTest.java b/src/test/java/io/antmedia/test/StreamSchedularUnitTest.java index cf401b9fa..ba3958857 100644 --- a/src/test/java/io/antmedia/test/StreamSchedularUnitTest.java +++ b/src/test/java/io/antmedia/test/StreamSchedularUnitTest.java @@ -1044,7 +1044,7 @@ public void testBandwidth() { AntMediaApplicationAdapter.STREAM_SOURCE); try { - newSource.setStreamId("zombiSource " + RandomStringUtils.randomAlphanumeric(12)); + newSource.setStreamId("zombiSource" + RandomStringUtils.randomAlphanumeric(12)); } catch (Exception e) { e.printStackTrace(); } @@ -1056,7 +1056,7 @@ public void testBandwidth() { AntMediaApplicationAdapter.STREAM_SOURCE); try { - newZombiSource.setStreamId("zombiSource " + RandomStringUtils.randomAlphanumeric(12)); + newZombiSource.setStreamId("newZombiSource" + RandomStringUtils.randomAlphanumeric(12)); } catch (Exception e) { e.printStackTrace(); } @@ -1179,7 +1179,7 @@ private int limitNetworkInterfaceBandwidth(String activeInterface) { logger.info("Running limitNetworkInterfaceBandwidth"); logger.info("active interface {}", activeInterface); - String command = "sudo wondershaper "+activeInterface+" 20 20"; + String command = "sudo wondershaper "+activeInterface+" 40 40"; logger.info("command : {}",command); return runCommand(command);