Use java.util.Optional in ShardLeaderStateChanged and PrimaryShardInfo
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / PrimaryShardInfoFutureCacheTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.utils;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.mock;
13 import akka.actor.ActorSelection;
14 import org.junit.Test;
15 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
16 import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
17 import scala.concurrent.Future;
18
19 /**
20  * Unit tests for PrimaryShardInfoFutureCache.
21  *
22  * @author Thomas Pantelis
23  */
24 public class PrimaryShardInfoFutureCacheTest {
25
26     @Test
27     public void testOperations() {
28         PrimaryShardInfoFutureCache cache = new PrimaryShardInfoFutureCache();
29
30         assertEquals("getIfPresent", null, cache.getIfPresent("foo"));
31
32         PrimaryShardInfo shardInfo = new PrimaryShardInfo(mock(ActorSelection.class), DataStoreVersions.CURRENT_VERSION);
33         cache.putSuccessful("foo", shardInfo);
34
35         Future<PrimaryShardInfo> future = cache.getIfPresent("foo");
36         assertNotNull("Null future", future);
37         assertEquals("getIfPresent", shardInfo, future.value().get().get());
38
39         cache.remove("foo");
40
41         assertEquals("getIfPresent", null, cache.getIfPresent("foo"));
42     }
43 }