Skip to content

Commit

Permalink
Fix test cases and add new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Nov 24, 2024
1 parent 39e5e3d commit d607be7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import io.antmedia.rest.model.Result;
import io.antmedia.security.AcceptOnlyStreamsInDataStore;
import io.antmedia.settings.ServerSettings;
import io.antmedia.statistic.HlsViewerStats;
import io.antmedia.statistic.type.WebRTCAudioReceiveStats;
import io.antmedia.statistic.type.WebRTCAudioSendStats;
import io.antmedia.statistic.type.WebRTCVideoReceiveStats;
Expand Down Expand Up @@ -827,8 +828,9 @@ public void testHookAfterDefined()

assertEquals(hookURL, spyAdaptor.getListenerHookURL(broadcast));


spyAdaptor = Mockito.spy(adapter);
Mockito.doNothing().when(spyAdaptor).resetHLSStats(Mockito.anyString());
Mockito.doNothing().when(spyAdaptor).resetDASHStats(Mockito.anyString());
appSettings = new AppSettings();
spyAdaptor.setServerSettings(new ServerSettings());
spyAdaptor.setAppSettings(appSettings);
Expand Down
62 changes: 60 additions & 2 deletions src/test/java/io/antmedia/test/db/DBStoresUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testMapDBStore() throws Exception {

DataStore dataStore = new MapDBStore("testdb", vertx);


testLocalLiveBroadcast(dataStore);
testUpdateBroadcastEncoderSettings(dataStore);
testSubscriberMetaData(dataStore);
testGetActiveBroadcastCount(dataStore);
Expand Down Expand Up @@ -231,6 +231,7 @@ public void testMemoryDataStore() throws Exception {

testVoDFunctions(dataStore);

testLocalLiveBroadcast(dataStore);
testUpdateBroadcastEncoderSettings(dataStore);
testSubscriberMetaData(dataStore);
testBlockSubscriber(dataStore);
Expand Down Expand Up @@ -293,8 +294,10 @@ public void testMongoStore() throws Exception {

dataStore = new MongoStore("127.0.0.1", "", "", "testdb");


testSaveDuplicateStreamId((MongoStore)dataStore);

testLocalLiveBroadcast(dataStore);
testUpdateBroadcastEncoderSettings(dataStore);
testSubscriberMetaData(dataStore);
testBlockSubscriber(dataStore);
Expand Down Expand Up @@ -360,6 +363,7 @@ public void testRedisStore() throws Exception {
dataStore.close(true);
dataStore = new RedisStore("redis://127.0.0.1:6379", "testdb");

testLocalLiveBroadcast(dataStore);
testUpdateBroadcastEncoderSettings(dataStore);
testSubscriberMetaData(dataStore);
testBlockSubscriber(dataStore);
Expand Down Expand Up @@ -644,6 +648,58 @@ public void testUnexpectedBroadcastOffset(DataStore dataStore) {
assertNotNull(broadcastList);
assertEquals(0, broadcastList.size());
}

public void testLocalLiveBroadcast(DataStore dataStore) {
clear(dataStore);

assertEquals(0, dataStore.getBroadcastCount());

long streamCount = 10;
String streamId = null;
for (int i = 0; i < streamCount; i++) {
Broadcast broadcast = new Broadcast(null, null);
broadcast.setStatus(AntMediaApplicationAdapter.BROADCAST_STATUS_BROADCASTING);
broadcast.setUpdateTime(System.currentTimeMillis());
streamId = dataStore.save(broadcast);
logger.info("Saved streamId:{}", streamId);
}


assertEquals(streamCount, dataStore.getActiveBroadcastCount());

if (dataStore instanceof MapDBStore || dataStore instanceof InMemoryDataStore) {
assertEquals(streamCount, dataStore.getLocalLiveBroadcastCount(ServerSettings.getLocalHostAddress()));

List<Broadcast> localLiveBroadcasts = dataStore.getLocalLiveBroadcasts(ServerSettings.getLocalHostAddress());
assertEquals(streamCount, localLiveBroadcasts.size());
} else {

//because there is no origin address registered
assertEquals(0, dataStore.getLocalLiveBroadcastCount(ServerSettings.getLocalHostAddress()));
List<Broadcast> localLiveBroadcasts = dataStore.getLocalLiveBroadcasts(ServerSettings.getLocalHostAddress());
assertEquals(0, localLiveBroadcasts.size());
}

clear(dataStore);

assertEquals(0, dataStore.getBroadcastCount());

streamCount = 15;
for (int i = 0; i < streamCount; i++) {
Broadcast broadcast = new Broadcast(null, null);
broadcast.setStatus(AntMediaApplicationAdapter.BROADCAST_STATUS_BROADCASTING);
broadcast.setUpdateTime(System.currentTimeMillis());
broadcast.setOriginAdress(ServerSettings.getLocalHostAddress());
streamId = dataStore.save(broadcast);
logger.info("Saved streamId:{}", streamId);
}

assertEquals(streamCount, dataStore.getLocalLiveBroadcastCount(ServerSettings.getLocalHostAddress()));

List<Broadcast> localLiveBroadcasts = dataStore.getLocalLiveBroadcasts(ServerSettings.getLocalHostAddress());
assertEquals(streamCount, localLiveBroadcasts.size());

}

public void testGetActiveBroadcastCount(DataStore dataStore) {

Expand All @@ -661,7 +717,9 @@ public void testGetActiveBroadcastCount(DataStore dataStore) {

String streamId = null;
for (int i = 0; i < streamCount; i++) {
streamId = dataStore.save(new Broadcast(null, null));
Broadcast broadcast = new Broadcast(null, null);
broadcast.setOriginAdress(ServerSettings.getLocalHostAddress());
streamId = dataStore.save(broadcast);
logger.info("Saved streamId:{}", streamId);
}

Expand Down

0 comments on commit d607be7

Please sign in to comment.