Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Ayaka Koshibe | e8e4535 | 2014-10-16 00:37:19 -0700 | [diff] [blame] | 16 | package org.onlab.onos.store.mastership.impl; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.junit.Assert.assertTrue; |
| 20 | import static org.onlab.onos.net.MastershipRole.*; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.onos.cluster.NodeId; |
| 24 | |
| 25 | import com.google.common.collect.Sets; |
| 26 | |
| 27 | public class RoleValueTest { |
| 28 | |
| 29 | private static final RoleValue RV = new RoleValue(); |
| 30 | |
| 31 | private static final NodeId NID1 = new NodeId("node1"); |
| 32 | private static final NodeId NID2 = new NodeId("node2"); |
| 33 | private static final NodeId NID3 = new NodeId("node3"); |
| 34 | |
| 35 | @Test |
| 36 | public void add() { |
| 37 | assertEquals("faulty initialization: ", 3, RV.value.size()); |
| 38 | RV.add(MASTER, NID1); |
| 39 | RV.add(STANDBY, NID2); |
| 40 | RV.add(STANDBY, NID3); |
| 41 | |
| 42 | assertEquals("wrong nodeID: ", NID1, RV.get(MASTER)); |
| 43 | assertTrue("wrong nodeIDs: ", |
| 44 | Sets.newHashSet(NID3, NID2).containsAll(RV.nodesOfRole(STANDBY))); |
| 45 | } |
| 46 | } |