Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Nov 25, 2024
1 parent d607be7 commit 6f6330e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/io/antmedia/AntMediaApplicationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public static boolean isInstanceAlive(String originAdress, String hostAddress, i
if (!result) {
logger.warn("Instance with origin address {} is not reachable through its app:{}", originAdress, appName);
}
return false;
return result;
}

public static boolean isEndpointReachable(String endpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ public void testEndpointReachable() {

endpointReachable = AntMediaApplicationAdapter.isEndpointReachable("http://antmedia.io:45454/not_exist");
assertFalse(endpointReachable);

boolean instanceAlive = AntMediaApplicationAdapter.isInstanceAlive("antmedia.io", null, 80, "");
assertTrue(instanceAlive);

instanceAlive = AntMediaApplicationAdapter.isInstanceAlive("antmedia.io", null, 4545, "");
assertFalse(instanceAlive);

instanceAlive = AntMediaApplicationAdapter.isInstanceAlive("", null, 4545, "");
assertTrue(instanceAlive);

instanceAlive = AntMediaApplicationAdapter.isInstanceAlive("localhost", "localhost", 4545, "");
assertTrue(instanceAlive);

}

Expand Down
31 changes: 31 additions & 0 deletions src/test/java/io/antmedia/test/StreamSchedularUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import io.antmedia.FFmpegUtilities;
import io.antmedia.datastore.db.DataStore;
import io.antmedia.datastore.db.IDataStoreFactory;
import io.antmedia.datastore.db.InMemoryDataStore;
import io.antmedia.datastore.db.MapDBStore;
import io.antmedia.datastore.db.types.Broadcast;
import io.antmedia.datastore.db.types.Broadcast.PlayListItem;
Expand Down Expand Up @@ -701,6 +702,36 @@ public void testSkipPlaylistItem() {
fail(e.getMessage());
}
}

@Test
public void testIsStreamRunning()
{
DataStore dataStore = new InMemoryDataStore("test");
StreamFetcherManager streamFetcherManager = Mockito.spy(new StreamFetcherManager(vertx, dataStore, appScope));

Broadcast broadcast = new Broadcast();

dataStore.save(broadcast);

boolean isStreamRunning = streamFetcherManager.isStreamRunning(broadcast);
assertFalse(isStreamRunning);

broadcast.setStatus(AntMediaApplicationAdapter.BROADCAST_STATUS_BROADCASTING);
broadcast.setUpdateTime(System.currentTimeMillis());

isStreamRunning = streamFetcherManager.isStreamRunning(broadcast);
assertTrue(isStreamRunning);

broadcast.setOriginAdress("not.accessible.antmedia.io");
isStreamRunning = streamFetcherManager.isStreamRunning(broadcast);
assertFalse(isStreamRunning);

broadcast.setUpdateTime(0);

isStreamRunning = streamFetcherManager.isStreamRunning(broadcast);
assertFalse(isStreamRunning);

}

@Test
public void testControlStreamFetchersPlayListAndRestart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ public void testStreamIdInUseCase()

assertFalse(filter.isPublishAllowed(scope, preparingBroadcast.getStreamId(), "mode", null, null));
assertFalse(filter.isPublishAllowed(scope, broadcastingBroadcast.getStreamId(), "mode", null, null));

//change origin adress that is something not accesible
broadcastingBroadcast.setOriginAdress("not.exist.antmedia.io");
//it shoudla allow to publish because it's not accessible
assertTrue(filter.isPublishAllowed(scope, broadcastingBroadcast.getStreamId(), "mode", null, null));
//change origin adress to empty
broadcastingBroadcast.setOriginAdress("");
//it shoudl not allow to publish because timeout is not passed
assertFalse(filter.isPublishAllowed(scope, broadcastingBroadcast.getStreamId(), "mode", null, null));


assertTrue(filter.isPublishAllowed(scope, offlineBroadcast.getStreamId(), "mode", null, null));
assertTrue(filter.isPublishAllowed(scope, stuckedBroadcast.getStreamId(), "mode", null, null));

Expand Down

0 comments on commit 6f6330e

Please sign in to comment.