blob: e5a3dea36dd51f42056e89eb838282ed76ad21b9 [file] [log] [blame]
Sho SHIMIZU5d62ba82014-08-21 10:23:47 -07001package net.onrc.onos.core.newintent;
2
3import com.hazelcast.core.EntryEvent;
4import com.hazelcast.core.EntryListener;
5import net.onrc.onos.api.newintent.Intent;
6import net.onrc.onos.api.newintent.IntentId;
7import net.onrc.onos.core.datastore.hazelcast.DummySharedCollectionsService;
8import org.junit.After;
9import org.junit.Before;
10import org.junit.Test;
11
12import java.util.concurrent.CountDownLatch;
13
14/**
15 * Suites of test of {@link IntentMap}.
16 */
17public class IntentMapTest {
18
19 private final IntentId id1 = new IntentId(1);
20 private DummySharedCollectionsService service;
21 private IntentMap<Intent> sut;
22
23 @Before
24 public void setUp() {
25 service = new DummySharedCollectionsService();
26 sut = new IntentMap<>("test", Intent.class, service);
27 }
28
29 @After
30 public void tearDown() {
31 sut.destroy();
32 }
33
34 /**
35 * Tests if listener is invoked when add/remove/update occurs.
36 *
37 * @throws InterruptedException if interrupt occurs
38 */
39 @Test(timeout = 1000)
40 public void testListener() throws InterruptedException {
41 final CountDownLatch latch = new CountDownLatch(3);
42
43 sut.addListener(new EntryListener<IntentId, Intent>() {
44 @Override
45 public void entryAdded(EntryEvent<IntentId, Intent> event) {
46 latch.countDown();
47 }
48
49 @Override
50 public void entryRemoved(EntryEvent<IntentId, Intent> event) {
51 latch.countDown();
52 }
53
54 @Override
55 public void entryUpdated(EntryEvent<IntentId, Intent> event) {
56 latch.countDown();
57 }
58
59 @Override
60 public void entryEvicted(EntryEvent<IntentId, Intent> event) {
61 }
62 });
63
64 sut.put(id1, new TestIntent(id1));
65 sut.put(id1, new TestIntent(id1));
66 sut.remove(id1);
67
68 latch.await();
69 }
70}