Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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; |
Ayaka Koshibe | a48f752 | 2015-04-01 17:06:09 -0700 | [diff] [blame] | 23 | import com.google.common.testing.EqualsTester; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 24 | |
| 25 | import static org.junit.Assert.assertEquals; |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 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); |
Ayaka Koshibe | a48f752 | 2015-04-01 17:06:09 -0700 | [diff] [blame] | 42 | private static final RoleInfo RI4 = new RoleInfo(null, BKUP2); |
| 43 | |
| 44 | @Test |
| 45 | public void testEquality() { |
| 46 | new EqualsTester() |
| 47 | .addEqualityGroup(RI1, new RoleInfo(new NodeId("n1"), Lists.newArrayList(N2, N3))) |
| 48 | .addEqualityGroup(RI3); |
| 49 | } |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 50 | |
| 51 | @Test |
| 52 | public void basics() { |
| 53 | assertEquals("wrong master", new NodeId("n1"), RI1.master()); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 54 | assertEquals("wrong Backups", RI1.backups(), Lists.newArrayList(N2, N3)); |
Ayaka Koshibe | a48f752 | 2015-04-01 17:06:09 -0700 | [diff] [blame] | 55 | assertEquals("wrong empty master", RI4.master(), null); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 56 | |
| 57 | List<NodeId> bkup3 = Lists.newArrayList(N3, new NodeId("n4")); |
| 58 | assertEquals("equals() broken", new RoleInfo(N1, bkup3), RI2); |
| 59 | } |
| 60 | } |