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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cluster; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.List; |
| 19 | |
| 20 | import org.junit.Test; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 21 | |
| 22 | import com.google.common.collect.Lists; |
| 23 | |
| 24 | import static org.junit.Assert.assertEquals; |
| 25 | import static org.junit.Assert.assertNotEquals; |
| 26 | |
| 27 | /** |
| 28 | * Test to check behavioral correctness of the RoleInfo structure. |
| 29 | */ |
| 30 | public class RoleInfoTest { |
| 31 | private static final NodeId N1 = new NodeId("n1"); |
| 32 | private static final NodeId N2 = new NodeId("n2"); |
| 33 | private static final NodeId N3 = new NodeId("n3"); |
| 34 | private static final NodeId N4 = new NodeId("n4"); |
| 35 | |
| 36 | private static final List<NodeId> BKUP1 = Lists.newArrayList(N2, N3); |
| 37 | private static final List<NodeId> BKUP2 = Lists.newArrayList(N3, N4); |
| 38 | |
| 39 | private static final RoleInfo RI1 = new RoleInfo(N1, BKUP1); |
| 40 | private static final RoleInfo RI2 = new RoleInfo(N1, BKUP2); |
| 41 | private static final RoleInfo RI3 = new RoleInfo(N2, BKUP1); |
| 42 | |
| 43 | @Test |
| 44 | public void basics() { |
| 45 | assertEquals("wrong master", new NodeId("n1"), RI1.master()); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 46 | assertEquals("wrong Backups", RI1.backups(), Lists.newArrayList(N2, N3)); |
| 47 | |
| 48 | assertNotEquals("equals() broken", RI1, RI2); |
| 49 | assertNotEquals("equals() broken", RI1, RI3); |
| 50 | |
| 51 | List<NodeId> bkup3 = Lists.newArrayList(N3, new NodeId("n4")); |
| 52 | assertEquals("equals() broken", new RoleInfo(N1, bkup3), RI2); |
| 53 | } |
| 54 | } |