Merge pull request #407 from n-shiota/ONOS131-release
Additional work for ONOS-131
diff --git a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
index 7e82bf0..640a49d 100644
--- a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
@@ -118,12 +118,17 @@
private long blockTop = 0L;
private static final long BLOCK_SIZE = 0x1000000L;
+
+ /**
+ * Returns a block of IDs which are unique and unused.
+ * Range of IDs is fixed size and is assigned incrementally as this method called.
+ */
@Override
- public IdBlock allocateUniqueIdBlock(){
+ public synchronized IdBlock allocateUniqueIdBlock(){
long blockHead = blockTop;
long blockTail = blockTop + BLOCK_SIZE;
- IdBlock block = new IdBlock(blockHead, blockTail, BLOCK_SIZE);
+ IdBlock block = new IdBlock(blockHead, blockTail - 1, BLOCK_SIZE);
blockTop = blockTail;
return block;
diff --git a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
index f9fb62e..2d2083f 100644
--- a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
@@ -379,6 +379,12 @@
return data;
}
+ /**
+ * Returns a block of IDs which are unique and unused.
+ * Range of IDs is fixed size and is assigned incrementally as this method called.
+ * Since the range of IDs is managed by Zookeeper in distributed way, this method may block when
+ * requests come up simultaneously.
+ */
public IdBlock allocateUniqueIdBlock(){
try {
AtomicValue<Long> result = null;
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
index 5c42452..9b1c4d6 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
@@ -6,7 +6,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -33,6 +32,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Unit test for {@link LinkStorageImpl}.
+ * @author Naoki Shiota
+ *
+ */
@RunWith(PowerMockRunner.class)
@PrepareForTest({LinkStorageImpl.class, GraphDBConnection.class, GraphDBOperation.class})
public class LinkStorageImplTest {
@@ -100,12 +104,14 @@
*/
@Before
public void setUp() throws Exception{
+ // Create mock GraphDBConnection (replace Singleton object to mock one)
PowerMock.mockStatic(GraphDBConnection.class);
PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
- conn = PowerMock.createNiceMock(GraphDBConnection.class);
+ conn = PowerMock.createMock(GraphDBConnection.class);
EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(conn).anyTimes();
PowerMock.replay(GraphDBConnection.class);
+ // Create mock GraphDBOperation
ope = createMockGraphDBOperation();
PowerMock.expectNew(GraphDBOperation.class, new Class<?>[] {GraphDBConnection.class}, EasyMock.anyObject(GraphDBConnection.class)).andReturn(ope).anyTimes();
PowerMock.replay(GraphDBOperation.class);
@@ -121,18 +127,16 @@
/**
* Closing code called after each tests.
- * Discard test graph data.
* @throws Exception
*/
@After
public void tearDown() throws Exception {
- // finish code
linkStorage.close();
}
// TODO: remove @Ignore after UPDATE method is implemented
/**
- * Test if update() can correctly updates LinkInfo for a Link.
+ * Test if {@link LinkStorageImpl#update(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
*/
@Ignore @Test
public void testUpdate_UpdateSingleLink() {
@@ -147,7 +151,7 @@
}
/**
- * Test if update() can correctly creates a Link.
+ * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly creates a Link.
*/
@Test
public void testUpdate_CreateSingleLink() {
@@ -157,18 +161,10 @@
//Use the link storage API to add the link
linkStorage.update(linkToCreate, ILinkStorage.DM_OPERATION.CREATE);
doTestLinkExist(linkToVerify);
-
- // Avoiding duplication is out of scope. DBOperation is responsible for this.
-// // Add same link
-// Link linkToCreateTwice = createFeasibleLink();
-// linkStorage.update(linkToCreateTwice, ILinkStorage.DM_OPERATION.CREATE);
-//
-// // this occurs assertion failure if there are two links in titanGraph
-// doTestLinkIsInGraph(linkToVerify);
}
/**
- * Test if update() can correctly inserts a Link.
+ * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)}can correctly inserts a Link.
*/
@Test
public void testUpdate_InsertSingleLink(){
@@ -181,7 +177,7 @@
}
/**
- * Test if update() can correctly deletes a Link.
+ * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly deletes a Link.
*/
@Test
public void testUpdate_DeleteSingleLink(){
@@ -194,7 +190,7 @@
}
/**
- * Test if update() can correctly creates multiple Links.
+ * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly creates multiple Links.
*/
@Test
public void testUpdate_CreateLinks(){
@@ -206,34 +202,10 @@
for(Link l : linksToVerify) {
doTestLinkExist(l);
}
-
- // Out of scope: DBOperation is responsible for avoiding duplication.
-// // Test creation of existing links
-// linksToCreate = createFeasibleLinks();
-// linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE);
-// for(Link l : linksToVerify) {
-// doTestLinkIsInGraph(l);
-// }
- }
-
- /**
- * Test if update() can handle mixture of normal/abnormal input for creation of Links.
- * Deprecated: DBOperation is responsible.
- */
- @Ignore @Test
- public void testUpdate_CreateLinks_Mixuture(){
- List<Link> linksToCreate = new ArrayList<Link>();
- linksToCreate.add(createFeasibleLink());
- linksToCreate.add(createExistingLink());
-
- // Test creation of mixture of new/existing links
- linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE);
- doTestLinkExist(createFeasibleLink());
- doTestLinkExist(createExistingLink());
}
/**
- * Test if update() can correctly inserts multiple Links.
+ * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly inserts multiple Links.
*/
@Test
public void testUpdate_InsertLinks(){
@@ -248,22 +220,7 @@
}
/**
- * Test if update() can handle mixture of normal/abnormal input for creation of Links.
- */
- @Ignore @Test
- public void testUpdate_InsertLinks_Mixuture(){
- List<Link> linksToInsert = new ArrayList<Link>();
- linksToInsert.add(createFeasibleLink());
- linksToInsert.add(createExistingLink());
-
- // Test insertion of mixture of new/existing links
- linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT);
- doTestLinkExist(createFeasibleLink());
- doTestLinkExist(createExistingLink());
- }
-
- /**
- * Test if update() can correctly deletes multiple Links.
+ * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly deletes multiple Links.
*/
@Test
public void testUpdate_DeleteLinks(){
@@ -277,24 +234,9 @@
}
}
- /**
- * Test if update() can handle mixture of normal/abnormal input for deletion of Links.
- */
- @Ignore @Test
- public void testUpdate_DeleteLinks_Mixuture(){
- List<Link> linksToDelete = new ArrayList<Link>();
- linksToDelete.add(createFeasibleLink());
- linksToDelete.add(createExistingLink());
-
- // Test deletion of mixture of new/existing links
- linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE);
- doTestLinkNotExist(createFeasibleLink());
- doTestLinkNotExist(createExistingLink());
- }
-
// TODO: remove @Ignore after UPDATE method is implemented
/**
- * Test if updateLink() can correctly updates LinkInfo for a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
*/
@Ignore @Test
public void testUpdateLink_Update() {
@@ -309,7 +251,7 @@
}
/**
- * Test if updateLink() can correctly creates a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly creates a Link.
*/
@Test
public void testUpdateLink_Create() {
@@ -322,7 +264,7 @@
}
/**
- * Test if updateLink() can correctly inserts a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly inserts a Link.
*/
@Test
public void testUpdateLink_Insert() {
@@ -337,7 +279,7 @@
// TODO: Check if addOrUpdateLink() should accept DELETE operation. If not, remove this test.
/**
- * Test if updateLink() can correctly deletes a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly deletes a Link.
*/
@Ignore @Test
public void testUpdateLink_Delete() {
@@ -357,7 +299,7 @@
}
/**
- * Test if getLinks() can correctly return Links connected to specific DPID and port.
+ * Test if {@link LinkStorageImpl#getLinks(Long, short)} can correctly return Links connected to specific DPID and port.
*/
@Test
public void testGetLinks_ByDpidPort(){
@@ -383,7 +325,7 @@
}
/**
- * Test if getLinks() can correctly return Links connected to specific MAC address.
+ * Test if {@link LinkStorageImpl#getLinks(String)} can correctly return Links connected to specific MAC address.
*/
@Test
public void testGetLinks_ByString() {
@@ -398,7 +340,7 @@
}
/**
- * Test if deleteLink() can correctly delete a Link.
+ * Test if {@link LinkStorageImpl#deleteLink(Link)} can correctly delete a Link.
*/
@Test
public void testDeleteLink() {
@@ -411,7 +353,7 @@
}
/**
- * Test if deleteLinks() can correctly delete Links.
+ * Test if {@link LinkStorageImpl#deleteLinks(List)} can correctly delete Links.
*/
@Test
public void testDeleteLinks(){
@@ -423,24 +365,9 @@
doTestLinkNotExist(l);
}
}
-
- /**
- * Test if deleteLinks() can handle mixture of normal/abnormal input.
- */
- @Ignore @Test
- public void testDeleteLinks_Mixture(){
- List<Link> linksToDelete = new ArrayList<Link>();
- linksToDelete.add(createFeasibleLink());
- linksToDelete.add(createExistingLink());
-
- // Test deletion of mixture of new/existing links
- linkStorage.deleteLinks(linksToDelete);
- doTestLinkNotExist(createFeasibleLink());
- doTestLinkNotExist(createExistingLink());
- }
/**
- * Test if getActiveLinks() can correctly return active Links.
+ * Test if {@link LinkStorageImpl#getActiveLinks()} can correctly return active Links.
*/
@Test
public void testGetActiveLinks() {
@@ -454,7 +381,7 @@
}
/**
- * Test if deleteLinksOnPort() can delete Links.
+ * Test if {@link LinkStorageImpl#deleteLinksOnPort(Long, short)} can delete Links.
*/
@Test
public void testDeleteLinksOnPort() {
@@ -493,11 +420,12 @@
* Test if titanGraph has specific Link with specific LinkInfo
* @param link
*/
+ // TODO: Fix me
private void doTestLinkHasStateOf(Link link, LinkInfo info) {
}
/**
- * Class defines a function called back when IPortObject#removeLink is called.
+ * Class defines a function called back when {@link IPortObject#removeLink(IPortObject)} is called.
* @author Naoki Shiota
*
*/
@@ -521,9 +449,8 @@
}
/**
- * Class defines a function called back when IPortObject#setLinkPort is called.
+ * Class defines a function called back when {@link IPortObject#setLinkPort(IPortObject)} is called.
* @author Naoki Shiota
- *
*/
private class SetLinkPortCallback implements IAnswer<Object> {
private long dpid;
@@ -546,7 +473,7 @@
}
/**
- * Class defines a function called back when IPortObject#getSwitch is called.
+ * Class defines a function called back when {@link IPortObject#getSwitch()} is called.
* @author Naoki Shiota
*
*/
@@ -565,7 +492,7 @@
}
/**
- * Class defines a function called back when IPortObject#getLinkedPorts is called.
+ * Class defines a function called back when {@link IPortObject#getLinkedPorts()} is called.
* @author Naoki Shiota
*
*/
@@ -594,7 +521,7 @@
}
/**
- * Class defines a function called back when ISwitchObject#getPorts is called.
+ * Class defines a function called back when {@link LinkStorageImplTest} is called.
* @author Naoki Shiota
*
*/
@@ -619,7 +546,7 @@
// ------------------------Creation of Mock-----------------------------
/**
- * Create a mock GraphDBOperation which hooks port-related methods.
+ * Create a mock {@link GraphDBOperation} which hooks port-related methods.
* @return EasyMock-wrapped GraphDBOperation object.
*/
@SuppressWarnings("serial")
@@ -692,8 +619,8 @@
}
/**
- * Create a mock IPortObject using given DPID and port number.
- * IPortObject can't store DPID, so DPID is stored to mockToPortInfoMap for later use.
+ * Create a mock {@link IPortObject} using given DPID and port number.
+ * {@link IPortObject} can't store DPID, so DPID is stored to mockToPortInfoMap for later use.
* Duplication is not checked.
* @param dpid DPID of a port
* @param number Port Number
@@ -725,7 +652,7 @@
}
/**
- * Create a mock ISwitchObject using given DPID number.
+ * Create a mock {@link ISwitchObject} using given DPID number.
* Duplication is not checked.
* @param dpid DPID of a switch
* @return EasyMock-wrapped ISwitchObject
@@ -811,7 +738,7 @@
}
/**
- * Returns new Link object of an existing link
+ * Returns new {@link Link} object of an existing link
* @return new Link object
*/
private Link createExistingLink() {
@@ -819,7 +746,7 @@
}
/**
- * Returns new Link object of a not-existing but feasible link
+ * Returns new {@link Link} object of a not-existing but feasible link
* @return new Link object
*/
private Link createFeasibleLink() {
@@ -833,7 +760,7 @@
}
/**
- * Returns list of Link objects which all has information of existing link in titanGraph
+ * Returns list of existing {@link Link} objects
* @return ArrayList of new Link objects
*/
private List<Link> createExistingLinks() {
@@ -844,7 +771,7 @@
}
/**
- * Returns list of Link objects which all has information of not-existing but feasible link
+ * Returns list of {@link Link} objects that are all not-existing but feasible
* @return ArrayList of new Link objects
*/
private List<Link> createFeasibleLinks() {
@@ -855,7 +782,7 @@
}
/**
- * Returns new LinkInfo object with convenient values.
+ * Returns new {@link LinkInfo} object with convenient values.
* @return LinkInfo object
*/
private LinkInfo createFeasibleLinkInfo(long time) {
diff --git a/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java b/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java
index 802c137..7c4a1a0 100644
--- a/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java
+++ b/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java
@@ -20,7 +20,7 @@
import org.openflow.util.HexString;
/**
- * Unit test for StandaloneRegistry.
+ * Unit test for {@link StandaloneRegistry}.
* @author Naoki Shiota
*
*/
@@ -30,14 +30,13 @@
protected StandaloneRegistry registry;
/**
- * Implementation of ControlChangeCallback which defines callback interfaces called by Registry.
+ * Implementation of {@link ControlChangeCallback} which defines callback interfaces called by Registry.
* This class remembers past callback parameters and provides methods to access them.
* This class also provides CountDownLatch so one can wait until the callback be called
- * specific times (specified by constructor param). Particularly, the first time callback
+ * specific times (specified by constructor parameter). Particularly, the first time callback
* called is supposed for registration, this class has an independent latch to wait for
* the first callback.
* @author Naoki Shiota
- *
*/
public static class LoggingCallback implements ControlChangeCallback {
private LinkedList<Long> dpidsCalledback = new LinkedList<Long>();
@@ -135,7 +134,7 @@
}
/**
- * Test if registerController() can run without error.
+ * Test if {@link StandaloneRegistry#registerController(String)} can run without error.
*/
@Test
public void testRegisterController() {
@@ -157,7 +156,7 @@
}
/**
- * Test if getControllerId() can return correct ID.
+ * Test if {@link StandaloneRegistry#getControllerId()} can return correct ID.
* @throws RegistryException
*/
@Test
@@ -178,7 +177,7 @@
}
/**
- * Test if getAllControllers() can return correct list of controllers.
+ * Test if {@link StandaloneRegistry#getAllControllers()} can return correct list of controllers.
* @throws RegistryException
*/
@Test
@@ -208,7 +207,7 @@
}
/**
- * Test if requestControl() can correctly take control for switch so that callback is called.
+ * Test if {@link StandaloneRegistry#requestControl(long, ControlChangeCallback)} can correctly take control for switch so that callback is called.
* @throws RegistryException
* @throws InterruptedException
*/
@@ -237,7 +236,7 @@
}
/**
- * Test if releaseControl() can correctly release the control so that callback is called.
+ * Test if {@link StandaloneRegistry#releaseControl(long)} can correctly release the control so that callback is called.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -262,7 +261,7 @@
}
/**
- * Test if hasControl() returns correct status.
+ * Test if {@link StandaloneRegistry#hasControl(long)} returns correct status.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -292,7 +291,7 @@
}
/**
- * Test if getControllerForSwitch() returns correct controller ID.
+ * Test if {@link StandaloneRegistry#getControllerForSwitch(long)} returns correct controller ID.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -339,7 +338,7 @@
}
/**
- * Test if getAllSwitches() returns correct list of switches.
+ * Test if {@link StandaloneRegistry#getAllSwitches()} returns correct list of switches.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -382,7 +381,7 @@
}
/**
- * Test if getSwitchesControlledByController() returns correct list of switches.
+ * Test if {@link StandaloneRegistry#getSwitchesControlledByController(String)} returns correct list of switches.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -426,7 +425,8 @@
}
/**
- * Test if allocateUniqueIdBlock() returns appropriate object.
+ * Test if {@link StandaloneRegistry#allocateUniqueIdBlock()} returns appropriate object.
+ * Get bulk of IdBlocks and check if they do have unique range of IDs.
*/
@Test
public void testAllocateUniqueIdBlock() {
@@ -454,7 +454,7 @@
assertTrue(lower.getSize() > 0L);
assertTrue(higher.getSize() > 0L);
- assertTrue(lower.getEnd() <= higher.getStart());
+ assertTrue(lower.getEnd() < higher.getStart());
}
}
}
diff --git a/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java b/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java
index f557663..3314ad2 100644
--- a/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java
+++ b/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java
@@ -41,8 +41,8 @@
import com.netflix.curator.x.discovery.ServiceInstance;
/**
- * Unit test for ZookeeperRegistry.
- * NOTE: FloodlightTestCase conflicts with PowerMock. If FloodLight-related methods need to be tested,
+ * Unit test for {@link ZookeeperRegistry}.
+ * NOTE: {@link FloodlightTestCase} conflicts with PowerMock. If FloodLight-related methods need to be tested,
* implement another test class to test them.
* @author Naoki Shiota
*
@@ -61,8 +61,8 @@
protected final String CONTROLLER_ID = "controller2013";
/**
- * Initialize ZookeeperRegistry Object and inject initial value with init() method.
- * This setup code also tests init() method itself.
+ * Initialize {@link ZookeeperRegistry} Object and inject initial value with {@link ZookeeperRegistry#init(FloodlightModuleContext)} method.
+ * This setup code also tests {@link ZookeeperRegistry#init(FloodlightModuleContext)} method itself.
*/
@Before
public void setUp() throws Exception {
@@ -97,8 +97,8 @@
}
/**
- * Test if registerController() method can go through without exception.
- * (Exceptions are usually out of test target, but registerController() throws an exception in case of invalid registration.)
+ * Test if {@link ZookeeperRegistry#registerController(String)} method can go through without exception.
+ * (Exceptions are usually out of test target, but {@link ZookeeperRegistry#registerController(String)} throws an exception in case of invalid registration.)
*/
@Test
public void testRegisterController() {
@@ -113,7 +113,7 @@
}
/**
- * Test if getControllerId() correctly returns registered ID.
+ * Test if {@link ZookeeperRegistry#getControllerId()} correctly returns registered ID.
* @throws Exception
*/
@Test
@@ -134,9 +134,9 @@
}
/**
- * Test if getAllControllers() returns all controllers.
- * Controllers are injected while setup. See createCuratorFrameworkMock() to what controllers
- * are injected using ServiceCache Mock.
+ * Test if {@link ZookeeperRegistry#getAllControllers()} returns all controllers.
+ * Controllers to be returned are injected while setup. See {@link ZookeeperRegistryTest#createCuratorFrameworkMock()}
+ * to what controllers are injected using mock {@link ServiceCache}.
* @throws Exception
*/
@Test
@@ -144,7 +144,6 @@
String controllerIdRegistered = "controller1";
String controllerIdNotRegistered = "controller2013";
- // Test registered controller
try {
Collection<String> ctrls = registry.getAllControllers();
assertTrue(ctrls.contains(controllerIdRegistered));
@@ -156,13 +155,14 @@
}
/**
- * Test if requestControl() correctly take control of specific switch.
- * Because requestControl() doesn't return values, inject mock LeaderLatch object and verify latch is correctly set up.
+ * Test if {@link ZookeeperRegistry#requestControl(long, net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback)}
+ * correctly take control of specific switch. Because {@link ZookeeperRegistry#requestControl(long, net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback)}
+ * doesn't return values, inject mock {@link LeaderLatch} object and verify latch is correctly set up.
* @throws Exception
*/
@Test
public void testRequestControl() throws Exception {
- // Mock of LeaderLatch
+ // Mock LeaderLatch
LeaderLatch latch = EasyMock.createMock(LeaderLatch.class);
latch.addListener(EasyMock.anyObject(SwitchLeaderListener.class));
EasyMock.expectLastCall().once();
@@ -172,7 +172,7 @@
PowerMock.expectNew(LeaderLatch.class,
EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))
- .andReturn(latch);
+ .andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
String controllerId = "controller2013";
@@ -192,8 +192,9 @@
}
/**
- * Test if releaseControl() correctly release control of specific switch.
- * Because releaseControl() doesn't return values, inject mock LeaderLatch object and verify latch is correctly set up.
+ * Test if {@link ZookeeperRegistry#releaseControl(long)} correctly release control of specific switch.
+ * Because {@link ZookeeperRegistry#releaseControl(long)} doesn't return values, inject mock
+ * {@link LeaderLatch} object and verify latch is correctly set up.
* @throws Exception
*/
@Test
@@ -212,25 +213,23 @@
PowerMock.expectNew(LeaderLatch.class,
EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))
- .andReturn(latch);
+ .andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
String controllerId = "controller2013";
registry.registerController(controllerId);
- long dpidToRequest = 1000L;
+ long dpidToRequest = 2000L;
LoggingCallback callback = new LoggingCallback(1);
- // to request and wait to take control
registry.requestControl(dpidToRequest, callback);
registry.releaseControl(dpidToRequest);
- // verify
EasyMock.verify(latch);
}
/**
- * Test if hasControl() returns correct status whether controller has control of specific switch.
+ * Test if {@link ZookeeperRegistry#hasControl(long)} returns correct status whether controller has control of specific switch.
* @throws Exception
*/
@Test
@@ -276,8 +275,8 @@
}
/**
- * Test if getControllerForSwitch() correctly returns controller ID of specific switch.
- * Relation between controllers and switches are defined by setPathChildrenCache() function.
+ * Test if {@link ZookeeperRegistry#getControllerForSwitch(long)} correctly returns controller ID of specific switch.
+ * Relation between controllers and switches are defined by {@link ZookeeperRegistryTest#setPathChildrenCache()} function.
* @throws Throwable
*/
@Test
@@ -295,11 +294,11 @@
}
/**
- * Test if getSwitchesControlledByController() returns correct list of switches controlled by
- * a controller.
+ * Test if {@link ZookeeperRegistry#getSwitchesControlledByController(String)} returns correct list of
+ * switches controlled by a controller.
* @throws Exception
*/
- // TODO: Test after implementation of getSwitch() is done.
+ // TODO: Test after getSwitchesControlledByController() is implemented.
@Ignore @Test
public void testGetSwitchesControlledByController() throws Exception {
String controllerIdRegistered = "controller1";
@@ -316,8 +315,8 @@
}
/**
- * Test if getAllSwitches() returns correct list of all switches.
- * Switches are injected in setPathChildrenCache() function.
+ * Test if {@link ZookeeperRegistry#getAllSwitches()} returns correct list of all switches.
+ * Switches are injected in {@link ZookeeperRegistryTest#setPathChildrenCache()} function.
* @throws Exception
*/
@Test
@@ -339,7 +338,7 @@
}
/**
- * Test if allocateUniqueIdBlock() can assign IdBlock without duplication.
+ * Test if {@link ZookeeperRegistry#allocateUniqueIdBlock()} can assign IdBlock without duplication.
*/
@Test
public void testAllocateUniqueIdBlock() {
@@ -374,20 +373,21 @@
}
}
+
+ //-------------------------- Creation of mock objects --------------------------
/**
- * Create mock CuratorFramework object with initial value below.
- * [Ctrl ID] : [DPID]
- * controller1 : 1000
- * controller2 : 1001
- * controller2 : 1002
+ * Create mock {@link CuratorFramework} object with initial value below.<br>
+ * [Ctrl ID] : [DPID]<br>
+ * controller1 : 1000<br>
+ * controller2 : 1001<br>
+ * controller2 : 1002<br>
* controller2013 : nothing
* @return Created mock object
* @throws Exception
*/
- @SuppressWarnings("serial")
+ @SuppressWarnings({ "serial", "unchecked" })
private CuratorFramework createCuratorFrameworkMock() throws Exception {
// Mock of AtomicValue
- @SuppressWarnings("unchecked")
AtomicValue<Long> atomicValue = EasyMock.createMock(AtomicValue.class);
EasyMock.expect(atomicValue.succeeded()).andReturn(true).anyTimes();
EasyMock.expect(atomicValue.preValue()).andAnswer(new IAnswer<Long>() {
@@ -408,7 +408,7 @@
}).anyTimes();
EasyMock.replay(atomicValue);
- // Mock of DistributedAtomicLong
+ // Mock DistributedAtomicLong
DistributedAtomicLong daLong = EasyMock.createMock(DistributedAtomicLong.class);
EasyMock.expect(daLong.add(EasyMock.anyLong())).andReturn(atomicValue).anyTimes();
EasyMock.replay(daLong);
@@ -418,8 +418,7 @@
andReturn(daLong).anyTimes();
PowerMock.replay(DistributedAtomicLong.class);
- // Mock of ListenerContainer
- @SuppressWarnings("unchecked")
+ // Mock ListenerContainer
ListenerContainer<PathChildrenCacheListener> listenerContainer = EasyMock.createMock(ListenerContainer.class);
listenerContainer.addListener(EasyMock.anyObject(PathChildrenCacheListener.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@@ -431,13 +430,13 @@
}).once();
EasyMock.replay(listenerContainer);
- // Mock of PathChildrenCache
+ // Mock PathChildrenCache
PathChildrenCache pathChildrenCacheMain = createPathChildrenCacheMock(CONTROLLER_ID, new String[] {"/switches"}, listenerContainer);
PathChildrenCache pathChildrenCache1 = createPathChildrenCacheMock("controller1", new String[] {HexString.toHexString(1000L)}, listenerContainer);
PathChildrenCache pathChildrenCache2 = createPathChildrenCacheMock("controller2", new String[] {
HexString.toHexString(1001L), HexString.toHexString(1002L) },listenerContainer);
- // Mock of PathChildrenCache constructor
+ // Mock PathChildrenCache constructor
PowerMock.expectNew(PathChildrenCache.class,
EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyBoolean()).
andReturn(pathChildrenCacheMain).once();
@@ -449,8 +448,7 @@
andReturn(pathChildrenCache2).anyTimes();
PowerMock.replay(PathChildrenCache.class);
- // Mock of ServiceCache
- @SuppressWarnings("unchecked")
+ // Mock ServiceCache
ServiceCache<ControllerService> serviceCache = EasyMock.createMock(ServiceCache.class);
serviceCache.start();
EasyMock.expectLastCall().once();
@@ -460,15 +458,13 @@
}}).anyTimes();
EasyMock.replay(serviceCache);
- // Mock of ServiceCacheBuilder
- @SuppressWarnings("unchecked")
+ // Mock ServiceCacheBuilder
ServiceCacheBuilder<ControllerService> serviceCacheBuilder = EasyMock.createMock(ServiceCacheBuilder.class);
EasyMock.expect(serviceCacheBuilder.name(EasyMock.anyObject(String.class))).andReturn(serviceCacheBuilder).once();
EasyMock.expect(serviceCacheBuilder.build()).andReturn(serviceCache).once();
EasyMock.replay(serviceCacheBuilder);
- // Mock of ServiceDiscovery
- @SuppressWarnings("unchecked")
+ // Mock ServiceDiscovery
ServiceDiscovery<ControllerService> serviceDiscovery = EasyMock.createMock(ServiceDiscovery.class);
serviceDiscovery.start();
EasyMock.expectLastCall().once();
@@ -477,15 +473,14 @@
EasyMock.expectLastCall().once();
EasyMock.replay(serviceDiscovery);
- // Mock of CuratorFramework
+ // Mock CuratorFramework
CuratorFramework client = EasyMock.createMock(CuratorFramework.class);
client.start();
EasyMock.expectLastCall().once();
EasyMock.expect(client.usingNamespace(EasyMock.anyObject(String.class))).andReturn(client);
EasyMock.replay(client);
- // Mock of ServiceDiscoveryBuilder
- @SuppressWarnings("unchecked")
+ // Mock ServiceDiscoveryBuilder
ServiceDiscoveryBuilder<ControllerService> builder = EasyMock.createMock(ServiceDiscoveryBuilder.class);
EasyMock.expect(builder.client(client)).andReturn(builder).once();
EasyMock.expect(builder.basePath(EasyMock.anyObject(String.class))).andReturn(builder);
@@ -500,9 +495,9 @@
}
/**
- * Create mock ServiceInstance object using given controller ID.
- * @param controllerId Controller ID to represent instance's payload (ControllerSeervice).
- * @return
+ * Create mock {@link ServiceInstance} object using given controller ID.
+ * @param controllerId Controller ID to represent instance's payload (ControllerService).
+ * @return Mock ServiceInstance object
*/
private ServiceInstance<ControllerService> createServiceInstanceMock(String controllerId) {
ControllerService controllerService = EasyMock.createMock(ControllerService.class);
@@ -518,11 +513,11 @@
}
/**
- * Create mock PathChildrenCache using given controller ID and DPIDs.
+ * Create mock {@link PathChildrenCache} using given controller ID and DPIDs.
* @param controllerId Controller ID to represent current data.
* @param paths List of HexString indicating switch's DPID.
* @param listener Callback object to be set as Listenable.
- * @return
+ * @return Mock PathChildrenCache object
* @throws Exception
*/
private PathChildrenCache createPathChildrenCacheMock(final String controllerId, final String [] paths,
@@ -549,11 +544,11 @@
}
/**
- * Create mock ChildData for {@link PathChildrenCache#getCurrentData()} return value.
+ * Create mock {@link ChildData} for {@link PathChildrenCache#getCurrentData()} return value.
* This object need to include 'sequence number' in tail of path string. ("-0" means 0th sequence)
* @param controllerId Controller ID
* @param path HexString indicating switch's DPID
- * @return
+ * @return Mock ChildData object
*/
private ChildData createChildDataMockForCurrentData(String controllerId, String path) {
ChildData data = EasyMock.createMock(ChildData.class);
@@ -570,21 +565,21 @@
*/
private void setPathChildrenCache() throws Exception {
pathChildrenCacheListener.childEvent(client,
- createChildDataEventMock("controller1", HexString.toHexString(1000L), PathChildrenCacheEvent.Type.CHILD_ADDED));
+ createChildrenCacheEventMock("controller1", HexString.toHexString(1000L), PathChildrenCacheEvent.Type.CHILD_ADDED));
pathChildrenCacheListener.childEvent(client,
- createChildDataEventMock("controller2", HexString.toHexString(1001L), PathChildrenCacheEvent.Type.CHILD_ADDED));
+ createChildrenCacheEventMock("controller2", HexString.toHexString(1001L), PathChildrenCacheEvent.Type.CHILD_ADDED));
pathChildrenCacheListener.childEvent(client,
- createChildDataEventMock("controller2", HexString.toHexString(1002L), PathChildrenCacheEvent.Type.CHILD_ADDED));
+ createChildrenCacheEventMock("controller2", HexString.toHexString(1002L), PathChildrenCacheEvent.Type.CHILD_ADDED));
}
/**
- * Create mock ChildDataEvent object using given controller ID and DPID.
+ * Create mock {@link PathChildrenCacheEvent} object using given controller ID and DPID.
* @param controllerId Controller ID.
* @param path HexString of DPID.
* @param type Event type to be set to mock object.
- * @return
+ * @return Mock PathChildrenCacheEvent object
*/
- private PathChildrenCacheEvent createChildDataEventMock(String controllerId, String path,
+ private PathChildrenCacheEvent createChildrenCacheEventMock(String controllerId, String path,
PathChildrenCacheEvent.Type type) {
PathChildrenCacheEvent event = EasyMock.createMock(PathChildrenCacheEvent.class);
ChildData data = EasyMock.createMock(ChildData.class);