Jonathan Hart | bd181b6 | 2013-02-17 16:05:38 -0800 | [diff] [blame^] | 1 | package net.floodlightcontroller.mastership; |
| 2 | |
| 3 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 4 | import net.floodlightcontroller.mastership.IMastershipService.MastershipCallback; |
| 5 | |
| 6 | import org.junit.Before; |
| 7 | import org.junit.Test; |
| 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; |
| 10 | |
| 11 | public class MastershipManagerTest { |
| 12 | protected static Logger log = LoggerFactory.getLogger(MastershipManagerTest.class); |
| 13 | private MastershipManager mm; |
| 14 | |
| 15 | @Before |
| 16 | public void setUp() throws Exception{ |
| 17 | //MockFloodlightProvider fp = new MockFloodlightProvider(); |
| 18 | FloodlightModuleContext fmc = new FloodlightModuleContext(); |
| 19 | |
| 20 | mm = new MastershipManager(); |
| 21 | |
| 22 | mm.init(fmc); |
| 23 | mm.startUp(fmc); |
| 24 | |
| 25 | } |
| 26 | |
| 27 | @Test |
| 28 | public void testAcquireMastership(){ |
| 29 | MastershipCallback cb = new MastershipCallback(){ |
| 30 | @Override |
| 31 | public void changeCallback(long dpid, boolean isMaster) { |
| 32 | log.info("Callback called!"); |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | long dpid = 1L; |
| 37 | |
| 38 | mm.acquireMastership(dpid, cb); |
| 39 | |
| 40 | try { |
| 41 | Thread.sleep(2000); |
| 42 | } catch (InterruptedException e) { |
| 43 | // TODO Auto-generated catch block |
| 44 | e.printStackTrace(); |
| 45 | } |
| 46 | |
| 47 | log.debug("Is master? {}", mm.amMaster(dpid)); |
| 48 | } |
| 49 | } |