blob: 0aec80a9239c78f60c0210240cfd6966641e13d2 [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;
25
26import static org.hamcrest.Matchers.is;
27import static org.junit.Assert.assertThat;
28
29/**
30 * Unit tests for the mastership event.
31 */
32public class PartitionEventTest {
33 private final long time = System.currentTimeMillis();
34 private final long time0 = 0;
35
36 private final PartitionId pid1 = PartitionId.from(1);
37 private final PartitionId pid2 = PartitionId.from(2);
38
39 private final NodeId nid1 = NodeId.nodeId("10.0.0.1");
40 private final NodeId nid2 = NodeId.nodeId("10.0.0.2");
41
42
43 private final Partition p1 =
Jordan Halterman00e92da2018-05-22 23:05:52 -070044 new DefaultPartition(pid1, ImmutableSet.of(nid1));
Jon Hallf074af92017-04-05 15:10:46 -070045 private final Partition p2 =
Jordan Halterman00e92da2018-05-22 23:05:52 -070046 new DefaultPartition(pid2, ImmutableSet.of(nid1, nid2));
Jon Hallf074af92017-04-05 15:10:46 -070047
48 private final PartitionEvent event1 =
49 new PartitionEvent(PartitionEvent.Type.UPDATED, p1, time);
50 private final PartitionEvent sameAsEvent1 =
51 new PartitionEvent(PartitionEvent.Type.UPDATED, p1, time);
52 private final PartitionEvent event2 =
53 new PartitionEvent(PartitionEvent.Type.OPENED, p1, time);
54 private final PartitionEvent event3 =
55 new PartitionEvent(PartitionEvent.Type.CLOSED, p1, time);
56 private final PartitionEvent event4 =
57 new PartitionEvent(PartitionEvent.Type.AVAILABLE, p1, time);
58 private final PartitionEvent event5 =
59 new PartitionEvent(PartitionEvent.Type.UNAVAILABLE, p1, time);
60 private final PartitionEvent event6 =
61 new PartitionEvent(PartitionEvent.Type.UPDATED, p2, time);
62 private final PartitionEvent event7 =
63 new PartitionEvent(PartitionEvent.Type.UPDATED, p1, time0);
64
65 /**
66 * Tests for proper operation of equals(), hashCode() and toString() methods.
67 */
68 @Test
69 public void checkEquals() {
70 new EqualsTester()
71 .addEqualityGroup(event1, sameAsEvent1)
72 .addEqualityGroup(event2)
73 .addEqualityGroup(event3)
74 .addEqualityGroup(event4)
75 .addEqualityGroup(event5)
76 .addEqualityGroup(event6)
77 .addEqualityGroup(event7)
78 .testEquals();
79 }
80
81 /**
82 * Tests that objects are created properly.
83 */
84 @Test
85 public void checkConstruction() {
86 assertThat(event1.type(), is(PartitionEvent.Type.UPDATED));
87 assertThat(event1.subject(), is(p1));
88 assertThat(event1.time(), is(time));
89 }
90
91}