@Test
public void testRollIndex() throws Exception {
// Create group and nodes
ClusterGroup clusterGroup = clusterManagementService.createGroup("Test group");
Assert.assertNotNull(clusterGroup);
Assert.assertEquals(0, clusterGroup.getRollingIndex());
ClusterNode clusterNode1 = clusterManagementService.createNode(clusterGroup.getId(),
"10.2.0.1", "Node 1", true);
Assert.assertNotNull(clusterNode1);
ClusterNode clusterNode2 = clusterManagementService.createNode(clusterGroup.getId(),
"10.2.0.2", "Node 2", true);
Assert.assertNotNull(clusterNode2);
ClusterNode clusterNode3 = clusterManagementService.createNode(clusterGroup.getId(),
"10.2.0.3", "Node 3", false);
Assert.assertNotNull(clusterNode3);
ClusterNode clusterNode4 = clusterManagementService.createNode(clusterGroup.getId(),
"10.2.0.4", "Node 4", true);
Assert.assertNotNull(clusterNode4);
ClusterNode clusterNode5 = clusterManagementService.createNode(clusterGroup.getId(),
"10.2.0.5", "Node 5", false);
Assert.assertNotNull(clusterNode5);
// Roll index
int index;
index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
Assert.assertEquals(1, index);
index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
Assert.assertEquals(3, index);
index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
Assert.assertEquals(0, index);
index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
Assert.assertEquals(1, index);
// Toggle nodes and roll
clusterManagementService.modifyNode(clusterNode3.getId(), "10.2.0.3", "Node 3", true);
clusterManagementService.modifyNode(clusterNode4.getId(), "10.2.0.4", "Node 4", false);
index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
Assert.assertEquals(2, index);
index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
Assert.assertEquals(0, index);
}