Bug 3194: Dynamically update PrimaryShardInfo cache when leader changes
[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 com.google.common.base.Optional;
15 import org.junit.Test;
16 import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
18 import scala.concurrent.Future;
19
20 /**
21  * Unit tests for PrimaryShardInfoFutureCache.
22  *
23  * @author Thomas Pantelis
24  */
25 public class PrimaryShardInfoFutureCacheTest {
26
27     @Test
28     public void testOperations() {
29         PrimaryShardInfoFutureCache cache = new PrimaryShardInfoFutureCache();
30
31         assertEquals("getIfPresent", null, cache.getIfPresent("foo"));
32
33         PrimaryShardInfo shardInfo = new PrimaryShardInfo(mock(ActorSelection.class), Optional.<DataTree>absent());
34         cache.putSuccessful("foo", shardInfo);
35
36         Future<PrimaryShardInfo> future = cache.getIfPresent("foo");
37         assertNotNull("Null future", future);
38         assertEquals("getIfPresent", shardInfo, future.value().get().get());
39
40         cache.remove("foo");
41
42         assertEquals("getIfPresent", null, cache.getIfPresent("foo"));
43     }
44 }