import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityTypeEntryWithEntityEntry;
import akka.actor.ActorRef;
-import com.google.common.base.Optional;
import com.google.common.collect.Sets;
import java.util.Collection;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import scala.concurrent.Await;
import scala.concurrent.Future;
-import scala.concurrent.duration.Duration;
+import scala.concurrent.duration.FiniteDuration;
/**
* Unit tests for DistributedEntityOwnershipService.
*
* @author Thomas Pantelis
*/
-public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnershipTest {
+public class DistributedEntityOwnershipServiceTest extends AbstractClusterRefEntityOwnershipTest {
static final String ENTITY_TYPE = "test";
static final String ENTITY_TYPE2 = "test2";
static final QName QNAME = QName.create("test", "2015-08-11", "foo");
@Test
public void testEntityOwnershipShardCreated() throws Exception {
- DistributedEntityOwnershipService service = DistributedEntityOwnershipService.start(dataStore.getActorContext(),
+ DistributedEntityOwnershipService service = DistributedEntityOwnershipService.start(dataStore.getActorUtils(),
EntityOwnerSelectionStrategyConfig.newBuilder().build());
- Future<ActorRef> future = dataStore.getActorContext().findLocalShardAsync(
+ Future<ActorRef> future = dataStore.getActorUtils().findLocalShardAsync(
DistributedEntityOwnershipService.ENTITY_OWNERSHIP_SHARD_NAME);
- ActorRef shardActor = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
+ ActorRef shardActor = Await.result(future, FiniteDuration.create(10, TimeUnit.SECONDS));
assertNotNull(DistributedEntityOwnershipService.ENTITY_OWNERSHIP_SHARD_NAME + " not found", shardActor);
service.close();
@Test
public void testRegisterCandidate() throws Exception {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(
- dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
+ dataStore.getActorUtils(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
YangInstanceIdentifier entityId = YangInstanceIdentifier.of(QNAME);
DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
verifyRegisterCandidateLocal(service, entity);
verifyEntityOwnershipCandidateRegistration(entity, reg);
verifyEntityCandidate(service.getLocalEntityOwnershipShard(), ENTITY_TYPE, entityId,
- dataStore.getActorContext().getCurrentMemberName().getName());
+ dataStore.getActorUtils().getCurrentMemberName().getName());
// Register the same entity - should throw exception
verifyEntityOwnershipCandidateRegistration(entity2, reg2);
verifyEntityCandidate(service.getLocalEntityOwnershipShard(), ENTITY_TYPE2, entityId,
- dataStore.getActorContext().getCurrentMemberName().getName());
+ dataStore.getActorUtils().getCurrentMemberName().getName());
service.close();
}
@Test
public void testCloseCandidateRegistration() throws Exception {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(
- dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
+ dataStore.getActorUtils(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
DOMEntity entity = new DOMEntity(ENTITY_TYPE, YangInstanceIdentifier.of(QNAME));
@Test
public void testListenerRegistration() {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(
- dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
+ dataStore.getActorUtils(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
YangInstanceIdentifier entityId = YangInstanceIdentifier.of(QNAME);
DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
@Test
public void testGetOwnershipState() throws Exception {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(
- dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
+ dataStore.getActorUtils(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
final Shard mockShard = Mockito.mock(Shard.class);
ShardDataTree shardDataTree = new ShardDataTree(mockShard, SchemaContextHelper.entityOwners(),
DOMEntity entity2 = new DOMEntity(ENTITY_TYPE, "two");
Optional<EntityOwnershipState> state = service.getOwnershipState(entity2);
- assertEquals("getOwnershipState present", false, state.isPresent());
+ assertFalse("getOwnershipState present", state.isPresent());
writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity2.getIdentifier(), "member-1"),
shardDataTree);
deleteNode(candidatePath(entityPath(entity2.getType(), entity2.getIdentifier()), "member-1"), shardDataTree);
Optional<EntityOwnershipState> state2 = service.getOwnershipState(entity2);
- assertEquals("getOwnershipState present", false, state2.isPresent());
+ assertFalse("getOwnershipState present", state2.isPresent());
service.close();
}
@Test
public void testIsCandidateRegistered() throws CandidateAlreadyRegisteredException {
- DistributedEntityOwnershipService service = DistributedEntityOwnershipService.start(dataStore.getActorContext(),
+ DistributedEntityOwnershipService service = DistributedEntityOwnershipService.start(dataStore.getActorUtils(),
EntityOwnerSelectionStrategyConfig.newBuilder().build());
final DOMEntity test = new DOMEntity("test-type", "test");
private static void verifyGetOwnershipState(final DistributedEntityOwnershipService service, final DOMEntity entity,
final EntityOwnershipState expState) {
Optional<EntityOwnershipState> state = service.getOwnershipState(entity);
- assertEquals("getOwnershipState present", true, state.isPresent());
+ assertTrue("getOwnershipState present", state.isPresent());
assertEquals("EntityOwnershipState", expState, state.get());
}