blob: c692b87ad6f899b121ca717c9fa420dd824b4a15 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 Koshibeabedb092014-10-20 17:01:31 -070016package org.onlab.onos.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;
23
24import static org.junit.Assert.assertEquals;
25import static org.junit.Assert.assertNotEquals;
26
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);
42
43 @Test
44 public void basics() {
45 assertEquals("wrong master", new NodeId("n1"), RI1.master());
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070046 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}