2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorRef;
12 import akka.actor.Status.Success;
13 import akka.testkit.JavaTestKit;
14 import java.util.Collections;
15 import java.util.concurrent.TimeUnit;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.datastore.Shard.Builder;
18 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
19 import org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider;
20 import org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration;
21 import org.opendaylight.controller.cluster.datastore.messages.CreatePrefixedShard;
22 import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard;
23 import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound;
24 import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound;
25 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
26 import org.opendaylight.controller.cluster.datastore.shardstrategy.PrefixShardStrategy;
27 import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
28 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
29 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
30 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Tests prefix shard creation in ShardManager.
38 public class PrefixShardCreationTest extends AbstractShardManagerTest {
40 private static final Logger LOG = LoggerFactory.getLogger(PrefixShardCreationTest.class);
42 private static final DOMDataTreeIdentifier TEST_ID =
43 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
46 public void testPrefixShardCreation() throws Exception {
48 LOG.info("testPrefixShardCreation starting");
49 new JavaTestKit(getSystem()) {
51 datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
53 final ActorRef shardManager = actorFactory.createActor(newShardMgrProps(
54 new ConfigurationImpl(new EmptyModuleShardConfigProvider())));
56 final SchemaContext schemaContext = TestModel.createTestContext();
57 shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
59 shardManager.tell(new FindLocalShard(
60 ClusterUtils.getCleanShardName(TestModel.TEST_PATH), true), getRef());
61 expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
63 final Builder builder = Shard.builder();
65 final CreatePrefixedShard createPrefixedShard = new CreatePrefixedShard(
66 new PrefixShardConfiguration(TEST_ID,
67 PrefixShardStrategy.NAME,
68 Collections.singletonList(MEMBER_1)),
69 datastoreContextBuilder.build(), builder);
71 shardManager.tell(createPrefixedShard, getRef());
72 expectMsgClass(duration("5 seconds"), Success.class);
74 shardManager.tell(new FindLocalShard(
75 ClusterUtils.getCleanShardName(TestModel.TEST_PATH), true), getRef());
76 expectMsgClass(duration("5 seconds"), LocalShardFound.class);