1616import java .util .concurrent .atomic .AtomicInteger ;
1717
1818import org .junit .After ;
19+ import org .junit .Assert ;
1920import org .junit .Before ;
2021import org .junit .FixMethodOrder ;
2122import org .junit .Test ;
2526import org .red5 .server .api .scope .ScopeType ;
2627import org .red5 .server .persistence .RamPersistence ;
2728import org .red5 .server .so .SharedObjectScope ;
29+ import org .red5 .server .stream .ClientBroadcastStream ;
2830import org .slf4j .Logger ;
2931import org .slf4j .LoggerFactory ;
3032import org .springframework .test .context .ContextConfiguration ;
3133import org .springframework .test .context .junit4 .AbstractJUnit4SpringContextTests ;
3234
3335@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
34- @ ContextConfiguration (locations = { " ScopeTest.xml" } )
36+ @ ContextConfiguration ("file:src/test/resources/org/red5/server/scope/ ScopeTest.xml" )
3537public class ScopeTest extends AbstractJUnit4SpringContextTests {
3638
3739 protected static Logger log = LoggerFactory .getLogger (ScopeTest .class );
@@ -78,10 +80,31 @@ public void testScopeCreation() throws InterruptedException {
7880 //Room 0 /default/junit/room0 (created in the spring config)
7981 assertNotNull (appScope .getScope ("room0" ));
8082 IScope room0 = appScope .getScope ("room0" );
81- log .debug ("Room#0: {}" , room0 );
83+ log .debug (">>>>>>>>>>>> Room#0: {}" , room0 );
8284 assertTrue (room0 .getDepth () == 2 );
85+ // create a broadcast scope with a stream and add it to the app
86+ BroadcastScope stream1 = new BroadcastScope (appScope , "stream1" );
87+ assertTrue ("Stream failed to be added to the app scope" , appScope .addChildScope (stream1 ));
88+ assertNotNull (appScope .hasChildScope (ScopeType .BROADCAST , "stream1" ));
89+ IBasicScope stream1Scope = appScope .getBasicScope ("stream1" );
90+ stream1Scope = appScope .getBasicScope (ScopeType .BROADCAST , "stream1" );
91+ log .debug (">>>>>>>>>>>> Stream#1: {}" , stream1Scope );
92+ ClientBroadcastStream stream = new ClientBroadcastStream ();
93+ stream1 .setClientBroadcastStream (stream );
94+ stream .setScope (appScope ); // do this or jmx fails setting the publish name
95+ stream .setPublishedName ("stream1" );
96+ // check again after stream added no-aliases
97+ stream1Scope = appScope .getBasicScope (ScopeType .BROADCAST , "stream1" );
98+ log .debug (">>>>>>>>>>>> Stream#1: {}" , stream1Scope );
99+ // add an alias
100+ stream .addAlias ("streamA" );
101+ // check again after stream added alias
102+ stream1Scope = appScope .getBasicScope (ScopeType .BROADCAST , "streamA" );
103+ log .debug (">>>>>>>>>>>> Stream#1: {}" , stream1Scope );
104+ // XXX to test adding rooms etc, uncomment this section
105+ /*
83106 // test runnables represent worker threads creating scopes
84- int workerCount = 10 , loops = 100 ;
107+ int workerCount = 3 , loops = 100;
85108 List<Worker> workers = new ArrayList<>();
86109 for (int s = 0; s < workerCount; s++) {
87110 workers.add(new Worker(appScope, loops));
@@ -102,11 +125,11 @@ public void testScopeCreation() throws InterruptedException {
102125 assertTrue(roomNames1.size() >= (workerCount + 1));
103126 roomNames1.forEach(name -> {
104127 IScope room = appScope.getScope(name);
105- log .info ("First level room: {}" , room );
128+ // log.info("First level room: {}", room);
106129 assertNotNull(room);
107130 // each room is expected to have a minimum of 2 child scopes
108131 Set<String> childNames = room.getScopeNames();
109- log .info ("{} child rooms: {}" , name , childNames );
132+ // log.info("{} child rooms: {}", name, childNames);
110133 // except for room0
111134 if (!"room0".equals(name)) {
112135 assertTrue(childNames.size() >= 2);
@@ -120,8 +143,8 @@ public void testScopeCreation() throws InterruptedException {
120143 }
121144 }
122145 assertTrue(appScope.getBasicScopeNames(ScopeType.ROOM).size() == 1);
123- //appScope.removeChildren();
124- //assertTrue(appScope.getBasicScopeNames(ScopeType.ROOM).size() == 0);
146+ *
147+ */
125148 log .info ("testScopeCreation-end" );
126149 }
127150
0 commit comments