blob: abcc659266d083a94764ffe84b87668014d2654d [file] [log] [blame]
Jon Hallf074af92017-04-05 15:10:46 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jon Hallf074af92017-04-05 15:10:46 -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 */
16package org.onosproject.store.primitives;
17
18import com.google.common.collect.ImmutableSet;
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21import org.onosproject.cluster.DefaultPartition;
22import org.onosproject.cluster.NodeId;
23import org.onosproject.cluster.Partition;
24import org.onosproject.cluster.PartitionId;
Jordan Halterman07f052b2017-10-08 14:22:41 -070025import org.onosproject.core.Version;
Jon Hallf074af92017-04-05 15:10:46 -070026
27import static org.hamcrest.Matchers.is;
28import static org.junit.Assert.assertThat;
29
30/**
31 * Unit tests for the mastership event.
32 */
33public class PartitionEventTest {
34 private final long time = System.currentTimeMillis();
35 private final long time0 = 0;
36
37 private final PartitionId pid1 = PartitionId.from(1);
38 private final PartitionId pid2 = PartitionId.from(2);
39
40 private final NodeId nid1 = NodeId.nodeId("10.0.0.1");
41 private final NodeId nid2 = NodeId.nodeId("10.0.0.2");
42
43
44 private final Partition p1 =
Jordan Halterman07f052b2017-10-08 14:22:41 -070045 new DefaultPartition(pid1, Version.version("1.0.0"), ImmutableSet.of(nid1));
Jon Hallf074af92017-04-05 15:10:46 -070046 private final Partition p2 =
Jordan Halterman07f052b2017-10-08 14:22:41 -070047 new DefaultPartition(pid2, Version.version("1.0.0"), ImmutableSet.of(nid1, nid2));
Jon Hallf074af92017-04-05 15:10:46 -070048
49 private final PartitionEvent event1 =
50 new PartitionEvent(PartitionEvent.Type.UPDATED, p1, time);
51 private final PartitionEvent sameAsEvent1 =
52 new PartitionEvent(PartitionEvent.Type.UPDATED, p1, time);
53 private final PartitionEvent event2 =
54 new PartitionEvent(PartitionEvent.Type.OPENED, p1, time);
55 private final PartitionEvent event3 =
56 new PartitionEvent(PartitionEvent.Type.CLOSED, p1, time);
57 private final PartitionEvent event4 =
58 new PartitionEvent(PartitionEvent.Type.AVAILABLE, p1, time);
59 private final PartitionEvent event5 =
60 new PartitionEvent(PartitionEvent.Type.UNAVAILABLE, p1, time);
61 private final PartitionEvent event6 =
62 new PartitionEvent(PartitionEvent.Type.UPDATED, p2, time);
63 private final PartitionEvent event7 =
64 new PartitionEvent(PartitionEvent.Type.UPDATED, p1, time0);
65
66 /**
67 * Tests for proper operation of equals(), hashCode() and toString() methods.
68 */
69 @Test
70 public void checkEquals() {
71 new EqualsTester()
72 .addEqualityGroup(event1, sameAsEvent1)
73 .addEqualityGroup(event2)
74 .addEqualityGroup(event3)
75 .addEqualityGroup(event4)
76 .addEqualityGroup(event5)
77 .addEqualityGroup(event6)
78 .addEqualityGroup(event7)
79 .testEquals();
80 }
81
82 /**
83 * Tests that objects are created properly.
84 */
85 @Test
86 public void checkConstruction() {
87 assertThat(event1.type(), is(PartitionEvent.Type.UPDATED));
88 assertThat(event1.subject(), is(p1));
89 assertThat(event1.time(), is(time));
90 }
91
92}