blob: 7c270c7feef0c6e65b021bc7f1f1464591e40666 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cluster;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070017
18import java.util.List;
19
20import org.junit.Test;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070021
22import com.google.common.collect.Lists;
Ayaka Koshibea48f7522015-04-01 17:06:09 -070023import com.google.common.testing.EqualsTester;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070024
25import static org.junit.Assert.assertEquals;
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070026
27/**
28 * Test to check behavioral correctness of the RoleInfo structure.
29 */
30public 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 Koshibea48f7522015-04-01 17:06:09 -070042 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 Koshibe67af1f42014-10-20 15:26:37 -070050
51 @Test
52 public void basics() {
53 assertEquals("wrong master", new NodeId("n1"), RI1.master());
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070054 assertEquals("wrong Backups", RI1.backups(), Lists.newArrayList(N2, N3));
Ayaka Koshibea48f7522015-04-01 17:06:09 -070055 assertEquals("wrong empty master", RI4.master(), null);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070056
57 List<NodeId> bkup3 = Lists.newArrayList(N3, new NodeId("n4"));
58 assertEquals("equals() broken", new RoleInfo(N1, bkup3), RI2);
59 }
60}